| 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 #import "base/strings/sys_string_conversions.h" |    9 #import "base/strings/sys_string_conversions.h" | 
|   10 #include "base/strings/utf_string_conversions.h" |   10 #include "base/strings/utf_string_conversions.h" | 
|   11 #include "components/strings/grit/components_strings.h" |   11 #include "components/strings/grit/components_strings.h" | 
|   12 #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h" |   12 #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h" | 
|   13 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |   13 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | 
|   14 #include "ios/chrome/browser/ui/ui_util.h" |   14 #include "ios/chrome/browser/ui/ui_util.h" | 
|   15 #include "ios/chrome/grit/ios_strings.h" |   15 #include "ios/chrome/grit/ios_strings.h" | 
|   16 #include "ios/chrome/test/app/chrome_test_util.h" |   16 #include "ios/chrome/test/app/chrome_test_util.h" | 
|   17 #import "ios/chrome/test/earl_grey/chrome_actions.h" |   17 #import "ios/chrome/test/earl_grey/chrome_actions.h" | 
|   18 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |   18 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 
|   19 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |   19 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 
|   20 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |   20 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 
|   21 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |   21 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 
|   22 #import "ios/testing/earl_grey/matchers.h" |   22 #import "ios/testing/earl_grey/matchers.h" | 
|   23 #import "ios/testing/wait_util.h" |   23 #import "ios/testing/wait_util.h" | 
 |   24 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 
