Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: ios/chrome/browser/ui/dialogs/javascript_dialog_egtest.mm

Issue 2957423002: Check page URL origin to determine JavaScript alert titles. (Closed)
Patch Set: Add string comparison unit test Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 assertWithMatcher:grey_notNil() 194 assertWithMatcher:grey_notNil()
195 error:&error]; 195 error:&error];
196 return !error; 196 return !error;
197 }; 197 };
198 GREYAssert(testing::WaitUntilConditionOrTimeout( 198 GREYAssert(testing::WaitUntilConditionOrTimeout(
199 testing::kWaitForUIElementTimeout, condition), 199 testing::kWaitForUIElementTimeout, condition),
200 @"Alert with title was not present: %@", alert_label); 200 @"Alert with title was not present: %@", alert_label);
201 } 201 }
202 202
203 void WaitForJavaScripDialogToBeShown() { 203 void WaitForJavaScripDialogToBeShown() {
204 NSString* alert_label = [DialogPresenter 204 GURL javaScriptURL = HttpServer::MakeUrl(kJavaScriptTestURL);
205 localizedTitleForJavaScriptAlertFromPage:HttpServer::MakeUrl( 205 NSString* alertLabel =
206 kJavaScriptTestURL)]; 206 [DialogPresenter localizedTitleForJavaScriptAlertFromPage:javaScriptURL
207 WaitForAlertToBeShown(alert_label); 207 mainFrameURL:javaScriptURL];
208 WaitForAlertToBeShown(alertLabel);
208 } 209 }
209 210
210 // Injects JavaScript to show a dialog with |type|, verifying that it was 211 // Injects JavaScript to show a dialog with |type|, verifying that it was
211 // properly displayed. 212 // properly displayed.
212 void ShowJavaScriptDialog(JavaScriptAlertType type) { 213 void ShowJavaScriptDialog(JavaScriptAlertType type) {
213 DisplayJavaScriptAlert(type); 214 DisplayJavaScriptAlert(type);
214 215
215 WaitForJavaScripDialogToBeShown(); 216 WaitForJavaScripDialogToBeShown();
216 217
217 // Check the message of the alert. 218 // Check the message of the alert.
218 id<GREYMatcher> messageLabel = 219 id<GREYMatcher> messageLabel =
219 chrome_test_util::StaticTextWithAccessibilityLabel( 220 chrome_test_util::StaticTextWithAccessibilityLabel(
220 GetMessageForAlertWithType(type)); 221 GetMessageForAlertWithType(type));
221 [[EarlGrey selectElementWithMatcher:messageLabel] 222 [[EarlGrey selectElementWithMatcher:messageLabel]
222 assertWithMatcher:grey_notNil()]; 223 assertWithMatcher:grey_notNil()];
223 } 224 }
224 225
225 // Assert no javascript alert is visible. 226 // Assert no javascript alert is visible.
226 void AssertJavaScriptAlertNotPresent() { 227 void AssertJavaScriptAlertNotPresent() {
227 ConditionBlock condition = ^{ 228 ConditionBlock condition = ^{
228 NSError* error = nil; 229 NSError* error = nil;
230 GURL javaScriptURL = HttpServer::MakeUrl(kJavaScriptTestURL);
229 NSString* alertLabel = [DialogPresenter 231 NSString* alertLabel = [DialogPresenter
230 localizedTitleForJavaScriptAlertFromPage:HttpServer::MakeUrl( 232 localizedTitleForJavaScriptAlertFromPage:javaScriptURL
231 kJavaScriptTestURL)]; 233 mainFrameURL:javaScriptURL];
232 id<GREYMatcher> titleLabel = 234 id<GREYMatcher> titleLabel =
233 chrome_test_util::StaticTextWithAccessibilityLabel(alertLabel); 235 chrome_test_util::StaticTextWithAccessibilityLabel(alertLabel);
234 [[EarlGrey selectElementWithMatcher:titleLabel] assertWithMatcher:grey_nil() 236 [[EarlGrey selectElementWithMatcher:titleLabel] assertWithMatcher:grey_nil()
235 error:&error]; 237 error:&error];
236 return !error; 238 return !error;
237 }; 239 };
238 240
239 GREYAssert(testing::WaitUntilConditionOrTimeout( 241 GREYAssert(testing::WaitUntilConditionOrTimeout(
240 testing::kWaitForJSCompletionTimeout, condition), 242 testing::kWaitForJSCompletionTimeout, condition),
241 @"Javascript alert title was still present"); 243 @"Javascript alert title was still present");
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // continues to animate until the dialog is closed. Disabling EarlGrey 569 // continues to animate until the dialog is closed. Disabling EarlGrey
568 // synchronization code for iPad allows the test to detect and dismiss the 570 // synchronization code for iPad allows the test to detect and dismiss the
569 // dialog while this animation is occurring. 571 // dialog while this animation is occurring.
570 if (IsIPadIdiom()) { 572 if (IsIPadIdiom()) {
571 [[GREYConfiguration sharedInstance] 573 [[GREYConfiguration sharedInstance]
572 setValue:@(NO) 574 setValue:@(NO)
573 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 575 forConfigKey:kGREYConfigKeySynchronizationEnabled];
574 } 576 }
575 577
576 // Wait for the alert to be shown. 578 // Wait for the alert to be shown.
577 NSString* alertLabel = [DialogPresenter 579 GURL javaScriptURL = HttpServer::MakeUrl(kJavaScriptTestURL);
578 localizedTitleForJavaScriptAlertFromPage:HttpServer::MakeUrl( 580 NSString* alertLabel =
579 kJavaScriptTestURL)]; 581 [DialogPresenter localizedTitleForJavaScriptAlertFromPage:javaScriptURL
582 mainFrameURL:javaScriptURL];
580 WaitForAlertToBeShown(alertLabel); 583 WaitForAlertToBeShown(alertLabel);
581 584
582 // Verify that the omnibox shows the correct URL when the dialog is visible. 585 // Verify that the omnibox shows the correct URL when the dialog is visible.
583 GURL onloadURL = HttpServer::MakeUrl(kOnLoadAlertURL); 586 GURL onloadURL = HttpServer::MakeUrl(kOnLoadAlertURL);
584 std::string title = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(onloadURL)); 587 std::string title = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(onloadURL));
585 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(title)] 588 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(title)]
586 assertWithMatcher:grey_notNil()]; 589 assertWithMatcher:grey_notNil()];
587 590
588 [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()]; 591 [[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()];
589 592
590 // Reenable synchronization on iPads now that the dialog has been dismissed. 593 // Reenable synchronization on iPads now that the dialog has been dismissed.
591 if (IsIPadIdiom()) { 594 if (IsIPadIdiom()) {
592 [[GREYConfiguration sharedInstance] 595 [[GREYConfiguration sharedInstance]
593 setValue:@(YES) 596 setValue:@(YES)
594 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 597 forConfigKey:kGREYConfigKeySynchronizationEnabled];
595 } 598 }
596 } 599 }
597 600
598 @end 601 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698