| OLD | NEW |
| 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 Loading... |
| 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 // Tests that an extension page can call window.open to an extension URL and |
| 506 // the new window has extension privileges. |
| 507 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 508 ASSERT_TRUE(LoadExtension( |
| 509 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 510 |
| 511 ui_test_utils::NavigateToURL( |
| 512 browser(), |
| 513 GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html")); |
| 514 |
| 515 bool result = false; |
| 516 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 517 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 518 L"testWindowOpen('newtab.html')", &result); |
| 519 ASSERT_TRUE(result); |
| 520 |
| 521 // Now the current tab should be the new tab. |
| 522 ui_test_utils::WaitForNavigation( |
| 523 &browser()->GetSelectedTabContents()->controller()); |
| 524 ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(), |
| 525 "/newtab.html"); |
| 526 |
| 527 result = false; |
| 528 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 529 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 530 L"testExtensionApi()", &result); |
| 531 EXPECT_TRUE(result); |
| 532 } |
| 533 |
| 534 // Tests that if an extension page calls window.open to an invalid extension |
| 535 // URL, the browser doesn't crash. |
| 536 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 537 ASSERT_TRUE(LoadExtension( |
| 538 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 539 |
| 540 ui_test_utils::NavigateToURL( |
| 541 browser(), |
| 542 GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html")); |
| 543 |
| 544 bool result = false; |
| 545 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 546 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 547 L"testWindowOpen('" |
| 548 L"chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab/newtab.html" |
| 549 L"')", &result); |
| 550 ASSERT_TRUE(result); |
| 551 |
| 552 // Now the current tab should be the new tab. |
| 553 ui_test_utils::WaitForNavigation( |
| 554 &browser()->GetSelectedTabContents()->controller()); |
| 555 ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(), |
| 556 "/newtab.html"); |
| 557 |
| 558 // If we got to this point, we didn't crash, so we're good. |
| 559 } |
| 560 |
| 561 // Tests that calling window.open from the newtab page to an extension URL |
| 562 // does not give the new window extension privileges - because the opening page |
| 563 // does not have extension privileges. |
| 564 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 565 ASSERT_TRUE(LoadExtension( |
| 566 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 567 |
| 568 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 569 |
| 570 bool result = false; |
| 571 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 572 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 573 L"window.open('" |
| 574 L"chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/newtab.html" |
| 575 L"');" |
| 576 L"window.domAutomationController.send(true);", &result); |
| 577 ASSERT_TRUE(result); |
| 578 |
| 579 // Now the current tab should be the new tab. |
| 580 ui_test_utils::WaitForNavigation( |
| 581 &browser()->GetSelectedTabContents()->controller()); |
| 582 ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(), |
| 583 "/newtab.html"); |
| 584 |
| 585 // Extension API should fail. |
| 586 result = false; |
| 587 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 588 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 589 L"testExtensionApi()", &result); |
| 590 EXPECT_FALSE(result); |
| 591 } |
| OLD | NEW |