| 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     // Due to the reloads, a timeout longer than what is provided in | 
|  321     // method that is not an EarlGrey matcher. |  322     // [ChromeEarlGrey waitForWebViewContainingText] is required, so call | 
|  322     id<GREYMatcher> web_view_match = nil; |  323     // WebViewContainingText directly. | 
|  323     web_view_match = chrome_test_util::WebViewContainingText(kContentToKeep); |  324     GREYAssert(testing::WaitUntilConditionOrTimeout( | 
|  324     ConditionBlock wait_for_loading = ^{ |  325                    kLoadOfflineTimeout, | 
|  325       NSError* error = nil; |  326                    ^bool { | 
|  326       [[EarlGrey selectElementWithMatcher:web_view_match] |  327                      return web::test::IsWebViewContainingText( | 
|  327           assertWithMatcher:grey_notNil() |  328                          chrome_test_util::GetCurrentWebState(), | 
|  328                       error:&error]; |  329                          kContentToKeep); | 
|  329       return error == nil; |  330                    }), | 
|  330     }; |  331                @"Waiting for online page."); | 
|  331     GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, |  | 
|  332                                                     wait_for_loading), |  | 
|  333                @"Page did not load."); |  | 
|  334   } else { |  332   } else { | 
|  335     [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; |  333     [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 
|  336   } |  334   } | 
|  337  |  335  | 
|  338   // Test Omnibox URL |  336   // Test Omnibox URL | 
|  339   GURL distillableURL = web::test::HttpServer::MakeUrl(kDistillableURL); |  337   GURL distillableURL = web::test::HttpServer::MakeUrl(kDistillableURL); | 
|  340   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  338   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  341                                           distillableURL.GetContent())] |  339                                           distillableURL.GetContent())] | 
|  342       assertWithMatcher:grey_notNil()]; |  340       assertWithMatcher:grey_notNil()]; | 
|  343  |  341  | 
|  344   // Test presence of online page |  342   // 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) { |  343   if (online) { | 
 |  344     [ChromeEarlGrey | 
 |  345         waitForWebViewContainingText:base::SysNSStringToUTF8(contentToKeep)]; | 
|  351     [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; |  346     [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 
|  352   } else { |  347   } else { | 
 |  348     // TODO(crbug.com/714157): Remove matcher that asserts grey_nil(). | 
 |  349     [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 
 |  350                                             kContentToKeep)] | 
 |  351         assertWithMatcher:grey_nil()]; | 
|  353     [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; |  352     [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 
|  354   } |  353   } | 
|  355  |  354  | 
|  356   // Test the presence of the omnibox offline chip. |  355   // Test the presence of the omnibox offline chip. | 
|  357   [[EarlGrey |  356   [[EarlGrey | 
|  358       selectElementWithMatcher:grey_allOf( |  357       selectElementWithMatcher:grey_allOf( | 
|  359                                    chrome_test_util::PageSecurityInfoButton(), |  358                                    chrome_test_util::PageSecurityInfoButton(), | 
|  360                                    chrome_test_util::ButtonWithImage( |  359                                    chrome_test_util::ButtonWithImage( | 
|  361                                        IDR_IOS_OMNIBOX_OFFLINE), |  360                                        IDR_IOS_OMNIBOX_OFFLINE), | 
|  362                                    nil)] |  361                                    nil)] | 
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  796       assertWithMatcher:grey_nil()]; |  795       assertWithMatcher:grey_nil()]; | 
|  797   TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |  796   TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 
|  798   TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |  797   TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 
|  799  |  798  | 
|  800   // Verify the background string is displayed. |  799   // Verify the background string is displayed. | 
|  801   [[EarlGrey selectElementWithMatcher:EmptyBackground()] |  800   [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 
|  802       assertWithMatcher:grey_notNil()]; |  801       assertWithMatcher:grey_notNil()]; | 
|  803 } |  802 } | 
|  804  |  803  | 
|  805 @end |  804 @end | 
| OLD | NEW |