| Index: ios/chrome/browser/web/navigation_egtest.mm
|
| diff --git a/ios/chrome/browser/web/navigation_egtest.mm b/ios/chrome/browser/web/navigation_egtest.mm
|
| index f73b4ae952102a23bd1792e65b108e0f286830bb..97968b13ce31746e8ce23c521d55eb090dff44a3 100644
|
| --- a/ios/chrome/browser/web/navigation_egtest.mm
|
| +++ b/ios/chrome/browser/web/navigation_egtest.mm
|
| @@ -5,6 +5,7 @@
|
| #import <XCTest/XCTest.h>
|
|
|
| #include "base/ios/ios_util.h"
|
| +#include "base/strings/sys_string_conversions.h"
|
| #include "components/strings/grit/components_strings.h"
|
| #include "ios/chrome/test/app/web_view_interaction_test_util.h"
|
| #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
|
| @@ -18,7 +19,6 @@
|
| using chrome_test_util::BackButton;
|
| using chrome_test_util::ForwardButton;
|
| using chrome_test_util::TapWebViewElementWithId;
|
| -using chrome_test_util::WebViewContainingText;
|
|
|
| namespace {
|
|
|
| @@ -44,8 +44,8 @@ const char kSampleFileBasedURL[] =
|
| "http://ios/testing/data/http_server_files/chromium_logo_page.html";
|
|
|
| // Strings used by history_go.html.
|
| -const char kOnLoadText[] = "OnLoadText";
|
| -const char kNoOpText[] = "NoOpText";
|
| +NSString* const kOnLoadText = @"OnLoadText";
|
| +NSString* const kNoOpText = @"NoOpText";
|
|
|
| // Button ids for history_go.html.
|
| NSString* const kGoNoParameterID = @"go-no-parameter";
|
| @@ -56,11 +56,11 @@ NSString* const kGoBackTwoID = @"go-back-2";
|
| // URLs and labels for tests that navigate back and forward.
|
| const char kBackHTMLButtonLabel[] = "BackHTMLButton";
|
| const char kForwardHTMLButtonLabel[] = "ForwardHTMLButton";
|
| -const char kForwardHTMLSentinel[] = "Forward page loaded";
|
| -const char kTestPageSentinel[] = "Test Page";
|
| const char kBackURL[] = "http://back";
|
| const char kForwardURL[] = "http://forward";
|
| const char kTestURL[] = "http://test";
|
| +NSString* const kForwardHTMLSentinel = @"Forward page loaded";
|
| +NSString* const kTestPageSentinel = @"Test Page";
|
|
|
| // URLs and labels for scenarioWindowLocation* tests.
|
| const char kHashChangeWithHistoryLabel[] = "hashChangedWithHistory";
|
| @@ -204,8 +204,7 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| const GURL windowHistoryURL =
|
| web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL);
|
| [ChromeEarlGrey loadURL:windowHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
|
|
| // Tap on the window.history.go() button. This will clear |kOnLoadText|, so
|
| // the subsequent check for |kOnLoadText| will only pass if a reload has
|
| @@ -213,8 +212,7 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID];
|
|
|
| // Verify that the onload text is reset.
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
| }
|
|
|
| // Tests reloading the current page via history.go(0).
|
| @@ -225,8 +223,7 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| const GURL windowHistoryURL =
|
| web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL);
|
| [ChromeEarlGrey loadURL:windowHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
|
|
| // Tap on the window.history.go() button. This will clear |kOnLoadText|, so
|
| // the subsequent check for |kOnLoadText| will only pass if a reload has
|
| @@ -234,8 +231,7 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID];
|
|
|
| // Verify that the onload text is reset.
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
| }
|
|
|
| // Tests that calling window.history.go() with an offset that is out of bounds
|
| @@ -247,22 +243,19 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| const GURL windowHistoryURL =
|
| web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL);
|
| [ChromeEarlGrey loadURL:windowHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
|
|
| // Tap on the window.history.go(2) button. This will clear all div text, so
|
| // the subsequent check for |kNoOpText| will only pass if no navigations have
|
| // occurred.
|
| [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kNoOpText];
|
|
|
| // Tap on the window.history.go(-2) button. This will clear all div text, so
|
| // the subsequent check for |kNoOpText| will only pass if no navigations have
|
| // occurred.
|
| [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kNoOpText];
|
| }
|
|
|
| // Tests going back and forward via history.go().
|
| @@ -287,21 +280,18 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| [ChromeEarlGrey loadURL:secondURL];
|
| [ChromeEarlGrey loadURL:thirdURL];
|
| [ChromeEarlGrey loadURL:fourthURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText("page4")]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:@"page4"];
|
|
|
| // Tap button to go back 3 pages.
|
| TapWebViewElementWithId("goBack");
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText("page1")]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:@"page1"];
|
| [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| firstURL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
|
|
| // Tap button to go forward 2 pages.
|
| TapWebViewElementWithId("goForward");
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText("page3")]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:@"page3"];
|
| [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| thirdURL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
| @@ -316,22 +306,19 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| const GURL windowHistoryURL =
|
| web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL);
|
| [ChromeEarlGrey loadURL:windowHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
|
|
| const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL);
|
| [ChromeEarlGrey loadURL:sampleURL];
|
|
|
| [ChromeEarlGrey loadURL:windowHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
|
|
| // Tap the window.history.go(-2) button. This will clear the current page's
|
| // |kOnLoadText|, so the subsequent check will only pass if another load
|
| // occurs.
|
| [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText];
|
| }
|
|
|
| #pragma mark window.history.[back/forward] operations
|
| @@ -377,17 +364,14 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| // Tap the back button in the toolbar and verify the page with forward button
|
| // is loaded.
|
| [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
|
| - [[EarlGrey
|
| - selectElementWithMatcher:WebViewContainingText(kForwardHTMLSentinel)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kForwardHTMLSentinel];
|
| [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| firstURL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
|
|
| // Tap the forward button in the HTML and verify the second URL is loaded.
|
| TapWebViewElementWithId(kForwardHTMLButtonLabel);
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPageSentinel)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:kTestPageSentinel];
|
| [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| secondURL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
| @@ -467,9 +451,8 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| page1URL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
| - [[EarlGrey
|
| - selectElementWithMatcher:WebViewContainingText(backHashChangeContent)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:base::SysUTF8ToNSString(
|
| + backHashChangeContent)];
|
|
|
| // Navigate forward to the new URL. This should fire a hashchange event.
|
| std::string forwardHashChangeContent = "forwardHashChange";
|
| @@ -480,16 +463,18 @@ class RedirectResponseProvider : public web::DataResponseProvider {
|
| selectElementWithMatcher:chrome_test_util::OmniboxText(
|
| hashChangedWithHistoryURL.GetContent())]
|
| assertWithMatcher:grey_notNil()];
|
| - [[EarlGrey
|
| - selectElementWithMatcher:WebViewContainingText(forwardHashChangeContent)]
|
| - assertWithMatcher:grey_notNil()];
|
| + [ChromeEarlGrey waitForWebViewContainingText:base::SysUTF8ToNSString(
|
| + forwardHashChangeContent)];
|
|
|
| // Load a hash URL directly. This shouldn't fire a hashchange event.
|
| std::string hashChangeContent = "FAIL_loadUrlHashChange";
|
| [self addHashChangeListenerWithContent:hashChangeContent];
|
| [ChromeEarlGrey loadURL:hashChangedWithHistoryURL];
|
| - [[EarlGrey selectElementWithMatcher:WebViewContainingText(hashChangeContent)]
|
| - assertWithMatcher:grey_nil()];
|
| + // TODO(crbug.com/714157): Remove matcher that waits.
|
| + [[EarlGrey
|
| + selectElementWithMatcher:chrome_test_util::WebViewNotContainingText(
|
| + hashChangeContent)]
|
| + assertWithMatcher:grey_notNil()];
|
| }
|
|
|
| // Loads a URL and replaces its location, then updates its location.hash
|
|
|