| 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.h" | 34 #import "ios/web/public/test/http_server.h" |
| 35 #import "ios/web/public/test/http_server_util.h" | 35 #import "ios/web/public/test/http_server_util.h" |
| 36 #import "ios/web/public/test/response_providers/delayed_response_provider.h" | 36 #import "ios/web/public/test/response_providers/delayed_response_provider.h" |
| 37 #import "ios/web/public/test/response_providers/html_response_provider.h" | 37 #import "ios/web/public/test/response_providers/html_response_provider.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( |
| 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 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 334 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 340 "localhost:8080/potato/")] | 335 "localhost:8080/potato/")] |
| 341 assertWithMatcher:grey_notNil()]; | 336 assertWithMatcher:grey_notNil()]; |
| 342 | 337 |
| 343 // Test presence of online page | 338 // Test that the offline and online pages are properly displayed. |
| 344 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | |
| 345 kContentToKeep)] | |
| 346 assertWithMatcher:online ? grey_notNil() : grey_nil()]; | |
| 347 | |
| 348 // Test presence of offline page. | |
| 349 if (online) { | 339 if (online) { |
| 340 [ChromeEarlGrey waitForWebViewContainingText:contentToKeep]; |
| 350 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 341 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; |
| 351 } else { | 342 } else { |
| 343 // TODO(crbug.com/714157): Remove matcher that asserts grey_nil(). |
| 344 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 345 kContentToKeep)] |
| 346 assertWithMatcher:grey_nil()]; |
| 352 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 347 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; |
| 353 } | 348 } |
| 354 | 349 |
| 355 // Test the presence of the omnibox offline chip. | 350 // Test the presence of the omnibox offline chip. |
| 356 [[EarlGrey | 351 [[EarlGrey |
| 357 selectElementWithMatcher:grey_allOf( | 352 selectElementWithMatcher:grey_allOf( |
| 358 chrome_test_util::PageSecurityInfoButton(), | 353 chrome_test_util::PageSecurityInfoButton(), |
| 359 chrome_test_util::ButtonWithImage( | 354 chrome_test_util::ButtonWithImage( |
| 360 IDR_IOS_OMNIBOX_OFFLINE), | 355 IDR_IOS_OMNIBOX_OFFLINE), |
| 361 nil)] | 356 nil)] |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 assertWithMatcher:grey_nil()]; | 785 assertWithMatcher:grey_nil()]; |
| 791 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 786 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |
| 792 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 787 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 793 | 788 |
| 794 // Verify the background string is displayed. | 789 // Verify the background string is displayed. |
| 795 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 790 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 796 assertWithMatcher:grey_notNil()]; | 791 assertWithMatcher:grey_notNil()]; |
| 797 } | 792 } |
| 798 | 793 |
| 799 @end | 794 @end |
| OLD | NEW |