|   24 #import "ios/web/public/test/http_server/http_server.h" |   25 #import "ios/web/public/test/http_server/http_server.h" | 
|   25 #include "ios/web/public/test/http_server/http_server_util.h" |   26 #include "ios/web/public/test/http_server/http_server_util.h" | 
|   26 #include "ios/web/public/test/url_test_util.h" |   27 #include "ios/web/public/test/url_test_util.h" | 
|   27 #include "ios/web/public/web_state/web_state.h" |   28 #include "ios/web/public/web_state/web_state.h" | 
|   28 #include "ui/base/l10n/l10n_util.h" |   29 #include "ui/base/l10n/l10n_util.h" | 
|   29 #include "ui/base/l10n/l10n_util_mac.h" |   30 #include "ui/base/l10n/l10n_util_mac.h" | 
|   30 #import "url/gurl.h" |   31 #import "url/gurl.h" | 
|   31  |   32  | 
|   32 #if !defined(__has_feature) || !__has_feature(objc_arc) |   33 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
|   33 #error "This file requires ARC support." |   34 #error "This file requires ARC support." | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  142     case JavaScriptAlertType::PROMPT: |  143     case JavaScriptAlertType::PROMPT: | 
|  143       return GetJavaScriptPromptTestScript(); |  144       return GetJavaScriptPromptTestScript(); | 
|  144   } |  145   } | 
|  145   GREYFail(@"JavascriptAlertType not recognized."); |  146   GREYFail(@"JavascriptAlertType not recognized."); | 
|  146   return nil; |  147   return nil; | 
|  147 } |  148 } | 
|  148  |  149  | 
|  149 // HTTP server constants. |  150 // HTTP server constants. | 
|  150  |  151  | 
|  151 // URL and response for a blank document. |  152 // URL and response for a blank document. | 
|  152 const char* kJavaScriptTestURL = "http://jsalerts"; |  153 const char kJavaScriptTestURL[] = "http://jsalerts"; | 
|  153 const char* kJavaScriptTestResponse = |  154 const char kJavaScriptTestResponse[] = | 
|  154     "<!DOCTYPE html><html><body></body></html>"; |  155     "<!DOCTYPE html><html><body></body></html>"; | 
|  155  |  156  | 
|  156 // URL and response for a page with an onload alert. |  157 // URL and response for a page with an onload alert. | 
|  157 const char* kOnLoadAlertURL = "http://onloadalert"; |  158 const char kOnLoadAlertURL[] = "http://onloadalert"; | 
|  158 const char* kOnLoadAlertResponse = |  159 const char kOnLoadAlertResponse[] = | 
|  159     "<!DOCTYPE html><html><body onload=\"alert('alert')\"></body></html>"; |  160     "<!DOCTYPE html><html><body onload=\"alert('alert')\"></body></html>"; | 
|  160  |  161  | 
|  161 // URL and response for a page with a link to |kOnLoadAlertURL|. |  162 // URL and response for a page with a link to |kOnLoadAlertURL|. | 
|  162 const char* kPageWithLinkURL = "http://pagewithlink"; |  163 const char kPageWithLinkURL[] = "http://pagewithlink"; | 
|  163 const char* kPageWithLinkResponseFormat = |  164 const char kPageWithLinkResponseFormat[] = | 
|  164     "<!DOCTYPE html><html><body><a id=\"%s\" href=\"%s\">%s</a></body></html>"; |  165     "<!DOCTYPE html><html><body><a id=\"%s\" href=\"%s\">%s</a></body></html>"; | 
|  165 const char* kPageWithLinkText = "LINK TO ONLOAD ALERT PAGE"; |  166 const char kPageWithLinkText[] = "LINK TO ONLOAD ALERT PAGE"; | 
|  166 const char* kLinkID = "link-id"; |  167 const char kLinkID[] = "link-id"; | 
|  167 std::string GetPageWithLinkResponse() { |  168 std::string GetPageWithLinkResponse() { | 
|  168   return base::SysNSStringToUTF8([NSString |  169   return base::SysNSStringToUTF8([NSString | 
|  169       stringWithFormat:@(kPageWithLinkResponseFormat), kLinkID, |  170       stringWithFormat:@(kPageWithLinkResponseFormat), kLinkID, | 
|  170                        HttpServer::MakeUrl(kOnLoadAlertURL).spec().c_str(), |  171                        HttpServer::MakeUrl(kOnLoadAlertURL).spec().c_str(), | 
|  171                        kPageWithLinkText]); |  172                        kPageWithLinkText]); | 
|  172 } |  173 } | 
|  173  |  174  | 
|  174 // Waits until |string| is displayed on the web view. |  | 
|  175 void WaitForWebDisplay(const std::string& string) { |  | 
|  176   id<GREYMatcher> response1Matcher = |  | 
|  177       chrome_test_util::WebViewContainingText(string); |  | 
|  178   [[EarlGrey selectElementWithMatcher:response1Matcher] |  | 
|  179       assertWithMatcher:grey_notNil()]; |  | 
|  180 } |  | 
|  181  |  175  | 
|  182 // Display the javascript alert. |  176 // Display the javascript alert. | 
|  183 void DisplayJavaScriptAlert(JavaScriptAlertType type) { |  177 void DisplayJavaScriptAlert(JavaScriptAlertType type) { | 
|  184   // Get the WebController. |  178   // Get the WebController. | 
|  185   web::WebState* webState = chrome_test_util::GetCurrentWebState(); |  179   web::WebState* webState = chrome_test_util::GetCurrentWebState(); | 
|  186  |  180  | 
|  187   // Evaluate JavaScript. |  181   // Evaluate JavaScript. | 
|  188   NSString* script = GetScriptForAlertWithType(type); |  182   NSString* script = GetScriptForAlertWithType(type); | 
|  189   webState->ExecuteJavaScript(base::SysNSStringToUTF16(script)); |  183   webState->ExecuteJavaScript(base::SysNSStringToUTF16(script)); | 
|  190 } |  184 } | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  317   if (!errorOK || !errorCancel) { |  311   if (!errorOK || !errorCancel) { | 
|  318     GREYFail(@"There are still alerts"); |  312     GREYFail(@"There are still alerts"); | 
|  319   } |  313   } | 
|  320   [super tearDown]; |  314   [super tearDown]; | 
|  321 } |  315 } | 
|  322  |  316  | 
|  323 #pragma mark - Utility |  317 #pragma mark - Utility | 
|  324  |  318  | 
|  325 - (void)loadBlankTestPage { |  319 - (void)loadBlankTestPage { | 
|  326   [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kJavaScriptTestURL)]; |  320   [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kJavaScriptTestURL)]; | 
|  327   WaitForWebDisplay(std::string()); |  321   [ChromeEarlGrey waitForWebViewContainingText:std::string()]; | 
|  328 } |  322 } | 
|  329  |  323  | 
|  330 - (void)loadPageWithLink { |  324 - (void)loadPageWithLink { | 
|  331   [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kPageWithLinkURL)]; |  325   [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kPageWithLinkURL)]; | 
|  332   WaitForWebDisplay(kPageWithLinkText); |  326   [ChromeEarlGrey waitForWebViewContainingText:kPageWithLinkText]; | 
|  333 } |  327 } | 
|  334  |  328  | 
|  335 #pragma mark - Tests |  329 #pragma mark - Tests | 
|  336  |  330  | 
|  337 // Tests that an alert is shown, and that the completion block is called. |  331 // Tests that an alert is shown, and that the completion block is called. | 
|  338 - (void)testShowJavaScriptAlert { |  332 - (void)testShowJavaScriptAlert { | 
|  339 // TODO(crbug.com/663026): Reenable the test for devices. |  333 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  340 #if !TARGET_IPHONE_SIMULATOR |  334 #if !TARGET_IPHONE_SIMULATOR | 
|  341   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  335   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  342                           @"alerts would prevent app alerts to present " |  336                           @"alerts would prevent app alerts to present " | 
|  343                           @"correctly."); |  337                           @"correctly."); | 
|  344 #endif |  338 #endif | 
|  345  |  339  | 
|  346   // Load the blank test page and show an alert. |  340   // Load the blank test page and show an alert. | 
|  347   [self loadBlankTestPage]; |  341   [self loadBlankTestPage]; | 
|  348   ShowJavaScriptDialog(JavaScriptAlertType::ALERT); |  342   ShowJavaScriptDialog(JavaScriptAlertType::ALERT); | 
|  349  |  343  | 
|  350   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  344   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  351  |  345  | 
|  352   // Wait for the html body to be reset to the correct value. |  346   // Wait for the html body to be reset to the correct value. | 
|  353   WaitForWebDisplay(kAlertResultBody); |  347   [ChromeEarlGrey waitForWebViewContainingText:kAlertResultBody]; | 
|  354 } |  348 } | 
|  355  |  349  | 
|  356 // Tests that a confirmation dialog is shown, and that the completion block is |  350 // Tests that a confirmation dialog is shown, and that the completion block is | 
|  357 // called with the correct value when the OK buton is tapped. |  351 // called with the correct value when the OK buton is tapped. | 
|  358 - (void)testShowJavaScriptConfirmationOK { |  352 - (void)testShowJavaScriptConfirmationOK { | 
|  359 // TODO(crbug.com/663026): Reenable the test for devices. |  353 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  360 #if !TARGET_IPHONE_SIMULATOR |  354 #if !TARGET_IPHONE_SIMULATOR | 
|  361   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  355   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  362                           @"alerts would prevent app alerts to present " |  356                           @"alerts would prevent app alerts to present " | 
|  363                           @"correctly."); |  357                           @"correctly."); | 
|  364 #endif |  358 #endif | 
|  365  |  359  | 
|  366   // Load the blank test page and show a confirmation dialog. |  360   // Load the blank test page and show a confirmation dialog. | 
|  367   [self loadBlankTestPage]; |  361   [self loadBlankTestPage]; | 
|  368   ShowJavaScriptDialog(JavaScriptAlertType::CONFIRMATION); |  362   ShowJavaScriptDialog(JavaScriptAlertType::CONFIRMATION); | 
|  369  |  363  | 
|  370   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  364   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  371  |  365  | 
|  372   // Wait for the html body to be reset to the correct value. |  366   // Wait for the html body to be reset to the correct value. | 
|  373   WaitForWebDisplay(kConfirmationResultBodyOK); |  367   [ChromeEarlGrey waitForWebViewContainingText:kConfirmationResultBodyOK]; | 
|  374 } |  368 } | 
|  375  |  369  | 
|  376 // Tests that a confirmation dialog is shown, and that the completion block is |  370 // Tests that a confirmation dialog is shown, and that the completion block is | 
|  377 // called with the correct value when the Cancel buton is tapped. |  371 // called with the correct value when the Cancel buton is tapped. | 
|  378 - (void)testShowJavaScriptConfirmationCancelled { |  372 - (void)testShowJavaScriptConfirmationCancelled { | 
|  379 // TODO(crbug.com/663026): Reenable the test for devices. |  373 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  380 #if !TARGET_IPHONE_SIMULATOR |  374 #if !TARGET_IPHONE_SIMULATOR | 
|  381   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  375   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  382                           @"alerts would prevent app alerts to present " |  376                           @"alerts would prevent app alerts to present " | 
|  383                           @"correctly."); |  377                           @"correctly."); | 
|  384 #endif |  378 #endif | 
|  385  |  379  | 
|  386   // Load the blank test page and show a confirmation dialog. |  380   // Load the blank test page and show a confirmation dialog. | 
|  387   [self loadBlankTestPage]; |  381   [self loadBlankTestPage]; | 
|  388   ShowJavaScriptDialog(JavaScriptAlertType::CONFIRMATION); |  382   ShowJavaScriptDialog(JavaScriptAlertType::CONFIRMATION); | 
|  389  |  383  | 
|  390   // Tap the Cancel button. |  384   // Tap the Cancel button. | 
|  391   TapCancel(); |  385   TapCancel(); | 
|  392  |  386  | 
|  393   // Wait for the html body to be reset to the correct value. |  387   // Wait for the html body to be reset to the correct value. | 
|  394   WaitForWebDisplay(kConfirmationResultBodyCancelled); |  388   [ChromeEarlGrey | 
 |  389       waitForWebViewContainingText:kConfirmationResultBodyCancelled]; | 
