| 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/strings/sys_string_conversions.h" |    7 #include "base/strings/sys_string_conversions.h" | 
|    8 #include "components/strings/grit/components_strings.h" |    8 #include "components/strings/grit/components_strings.h" | 
|    9 #include "ios/chrome/browser/ui/ui_util.h" |    9 #include "ios/chrome/browser/ui/ui_util.h" | 
|   10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |   10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  227 } |  227 } | 
|  228  |  228  | 
|  229 // Tests calling pushState with unicode characters. |  229 // Tests calling pushState with unicode characters. | 
|  230 - (void)testHtml5HistoryPushUnicodeCharacters { |  230 - (void)testHtml5HistoryPushUnicodeCharacters { | 
|  231   const GURL pushStateUnicodeURLEncoded = web::test::HttpServer::MakeUrl( |  231   const GURL pushStateUnicodeURLEncoded = web::test::HttpServer::MakeUrl( | 
|  232       "http://ios/testing/data/http_server_files/" |  232       "http://ios/testing/data/http_server_files/" | 
|  233       "history.html#unicode%E1%84%91"); |  233       "history.html#unicode%E1%84%91"); | 
|  234   const GURL pushStateUnicode2URLEncoded = web::test::HttpServer::MakeUrl( |  234   const GURL pushStateUnicode2URLEncoded = web::test::HttpServer::MakeUrl( | 
|  235       "http://ios/testing/data/http_server_files/" |  235       "http://ios/testing/data/http_server_files/" | 
|  236       "history.html#unicode2%E2%88%A2"); |  236       "history.html#unicode2%E2%88%A2"); | 
|  237   std::string pushStateUnicodeLabel = "Action: pushStateUnicodeᄑ"; |  237   const char pushStateUnicodeLabel[] = "Action: pushStateUnicodeᄑ"; | 
|  238   NSString* pushStateUnicodeStatus = @"pushStateUnicodeᄑ"; |  238   NSString* pushStateUnicodeStatus = @"pushStateUnicodeᄑ"; | 
|  239   std::string pushStateUnicode2Label = "Action: pushStateUnicode2∢"; |  239   const char pushStateUnicode2Label[] = "Action: pushStateUnicode2∢"; | 
|  240   NSString* pushStateUnicode2Status = @"pushStateUnicode2∢"; |  240   NSString* pushStateUnicode2Status = @"pushStateUnicode2∢"; | 
|  241  |  241  | 
|  242   web::test::SetUpFileBasedHttpServer(); |  242   web::test::SetUpFileBasedHttpServer(); | 
|  243   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)]; |  243   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)]; | 
|  244  |  244  | 
|  245   // TODO(crbug.com/643458): The fact that the URL shows %-escaped is due to |  245   // TODO(crbug.com/643458): The fact that the URL shows %-escaped is due to | 
|  246   // NSURL escaping to make UIWebView/JS happy. See if it's possible to |  246   // NSURL escaping to make UIWebView/JS happy. See if it's possible to | 
|  247   // represent differently such that it displays unescaped. |  247   // represent differently such that it displays unescaped. | 
|  248   // Do 2 push states with unicode characters. |  248   // Do 2 push states with unicode characters. | 
|  249   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode"]; |  249   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode"]; | 
|  250   [[EarlGrey |  250   [[EarlGrey | 
|  251       selectElementWithMatcher:chrome_test_util::OmniboxText( |  251       selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  252                                    pushStateUnicodeURLEncoded.GetContent())] |  252                                    pushStateUnicodeURLEncoded.GetContent())] | 
|  253       assertWithMatcher:grey_notNil()]; |  253       assertWithMatcher:grey_notNil()]; | 
|  254   [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |  254   [ChromeEarlGrey waitForWebViewContainingText:pushStateUnicodeLabel]; | 
|  255                                           pushStateUnicodeLabel)] |  | 
|  256       assertWithMatcher:grey_notNil()]; |  | 
|  257  |  255  | 
|  258   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode2"]; |  256   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode2"]; | 
|  259   [[EarlGrey |  257   [[EarlGrey | 
|  260       selectElementWithMatcher:chrome_test_util::OmniboxText( |  258       selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  261                                    pushStateUnicode2URLEncoded.GetContent())] |  259                                    pushStateUnicode2URLEncoded.GetContent())] | 
|  262       assertWithMatcher:grey_notNil()]; |  260       assertWithMatcher:grey_notNil()]; | 
|  263   [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |  261   [ChromeEarlGrey waitForWebViewContainingText:pushStateUnicode2Label]; | 
|  264                                           pushStateUnicode2Label)] |  | 
|  265       assertWithMatcher:grey_notNil()]; |  | 
|  266  |  262  | 
|  267   // Do a push state without a unicode character. |  263   // Do a push state without a unicode character. | 
|  268   const GURL pushStatePathURL = |  264   const GURL pushStatePathURL = | 
|  269       web::test::HttpServer::MakeUrl(kPushStatePathURL); |  265       web::test::HttpServer::MakeUrl(kPushStatePathURL); | 
|  270   [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"]; |  266   [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"]; | 
|  271  |  267  | 
|  272   [self assertStatusText:@"pushStatePath" |  268   [self assertStatusText:@"pushStatePath" | 
|  273                  withURL:pushStatePathURL |  269                  withURL:pushStatePathURL | 
|  274               pageLoaded:NO]; |  270               pageLoaded:NO]; | 
|  275  |  271  | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  323       assertWithMatcher:grey_notNil()]; |  319       assertWithMatcher:grey_notNil()]; | 
|  324 } |  320 } | 
|  325  |  321  | 
|  326 #pragma mark - Utility methods |  322 #pragma mark - Utility methods | 
|  327  |  323  | 
|  328 // Assert that status text |status| is displayed in the webview, that "onloaded" |  324 // Assert that status text |status| is displayed in the webview, that "onloaded" | 
|  329 // text is displayed if pageLoaded is YES, and that the URL is as expected. |  325 // text is displayed if pageLoaded is YES, and that the URL is as expected. | 
|  330 - (void)assertStatusText:(NSString*)status |  326 - (void)assertStatusText:(NSString*)status | 
|  331                  withURL:(const GURL&)urlToVerify |  327                  withURL:(const GURL&)urlToVerify | 
|  332               pageLoaded:(BOOL)pageLoaded { |  328               pageLoaded:(BOOL)pageLoaded { | 
|  333   id<GREYMatcher> pageLoadedMatcher = |  329   if (pageLoaded) { | 
|  334       pageLoaded ? chrome_test_util::WebViewContainingText("onload") |  330     [ChromeEarlGrey waitForWebViewContainingText:"onload"]; | 
|  335                  : chrome_test_util::WebViewNotContainingText("onload"); |  331   } else { | 
|  336   [[EarlGrey selectElementWithMatcher:pageLoadedMatcher] |  332     id<GREYMatcher> pageLoadedMatcher = | 
|  337       assertWithMatcher:grey_notNil()]; |  333         chrome_test_util::WebViewNotContainingText("onload"); | 
 |  334     [[EarlGrey selectElementWithMatcher:pageLoadedMatcher] | 
 |  335         assertWithMatcher:grey_notNil()]; | 
 |  336   } | 
|  338  |  337  | 
|  339   if (status != NULL) { |  338   if (status != NULL) { | 
|  340     NSString* statusLabel = [NSString stringWithFormat:@"Action: %@", status]; |  339     NSString* statusLabel = [NSString stringWithFormat:@"Action: %@", status]; | 
|  341     [[EarlGrey |  340     [ChromeEarlGrey | 
|  342         selectElementWithMatcher:chrome_test_util::WebViewContainingText( |  341         waitForWebViewContainingText:base::SysNSStringToUTF8(statusLabel)]; | 
|  343                                      base::SysNSStringToUTF8(statusLabel))] |  | 
|  344         assertWithMatcher:grey_notNil()]; |  | 
|  345   } |  342   } | 
|  346  |  343  | 
|  347   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |  344   [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|  348                                           urlToVerify.GetContent())] |  345                                           urlToVerify.GetContent())] | 
|  349       assertWithMatcher:grey_notNil()]; |  346       assertWithMatcher:grey_notNil()]; | 
|  350 } |  347 } | 
|  351  |  348  | 
|  352 @end |  349 @end | 
| OLD | NEW |