| 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 <XCTest/XCTest.h> |    5 #import <XCTest/XCTest.h> | 
|    6  |    6  | 
|    7 #include "base/mac/foundation_util.h" |    7 #include "base/mac/foundation_util.h" | 
|    8 #include "base/metrics/field_trial.h" |    8 #include "base/metrics/field_trial.h" | 
|    9 #include "base/strings/sys_string_conversions.h" |    9 #include "base/strings/sys_string_conversions.h" | 
|   10 #include "components/strings/grit/components_strings.h" |   10 #include "components/strings/grit/components_strings.h" | 
|   11 #include "components/version_info/version_info.h" |   11 #include "components/version_info/version_info.h" | 
|   12 #include "ios/chrome/browser/chrome_url_constants.h" |   12 #include "ios/chrome/browser/chrome_url_constants.h" | 
|   13 #include "ios/chrome/browser/experimental_flags.h" |   13 #include "ios/chrome/browser/experimental_flags.h" | 
|   14 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |   14 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" | 
|   15 #include "ios/chrome/test/app/navigation_test_util.h" |   15 #include "ios/chrome/test/app/navigation_test_util.h" | 
|   16 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |   16 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 
|   17 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |   17 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 
 |   18 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 
|   18 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |   19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 
|   19 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |   20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 
|   20 #import "ios/testing/wait_util.h" |   21 #import "ios/testing/wait_util.h" | 
|   21 #import "ios/web/public/web_client.h" |   22 #import "ios/web/public/web_client.h" | 
|   22 #include "ui/base/device_form_factor.h" |   23 #include "ui/base/device_form_factor.h" | 
|   23 #include "ui/base/l10n/l10n_util.h" |   24 #include "ui/base/l10n/l10n_util.h" | 
|   24 #include "url/scheme_host_port.h" |   25 #include "url/scheme_host_port.h" | 
|   25  |   26  | 
|   26 #if !defined(__has_feature) || !__has_feature(objc_arc) |   27 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
|   27 #error "This file requires ARC support." |   28 #error "This file requires ARC support." | 
|   28 #endif |   29 #endif | 
|   29  |   30  | 
|   30 using chrome_test_util::BackButton; |   31 using chrome_test_util::BackButton; | 
|   31 using chrome_test_util::ForwardButton; |   32 using chrome_test_util::ForwardButton; | 
|   32 using chrome_test_util::TapWebViewElementWithId; |   33 using chrome_test_util::TapWebViewElementWithId; | 
|   33 using chrome_test_util::WebViewContainingText; |  | 
|   34  |   34  | 
|   35 namespace { |   35 namespace { | 
|   36  |   36  | 
|   37 // Loads WebUI page with given |host|. |   37 // Loads WebUI page with given |host|. | 
|   38 void LoadWebUIUrl(const std::string& host) { |   38 void LoadWebUIUrl(const std::string& host) { | 
|   39   GURL web_ui_url(url::SchemeHostPort(kChromeUIScheme, host, 0).Serialize()); |   39   GURL web_ui_url(url::SchemeHostPort(kChromeUIScheme, host, 0).Serialize()); | 
|   40   [ChromeEarlGrey loadURL:web_ui_url]; |   40   [ChromeEarlGrey loadURL:web_ui_url]; | 
|   41 } |   41 } | 
|   42  |   42  | 
|   43 // Adds wait for omnibox text matcher so that omnibox text can be updated. |   43 // Adds wait for omnibox text matcher so that omnibox text can be updated. | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   79  |   79  | 
|   80 @implementation WebUITestCase |   80 @implementation WebUITestCase | 
|   81  |   81  | 
|   82 // Tests that chrome://version renders and contains correct version number and |   82 // Tests that chrome://version renders and contains correct version number and | 
|   83 // user agent string. |   83 // user agent string. | 
|   84 - (void)testVersion { |   84 - (void)testVersion { | 
|   85   LoadWebUIUrl(kChromeUIVersionHost); |   85   LoadWebUIUrl(kChromeUIVersionHost); | 
|   86  |   86  | 
|   87   // Verify that app version is present on the page. |   87   // Verify that app version is present on the page. | 
|   88   const std::string version = version_info::GetVersionNumber(); |   88   const std::string version = version_info::GetVersionNumber(); | 
|   89   [[EarlGrey selectElementWithMatcher:WebViewContainingText(version)] |   89   [ChromeEarlGrey waitForWebViewContainingText:version]; | 
|   90       assertWithMatcher:grey_notNil()]; |  | 
|   91  |   90  | 
|   92   // Verify that mobile User Agent string is present on the page. |   91   // Verify that mobile User Agent string is present on the page. | 
|   93   const std::string userAgent = |   92   const std::string userAgent = | 
|   94       web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE); |   93       web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE); | 
|   95   [[EarlGrey selectElementWithMatcher:WebViewContainingText(userAgent)] |   94   [ChromeEarlGrey waitForWebViewContainingText:userAgent]; | 
|   96       assertWithMatcher:grey_notNil()]; |  | 
|   97 } |   95 } | 
|   98  |   96  | 
|   99 // Tests that chrome://physical-web renders and the page title is present. |   97 // Tests that chrome://physical-web renders and the page title is present. | 
|  100 - (void)testPhysicalWeb { |   98 - (void)testPhysicalWeb { | 
|  101   // Enable the Physical Web via Chrome variation. |   99   // Enable the Physical Web via Chrome variation. | 
|  102   base::FieldTrialList::CreateFieldTrial("PhysicalWebEnabled", "Enabled"); |  100   base::FieldTrialList::CreateFieldTrial("PhysicalWebEnabled", "Enabled"); | 
|  103  |  101  | 
|  104   LoadWebUIUrl(kChromeUIPhysicalWebHost); |  102   LoadWebUIUrl(kChromeUIPhysicalWebHost); | 
|  105  |  103  | 
|  106   // Verify that the title string is present on the page. |  104   // Verify that the title string is present on the page. | 
|  107   std::string pageTitle = l10n_util::GetStringUTF8(IDS_PHYSICAL_WEB_UI_TITLE); |  105   const std::string pageTitle = | 
|  108   [[EarlGrey selectElementWithMatcher:WebViewContainingText(pageTitle)] |  106       l10n_util::GetStringUTF8(IDS_PHYSICAL_WEB_UI_TITLE); | 
|  109       assertWithMatcher:grey_notNil()]; |  107   [ChromeEarlGrey waitForWebViewContainingText:pageTitle]; | 
|  110 } |  108 } | 
|  111  |  109  | 
|  112 // Tests that clicking on a link for a native page from chrome://chrome-urls |  110 // Tests that clicking on a link for a native page from chrome://chrome-urls | 
|  113 // navigates to that page. |  111 // navigates to that page. | 
|  114 - (void)testChromeURLNavigateToNativePage { |  112 - (void)testChromeURLNavigateToNativePage { | 
|  115   LoadWebUIUrl(kChromeUIChromeURLsHost); |  113   LoadWebUIUrl(kChromeUIChromeURLsHost); | 
|  116  |  114  | 
|  117   // Tap on chrome://terms link on the page. |  115   // Tap on chrome://terms link on the page. | 
|  118   chrome_test_util::TapWebViewElementWithId(kChromeUITermsHost); |  116   chrome_test_util::TapWebViewElementWithId(kChromeUITermsHost); | 
|  119  |  117  | 
|  120   // Verify that the resulting page is chrome://terms. |  118   // Verify that the resulting page is chrome://terms. | 
|  121   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://terms")] |  119   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://terms")] | 
|  122       assertWithMatcher:grey_sufficientlyVisible()]; |  120       assertWithMatcher:grey_sufficientlyVisible()]; | 
|  123   const std::string kTermsText = "Google Chrome Terms of Service"; |  121   const std::string kTermsText = "Google Chrome Terms of Service"; | 
|  124   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTermsText)] |  122   [ChromeEarlGrey waitForWebViewContainingText:kTermsText]; | 
|  125       assertWithMatcher:grey_notNil()]; |  | 
|  126 } |  123 } | 
|  127  |  124  | 
|  128 // Tests that back navigation functions properly after navigation via anchor |  125 // Tests that back navigation functions properly after navigation via anchor | 
|  129 // click. |  126 // click. | 
|  130 - (void)testChromeURLBackNavigationFromAnchorClick { |  127 - (void)testChromeURLBackNavigationFromAnchorClick { | 
|  131   LoadWebUIUrl(kChromeUIChromeURLsHost); |  128   LoadWebUIUrl(kChromeUIChromeURLsHost); | 
|  132  |  129  | 
|  133   // Tap on chrome://version link on the page. |  130   // Tap on chrome://version link on the page. | 
|  134   chrome_test_util::TapWebViewElementWithId(kChromeUIVersionHost); |  131   chrome_test_util::TapWebViewElementWithId(kChromeUIVersionHost); | 
|  135  |  132  | 
|  136   // Verify that the resulting page is chrome://version. |  133   // Verify that the resulting page is chrome://version. | 
|  137   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://version")] |  134   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://version")] | 
|  138       assertWithMatcher:grey_sufficientlyVisible()]; |  135       assertWithMatcher:grey_sufficientlyVisible()]; | 
|  139   const std::string kAuthorsText = "The Chromium Authors"; |  136   [ChromeEarlGrey waitForWebViewContainingText:"The Chromium Authors"]; | 
|  140   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kAuthorsText)] |  | 
|  141       assertWithMatcher:grey_notNil()]; |  | 
|  142  |  137  | 
|  143   // Tap the back button in the toolbar and verify that the resulting page is |  138   // Tap the back button in the toolbar and verify that the resulting page is | 
|  144   // the previously visited page chrome://chrome-urls. |  139   // the previously visited page chrome://chrome-urls. | 
|  145   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |  140   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 
|  146   [[EarlGrey |  141   [[EarlGrey | 
|  147       selectElementWithMatcher:WaitForOmniboxText("chrome://chrome-urls")] |  142       selectElementWithMatcher:WaitForOmniboxText("chrome://chrome-urls")] | 
|  148       assertWithMatcher:grey_sufficientlyVisible()]; |  143       assertWithMatcher:grey_sufficientlyVisible()]; | 
|  149   const std::string kChromeURLsText = "List of Chrome URLs"; |  144   [ChromeEarlGrey waitForWebViewContainingText:"List of Chrome URLs"]; | 
|  150   [[EarlGrey selectElementWithMatcher:WebViewContainingText(kChromeURLsText)] |  | 
|  151       assertWithMatcher:grey_notNil()]; |  | 
|  152 } |  145 } | 
|  153  |  146  | 
|  154 // Tests that back and forward navigation between chrome URLs functions |  147 // Tests that back and forward navigation between chrome URLs functions | 
|  155 // properly. |  148 // properly. | 
|  156 - (void)testChromeURLBackAndForwardNavigation { |  149 - (void)testChromeURLBackAndForwardNavigation { | 
|  157   // Navigate to the first URL chrome://version. |  150   // Navigate to the first URL chrome://version. | 
|  158   LoadWebUIUrl(kChromeUIVersionHost); |  151   LoadWebUIUrl(kChromeUIVersionHost); | 
|  159  |  152  | 
|  160   // Navigate to the second URL chrome://flags. |  153   // Navigate to the second URL chrome://flags. | 
|  161   LoadWebUIUrl(kChromeUIFlagsHost); |  154   LoadWebUIUrl(kChromeUIFlagsHost); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  206   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText(kChromeInvalidURL)] |  199   [[EarlGrey selectElementWithMatcher:WaitForOmniboxText(kChromeInvalidURL)] | 
|  207       assertWithMatcher:grey_sufficientlyVisible()]; |  200       assertWithMatcher:grey_sufficientlyVisible()]; | 
|  208   NSString* kError = |  201   NSString* kError = | 
|  209       l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |  202       l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); | 
|  210   id<GREYMatcher> messageMatcher = [GREYMatchers matcherForText:kError]; |  203   id<GREYMatcher> messageMatcher = [GREYMatchers matcherForText:kError]; | 
|  211   [[EarlGrey selectElementWithMatcher:messageMatcher] |  204   [[EarlGrey selectElementWithMatcher:messageMatcher] | 
|  212       assertWithMatcher:grey_notNil()]; |  205       assertWithMatcher:grey_notNil()]; | 
|  213 } |  206 } | 
|  214  |  207  | 
|  215 @end |  208 @end | 
| OLD | NEW |