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

Side by Side Diff: ios/chrome/browser/ui/toolbar/toolbar_egtest.mm

Issue 2761173002: Disallow JS execution on WebUI pages. (Closed)
Patch Set: Actually fixed ToolbarTestCase 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 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 <XCTest/XCTest.h> 6 #import <XCTest/XCTest.h>
7 7
8 #include "base/ios/ios_util.h" 8 #include "base/ios/ios_util.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 10 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 333 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
334 assertWithMatcher:chrome_test_util::OmniboxText("")]; 334 assertWithMatcher:chrome_test_util::OmniboxText("")];
335 } 335 }
336 336
337 // Types JavaScript into Omnibox and verify that an alert is displayed. 337 // Types JavaScript into Omnibox and verify that an alert is displayed.
338 - (void)testTypeJavaScriptIntoOmnibox { 338 - (void)testTypeJavaScriptIntoOmnibox {
339 // TODO(crbug.com/642544): Enable the test for iPad when typing bug is fixed. 339 // TODO(crbug.com/642544): Enable the test for iPad when typing bug is fixed.
340 if (IsIPadIdiom() && base::ios::IsRunningOnIOS10OrLater()) { 340 if (IsIPadIdiom() && base::ios::IsRunningOnIOS10OrLater()) {
341 EARL_GREY_TEST_DISABLED(@"Disabled for iOS10 iPad due to a typing bug."); 341 EARL_GREY_TEST_DISABLED(@"Disabled for iOS10 iPad due to a typing bug.");
342 } 342 }
343 [ChromeEarlGrey loadURL:GURL("chrome://version")]; 343
344 std::map<GURL, std::string> responses;
345 GURL URL = web::test::HttpServer::MakeUrl("http://foo");
346 responses[URL] = "bar";
347 web::test::SetUpSimpleHttpServer(responses);
348 [ChromeEarlGrey loadURL:GURL(URL)];
349
344 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 350 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
345 performAction:grey_typeText(@"javascript:alert('Hello');")]; 351 performAction:grey_typeText(@"javascript:alert('Hello');")];
346 352
347 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] 353 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
348 performAction:grey_tap()]; 354 performAction:grey_tap()];
349 355
350 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")] 356 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")]
351 assertWithMatcher:grey_notNil()]; 357 assertWithMatcher:grey_notNil()];
352 } 358 }
353 359
360 // Loads WebUI page, types JavaScript into Omnibox and verify that alert is not
lpromero 2017/03/23 12:43:48 Nit: verifies
Eugene But (OOO till 7-30) 2017/03/23 17:45:08 Done.
361 // displayed. WebUI pages have elevated previledges and should not allow script
lpromero 2017/03/23 12:43:48 Nit: privileges
Eugene But (OOO till 7-30) 2017/03/23 17:45:08 Done.
362 // execution.
363 - (void)testTypeJavaScriptIntoOmniboxWithWebUIPage {
364 // TODO(crbug.com/642544): Enable the test for iPad when typing bug is fixed.
365 if (IsIPadIdiom() && base::ios::IsRunningOnIOS10OrLater()) {
366 EARL_GREY_TEST_DISABLED(@"Disabled for iOS10 iPad due to a typing bug.");
367 }
368 [ChromeEarlGrey loadURL:GURL("chrome://version")];
369 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
370 performAction:grey_typeText(@"javascript:alert('Hello');")];
371
372 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
373 performAction:grey_tap()];
374
375 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hello")]
376 assertWithMatcher:grey_nil()];
377 }
378
354 // Tests typing in the omnibox. 379 // Tests typing in the omnibox.
355 - (void)testToolbarOmniboxTyping { 380 - (void)testToolbarOmniboxTyping {
356 SelectNewTabPagePanel(NewTabPage::kMostVisitedPanel); 381 SelectNewTabPagePanel(NewTabPage::kMostVisitedPanel);
357 382
358 id<GREYMatcher> locationbarButton = grey_allOf( 383 id<GREYMatcher> locationbarButton = grey_allOf(
359 grey_accessibilityLabel(l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)), 384 grey_accessibilityLabel(l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)),
360 grey_minimumVisiblePercent(0.2), nil); 385 grey_minimumVisiblePercent(0.2), nil);
361 [[EarlGrey selectElementWithMatcher:locationbarButton] 386 [[EarlGrey selectElementWithMatcher:locationbarButton]
362 assertWithMatcher:grey_text(@"Search or type URL")]; 387 assertWithMatcher:grey_text(@"Search or type URL")];
363 388
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 469
445 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(clearText)] 470 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(clearText)]
446 performAction:grey_tap()]; 471 performAction:grey_tap()];
447 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 472 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
448 assertWithMatcher:chrome_test_util::OmniboxText("")]; 473 assertWithMatcher:chrome_test_util::OmniboxText("")];
449 474
450 SelectNewTabPagePanel(NewTabPage::kMostVisitedPanel); 475 SelectNewTabPagePanel(NewTabPage::kMostVisitedPanel);
451 } 476 }
452 } 477 }
453 @end 478 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698