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

Side by Side Diff: chrome/browser/extensions/extension_browsertests_misc.cc

Issue 172120: Revert "Revert "Allow DOMUI pages to call window.open(), giving DOMUI privileges to the new"" (Closed)
Patch Set: Created 11 years, 3 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
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_factory.cc ('k') | chrome/browser/extensions/extension_dom_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "base/ref_counted.h" 5 #include "base/ref_counted.h"
6 #include "chrome/browser/browser.h" 6 #include "chrome/browser/browser.h"
7 #include "chrome/browser/browser_list.h" 7 #include "chrome/browser/browser_list.h"
8 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 494
495 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 495 ExtensionsService* service = browser()->profile()->GetExtensionsService();
496 EXPECT_EQ(0u, service->extensions()->size()); 496 EXPECT_EQ(0u, service->extensions()->size());
497 ASSERT_EQ(1u, service->disabled_extensions()->size()); 497 ASSERT_EQ(1u, service->disabled_extensions()->size());
498 498
499 // Now try uninstalling it. 499 // Now try uninstalling it.
500 UninstallExtension(service->disabled_extensions()->at(0)->id()); 500 UninstallExtension(service->disabled_extensions()->at(0)->id());
501 EXPECT_EQ(0u, service->extensions()->size()); 501 EXPECT_EQ(0u, service->extensions()->size());
502 EXPECT_EQ(0u, service->disabled_extensions()->size()); 502 EXPECT_EQ(0u, service->disabled_extensions()->size());
503 } 503 }
504
505 // Helper function for common code shared by the 3 WindowOpen tests below.
506 static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url,
507 const std::string& newtab_url) {
508 ui_test_utils::NavigateToURL(browser, start_url);
509
510 bool result = false;
511 ui_test_utils::ExecuteJavaScriptAndExtractBool(
512 browser->GetSelectedTabContents()->render_view_host(), L"",
513 L"window.open('" + UTF8ToWide(newtab_url) + L"');"
514 L"window.domAutomationController.send(true);", &result);
515 EXPECT_TRUE(result);
516
517 // Now the current tab should be the new tab.
518 TabContents* newtab = browser->GetSelectedTabContents();
519 GURL expected_url = start_url.Resolve(newtab_url);
520 if (newtab->GetURL() != expected_url) {
521 ui_test_utils::WaitForNavigation(
522 &browser->GetSelectedTabContents()->controller());
523 }
524 EXPECT_EQ(newtab->GetURL(), expected_url);
525
526 return newtab;
527 }
528
529 // Tests that an extension page can call window.open to an extension URL and
530 // the new window has extension privileges.
531 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
532 ASSERT_TRUE(LoadExtension(
533 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
534
535 TabContents* newtab = WindowOpenHelper(
536 browser(),
537 GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html"),
538 "newtab.html");
539
540 bool result = false;
541 ui_test_utils::ExecuteJavaScriptAndExtractBool(
542 newtab->render_view_host(), L"", L"testExtensionApi()", &result);
543 EXPECT_TRUE(result);
544 }
545
546 // Tests that if an extension page calls window.open to an invalid extension
547 // URL, the browser doesn't crash.
548 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
549 ASSERT_TRUE(LoadExtension(
550 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
551
552 TabContents* newtab = WindowOpenHelper(
553 browser(),
554 GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html"),
555 "chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab/newtab.html");
556
557 // If we got to this point, we didn't crash, so we're good.
558 }
559
560 // Tests that calling window.open from the newtab page to an extension URL
561 // does not give the new window extension privileges - because the opening page
562 // does not have extension privileges.
563 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
564 ASSERT_TRUE(LoadExtension(
565 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
566
567 TabContents* newtab = WindowOpenHelper(
568 browser(),
569 GURL("about:blank"),
570 "chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/newtab.html");
571
572 // Extension API should fail.
573 bool result = false;
574 ui_test_utils::ExecuteJavaScriptAndExtractBool(
575 newtab->render_view_host(), L"", L"testExtensionApi()", &result);
576 EXPECT_FALSE(result);
577 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_factory.cc ('k') | chrome/browser/extensions/extension_dom_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698