Commit 93137cbd authored by Mike Baxley's avatar Mike Baxley Committed by Commit Bot

Add EarlGrey test to verify NTP tiles on a redirect URL.

Test verifies that only one tile is present.

Bug: 741329
Change-Id: I30bb1d7f1f0a5af13ccb2d364d97fe3d67ae6d88
Reviewed-on: https://chromium-review.googlesource.com/568025
Commit-Queue: Mike Baxley <baxley@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485954}
parent b1d969fc
......@@ -11,6 +11,8 @@
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/wait_util.h"
#import "ios/web/public/test/http_server/html_response_provider.h"
#import "ios/web/public/test/http_server/html_response_provider_impl.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
......@@ -18,12 +20,19 @@
#error "This file requires ARC support."
#endif
using web::test::HttpServer;
// Test case for NTP tiles.
@interface NTPTilesTest : ChromeTestCase
@end
@implementation NTPTilesTest
- (void)tearDown {
chrome_test_util::ClearBrowsingHistory();
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
// Tests that loading a URL ends up creating an NTP tile.
- (void)testTopSitesTileAfterLoadURL {
std::map<GURL, std::string> responses;
......@@ -54,4 +63,55 @@
assertWithMatcher:grey_notNil()];
}
// Tests that only one NTP tile is displayed for a TopSite that involves a
// redirect.
- (void)testTopSitesTileAfterRedirect {
std::map<GURL, HtmlResponseProviderImpl::Response> responses;
const GURL firstRedirectURL = HttpServer::MakeUrl("http://firstRedirect/");
const GURL destinationURL = HttpServer::MakeUrl("http://destination/");
responses[firstRedirectURL] = HtmlResponseProviderImpl::GetRedirectResponse(
destinationURL, net::HTTP_MOVED_PERMANENTLY);
// Add titles to both responses, which is what will show up on the NTP.
responses[firstRedirectURL].body =
"<head><title>title1</title></head>"
"<body>Should redirect away.</body>";
const char kFinalPageContent[] =
"<head><title>title2</title></head>"
"<body>redirect complete</body>";
responses[destinationURL] =
HtmlResponseProviderImpl::GetSimpleResponse(kFinalPageContent);
std::unique_ptr<web::DataResponseProvider> provider(
new HtmlResponseProvider(responses));
web::test::SetUpHttpServer(std::move(provider));
// Clear history and verify that the tile does not exist.
chrome_test_util::ClearBrowsingHistory();
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
chrome_test_util::OpenNewTab();
[[EarlGrey selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabel(@"title2")]
assertWithMatcher:grey_nil()];
// Load first URL and expect redirect to destination URL.
[ChromeEarlGrey loadURL:firstRedirectURL];
[ChromeEarlGrey waitForWebViewContainingText:"redirect complete"];
// After loading URL, need to do another action before opening a new tab
// with the icon present.
[ChromeEarlGrey goBack];
chrome_test_util::OpenNewTab();
// Which of the two tiles that is displayed is an implementation detail, and
// this test helps document it. The purpose of the test is to verify that only
// one tile is displayed.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabel(@"title2")]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabel(@"title1")]
assertWithMatcher:grey_nil()];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment