| 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 "ios/chrome/browser/experimental_flags.h" | 10 #include "ios/chrome/browser/experimental_flags.h" |
| 11 #include "ios/chrome/browser/ui/ui_util.h" | 11 #include "ios/chrome/browser/ui/ui_util.h" |
| 12 #import "ios/chrome/test/app/chrome_test_util.h" | 12 #import "ios/chrome/test/app/chrome_test_util.h" |
| 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 17 #import "ios/testing/earl_grey/disabled_test_macros.h" | 17 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| 18 #import "ios/web/public/test/http_server.h" | 18 #import "ios/web/public/test/http_server.h" |
| 19 #include "ios/web/public/test/http_server_util.h" | 19 #include "ios/web/public/test/http_server_util.h" |
| 20 #include "ios/web/public/test/response_providers/html_response_provider.h" | 20 #include "ios/web/public/test/response_providers/html_response_provider.h" |
| 21 #include "ios/web/public/test/url_test_util.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 using chrome_test_util::WebViewContainingText; | 24 using chrome_test_util::WebViewContainingText; |
| 24 using chrome_test_util::OmniboxText; | 25 using chrome_test_util::OmniboxText; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const char kTestPage1[] = "Test Page 1"; | 29 const char kTestPage1[] = "Test Page 1"; |
| 29 const char kTestPage2[] = "Test Page 2"; | 30 const char kTestPage2[] = "Test Page 2"; |
| 30 const char kTestPage3[] = "Test Page 3"; | 31 const char kTestPage3[] = "Test Page 3"; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 231 |
| 231 // Purge web view caches and pause the server to make sure that tests can | 232 // Purge web view caches and pause the server to make sure that tests can |
| 232 // verify omnibox state before server starts responding. | 233 // verify omnibox state before server starts responding. |
| 233 PurgeCachedWebViewPages(); | 234 PurgeCachedWebViewPages(); |
| 234 [self setServerPaused:YES]; | 235 [self setServerPaused:YES]; |
| 235 | 236 |
| 236 // Go back in history and verify that URL2 (committed URL) is displayed even | 237 // Go back in history and verify that URL2 (committed URL) is displayed even |
| 237 // though URL1 is a pending URL. | 238 // though URL1 is a pending URL. |
| 238 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 239 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| 239 performAction:grey_longPress()]; | 240 performAction:grey_longPress()]; |
| 240 NSString* URL1Spec = base::SysUTF8ToNSString(_testURL1.spec()); | 241 NSString* URL1Title = |
| 241 [[EarlGrey selectElementWithMatcher:grey_text(URL1Spec)] | 242 base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(_testURL1)); |
| 243 [[EarlGrey selectElementWithMatcher:grey_text(URL1Title)] |
| 242 performAction:grey_tap()]; | 244 performAction:grey_tap()]; |
| 243 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 245 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], |
| 244 @"Last request URL: %@", self.lastRequestURLSpec); | 246 @"Last request URL: %@", self.lastRequestURLSpec); |
| 245 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 247 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |
| 246 assertWithMatcher:grey_notNil()]; | 248 assertWithMatcher:grey_notNil()]; |
| 247 | 249 |
| 248 // Make server respond so URL1 becomes committed. | 250 // Make server respond so URL1 becomes committed. |
| 249 [self setServerPaused:NO]; | 251 [self setServerPaused:NO]; |
| 250 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] | 252 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |
| 251 assertWithMatcher:grey_notNil()]; | 253 assertWithMatcher:grey_notNil()]; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { | 591 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { |
| 590 return [[GREYCondition | 592 return [[GREYCondition |
| 591 conditionWithName:@"Wait for received request" | 593 conditionWithName:@"Wait for received request" |
| 592 block:^{ | 594 block:^{ |
| 593 return _responseProvider->last_request_url() == URL ? YES | 595 return _responseProvider->last_request_url() == URL ? YES |
| 594 : NO; | 596 : NO; |
| 595 }] waitWithTimeout:10]; | 597 }] waitWithTimeout:10]; |
| 596 } | 598 } |
| 597 | 599 |
| 598 @end | 600 @end |
| OLD | NEW |