|  395 } |  390 } | 
|  396  |  391  | 
|  397 // Tests that a prompt dialog is shown, and that the completion block is called |  392 // Tests that a prompt dialog is shown, and that the completion block is called | 
|  398 // with the correct value when the OK buton is tapped. |  393 // with the correct value when the OK buton is tapped. | 
|  399 - (void)testShowJavaScriptPromptOK { |  394 - (void)testShowJavaScriptPromptOK { | 
|  400 // TODO(crbug.com/663026): Reenable the test for devices. |  395 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  401 #if !TARGET_IPHONE_SIMULATOR |  396 #if !TARGET_IPHONE_SIMULATOR | 
|  402   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  397   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  403                           @"alerts would prevent app alerts to present " |  398                           @"alerts would prevent app alerts to present " | 
|  404                           @"correctly."); |  399                           @"correctly."); | 
|  405 #endif |  400 #endif | 
|  406  |  401  | 
|  407   // Load the blank test page and show a prompt dialog. |  402   // Load the blank test page and show a prompt dialog. | 
|  408   [self loadBlankTestPage]; |  403   [self loadBlankTestPage]; | 
|  409   ShowJavaScriptDialog(JavaScriptAlertType::PROMPT); |  404   ShowJavaScriptDialog(JavaScriptAlertType::PROMPT); | 
|  410  |  405  | 
|  411   // Enter text into text field. |  406   // Enter text into text field. | 
|  412   TypeInPrompt(@(kPromptTestUserInput)); |  407   TypeInPrompt(@(kPromptTestUserInput)); | 
|  413  |  408  | 
|  414   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  409   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  415  |  410  | 
|  416   // Wait for the html body to be reset to the input text. |  411   // Wait for the html body to be reset to the input text. | 
|  417   WaitForWebDisplay(kPromptTestUserInput); |  412   [ChromeEarlGrey waitForWebViewContainingText:kPromptTestUserInput]; | 
|  418 } |  413 } | 
|  419  |  414  | 
|  420 // Tests that a prompt dialog is shown, and that the completion block is called |  415 // Tests that a prompt dialog is shown, and that the completion block is called | 
|  421 // with the correct value when the Cancel buton is tapped. |  416 // with the correct value when the Cancel buton is tapped. | 
|  422 - (void)testShowJavaScriptPromptCancelled { |  417 - (void)testShowJavaScriptPromptCancelled { | 
|  423 // TODO(crbug.com/663026): Reenable the test for devices. |  418 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  424 #if !TARGET_IPHONE_SIMULATOR |  419 #if !TARGET_IPHONE_SIMULATOR | 
|  425   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  420   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  426                           @"alerts would prevent app alerts to present " |  421                           @"alerts would prevent app alerts to present " | 
|  427                           @"correctly."); |  422                           @"correctly."); | 
|  428 #endif |  423 #endif | 
|  429  |  424  | 
|  430   // Load the blank test page and show a prompt dialog. |  425   // Load the blank test page and show a prompt dialog. | 
|  431   [self loadBlankTestPage]; |  426   [self loadBlankTestPage]; | 
|  432   ShowJavaScriptDialog(JavaScriptAlertType::PROMPT); |  427   ShowJavaScriptDialog(JavaScriptAlertType::PROMPT); | 
|  433  |  428  | 
|  434   // Enter text into text field. |  429   // Enter text into text field. | 
|  435   TypeInPrompt(@(kPromptTestUserInput)); |  430   TypeInPrompt(@(kPromptTestUserInput)); | 
|  436  |  431  | 
|  437   // Tap the Cancel button. |  432   // Tap the Cancel button. | 
|  438   TapCancel(); |  433   TapCancel(); | 
|  439  |  434  | 
|  440   // Wait for the html body to be reset to the cancel text. |  435   // Wait for the html body to be reset to the cancel text. | 
|  441   WaitForWebDisplay(kPromptResultBodyCancelled); |  436   [ChromeEarlGrey waitForWebViewContainingText:kPromptResultBodyCancelled]; | 
|  442 } |  437 } | 
|  443  |  438  | 
|  444 // Tests that JavaScript alerts that are shown in a loop can be suppressed. |  439 // Tests that JavaScript alerts that are shown in a loop can be suppressed. | 
|  445 - (void)testShowJavaScriptAlertLoop { |  440 - (void)testShowJavaScriptAlertLoop { | 
|  446   // Load the blank test page and show alerts in a loop. |  441   // Load the blank test page and show alerts in a loop. | 
|  447   [self loadBlankTestPage]; |  442   [self loadBlankTestPage]; | 
|  448   web::WebState* webState = chrome_test_util::GetCurrentWebState(); |  443   web::WebState* webState = chrome_test_util::GetCurrentWebState(); | 
|  449   NSString* script = GetJavaScriptAlertLoopScript(); |  444   NSString* script = GetJavaScriptAlertLoopScript(); | 
|  450   webState->ExecuteJavaScript(base::SysNSStringToUTF16(script)); |  445   webState->ExecuteJavaScript(base::SysNSStringToUTF16(script)); | 
|  451   WaitForJavaScripDialogToBeShown(); |  446   WaitForJavaScripDialogToBeShown(); | 
|  452  |  447  | 
|  453   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  448   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  454   WaitForJavaScripDialogToBeShown(); |  449   WaitForJavaScripDialogToBeShown(); | 
|  455  |  450  | 
|  456   // Tap the suppress dialogs button. |  451   // Tap the suppress dialogs button. | 
|  457   TapSuppressDialogsButton(); |  452   TapSuppressDialogsButton(); | 
|  458  |  453  | 
|  459   // Wait for confirmation action sheet to be shown. |  454   // Wait for confirmation action sheet to be shown. | 
|  460   NSString* alertLabel = |  455   NSString* alertLabel = | 
|  461       l10n_util::GetNSString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION); |  456       l10n_util::GetNSString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION); | 
|  462   WaitForAlertToBeShown(alertLabel); |  457   WaitForAlertToBeShown(alertLabel); | 
|  463  |  458  | 
|  464   // Tap the suppress dialogs confirmation button. |  459   // Tap the suppress dialogs confirmation button. | 
|  465   TapSuppressDialogsButton(); |  460   TapSuppressDialogsButton(); | 
|  466  |  461  | 
|  467   // Wait for the html body to be reset to the loop finished text. |  462   // Wait for the html body to be reset to the loop finished text. | 
|  468   WaitForWebDisplay(kAlertLoopFinishedText); |  463   [ChromeEarlGrey waitForWebViewContainingText:kAlertLoopFinishedText]; | 
|  469 } |  464 } | 
|  470  |  465  | 
|  471 // Tests to ensure crbug.com/658260 does not regress. |  466 // Tests to ensure crbug.com/658260 does not regress. | 
|  472 // Tests that if an alert should be called when settings are displays, the alert |  467 // Tests that if an alert should be called when settings are displays, the alert | 
|  473 // waits for the dismiss of the settings. |  468 // waits for the dismiss of the settings. | 
|  474 - (void)testShowJavaScriptBehindSettings { |  469 - (void)testShowJavaScriptBehindSettings { | 
|  475 // TODO(crbug.com/663026): Reenable the test for devices. |  470 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  476 #if !TARGET_IPHONE_SIMULATOR |  471 #if !TARGET_IPHONE_SIMULATOR | 
|  477   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  472   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  478                           @"alerts would prevent app alerts to present " |  473                           @"alerts would prevent app alerts to present " | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  498   // Close the settings. |  493   // Close the settings. | 
|  499   [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |  494   [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] | 
|  500       performAction:grey_tap()]; |  495       performAction:grey_tap()]; | 
|  501  |  496  | 
|  502   // Make sure the alert is present. |  497   // Make sure the alert is present. | 
|  503   WaitForJavaScripDialogToBeShown(); |  498   WaitForJavaScripDialogToBeShown(); | 
|  504  |  499  | 
|  505   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  500   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  506  |  501  | 
|  507   // Wait for the html body to be reset to the correct value. |  502   // Wait for the html body to be reset to the correct value. | 
|  508   WaitForWebDisplay(kAlertResultBody); |  503   [ChromeEarlGrey waitForWebViewContainingText:kAlertResultBody]; | 
|  509 } |  504 } | 
|  510  |  505  | 
|  511 // Tests that an alert is presented after displaying the share menu. |  506 // Tests that an alert is presented after displaying the share menu. | 
|  512 - (void)testShowJavaScriptAfterShareMenu { |  507 - (void)testShowJavaScriptAfterShareMenu { | 
|  513 // TODO(crbug.com/663026): Reenable the test for devices. |  508 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  514 #if !TARGET_IPHONE_SIMULATOR |  509 #if !TARGET_IPHONE_SIMULATOR | 
|  515   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  510   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  516                           @"alerts would prevent app alerts to present " |  511                           @"alerts would prevent app alerts to present " | 
|  517                           @"correctly."); |  512                           @"correctly."); | 
|  518 #endif |  513 #endif | 
|  519  |  514  | 
|  520   // Load the blank test page. |  515   // Load the blank test page. | 
|  521   [self loadBlankTestPage]; |  516   [self loadBlankTestPage]; | 
|  522  |  517  | 
|  523   [ChromeEarlGreyUI openShareMenu]; |  518   [ChromeEarlGreyUI openShareMenu]; | 
|  524  |  519  | 
|  525   // Copy URL, dismissing the share menu. |  520   // Copy URL, dismissing the share menu. | 
|  526   id<GREYMatcher> printButton = |  521   id<GREYMatcher> printButton = | 
|  527       grey_allOf(grey_accessibilityLabel(@"Copy"), |  522       grey_allOf(grey_accessibilityLabel(@"Copy"), | 
|  528                  grey_accessibilityTrait(UIAccessibilityTraitButton), nil); |  523                  grey_accessibilityTrait(UIAccessibilityTraitButton), nil); | 
|  529   [[EarlGrey selectElementWithMatcher:printButton] performAction:grey_tap()]; |  524   [[EarlGrey selectElementWithMatcher:printButton] performAction:grey_tap()]; | 
|  530  |  525  | 
|  531   // Show an alert and assert it is present. |  526   // Show an alert and assert it is present. | 
|  532   ShowJavaScriptDialog(JavaScriptAlertType::ALERT); |  527   ShowJavaScriptDialog(JavaScriptAlertType::ALERT); | 
|  533  |  528  | 
|  534   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; |  529   [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; | 
|  535  |  530  | 
|  536   // Wait for the html body to be reset to the correct value. |  531   // Wait for the html body to be reset to the correct value. | 
|  537   WaitForWebDisplay(kAlertResultBody); |  532   [ChromeEarlGrey waitForWebViewContainingText:kAlertResultBody]; | 
|  538 } |  533 } | 
|  539  |  534  | 
|  540 // Tests that an alert is presented after a new tab animation is finished. |  535 // Tests that an alert is presented after a new tab animation is finished. | 
|  541 - (void)testShowJavaScriptAfterNewTabAnimation { |  536 - (void)testShowJavaScriptAfterNewTabAnimation { | 
|  542 // TODO(crbug.com/663026): Reenable the test for devices. |  537 // TODO(crbug.com/663026): Reenable the test for devices. | 
|  543 #if !TARGET_IPHONE_SIMULATOR |  538 #if !TARGET_IPHONE_SIMULATOR | 
|  544   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |  539   EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 
|  545                           @"alerts would prevent app alerts to present " |  540                           @"alerts would prevent app alerts to present " | 
|  546                           @"correctly."); |  541                           @"correctly."); | 
|  547 #endif |  542 #endif | 
|  548  |  543  | 
|  549   // Load the test page with a link to kOnLoadAlertURL and long tap on the link. |  544   // Load the test page with a link to kOnLoadAlertURL and long tap on the link. | 
|  550   [self loadPageWithLink]; |  545   [self loadPageWithLink]; | 
 |  546  | 
 |  547   // TODO(crbug.com/712358): Use method LongPressElementAndTapOnButton once | 
 |  548   // it is moved out of context_menu_egtests.mm and into a shared location. | 
 |  549   [ChromeEarlGrey waitForWebViewContainingText:kPageWithLinkText]; | 
