| 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 <EarlGrey/EarlGrey.h> |    5 #import <EarlGrey/EarlGrey.h> | 
|    6  |    6  | 
|    7 #include "base/memory/ptr_util.h" |    7 #include "base/memory/ptr_util.h" | 
|    8 #include "base/strings/stringprintf.h" |    8 #include "base/strings/stringprintf.h" | 
|    9 #include "base/strings/sys_string_conversions.h" |    9 #include "base/strings/sys_string_conversions.h" | 
|   10 #include "base/strings/utf_string_conversions.h" |   10 #include "base/strings/utf_string_conversions.h" | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   21 #include "ios/web/public/test/http_server/html_response_provider.h" |   21 #include "ios/web/public/test/http_server/html_response_provider.h" | 
|   22 #import "ios/web/public/test/http_server/http_server.h" |   22 #import "ios/web/public/test/http_server/http_server.h" | 
|   23 #include "ios/web/public/test/http_server/http_server_util.h" |   23 #include "ios/web/public/test/http_server/http_server_util.h" | 
|   24 #include "ios/web/public/test/url_test_util.h" |   24 #include "ios/web/public/test/url_test_util.h" | 
|   25 #include "url/gurl.h" |   25 #include "url/gurl.h" | 
|   26  |   26  | 
|   27 #if !defined(__has_feature) || !__has_feature(objc_arc) |   27 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
|   28 #error "This file requires ARC support." |   28 #error "This file requires ARC support." | 
|   29 #endif |   29 #endif | 
|   30  |   30  | 
|   31 using chrome_test_util::WebViewContainingText; |  | 
|   32 using chrome_test_util::OmniboxText; |   31 using chrome_test_util::OmniboxText; | 
|   33  |   32  | 
|   34 namespace { |   33 namespace { | 
|   35  |   34  | 
|   36 const char kTestPage1[] = "Test Page 1"; |   35 const char kTestPage1[] = "Test Page 1"; | 
|   37 const char kTestPage2[] = "Test Page 2"; |   36 const char kTestPage2[] = "Test Page 2"; | 
|   38 const char kTestPage3[] = "Test Page 3"; |   37 const char kTestPage3[] = "Test Page 3"; | 
|   39 const char kGoBackLink[] = "go-back"; |   38 const char kGoBackLink[] = "go-back"; | 
|   40 const char kGoForwardLink[] = "go-forward"; |   39 const char kGoForwardLink[] = "go-forward"; | 
|   41 const char kGoNegativeDeltaLink[] = "go-negative-delta"; |   40 const char kGoNegativeDeltaLink[] = "go-negative-delta"; | 
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  191   // displayed even though URL1 is a pending URL. |  190   // displayed even though URL1 is a pending URL. | 
|  192   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  191   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  193       performAction:grey_tap()]; |  192       performAction:grey_tap()]; | 
|  194   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |  193   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 
|  195              @"Last request URL: %@", self.lastRequestURLSpec); |  194              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  196   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  195   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  197       assertWithMatcher:grey_notNil()]; |  196       assertWithMatcher:grey_notNil()]; | 
|  198  |  197  | 
|  199   // Make server respond so URL1 becomes committed. |  198   // Make server respond so URL1 becomes committed. | 
|  200   [self setServerPaused:NO]; |  199   [self setServerPaused:NO]; | 
|  201   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  200   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  202       assertWithMatcher:grey_notNil()]; |  | 
|  203   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  201   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  204       assertWithMatcher:grey_notNil()]; |  202       assertWithMatcher:grey_notNil()]; | 
|  205  |  203  | 
|  206   // Purge web view caches and pause the server to make sure that tests can |  204   // Purge web view caches and pause the server to make sure that tests can | 
|  207   // verify omnibox state before server starts responding. |  205   // verify omnibox state before server starts responding. | 
|  208   PurgeCachedWebViewPages(); |  206   PurgeCachedWebViewPages(); | 
|  209   [self setServerPaused:YES]; |  207   [self setServerPaused:YES]; | 
|  210  |  208  | 
|  211   // Tap the forward button in the toolbar and verify that URL1 (committed URL) |  209   // Tap the forward button in the toolbar and verify that URL1 (committed URL) | 
|  212   // is displayed even though URL2 is a pending URL. |  210   // is displayed even though URL2 is a pending URL. | 
|  213   [[EarlGrey selectElementWithMatcher:chrome_test_util::ForwardButton()] |  211   [[EarlGrey selectElementWithMatcher:chrome_test_util::ForwardButton()] | 
|  214       performAction:grey_tap()]; |  212       performAction:grey_tap()]; | 
|  215   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], |  213   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], | 
|  216              @"Last request URL: %@", self.lastRequestURLSpec); |  214              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  217   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  215   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  218       assertWithMatcher:grey_notNil()]; |  216       assertWithMatcher:grey_notNil()]; | 
|  219  |  217  | 
|  220   // Make server respond so URL2 becomes committed. |  218   // Make server respond so URL2 becomes committed. | 
|  221   [self setServerPaused:NO]; |  219   [self setServerPaused:NO]; | 
|  222   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] |  220   [ChromeEarlGrey waitForWebViewContainingText:kTestPage2]; | 
|  223       assertWithMatcher:grey_notNil()]; |  | 
|  224   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  221   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  225       assertWithMatcher:grey_notNil()]; |  222       assertWithMatcher:grey_notNil()]; | 
|  226 } |  223 } | 
|  227  |  224  | 
|  228 // Tests that visible URL is always the same as last committed URL during |  225 // Tests that visible URL is always the same as last committed URL during | 
|  229 // pending navigations initialted from back history popover. |  226 // pending navigations initialted from back history popover. | 
|  230 - (void)testHistoryNavigation { |  227 - (void)testHistoryNavigation { | 
|  231   // Purge web view caches and pause the server to make sure that tests can |  228   // Purge web view caches and pause the server to make sure that tests can | 
|  232   // verify omnibox state before server starts responding. |  229   // verify omnibox state before server starts responding. | 
|  233   PurgeCachedWebViewPages(); |  230   PurgeCachedWebViewPages(); | 
|  234   [self setServerPaused:YES]; |  231   [self setServerPaused:YES]; | 
|  235  |  232  | 
|  236   // Go back in history and verify that URL2 (committed URL) is displayed even |  233   // Go back in history and verify that URL2 (committed URL) is displayed even | 
|  237   // though URL1 is a pending URL. |  234   // though URL1 is a pending URL. | 
|  238   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  235   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  239       performAction:grey_longPress()]; |  236       performAction:grey_longPress()]; | 
|  240   NSString* URL1Title = |  237   NSString* URL1Title = | 
|  241       base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(_testURL1)); |  238       base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(_testURL1)); | 
|  242   [[EarlGrey selectElementWithMatcher:grey_text(URL1Title)] |  239   [[EarlGrey selectElementWithMatcher:grey_text(URL1Title)] | 
|  243       performAction:grey_tap()]; |  240       performAction:grey_tap()]; | 
|  244   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |  241   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 
|  245              @"Last request URL: %@", self.lastRequestURLSpec); |  242              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  246   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  243   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  247       assertWithMatcher:grey_notNil()]; |  244       assertWithMatcher:grey_notNil()]; | 
|  248  |  245  | 
|  249   // Make server respond so URL1 becomes committed. |  246   // Make server respond so URL1 becomes committed. | 
|  250   [self setServerPaused:NO]; |  247   [self setServerPaused:NO]; | 
|  251   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  248   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  252       assertWithMatcher:grey_notNil()]; |  | 
|  253   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  249   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  254       assertWithMatcher:grey_notNil()]; |  250       assertWithMatcher:grey_notNil()]; | 
|  255 } |  251 } | 
|  256  |  252  | 
|  257 // Tests that stopping a pending Back navigation and reloading reloads committed |  253 // Tests that stopping a pending Back navigation and reloading reloads committed | 
|  258 // URL, not pending URL. |  254 // URL, not pending URL. | 
|  259 - (void)testStoppingPendingBackNavigationAndReload { |  255 - (void)testStoppingPendingBackNavigationAndReload { | 
|  260   // Purge web view caches and pause the server to make sure that tests can |  256   // Purge web view caches and pause the server to make sure that tests can | 
|  261   // verify omnibox state before server starts responding. |  257   // verify omnibox state before server starts responding. | 
|  262   PurgeCachedWebViewPages(); |  258   PurgeCachedWebViewPages(); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  274             setValue:@YES |  270             setValue:@YES | 
|  275         forConfigKey:kGREYConfigKeySynchronizationEnabled]; |  271         forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 
|  276     [ChromeEarlGreyUI openToolsMenu]; |  272     [ChromeEarlGreyUI openToolsMenu]; | 
|  277   } |  273   } | 
|  278   [[EarlGrey selectElementWithMatcher:chrome_test_util::StopButton()] |  274   [[EarlGrey selectElementWithMatcher:chrome_test_util::StopButton()] | 
|  279       performAction:grey_tap()]; |  275       performAction:grey_tap()]; | 
|  280   [ChromeEarlGreyUI reload]; |  276   [ChromeEarlGreyUI reload]; | 
|  281  |  277  | 
|  282   // Make server respond and verify that page2 was reloaded, not page1. |  278   // Make server respond and verify that page2 was reloaded, not page1. | 
|  283   [self setServerPaused:NO]; |  279   [self setServerPaused:NO]; | 
|  284   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] |  280   [ChromeEarlGrey waitForWebViewContainingText:kTestPage2]; | 
|  285       assertWithMatcher:grey_notNil()]; |  | 
|  286   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  281   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  287       assertWithMatcher:grey_notNil()]; |  282       assertWithMatcher:grey_notNil()]; | 
|  288 } |  283 } | 
|  289  |  284  | 
|  290 // Tests that visible URL is always the same as last committed URL during |  285 // Tests that visible URL is always the same as last committed URL during | 
|  291 // back forward navigations initiated with JS. |  286 // back forward navigations initiated with JS. | 
|  292 - (void)testJSBackForwardNavigation { |  287 - (void)testJSBackForwardNavigation { | 
|  293   // Purge web view caches and pause the server to make sure that tests can |  288   // Purge web view caches and pause the server to make sure that tests can | 
|  294   // verify omnibox state before server starts responding. |  289   // verify omnibox state before server starts responding. | 
|  295   PurgeCachedWebViewPages(); |  290   PurgeCachedWebViewPages(); | 
|  296   [self setServerPaused:YES]; |  291   [self setServerPaused:YES]; | 
|  297  |  292  | 
|  298   // Tap the back button on the page and verify that URL2 (committed URL) is |  293   // Tap the back button on the page and verify that URL2 (committed URL) is | 
|  299   // displayed even though URL1 is a pending URL. |  294   // displayed even though URL1 is a pending URL. | 
|  300   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; |  295   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; | 
|  301   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |  296   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 
|  302              @"Last request URL: %@", self.lastRequestURLSpec); |  297              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  303   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  298   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  304       assertWithMatcher:grey_notNil()]; |  299       assertWithMatcher:grey_notNil()]; | 
|  305  |  300  | 
|  306   // Make server respond so URL1 becomes committed. |  301   // Make server respond so URL1 becomes committed. | 
|  307   [self setServerPaused:NO]; |  302   [self setServerPaused:NO]; | 
|  308   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  303   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  309       assertWithMatcher:grey_notNil()]; |  | 
|  310   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  304   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  311       assertWithMatcher:grey_notNil()]; |  305       assertWithMatcher:grey_notNil()]; | 
|  312  |  306  | 
|  313   // Purge web view caches and pause the server to make sure that tests can |  307   // Purge web view caches and pause the server to make sure that tests can | 
|  314   // verify omnibox state before server starts responding. |  308   // verify omnibox state before server starts responding. | 
|  315   PurgeCachedWebViewPages(); |  309   PurgeCachedWebViewPages(); | 
|  316   [self setServerPaused:YES]; |  310   [self setServerPaused:YES]; | 
|  317  |  311  | 
|  318   // Tap the forward button on the page and verify that URL1 (committed URL) |  312   // Tap the forward button on the page and verify that URL1 (committed URL) | 
|  319   // is displayed even though URL2 is a pending URL. |  313   // is displayed even though URL2 is a pending URL. | 
|  320   [ChromeEarlGrey |  314   [ChromeEarlGrey | 
|  321       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)]; |  315       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)]; | 
|  322   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], |  316   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], | 
|  323              @"Last request URL: %@", self.lastRequestURLSpec); |  317              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  324   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  318   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  325       assertWithMatcher:grey_notNil()]; |  319       assertWithMatcher:grey_notNil()]; | 
|  326  |  320  | 
|  327   // Make server respond so URL2 becomes committed. |  321   // Make server respond so URL2 becomes committed. | 
|  328   [self setServerPaused:NO]; |  322   [self setServerPaused:NO]; | 
|  329   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] |  323   [ChromeEarlGrey waitForWebViewContainingText:kTestPage2]; | 
|  330       assertWithMatcher:grey_notNil()]; |  | 
|  331   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  324   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  332       assertWithMatcher:grey_notNil()]; |  325       assertWithMatcher:grey_notNil()]; | 
|  333 } |  326 } | 
|  334  |  327  | 
|  335 // Tests that visible URL is always the same as last committed URL during go |  328 // Tests that visible URL is always the same as last committed URL during go | 
|  336 // navigations initiated with JS. |  329 // navigations initiated with JS. | 
|  337 - (void)testJSGoNavigation { |  330 - (void)testJSGoNavigation { | 
|  338   // Purge web view caches and pause the server to make sure that tests can |  331   // Purge web view caches and pause the server to make sure that tests can | 
|  339   // verify omnibox state before server starts responding. |  332   // verify omnibox state before server starts responding. | 
|  340   PurgeCachedWebViewPages(); |  333   PurgeCachedWebViewPages(); | 
|  341   [self setServerPaused:YES]; |  334   [self setServerPaused:YES]; | 
|  342  |  335  | 
|  343   // Tap the go negative delta button on the page and verify that URL2 |  336   // Tap the go negative delta button on the page and verify that URL2 | 
|  344   // (committed URL) is displayed even though URL1 is a pending URL. |  337   // (committed URL) is displayed even though URL1 is a pending URL. | 
|  345   [ChromeEarlGrey |  338   [ChromeEarlGrey | 
|  346       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)]; |  339       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)]; | 
|  347   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |  340   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 
|  348              @"Last request URL: %@", self.lastRequestURLSpec); |  341              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  349   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  342   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  350       assertWithMatcher:grey_notNil()]; |  343       assertWithMatcher:grey_notNil()]; | 
|  351  |  344  | 
|  352   // Make server respond so URL1 becomes committed. |  345   // Make server respond so URL1 becomes committed. | 
|  353   [self setServerPaused:NO]; |  346   [self setServerPaused:NO]; | 
|  354   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  347   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  355       assertWithMatcher:grey_notNil()]; |  | 
|  356   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  348   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  357       assertWithMatcher:grey_notNil()]; |  349       assertWithMatcher:grey_notNil()]; | 
|  358  |  350  | 
|  359   // Purge web view caches and pause the server to make sure that tests can |  351   // Purge web view caches and pause the server to make sure that tests can | 
|  360   // verify omnibox state before server starts responding. |  352   // verify omnibox state before server starts responding. | 
|  361   PurgeCachedWebViewPages(); |  353   PurgeCachedWebViewPages(); | 
|  362   [self setServerPaused:YES]; |  354   [self setServerPaused:YES]; | 
|  363  |  355  | 
|  364   // Tap go positive delta button on the page and verify that URL1 (committed |  356   // Tap go positive delta button on the page and verify that URL1 (committed | 
|  365   // URL) is displayed even though URL2 is a pending URL. |  357   // URL) is displayed even though URL2 is a pending URL. | 
|  366   [ChromeEarlGrey |  358   [ChromeEarlGrey | 
|  367       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)]; |  359       tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)]; | 
|  368   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], |  360   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], | 
|  369              @"Last request URL: %@", self.lastRequestURLSpec); |  361              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  370   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  362   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  371       assertWithMatcher:grey_notNil()]; |  363       assertWithMatcher:grey_notNil()]; | 
|  372  |  364  | 
|  373   // Make server respond so URL2 becomes committed. |  365   // Make server respond so URL2 becomes committed. | 
|  374   [self setServerPaused:NO]; |  366   [self setServerPaused:NO]; | 
|  375   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] |  367   [ChromeEarlGrey waitForWebViewContainingText:kTestPage2]; | 
|  376       assertWithMatcher:grey_notNil()]; |  | 
|  377   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  368   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  378       assertWithMatcher:grey_notNil()]; |  369       assertWithMatcher:grey_notNil()]; | 
|  379 } |  370 } | 
|  380  |  371  | 
|  381 // Tests that visible URL is always the same as last committed URL during go |  372 // Tests that visible URL is always the same as last committed URL during go | 
|  382 // back navigation started with pending reload in progress. |  373 // back navigation started with pending reload in progress. | 
|  383 - (void)testBackNavigationWithPendingReload { |  374 - (void)testBackNavigationWithPendingReload { | 
|  384   // Purge web view caches and pause the server to make sure that tests can |  375   // Purge web view caches and pause the server to make sure that tests can | 
|  385   // verify omnibox state before server starts responding. |  376   // verify omnibox state before server starts responding. | 
|  386   PurgeCachedWebViewPages(); |  377   PurgeCachedWebViewPages(); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  402   // pending URL. |  393   // pending URL. | 
|  403   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  394   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  404       performAction:grey_tap()]; |  395       performAction:grey_tap()]; | 
|  405   // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 |  396   // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 | 
|  406   // request here. |  397   // request here. | 
|  407   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  398   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  408       assertWithMatcher:grey_notNil()]; |  399       assertWithMatcher:grey_notNil()]; | 
|  409  |  400  | 
|  410   // Make server respond so URL1 becomes committed. |  401   // Make server respond so URL1 becomes committed. | 
|  411   [self setServerPaused:NO]; |  402   [self setServerPaused:NO]; | 
|  412   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  403   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  413       assertWithMatcher:grey_notNil()]; |  | 
|  414   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  404   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  415       assertWithMatcher:grey_notNil()]; |  405       assertWithMatcher:grey_notNil()]; | 
|  416 } |  406 } | 
|  417  |  407  | 
|  418 // Tests that visible URL is always the same as last committed URL during go |  408 // Tests that visible URL is always the same as last committed URL during go | 
|  419 // back navigation initiated with pending renderer-initiated navigation in |  409 // back navigation initiated with pending renderer-initiated navigation in | 
|  420 // progress. |  410 // progress. | 
|  421 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { |  411 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { | 
|  422   // Purge web view caches and pause the server to make sure that tests can |  412   // Purge web view caches and pause the server to make sure that tests can | 
|  423   // verify omnibox state before server starts responding. |  413   // verify omnibox state before server starts responding. | 
|  424   PurgeCachedWebViewPages(); |  414   PurgeCachedWebViewPages(); | 
|  425   [self setServerPaused:YES]; |  415   [self setServerPaused:YES]; | 
|  426  |  416  | 
|  427   // Start renderer initiated navigation. |  417   // Start renderer initiated navigation. | 
|  428   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; |  418   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; | 
|  429  |  419  | 
|  430   // Do not wait until renderer-initiated navigation is finished, tap the back |  420   // Do not wait until renderer-initiated navigation is finished, tap the back | 
|  431   // button in the toolbar and verify that URL2 (committed URL) is displayed |  421   // button in the toolbar and verify that URL2 (committed URL) is displayed | 
|  432   // even though URL1 is a pending URL. |  422   // even though URL1 is a pending URL. | 
|  433   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  423   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  434       performAction:grey_tap()]; |  424       performAction:grey_tap()]; | 
|  435   // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 |  425   // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 | 
|  436   // request here. |  426   // request here. | 
|  437   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  427   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  438       assertWithMatcher:grey_notNil()]; |  428       assertWithMatcher:grey_notNil()]; | 
|  439  |  429  | 
|  440   // Make server respond so URL1 becomes committed. |  430   // Make server respond so URL1 becomes committed. | 
|  441   [self setServerPaused:NO]; |  431   [self setServerPaused:NO]; | 
|  442   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  432   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  443       assertWithMatcher:grey_notNil()]; |  | 
|  444   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  433   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  445       assertWithMatcher:grey_notNil()]; |  434       assertWithMatcher:grey_notNil()]; | 
|  446 } |  435 } | 
|  447  |  436  | 
|  448 // Tests that visible URL is always the same as last committed URL during |  437 // Tests that visible URL is always the same as last committed URL during | 
|  449 // renderer-initiated navigation started with pending back navigation in |  438 // renderer-initiated navigation started with pending back navigation in | 
|  450 // progress. |  439 // progress. | 
|  451 - (void)testRendererInitiatedNavigationWithPendingBackNavigation { |  440 - (void)testRendererInitiatedNavigationWithPendingBackNavigation { | 
|  452   // Purge web view caches and pause the server to make sure that tests can |  441   // Purge web view caches and pause the server to make sure that tests can | 
|  453   // verify omnibox state before server starts responding. |  442   // verify omnibox state before server starts responding. | 
|  454   PurgeCachedWebViewPages(); |  443   PurgeCachedWebViewPages(); | 
|  455   [self setServerPaused:YES]; |  444   [self setServerPaused:YES]; | 
|  456  |  445  | 
|  457   // Tap the back button in the toolbar and verify that URL2 (committed URL) is |  446   // Tap the back button in the toolbar and verify that URL2 (committed URL) is | 
|  458   // displayed even though URL1 is a pending URL. |  447   // displayed even though URL1 is a pending URL. | 
|  459   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  448   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  460       performAction:grey_tap()]; |  449       performAction:grey_tap()]; | 
|  461   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |  450   GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 
|  462              @"Last request URL: %@", self.lastRequestURLSpec); |  451              @"Last request URL: %@", self.lastRequestURLSpec); | 
|  463   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  452   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  464       assertWithMatcher:grey_notNil()]; |  453       assertWithMatcher:grey_notNil()]; | 
|  465  |  454  | 
|  466   // Interrupt back navigation with renderer initiated navigation. |  455   // Interrupt back navigation with renderer initiated navigation. | 
|  467   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; |  456   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; | 
|  468   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |  457   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 
|  469       assertWithMatcher:grey_notNil()]; |  458       assertWithMatcher:grey_notNil()]; | 
|  470  |  459  | 
|  471   // Make server respond so URL1 becomes committed. |  460   // Make server respond so URL1 becomes committed. | 
|  472   [self setServerPaused:NO]; |  461   [self setServerPaused:NO]; | 
|  473   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage3)] |  462   [ChromeEarlGrey waitForWebViewContainingText:kTestPage3]; | 
|  474       assertWithMatcher:grey_notNil()]; |  | 
|  475   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] |  463   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] | 
|  476       assertWithMatcher:grey_notNil()]; |  464       assertWithMatcher:grey_notNil()]; | 
|  477 } |  465 } | 
|  478  |  466  | 
|  479 // Tests that visible URL is always the same as last committed URL if user |  467 // Tests that visible URL is always the same as last committed URL if user | 
|  480 // issues 2 go back commands. |  468 // issues 2 go back commands. | 
|  481 - (void)testDoubleBackNavigation { |  469 - (void)testDoubleBackNavigation { | 
|  482   // Create 3rd entry in the history, to be able to go back twice. |  470   // Create 3rd entry in the history, to be able to go back twice. | 
|  483   [ChromeEarlGrey loadURL:_testURL3]; |  471   [ChromeEarlGrey loadURL:_testURL3]; | 
|  484  |  472  | 
|  485   // Purge web view caches and pause the server to make sure that tests can |  473   // Purge web view caches and pause the server to make sure that tests can | 
|  486   // verify omnibox state before server starts responding. |  474   // verify omnibox state before server starts responding. | 
|  487   PurgeCachedWebViewPages(); |  475   PurgeCachedWebViewPages(); | 
|  488   [self setServerPaused:YES]; |  476   [self setServerPaused:YES]; | 
|  489  |  477  | 
|  490   // Tap the back button twice in the toolbar and verify that URL3 (committed |  478   // Tap the back button twice in the toolbar and verify that URL3 (committed | 
|  491   // URL) is displayed even though URL1 is a pending URL. |  479   // URL) is displayed even though URL1 is a pending URL. | 
|  492   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  480   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  493       performAction:grey_tap()]; |  481       performAction:grey_tap()]; | 
|  494   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  482   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  495       performAction:grey_tap()]; |  483       performAction:grey_tap()]; | 
|  496   // Server will receive only one request either for |_testURL2| or for |  484   // Server will receive only one request either for |_testURL2| or for | 
|  497   // |_testURL1| depending on load timing and then will pause. So there is no |  485   // |_testURL1| depending on load timing and then will pause. So there is no | 
|  498   // need to wait for particular request. |  486   // need to wait for particular request. | 
|  499   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] |  487   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] | 
|  500       assertWithMatcher:grey_notNil()]; |  488       assertWithMatcher:grey_notNil()]; | 
|  501  |  489  | 
|  502   // Make server respond so URL1 becomes committed. |  490   // Make server respond so URL1 becomes committed. | 
|  503   [self setServerPaused:NO]; |  491   [self setServerPaused:NO]; | 
|  504   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  492   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  505       assertWithMatcher:grey_notNil()]; |  | 
|  506   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  493   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  507       assertWithMatcher:grey_notNil()]; |  494       assertWithMatcher:grey_notNil()]; | 
|  508 } |  495 } | 
|  509  |  496  | 
|  510 // Tests that visible URL is always the same as last committed URL if user |  497 // Tests that visible URL is always the same as last committed URL if user | 
|  511 // issues 2 go forward commands to WebUI page (crbug.com/711465). |  498 // issues 2 go forward commands to WebUI page (crbug.com/711465). | 
|  512 - (void)testDoubleForwardNavigationToWebUIPage { |  499 - (void)testDoubleForwardNavigationToWebUIPage { | 
|  513   // Create 3rd entry in the history, to be able to go back twice. |  500   // Create 3rd entry in the history, to be able to go back twice. | 
|  514   GURL URL(kChromeUIVersionURL); |  501   GURL URL(kChromeUIVersionURL); | 
|  515   [ChromeEarlGrey loadURL:GURL(kChromeUIVersionURL)]; |  502   [ChromeEarlGrey loadURL:GURL(kChromeUIVersionURL)]; | 
|  516  |  503  | 
|  517   // Tap the back button twice in the toolbar and wait for URL 1 to load. |  504   // Tap the back button twice in the toolbar and wait for URL 1 to load. | 
|  518   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  505   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  519       performAction:grey_tap()]; |  506       performAction:grey_tap()]; | 
|  520   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |  507   [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
|  521       performAction:grey_tap()]; |  508       performAction:grey_tap()]; | 
|  522   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  509   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  523       assertWithMatcher:grey_notNil()]; |  | 
|  524  |  510  | 
|  525   // Quickly (using chrome command) navigate forward twice and wait for |  511   // Quickly (using chrome command) navigate forward twice and wait for | 
|  526   // kChromeUIVersionURL to load. |  512   // kChromeUIVersionURL to load. | 
|  527   GenericChromeCommand* forwardCommand = |  513   GenericChromeCommand* forwardCommand = | 
|  528       [[GenericChromeCommand alloc] initWithTag:IDC_FORWARD]; |  514       [[GenericChromeCommand alloc] initWithTag:IDC_FORWARD]; | 
|  529   chrome_test_util::RunCommandWithActiveViewController(forwardCommand); |  515   chrome_test_util::RunCommandWithActiveViewController(forwardCommand); | 
|  530   chrome_test_util::RunCommandWithActiveViewController(forwardCommand); |  516   chrome_test_util::RunCommandWithActiveViewController(forwardCommand); | 
|  531  |  517  | 
|  532   const std::string version = version_info::GetVersionNumber(); |  518   const std::string version = version_info::GetVersionNumber(); | 
|  533   [[EarlGrey selectElementWithMatcher:WebViewContainingText(version)] |  519   [ChromeEarlGrey waitForWebViewContainingText:version]; | 
|  534       assertWithMatcher:grey_notNil()]; |  | 
|  535  |  520  | 
|  536   // Make sure that kChromeUIVersionURL URL is displayed in the omnibox. |  521   // Make sure that kChromeUIVersionURL URL is displayed in the omnibox. | 
|  537   std::string expectedText = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(URL)); |  522   std::string expectedText = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(URL)); | 
|  538   [[EarlGrey selectElementWithMatcher:OmniboxText(expectedText)] |  523   [[EarlGrey selectElementWithMatcher:OmniboxText(expectedText)] | 
|  539       assertWithMatcher:grey_notNil()]; |  524       assertWithMatcher:grey_notNil()]; | 
|  540 } |  525 } | 
|  541  |  526  | 
|  542 // Tests that visible URL is always the same as last committed URL if page calls |  527 // Tests that visible URL is always the same as last committed URL if page calls | 
|  543 // window.history.back() twice. |  528 // window.history.back() twice. | 
|  544 - (void)testDoubleBackJSNavigation { |  529 - (void)testDoubleBackJSNavigation { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  555   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; |  540   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; | 
|  556   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; |  541   [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; | 
|  557   // Server will receive only one request either for |_testURL2| or for |  542   // Server will receive only one request either for |_testURL2| or for | 
|  558   // |_testURL1| depending on load timing and then will pause. So there is no |  543   // |_testURL1| depending on load timing and then will pause. So there is no | 
|  559   // need to wait for particular request. |  544   // need to wait for particular request. | 
|  560   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] |  545   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] | 
|  561       assertWithMatcher:grey_notNil()]; |  546       assertWithMatcher:grey_notNil()]; | 
|  562  |  547  | 
|  563   // Make server respond so URL1 becomes committed. |  548   // Make server respond so URL1 becomes committed. | 
|  564   [self setServerPaused:NO]; |  549   [self setServerPaused:NO]; | 
|  565   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |  550   [ChromeEarlGrey waitForWebViewContainingText:kTestPage1]; | 
|  566       assertWithMatcher:grey_notNil()]; |  | 
|  567   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |  551   [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 
|  568       assertWithMatcher:grey_notNil()]; |  552       assertWithMatcher:grey_notNil()]; | 
|  569 } |  553 } | 
|  570  |  554  | 
|  571 #pragma mark - |  555 #pragma mark - | 
|  572 #pragma mark Private |  556 #pragma mark Private | 
|  573  |  557  | 
|  574 - (NSString*)lastRequestURLSpec { |  558 - (NSString*)lastRequestURLSpec { | 
|  575   return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec()); |  559   return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec()); | 
|  576 } |  560 } | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  590 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { |  574 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { | 
|  591   return [[GREYCondition |  575   return [[GREYCondition | 
|  592       conditionWithName:@"Wait for received request" |  576       conditionWithName:@"Wait for received request" | 
|  593                   block:^{ |  577                   block:^{ | 
|  594                     return _responseProvider->last_request_url() == URL ? YES |  578                     return _responseProvider->last_request_url() == URL ? YES | 
|  595                                                                         : NO; |  579                                                                         : NO; | 
|  596                   }] waitWithTimeout:10]; |  580                   }] waitWithTimeout:10]; | 
|  597 } |  581 } | 
|  598  |  582  | 
|  599 @end |  583 @end | 
| OLD | NEW |