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

Unified Diff: ios/chrome/browser/ui/settings/block_popups_egtest.mm

Issue 2761173002: Disallow JS execution on WebUI pages. (Closed)
Patch Set: Addressed review comments Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ios/chrome/browser/ui/toolbar/toolbar_egtest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/settings/block_popups_egtest.mm
diff --git a/ios/chrome/browser/ui/settings/block_popups_egtest.mm b/ios/chrome/browser/ui/settings/block_popups_egtest.mm
index 6aaf60933e4aa6faf8858359638e9e2c412c13e7..9c8860a25b3b154c6bb43709b5e2664a71ef04ed 100644
--- a/ios/chrome/browser/ui/settings/block_popups_egtest.mm
+++ b/ios/chrome/browser/ui/settings/block_popups_egtest.mm
@@ -39,12 +39,14 @@ namespace {
const char* kBlockPopupsUrl = "http://blockpopups";
const char* kOpenedWindowUrl = "http://openedwindow";
-// JavaScript to open a new window after a short delay.
+// Page with a button that opens a new window after a short delay.
NSString* kBlockPopupsResponseTemplate =
@"<input type=\"button\" onclick=\"setTimeout(function() {"
"window.open('%@')}, 1)\" "
- "id=\"openWindow\" "
+ "id=\"open-window\" "
"value=\"openWindow\">";
+// JavaScript that clicks that button.
+NSString* kOpenPopupScript = @"document.getElementById('open-window').click()";
const std::string kOpenedWindowResponse = "Opened window";
// Opens the block popups settings page. Must be called from the NTP.
@@ -201,8 +203,10 @@ class ScopedBlockPopupsException {
[ChromeEarlGrey loadURL:blockPopupsURL];
chrome_test_util::AssertMainTabCount(1U);
- // Tap the "Open Window" link and make sure the popup opened in a new tab.
- chrome_test_util::TapWebViewElementWithId("openWindow");
+ // Request popup and make sure the popup opened in a new tab.
+ NSError* error = nil;
+ chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error);
+ GREYAssert(!error, @"Error during script execution: %@", error);
chrome_test_util::AssertMainTabCount(2U);
// No infobar should be displayed.
@@ -229,10 +233,13 @@ class ScopedBlockPopupsException {
[ChromeEarlGrey loadURL:blockPopupsURL];
chrome_test_util::AssertMainTabCount(1U);
- // Tap the "Open Window" link, then make sure the popup was blocked and an
- // infobar was displayed. The window.open() call is run via async JS, so the
- // infobar may not open immediately.
- chrome_test_util::TapWebViewElementWithId("openWindow");
+ // Request popup, then make sure it was blocked and an infobar was displayed.
+ // The window.open() call is run via async JS, so the infobar may not open
+ // immediately.
+ NSError* error = nil;
+ chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error);
+ GREYAssert(!error, @"Error during script execution: %@", error);
+
[[GREYCondition
conditionWithName:@"Wait for blocked popups infobar to show"
block:^BOOL {
« no previous file with comments | « no previous file | ios/chrome/browser/ui/toolbar/toolbar_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698