|  551   id<GREYMatcher> webViewMatcher = |  550   id<GREYMatcher> webViewMatcher = | 
|  552       chrome_test_util::WebViewContainingText(std::string(kPageWithLinkText)); |  551       web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | 
 |  552  | 
|  553   [[EarlGrey selectElementWithMatcher:webViewMatcher] |  553   [[EarlGrey selectElementWithMatcher:webViewMatcher] | 
|  554       performAction:chrome_test_util::LongPressElementForContextMenu( |  554       performAction:chrome_test_util::LongPressElementForContextMenu( | 
|  555                         kLinkID, true /* menu should appear */)]; |  555                         kLinkID, true /* menu should appear */)]; | 
|  556  |  556  | 
|  557   // Tap on the "Open In New Tab" button. |  557   // Tap on the "Open In New Tab" button. | 
|  558   id<GREYMatcher> newTabMatcher = testing::ContextMenuItemWithText( |  558   id<GREYMatcher> newTabMatcher = testing::ContextMenuItemWithText( | 
|  559       l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)); |  559       l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 
|  560   [[EarlGrey selectElementWithMatcher:newTabMatcher] performAction:grey_tap()]; |  560   [[EarlGrey selectElementWithMatcher:newTabMatcher] performAction:grey_tap()]; | 
|  561  |  561  | 
|  562   // This test case requires that a dialog is presented in the onload event so |  562   // This test case requires that a dialog is presented in the onload event so | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  589  |  589  | 
|  590   // Reenable synchronization on iPads now that the dialog has been dismissed. |  590   // Reenable synchronization on iPads now that the dialog has been dismissed. | 
|  591   if (IsIPadIdiom()) { |  591   if (IsIPadIdiom()) { | 
|  592     [[GREYConfiguration sharedInstance] |  592     [[GREYConfiguration sharedInstance] | 
|  593             setValue:@(YES) |  593             setValue:@(YES) | 
|  594         forConfigKey:kGREYConfigKeySynchronizationEnabled]; |  594         forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 
|  595   } |  595   } | 
|  596 } |  596 } | 
|  597  |  597  | 
|  598 @end |  598 @end | 
| OLD | NEW |