Chromium Code Reviews| 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 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> | 
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> | 
| 8 | 8 | 
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" | 
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 
| 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 
| 30 #import "ios/testing/wait_util.h" | 30 #import "ios/testing/wait_util.h" | 
| 31 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" | 31 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" | 
| 32 #import "ios/web/public/navigation_manager.h" | 32 #import "ios/web/public/navigation_manager.h" | 
| 33 #import "ios/web/public/reload_type.h" | 33 #import "ios/web/public/reload_type.h" | 
| 34 #import "ios/web/public/test/http_server/delayed_response_provider.h" | 34 #import "ios/web/public/test/http_server/delayed_response_provider.h" | 
| 35 #import "ios/web/public/test/http_server/html_response_provider.h" | 35 #import "ios/web/public/test/http_server/html_response_provider.h" | 
| 36 #import "ios/web/public/test/http_server/http_server.h" | 36 #import "ios/web/public/test/http_server/http_server.h" | 
| 37 #include "ios/web/public/test/http_server/http_server_util.h" | 37 #include "ios/web/public/test/http_server/http_server_util.h" | 
| 38 #import "ios/web/public/test/web_view_content_test_util.h" | |
| 38 #include "net/base/network_change_notifier.h" | 39 #include "net/base/network_change_notifier.h" | 
| 39 | 40 | 
| 40 #if !defined(__has_feature) || !__has_feature(objc_arc) | 41 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
| 41 #error "This file requires ARC support." | 42 #error "This file requires ARC support." | 
| 42 #endif | 43 #endif | 
| 43 | 44 | 
| 44 namespace { | 45 namespace { | 
| 45 const char kContentToRemove[] = "Text that distillation should remove."; | 46 const char kContentToRemove[] = "Text that distillation should remove."; | 
| 46 const char kContentToKeep[] = "Text that distillation should keep."; | 47 const char kContentToKeep[] = "Text that distillation should keep."; | 
| 47 const char kDistillableTitle[] = "Tomato"; | 48 const char kDistillableTitle[] = "Tomato"; | 
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 responses[non_distillable_page_url] = | 311 responses[non_distillable_page_url] = | 
| 311 "<html><head><title>greens</title></head></html>"; | 312 "<html><head><title>greens</title></head></html>"; | 
| 312 return responses; | 313 return responses; | 
| 313 } | 314 } | 
| 314 | 315 | 
| 315 // Tests that the correct version of kDistillableURL is displayed. | 316 // Tests that the correct version of kDistillableURL is displayed. | 
| 316 void AssertIsShowingDistillablePage(bool online) { | 317 void AssertIsShowingDistillablePage(bool online) { | 
| 317 NSString* contentToKeep = base::SysUTF8ToNSString(kContentToKeep); | 318 NSString* contentToKeep = base::SysUTF8ToNSString(kContentToKeep); | 
| 318 // There will be multiple reloads, wait for the page to be displayed. | 319 // There will be multiple reloads, wait for the page to be displayed. | 
| 319 if (online) { | 320 if (online) { | 
| 320 // TODO(crbug.com/707009): Remove use of WebViewContainingText, with a | 321 GREYAssert(testing::WaitUntilConditionOrTimeout( | 
| 
 
Eugene But (OOO till 7-30)
2017/06/12 03:47:11
Do you want to explain in the comments why waitFor
 
baxley
2017/06/12 16:41:17
Done.
 
 | |
| 321 // method that is not an EarlGrey matcher. | 322 kLoadOfflineTimeout, | 
| 322 id<GREYMatcher> web_view_match = nil; | 323 ^bool { | 
| 323 web_view_match = chrome_test_util::WebViewContainingText(kContentToKeep); | 324 return web::test::WebViewContainingText( | 
| 324 ConditionBlock wait_for_loading = ^{ | 325 chrome_test_util::GetCurrentWebState(), | 
| 325 NSError* error = nil; | 326 kContentToKeep); | 
| 326 [[EarlGrey selectElementWithMatcher:web_view_match] | 327 }), | 
| 327 assertWithMatcher:grey_notNil() | 328 @"Waiting for online page."); | 
| 328 error:&error]; | |
| 329 return error == nil; | |
| 330 }; | |
| 331 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, | |
| 332 wait_for_loading), | |
| 333 @"Page did not load."); | |
| 334 } else { | 329 } else { | 
| 335 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 330 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 
| 336 } | 331 } | 
| 337 | 332 | 
| 338 // Test Omnibox URL | 333 // Test Omnibox URL | 
| 339 GURL distillableURL = web::test::HttpServer::MakeUrl(kDistillableURL); | 334 GURL distillableURL = web::test::HttpServer::MakeUrl(kDistillableURL); | 
| 340 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 335 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
| 341 distillableURL.GetContent())] | 336 distillableURL.GetContent())] | 
| 342 assertWithMatcher:grey_notNil()]; | 337 assertWithMatcher:grey_notNil()]; | 
| 343 | 338 | 
| 344 // Test presence of online page | 339 // Test that the offline and online pages are properly displayed. | 
| 345 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | |
| 346 kContentToKeep)] | |
| 347 assertWithMatcher:online ? grey_notNil() : grey_nil()]; | |
| 348 | |
| 349 // Test presence of offline page. | |
| 350 if (online) { | 340 if (online) { | 
| 341 [ChromeEarlGrey | |
| 342 waitForWebViewContainingText:base::SysNSStringToUTF8(contentToKeep)]; | |
| 351 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 343 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 
| 352 } else { | 344 } else { | 
| 345 // TODO(crbug.com/714157): Remove matcher that asserts grey_nil(). | |
| 346 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | |
| 347 kContentToKeep)] | |
| 348 assertWithMatcher:grey_nil()]; | |
| 353 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 349 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 
| 354 } | 350 } | 
| 355 | 351 | 
| 356 // Test the presence of the omnibox offline chip. | 352 // Test the presence of the omnibox offline chip. | 
| 357 [[EarlGrey | 353 [[EarlGrey | 
| 358 selectElementWithMatcher:grey_allOf( | 354 selectElementWithMatcher:grey_allOf( | 
| 359 chrome_test_util::PageSecurityInfoButton(), | 355 chrome_test_util::PageSecurityInfoButton(), | 
| 360 chrome_test_util::ButtonWithImage( | 356 chrome_test_util::ButtonWithImage( | 
| 361 IDR_IOS_OMNIBOX_OFFLINE), | 357 IDR_IOS_OMNIBOX_OFFLINE), | 
| 362 nil)] | 358 nil)] | 
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 assertWithMatcher:grey_nil()]; | 792 assertWithMatcher:grey_nil()]; | 
| 797 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 793 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 
| 798 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 794 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 
| 799 | 795 | 
| 800 // Verify the background string is displayed. | 796 // Verify the background string is displayed. | 
| 801 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 797 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 
| 802 assertWithMatcher:grey_notNil()]; | 798 assertWithMatcher:grey_notNil()]; | 
| 803 } | 799 } | 
| 804 | 800 | 
| 805 @end | 801 @end | 
| OLD | NEW |