| 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 22 matching lines...) Expand all Loading... |
| 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 | 38 |
| 39 #if !defined(__has_feature) || !__has_feature(objc_arc) | 39 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 40 #error "This file requires ARC support." | 40 #error "This file requires ARC support." |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 using chrome_test_util::StaticHtmlViewContainingText; |
| 44 |
| 43 namespace { | 45 namespace { |
| 44 const char kContentToRemove[] = "Text that distillation should remove."; | 46 const char kContentToRemove[] = "Text that distillation should remove."; |
| 45 const char kContentToKeep[] = "Text that distillation should keep."; | 47 const char kContentToKeep[] = "Text that distillation should keep."; |
| 46 const char kDistillableTitle[] = "Tomato"; | 48 const char kDistillableTitle[] = "Tomato"; |
| 47 const char kDistillableURL[] = "http://potato"; | 49 const char kDistillableURL[] = "http://potato"; |
| 48 const char kNonDistillableURL[] = "http://beans"; | 50 const char kNonDistillableURL[] = "http://beans"; |
| 49 const char kReadTitle[] = "foobar"; | 51 const char kReadTitle[] = "foobar"; |
| 50 const char kReadURL[] = "http://readfoobar.com"; | 52 const char kReadURL[] = "http://readfoobar.com"; |
| 51 const char kUnreadTitle[] = "I am an unread entry"; | 53 const char kUnreadTitle[] = "I am an unread entry"; |
| 52 const char kUnreadURL[] = "http://unreadfoobar.com"; | 54 const char kUnreadURL[] = "http://unreadfoobar.com"; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 "</article>" + content_to_remove * 20 + "</html>"; | 288 "</article>" + content_to_remove * 20 + "</html>"; |
| 287 const GURL non_distillable_page_url = | 289 const GURL non_distillable_page_url = |
| 288 web::test::HttpServer::MakeUrl(kNonDistillableURL); | 290 web::test::HttpServer::MakeUrl(kNonDistillableURL); |
| 289 responses[non_distillable_page_url] = | 291 responses[non_distillable_page_url] = |
| 290 "<html><head><title>greens</title></head></html>"; | 292 "<html><head><title>greens</title></head></html>"; |
| 291 return responses; | 293 return responses; |
| 292 } | 294 } |
| 293 | 295 |
| 294 // Tests that the correct version of kDistillableURL is displayed. | 296 // Tests that the correct version of kDistillableURL is displayed. |
| 295 void AssertIsShowingDistillablePage(bool online) { | 297 void AssertIsShowingDistillablePage(bool online) { |
| 296 // There will be multiple reload. Wait. | 298 NSString* contentToKeep = base::SysUTF8ToNSString(kContentToKeep); |
| 297 id<GREYMatcher> web_view_match = nil; | 299 // There will be multiple reloads, wait for the page to be displayed. |
| 298 if (online) { | 300 if (online) { |
| 301 // TODO(crbug.com/707009): Remove use of WebViewContainingText, with a |
| 302 // method that is not an EarlGrey matcher. |
| 303 id<GREYMatcher> web_view_match = nil; |
| 299 web_view_match = chrome_test_util::WebViewContainingText(kContentToKeep); | 304 web_view_match = chrome_test_util::WebViewContainingText(kContentToKeep); |
| 305 ConditionBlock wait_for_loading = ^{ |
| 306 NSError* error = nil; |
| 307 [[EarlGrey selectElementWithMatcher:web_view_match] |
| 308 assertWithMatcher:grey_notNil() |
| 309 error:&error]; |
| 310 return error == nil; |
| 311 }; |
| 312 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, |
| 313 wait_for_loading), |
| 314 @"Page did not load."); |
| 300 } else { | 315 } else { |
| 301 web_view_match = chrome_test_util::StaticHtmlViewContainingText( | 316 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep |
| 302 base::SysUTF8ToNSString(kContentToKeep)); | 317 isTextPresent:YES]; |
| 303 } | 318 } |
| 304 ConditionBlock wait_for_loading = ^{ | |
| 305 NSError* error = nil; | |
| 306 [[EarlGrey selectElementWithMatcher:web_view_match] | |
| 307 assertWithMatcher:grey_notNil() | |
| 308 error:&error]; | |
| 309 return error == nil; | |
| 310 }; | |
| 311 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, | |
| 312 wait_for_loading), | |
| 313 @"Page did not load."); | |
| 314 | 319 |
| 315 // Test Omnibox URL | 320 // Test Omnibox URL |
| 316 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 321 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 317 "localhost:8080/potato/")] | 322 "localhost:8080/potato/")] |
| 318 assertWithMatcher:grey_notNil()]; | 323 assertWithMatcher:grey_notNil()]; |
| 319 | 324 |
| 320 // Test presence of online page | 325 // Test presence of online page |
| 321 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 326 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 322 kContentToKeep)] | 327 kContentToKeep)] |
| 323 assertWithMatcher:online ? grey_notNil() : grey_nil()]; | 328 assertWithMatcher:online ? grey_notNil() : grey_nil()]; |
| 324 | 329 |
| 325 // Test presence of offline page | 330 // Test presence of offline page |
| 326 [[EarlGrey | 331 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep |
| 327 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText( | 332 isTextPresent:!online]; |
| 328 base::SysUTF8ToNSString(kContentToKeep))] | |
| 329 assertWithMatcher:online ? grey_nil() : grey_notNil()]; | |
| 330 | 333 |
| 331 // Test the presence of the omnibox offline chip. | 334 // Test the presence of the omnibox offline chip. |
| 332 [[EarlGrey | 335 [[EarlGrey |
| 333 selectElementWithMatcher:grey_allOf( | 336 selectElementWithMatcher:grey_allOf( |
| 334 chrome_test_util::PageSecurityInfoButton(), | 337 chrome_test_util::PageSecurityInfoButton(), |
| 335 chrome_test_util::ButtonWithImage( | 338 chrome_test_util::ButtonWithImage( |
| 336 IDR_IOS_OMNIBOX_OFFLINE), | 339 IDR_IOS_OMNIBOX_OFFLINE), |
| 337 nil)] | 340 nil)] |
| 338 assertWithMatcher:online ? grey_nil() : grey_notNil()]; | 341 assertWithMatcher:online ? grey_nil() : grey_notNil()]; |
| 339 } | 342 } |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 assertWithMatcher:grey_nil()]; | 748 assertWithMatcher:grey_nil()]; |
| 746 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 749 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |
| 747 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 750 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 748 | 751 |
| 749 // Verify the background string is displayed. | 752 // Verify the background string is displayed. |
| 750 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 753 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 751 assertWithMatcher:grey_notNil()]; | 754 assertWithMatcher:grey_notNil()]; |
| 752 } | 755 } |
| 753 | 756 |
| 754 @end | 757 @end |
| OLD | NEW |