| OLD | NEW | 
|    1 // Copyright 2016 The Chromium Authors. All rights reserved. |    1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #import <XCTest/XCTest.h> |    5 #import <XCTest/XCTest.h> | 
|    6  |    6  | 
|    7 #include "base/ios/ios_util.h" |    7 #include "base/ios/ios_util.h" | 
|    8 #include "components/strings/grit/components_strings.h" |    8 #include "components/strings/grit/components_strings.h" | 
|    9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |    9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 
|   10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |   10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 
|   11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |   11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 
|   12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |   12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 
|   13 #include "ios/web/public/test/http_server/data_response_provider.h" |   13 #include "ios/web/public/test/http_server/data_response_provider.h" | 
|   14 #import "ios/web/public/test/http_server/http_server.h" |   14 #import "ios/web/public/test/http_server/http_server.h" | 
|   15 #include "ios/web/public/test/http_server/http_server_util.h" |   15 #include "ios/web/public/test/http_server/http_server_util.h" | 
|   16 #include "ui/base/l10n/l10n_util.h" |   16 #include "ui/base/l10n/l10n_util.h" | 
|   17  |   17  | 
|   18 #if !defined(__has_feature) || !__has_feature(objc_arc) |   18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
|   19 #error "This file requires ARC support." |   19 #error "This file requires ARC support." | 
|   20 #endif |   20 #endif | 
|   21  |   21  | 
|   22 using chrome_test_util::BackButton; |   22 using chrome_test_util::BackButton; | 
|   23 using chrome_test_util::ForwardButton; |   23 using chrome_test_util::ForwardButton; | 
|   24 using chrome_test_util::TapWebViewElementWithId; |   24 using chrome_test_util::TapWebViewElementWithId; | 
|   25 using chrome_test_util::WebViewContainingText; |  | 
|   26  |   25  | 
|   27 namespace { |   26 namespace { | 
|   28  |   27  | 
|   29 // URL for the test window.history.go() test file.  The page at this URL |   28 // URL for the test window.history.go() test file.  The page at this URL | 
|   30 // contains several buttons that trigger window.history commands.  Additionally |   29 // contains several buttons that trigger window.history commands.  Additionally | 
|   31 // the page contains several divs used to display the state of the page: |   30 // the page contains several divs used to display the state of the page: | 
|   32 // - A div that is populated with |kOnLoadText| when the onload event fires. |   31 // - A div that is populated with |kOnLoadText| when the onload event fires. | 
|   33 // - A div that is populated with |kNoOpText| 1s after a button is tapped. |   32 // - A div that is populated with |kNoOpText| 1s after a button is tapped. | 
|   34 // - A div that is populated with |kPopStateReceivedText| when a popstate event |   33 // - A div that is populated with |kPopStateReceivedText| when a popstate event | 
|   35 //   is received by the page. |   34 //   is received by the page. | 
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  201 #pragma mark window.history.go operations |  200 #pragma mark window.history.go operations | 
|  202  |  201  | 
|  203 // Tests reloading the current page via window.history.go() with no parameters. |  202 // Tests reloading the current page via window.history.go() with no parameters. | 
|  204 - (void)testHistoryGoNoParameter { |  203 - (void)testHistoryGoNoParameter { | 
|  205   web::test::SetUpFileBasedHttpServer(); |  204   web::test::SetUpFileBasedHttpServer(); | 
|  206  |  205  | 
|  207   // Load the history test page and ensure that its onload text is visible. |  206   // Load the history test page and ensure that its onload text is visible. | 
|  208   const GURL windowHistoryURL = |  207   const GURL windowHistoryURL = | 
|  209       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |  208       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 
|  210   [ChromeEarlGrey loadURL:windowHistoryURL]; |  209   [ChromeEarlGrey loadURL:windowHistoryURL]; | 
|  211   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  210   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  212       assertWithMatcher:grey_notNil()]; |  | 
|  213  |  211  | 
|  214   // Tap on the window.history.go() button.  This will clear |kOnLoadText|, so |  212   // Tap on the window.history.go() button.  This will clear |kOnLoadText|, so | 
|  215   // the subsequent check for |kOnLoadText| will only pass if a reload has |  213   // the subsequent check for |kOnLoadText| will only pass if a reload has | 
|  216   // occurred. |  214   // occurred. | 
|  217   [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; |  215   [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; | 
|  218  |  216  | 
|  219   // Verify that the onload text is reset. |  217   // Verify that the onload text is reset. | 
|  220   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  218   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  221       assertWithMatcher:grey_notNil()]; |  | 
|  222 } |  219 } | 
|  223  |  220  | 
|  224 // Tests reloading the current page via history.go(0). |  221 // Tests reloading the current page via history.go(0). | 
|  225 - (void)testHistoryGoDeltaZero { |  222 - (void)testHistoryGoDeltaZero { | 
|  226   web::test::SetUpFileBasedHttpServer(); |  223   web::test::SetUpFileBasedHttpServer(); | 
|  227  |  224  | 
|  228   // Load the history test page and ensure that its onload text is visible. |  225   // Load the history test page and ensure that its onload text is visible. | 
|  229   const GURL windowHistoryURL = |  226   const GURL windowHistoryURL = | 
|  230       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |  227       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 
|  231   [ChromeEarlGrey loadURL:windowHistoryURL]; |  228   [ChromeEarlGrey loadURL:windowHistoryURL]; | 
|  232   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  229   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  233       assertWithMatcher:grey_notNil()]; |  | 
|  234  |  230  | 
|  235   // Tap on the window.history.go() button.  This will clear |kOnLoadText|, so |  231   // Tap on the window.history.go() button.  This will clear |kOnLoadText|, so | 
|  236   // the subsequent check for |kOnLoadText| will only pass if a reload has |  232   // the subsequent check for |kOnLoadText| will only pass if a reload has | 
|  237   // occurred. |  233   // occurred. | 
|  238   [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; |  234   [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; | 
|  239  |  235  | 
|  240   // Verify that the onload text is reset. |  236   // Verify that the onload text is reset. | 
|  241   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  237   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  242       assertWithMatcher:grey_notNil()]; |  | 
|  243 } |  238 } | 
|  244  |  239  | 
|  245 // Tests that calling window.history.go() with an offset that is out of bounds |  240 // Tests that calling window.history.go() with an offset that is out of bounds | 
|  246 // is a no-op. |  241 // is a no-op. | 
|  247 - (void)testHistoryGoOutOfBounds { |  242 - (void)testHistoryGoOutOfBounds { | 
|  248   web::test::SetUpFileBasedHttpServer(); |  243   web::test::SetUpFileBasedHttpServer(); | 
|  249  |  244  | 
|  250   // Load the history test page and ensure that its onload text is visible. |  245   // Load the history test page and ensure that its onload text is visible. | 
|  251   const GURL windowHistoryURL = |  246   const GURL windowHistoryURL = | 
|  252       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |  247       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 
|  253   [ChromeEarlGrey loadURL:windowHistoryURL]; |  248   [ChromeEarlGrey loadURL:windowHistoryURL]; | 
|  254   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  249   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  255       assertWithMatcher:grey_notNil()]; |  | 
|  256  |  250  | 
|  257   // Tap on the window.history.go(2) button.  This will clear all div text, so |  251   // Tap on the window.history.go(2) button.  This will clear all div text, so | 
|  258   // the subsequent check for |kNoOpText| will only pass if no navigations have |  252   // the subsequent check for |kNoOpText| will only pass if no navigations have | 
|  259   // occurred. |  253   // occurred. | 
|  260   [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; |  254   [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; | 
|  261   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] |  255   [ChromeEarlGrey waitForWebViewContainingText:kNoOpText]; | 
|  262       assertWithMatcher:grey_notNil()]; |  | 
|  263  |  256  | 
|  264   // Tap on the window.history.go(-2) button.  This will clear all div text, so |  257   // Tap on the window.history.go(-2) button.  This will clear all div text, so | 
|  265   // the subsequent check for |kNoOpText| will only pass if no navigations have |  258   // the subsequent check for |kNoOpText| will only pass if no navigations have | 
|  266   // occurred. |  259   // occurred. | 
|  267   [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |  260   [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 
|  268   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] |  261   [ChromeEarlGrey waitForWebViewContainingText:kNoOpText]; | 
|  269       assertWithMatcher:grey_notNil()]; |  | 
|  270 } |  262 } | 
|  271  |  263  | 
|  272 // Tests going back and forward via history.go(). |  264 // Tests going back and forward via history.go(). | 
|  273 - (void)testHistoryGoDelta { |  265 - (void)testHistoryGoDelta { | 
|  274   std::map<GURL, std::string> responses; |  266   std::map<GURL, std::string> responses; | 
|  275   const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); |  267   const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); | 
|  276   const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); |  268   const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); | 
|  277   const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); |  269   const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); | 
|  278   const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); |  270   const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); | 
|  279   responses[firstURL] = |  271   responses[firstURL] = | 
|  280       "page1 <input type='button' value='goForward' id='goForward' " |  272       "page1 <input type='button' value='goForward' id='goForward' " | 
|  281       "onclick='window.history.go(2)' />"; |  273       "onclick='window.history.go(2)' />"; | 
|  282   responses[secondURL] = "page2"; |  274   responses[secondURL] = "page2"; | 
|  283   responses[thirdURL] = "page3"; |  275   responses[thirdURL] = "page3"; | 
|  284   responses[fourthURL] = |  276   responses[fourthURL] = | 
|  285       "page4 <input type='button' value='goBack' id='goBack' " |  277       "page4 <input type='button' value='goBack' id='goBack' " | 
|  286       "onclick='window.history.go(-3)' />"; |  278       "onclick='window.history.go(-3)' />"; | 
|  287   web::test::SetUpSimpleHttpServer(responses); |  279   web::test::SetUpSimpleHttpServer(responses); | 
|  288  |  280  | 
|  289   // Load 4 pages. |  281   // Load 4 pages. | 
|  290   [ChromeEarlGrey loadURL:firstURL]; |  282   [ChromeEarlGrey loadURL:firstURL]; | 
|  291   [ChromeEarlGrey loadURL:secondURL]; |  283   [ChromeEarlGrey loadURL:secondURL]; | 
|  292   [ChromeEarlGrey loadURL:thirdURL]; |  284   [ChromeEarlGrey loadURL:thirdURL]; | 
|  293   [ChromeEarlGrey loadURL:fourthURL]; |  285   [ChromeEarlGrey loadURL:fourthURL]; | 
|  294   [[EarlGrey selectElementWithMatcher:WebViewContainingText("page4")] |  286   [ChromeEarlGrey waitForWebViewContainingText:"page4"]; | 
|  295       assertWithMatcher:grey_notNil()]; |  | 
|  296  |  287  | 
|  297   // Tap button to go back 3 pages. |  288   // Tap button to go back 3 pages. | 
|  298   TapWebViewElementWithId("goBack"); |  289   TapWebViewElementWithId("goBack"); | 
|  299   [[EarlGrey selectElementWithMatcher:WebViewContainingText("page1")] |  290   [ChromeEarlGrey waitForWebViewContainingText:"page1"]; | 
|  300       assertWithMatcher:grey_notNil()]; |  | 
|  301   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  291   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  302                                           firstURL.GetContent())] |  292                                           firstURL.GetContent())] | 
|  303       assertWithMatcher:grey_notNil()]; |  293       assertWithMatcher:grey_notNil()]; | 
|  304  |  294  | 
|  305   // Tap button to go forward 2 pages. |  295   // Tap button to go forward 2 pages. | 
|  306   TapWebViewElementWithId("goForward"); |  296   TapWebViewElementWithId("goForward"); | 
|  307   [[EarlGrey selectElementWithMatcher:WebViewContainingText("page3")] |  297   [ChromeEarlGrey waitForWebViewContainingText:"page3"]; | 
|  308       assertWithMatcher:grey_notNil()]; |  | 
|  309   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  298   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  310                                           thirdURL.GetContent())] |  299                                           thirdURL.GetContent())] | 
|  311       assertWithMatcher:grey_notNil()]; |  300       assertWithMatcher:grey_notNil()]; | 
|  312 } |  301 } | 
|  313  |  302  | 
|  314 // Tests that calls to window.history.go() that span multiple documents causes |  303 // Tests that calls to window.history.go() that span multiple documents causes | 
|  315 // a load to occur. |  304 // a load to occur. | 
|  316 - (void)testHistoryCrossDocumentLoad { |  305 - (void)testHistoryCrossDocumentLoad { | 
|  317   web::test::SetUpFileBasedHttpServer(); |  306   web::test::SetUpFileBasedHttpServer(); | 
|  318  |  307  | 
|  319   // Load the history test page and ensure that its onload text is visible. |  308   // Load the history test page and ensure that its onload text is visible. | 
|  320   const GURL windowHistoryURL = |  309   const GURL windowHistoryURL = | 
|  321       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |  310       web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 
|  322   [ChromeEarlGrey loadURL:windowHistoryURL]; |  311   [ChromeEarlGrey loadURL:windowHistoryURL]; | 
|  323   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  312   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  324       assertWithMatcher:grey_notNil()]; |  | 
|  325  |  313  | 
|  326   const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); |  314   const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); | 
|  327   [ChromeEarlGrey loadURL:sampleURL]; |  315   [ChromeEarlGrey loadURL:sampleURL]; | 
|  328  |  316  | 
|  329   [ChromeEarlGrey loadURL:windowHistoryURL]; |  317   [ChromeEarlGrey loadURL:windowHistoryURL]; | 
|  330   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  318   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  331       assertWithMatcher:grey_notNil()]; |  | 
|  332  |  319  | 
|  333   // Tap the window.history.go(-2) button.  This will clear the current page's |  320   // Tap the window.history.go(-2) button.  This will clear the current page's | 
|  334   // |kOnLoadText|, so the subsequent check will only pass if another load |  321   // |kOnLoadText|, so the subsequent check will only pass if another load | 
|  335   // occurs. |  322   // occurs. | 
|  336   [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |  323   [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 
|  337   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |  324   [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; | 
|  338       assertWithMatcher:grey_notNil()]; |  | 
|  339 } |  325 } | 
|  340  |  326  | 
|  341 #pragma mark window.history.[back/forward] operations |  327 #pragma mark window.history.[back/forward] operations | 
|  342  |  328  | 
|  343 // Tests going back via history.back() then forward via forward button. |  329 // Tests going back via history.back() then forward via forward button. | 
|  344 - (void)testHistoryBackNavigation { |  330 - (void)testHistoryBackNavigation { | 
|  345   SetupBackAndForwardResponseProvider(); |  331   SetupBackAndForwardResponseProvider(); | 
|  346  |  332  | 
|  347   // Navigate to a URL. |  333   // Navigate to a URL. | 
|  348   const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); |  334   const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  374   const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); |  360   const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); | 
|  375   [ChromeEarlGrey loadURL:firstURL]; |  361   [ChromeEarlGrey loadURL:firstURL]; | 
|  376  |  362  | 
|  377   // Navigate to some other page. |  363   // Navigate to some other page. | 
|  378   const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); |  364   const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); | 
|  379   [ChromeEarlGrey loadURL:secondURL]; |  365   [ChromeEarlGrey loadURL:secondURL]; | 
|  380  |  366  | 
|  381   // Tap the back button in the toolbar and verify the page with forward button |  367   // Tap the back button in the toolbar and verify the page with forward button | 
|  382   // is loaded. |  368   // is loaded. | 
|  383   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |  369   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 
|  384   [[EarlGrey |  370   [ChromeEarlGrey waitForWebViewContainingText:kForwardHTMLSentinel]; | 
|  385       selectElementWithMatcher:WebViewContainingText(kForwardHTMLSentinel)] |  | 
|  386       assertWithMatcher:grey_notNil()]; |  | 
|  387   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  371   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  388                                           firstURL.GetContent())] |  372                                           firstURL.GetContent())] | 
|  389       assertWithMatcher:grey_notNil()]; |  373       assertWithMatcher:grey_notNil()]; | 
|  390  |  374  | 
|  391   // Tap the forward button in the HTML and verify the second URL is loaded. |  375   // Tap the forward button in the HTML and verify the second URL is loaded. | 
|  392   TapWebViewElementWithId(kForwardHTMLButtonLabel); |  376   TapWebViewElementWithId(kForwardHTMLButtonLabel); | 
|  393   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPageSentinel)] |  377   [ChromeEarlGrey waitForWebViewContainingText:kTestPageSentinel]; | 
|  394       assertWithMatcher:grey_notNil()]; |  | 
|  395   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  378   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  396                                           secondURL.GetContent())] |  379                                           secondURL.GetContent())] | 
|  397       assertWithMatcher:grey_notNil()]; |  380       assertWithMatcher:grey_notNil()]; | 
|  398  |  381  | 
|  399   // Verify that the forward button is not enabled. |  382   // Verify that the forward button is not enabled. | 
|  400   // TODO(crbug.com/638674): Evaluate if size class determination can move to |  383   // TODO(crbug.com/638674): Evaluate if size class determination can move to | 
|  401   // shared code. |  384   // shared code. | 
|  402   if (UIApplication.sharedApplication.keyWindow.traitCollection |  385   if (UIApplication.sharedApplication.keyWindow.traitCollection | 
|  403           .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { |  386           .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { | 
|  404     // In horizontally compact environments, the forward button is not visible. |  387     // In horizontally compact environments, the forward button is not visible. | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  464   // Click link to update location.hash and go to new URL (same page). |  447   // Click link to update location.hash and go to new URL (same page). | 
|  465   chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); |  448   chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 
|  466  |  449  | 
|  467   // Navigate back to original URL. This should fire a hashchange event. |  450   // Navigate back to original URL. This should fire a hashchange event. | 
|  468   std::string backHashChangeContent = "backHashChange"; |  451   std::string backHashChangeContent = "backHashChange"; | 
|  469   [self addHashChangeListenerWithContent:backHashChangeContent]; |  452   [self addHashChangeListenerWithContent:backHashChangeContent]; | 
|  470   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |  453   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 
|  471   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  454   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  472                                           page1URL.GetContent())] |  455                                           page1URL.GetContent())] | 
|  473       assertWithMatcher:grey_notNil()]; |  456       assertWithMatcher:grey_notNil()]; | 
|  474   [[EarlGrey |  457   [ChromeEarlGrey waitForWebViewContainingText:backHashChangeContent]; | 
|  475       selectElementWithMatcher:WebViewContainingText(backHashChangeContent)] |  | 
|  476       assertWithMatcher:grey_notNil()]; |  | 
|  477  |  458  | 
|  478   // Navigate forward to the new URL. This should fire a hashchange event. |  459   // Navigate forward to the new URL. This should fire a hashchange event. | 
|  479   std::string forwardHashChangeContent = "forwardHashChange"; |  460   std::string forwardHashChangeContent = "forwardHashChange"; | 
|  480   [self addHashChangeListenerWithContent:forwardHashChangeContent]; |  461   [self addHashChangeListenerWithContent:forwardHashChangeContent]; | 
|  481   [[EarlGrey selectElementWithMatcher:ForwardButton()] |  462   [[EarlGrey selectElementWithMatcher:ForwardButton()] | 
|  482       performAction:grey_tap()]; |  463       performAction:grey_tap()]; | 
|  483   [[EarlGrey |  464   [[EarlGrey | 
|  484       selectElementWithMatcher:chrome_test_util::OmniboxText( |  465       selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  485                                    hashChangedWithHistoryURL.GetContent())] |  466                                    hashChangedWithHistoryURL.GetContent())] | 
|  486       assertWithMatcher:grey_notNil()]; |  467       assertWithMatcher:grey_notNil()]; | 
|  487   [[EarlGrey |  468   [ChromeEarlGrey waitForWebViewContainingText:forwardHashChangeContent]; | 
|  488       selectElementWithMatcher:WebViewContainingText(forwardHashChangeContent)] |  | 
|  489       assertWithMatcher:grey_notNil()]; |  | 
|  490  |  469  | 
|  491   // Load a hash URL directly. This shouldn't fire a hashchange event. |  470   // Load a hash URL directly. This shouldn't fire a hashchange event. | 
|  492   std::string hashChangeContent = "FAIL_loadUrlHashChange"; |  471   std::string hashChangeContent = "FAIL_loadUrlHashChange"; | 
|  493   [self addHashChangeListenerWithContent:hashChangeContent]; |  472   [self addHashChangeListenerWithContent:hashChangeContent]; | 
|  494   [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; |  473   [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; | 
|  495   [[EarlGrey selectElementWithMatcher:WebViewContainingText(hashChangeContent)] |  474   // TODO(crbug.com/714157): Remove matcher that waits. | 
|  496       assertWithMatcher:grey_nil()]; |  475   [[EarlGrey | 
 |  476       selectElementWithMatcher:chrome_test_util::WebViewNotContainingText( | 
 |  477                                    hashChangeContent)] | 
 |  478       assertWithMatcher:grey_notNil()]; | 
|  497 } |  479 } | 
|  498  |  480  | 
|  499 // Loads a URL and replaces its location, then updates its location.hash |  481 // Loads a URL and replaces its location, then updates its location.hash | 
|  500 // and verifies that going back returns to the replaced entry. |  482 // and verifies that going back returns to the replaced entry. | 
|  501 - (void)testWindowLocationReplaceAndChangeHash { |  483 - (void)testWindowLocationReplaceAndChangeHash { | 
|  502   std::map<GURL, std::string> responses; |  484   std::map<GURL, std::string> responses; | 
|  503   const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); |  485   const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); | 
|  504   const GURL hashChangedWithoutHistoryURL = |  486   const GURL hashChangedWithoutHistoryURL = | 
|  505       web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); |  487       web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); | 
|  506   const GURL hashChangedWithHistoryURL = |  488   const GURL hashChangedWithHistoryURL = | 
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  679   // Navigate forward and assert the the resulting page is the proper |  661   // Navigate forward and assert the the resulting page is the proper | 
|  680   // destination. |  662   // destination. | 
|  681   [[EarlGrey selectElementWithMatcher:ForwardButton()] |  663   [[EarlGrey selectElementWithMatcher:ForwardButton()] | 
|  682       performAction:grey_tap()]; |  664       performAction:grey_tap()]; | 
|  683   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  665   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  684                                           destinationURL.GetContent())] |  666                                           destinationURL.GetContent())] | 
|  685       assertWithMatcher:grey_notNil()]; |  667       assertWithMatcher:grey_notNil()]; | 
|  686 } |  668 } | 
|  687  |  669  | 
|  688 @end |  670 @end | 
| OLD | NEW |