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" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 306 |
307 // Dismiss JavaScript alert by tapping Cancel. | 307 // Dismiss JavaScript alert by tapping Cancel. |
308 [[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()] | 308 [[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()] |
309 performAction:grey_tap() | 309 performAction:grey_tap() |
310 error:&errorCancel]; | 310 error:&errorCancel]; |
311 // Dismiss JavaScript alert by tapping OK. | 311 // Dismiss JavaScript alert by tapping OK. |
312 id<GREYMatcher> OKButton = | 312 id<GREYMatcher> OKButton = |
313 chrome_test_util::ButtonWithAccessibilityLabelId(IDS_OK); | 313 chrome_test_util::ButtonWithAccessibilityLabelId(IDS_OK); |
314 [[EarlGrey selectElementWithMatcher:OKButton] performAction:grey_tap() | 314 [[EarlGrey selectElementWithMatcher:OKButton] performAction:grey_tap() |
315 error:&errorOK]; | 315 error:&errorOK]; |
316 // Reenable synchronization in case it was disabled by a test. See comments | |
317 // in testShowJavaScriptAfterNewTabAnimation for details. | |
318 [[GREYConfiguration sharedInstance] | |
319 setValue:@(YES) | |
320 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | |
baxley
2017/04/19 19:50:39
sorry for the churn, what do you think about doing
| |
316 | 321 |
317 if (!errorOK || !errorCancel) { | 322 if (!errorOK || !errorCancel) { |
318 GREYFail(@"There are still alerts"); | 323 GREYFail(@"There are still alerts"); |
319 } | 324 } |
320 [super tearDown]; | 325 [super tearDown]; |
321 } | 326 } |
322 | 327 |
323 #pragma mark - Utility | 328 #pragma mark - Utility |
324 | 329 |
325 - (void)loadBlankTestPage { | 330 - (void)loadBlankTestPage { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 | 553 |
549 // Tests that an alert is presented after a new tab animation is finished. | 554 // Tests that an alert is presented after a new tab animation is finished. |
550 - (void)testShowJavaScriptAfterNewTabAnimation { | 555 - (void)testShowJavaScriptAfterNewTabAnimation { |
551 // TODO(crbug.com/663026): Reenable the test for devices. | 556 // TODO(crbug.com/663026): Reenable the test for devices. |
552 #if !TARGET_IPHONE_SIMULATOR | 557 #if !TARGET_IPHONE_SIMULATOR |
553 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 558 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |
554 @"alerts would prevent app alerts to present " | 559 @"alerts would prevent app alerts to present " |
555 @"correctly."); | 560 @"correctly."); |
556 #endif | 561 #endif |
557 | 562 |
558 // TODO(crbug.com/711291): reenable this on tablets. | |
559 if (IsIPadIdiom()) { | |
560 EARL_GREY_TEST_DISABLED(@"Disabled for iPad."); | |
561 } | |
562 | |
563 // Load the test page with a link to kOnLoadAlertURL and long tap on the link. | 563 // Load the test page with a link to kOnLoadAlertURL and long tap on the link. |
564 [self loadPageWithLink]; | 564 [self loadPageWithLink]; |
565 id<GREYMatcher> webViewMatcher = | 565 id<GREYMatcher> webViewMatcher = |
566 chrome_test_util::WebViewContainingText(std::string(kPageWithLinkText)); | 566 chrome_test_util::WebViewContainingText(std::string(kPageWithLinkText)); |
567 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 567 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
568 performAction:chrome_test_util::LongPressElementForContextMenu( | 568 performAction:chrome_test_util::LongPressElementForContextMenu( |
569 kLinkID, true /* menu should appear */)]; | 569 kLinkID, true /* menu should appear */)]; |
570 | 570 |
571 // Tap on the "Open In New Tab" button. | 571 // Tap on the "Open In New Tab" button. |
572 id<GREYMatcher> newTabMatcher = testing::ContextMenuItemWithText( | 572 id<GREYMatcher> newTabMatcher = testing::ContextMenuItemWithText( |
573 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 573 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
574 [[EarlGrey selectElementWithMatcher:newTabMatcher] performAction:grey_tap()]; | 574 [[EarlGrey selectElementWithMatcher:newTabMatcher] performAction:grey_tap()]; |
575 | 575 |
576 // This test case requires that a dialog is presented in the onload event so | |
577 // that the DialogPresenter attempts to display during a new tab animation. | |
578 // Because presenting a dialog halts the JavaScript execution on the page, | |
579 // this prevents the page loaded event from being received until the alert is | |
580 // closed. On iPad, this means that there is a loading indicator that | |
581 // continues to animate until the dialog is closed. Disabling EarlGrey | |
582 // synchronization code for iPad allows the test to detect and dismiss the | |
583 // dialog while this animation is occurring. | |
584 if (IsIPadIdiom()) { | |
585 [[GREYConfiguration sharedInstance] | |
586 setValue:@(NO) | |
587 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | |
588 } | |
589 | |
576 // Wait for the alert to be shown. | 590 // Wait for the alert to be shown. |
577 NSString* alertLabel = [DialogPresenter | 591 NSString* alertLabel = [DialogPresenter |
578 localizedTitleForJavaScriptAlertFromPage:HttpServer::MakeUrl( | 592 localizedTitleForJavaScriptAlertFromPage:HttpServer::MakeUrl( |
579 kJavaScriptTestURL)]; | 593 kJavaScriptTestURL)]; |
580 WaitForAlertToBeShown(alertLabel); | 594 WaitForAlertToBeShown(alertLabel); |
581 | 595 |
582 // Verify that the omnibox shows the correct URL when the dialog is visible. | 596 // Verify that the omnibox shows the correct URL when the dialog is visible. |
583 GURL onloadURL = HttpServer::MakeUrl(kOnLoadAlertURL); | 597 GURL onloadURL = HttpServer::MakeUrl(kOnLoadAlertURL); |
584 std::string title = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(onloadURL)); | 598 std::string title = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(onloadURL)); |
585 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(title)] | 599 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(title)] |
586 assertWithMatcher:grey_notNil()]; | 600 assertWithMatcher:grey_notNil()]; |
587 | 601 |
588 // Close the alert. | 602 // Close the alert. |
589 TapOK(); | 603 TapOK(); |
604 | |
605 // Reenable synchronization on iPads now that the dialog has been dismissed. | |
606 if (IsIPadIdiom()) { | |
607 [[GREYConfiguration sharedInstance] | |
608 setValue:@(YES) | |
609 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | |
610 } | |
590 } | 611 } |
591 | 612 |
592 @end | 613 @end |
OLD | NEW |