OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 8 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 ExtensionProcessManager* manager = | 642 ExtensionProcessManager* manager = |
643 browser()->profile()->GetExtensionProcessManager(); | 643 browser()->profile()->GetExtensionProcessManager(); |
644 ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); | 644 ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); |
645 | 645 |
646 bool result = false; | 646 bool result = false; |
647 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 647 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
648 host->render_view_host(), L"", L"testLastError()", &result)); | 648 host->render_view_host(), L"", L"testLastError()", &result)); |
649 EXPECT_TRUE(result); | 649 EXPECT_TRUE(result); |
650 } | 650 } |
651 | 651 |
652 // Helper function for common code shared by the 3 WindowOpen tests below. | |
653 static void WindowOpenHelper(Browser* browser, const GURL& start_url, | |
654 const std::string& newtab_url, | |
655 WebContents** newtab_result) { | |
656 ui_test_utils::NavigateToURL(browser, start_url); | |
657 | |
658 ui_test_utils::WindowedNotificationObserver observer( | |
659 content::NOTIFICATION_LOAD_STOP, | |
660 content::NotificationService::AllSources()); | |
661 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | |
662 browser->GetSelectedWebContents()->GetRenderViewHost(), L"", | |
663 L"window.open('" + UTF8ToWide(newtab_url) + L"');")); | |
664 | |
665 // Now the active tab in last active window should be the new tab. | |
666 Browser* last_active_browser = BrowserList::GetLastActive(); | |
667 EXPECT_TRUE(last_active_browser); | |
668 WebContents* newtab = last_active_browser->GetSelectedWebContents(); | |
669 EXPECT_TRUE(newtab); | |
670 GURL expected_url = start_url.Resolve(newtab_url); | |
671 observer.Wait(); | |
672 EXPECT_EQ(expected_url, | |
673 newtab->GetController().GetLastCommittedEntry()->GetURL()); | |
674 if (newtab_result) | |
675 *newtab_result = newtab; | |
676 } | |
677 | |
678 // Tests that an extension page can call window.open to an extension URL and | 652 // Tests that an extension page can call window.open to an extension URL and |
679 // the new window has extension privileges. | 653 // the new window has extension privileges. |
680 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { | 654 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
681 ASSERT_TRUE(LoadExtension( | 655 ASSERT_TRUE(LoadExtension( |
682 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 656 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
683 | 657 |
| 658 GURL start_url(std::string("chrome-extension://") + |
| 659 last_loaded_extension_id_ + "/test.html"); |
| 660 ui_test_utils::NavigateToURL(browser(), start_url); |
684 WebContents* newtab; | 661 WebContents* newtab; |
685 ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( | 662 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(), |
686 browser(), | 663 start_url.Resolve("newtab.html"), true, &newtab)); |
687 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | |
688 "/test.html"), | |
689 "newtab.html", &newtab)); | |
690 | 664 |
691 bool result = false; | 665 bool result = false; |
692 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 666 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
693 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 667 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
694 EXPECT_TRUE(result); | 668 EXPECT_TRUE(result); |
695 } | 669 } |
696 | 670 |
697 // Tests that if an extension page calls window.open to an invalid extension | 671 // Tests that if an extension page calls window.open to an invalid extension |
698 // URL, the browser doesn't crash. | 672 // URL, the browser doesn't crash. |
699 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { | 673 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
700 ASSERT_TRUE(LoadExtension( | 674 ASSERT_TRUE(LoadExtension( |
701 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 675 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
702 | 676 |
703 ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( | 677 GURL start_url(std::string("chrome-extension://") + |
704 browser(), | 678 last_loaded_extension_id_ + "/test.html"); |
705 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 679 ui_test_utils::NavigateToURL(browser(), start_url); |
706 "/test.html"), | 680 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(), |
707 "chrome-extension://thisissurelynotavalidextensionid/newtab.html", NULL)); | 681 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 682 false, NULL)); |
708 | 683 |
709 // If we got to this point, we didn't crash, so we're good. | 684 // If we got to this point, we didn't crash, so we're good. |
710 } | 685 } |
711 | 686 |
712 // Tests that calling window.open from the newtab page to an extension URL | 687 // Tests that calling window.open from the newtab page to an extension URL |
713 // gives the new window extension privileges - even though the opening page | 688 // gives the new window extension privileges - even though the opening page |
714 // does not have extension privileges, we break the script connection, so | 689 // does not have extension privileges, we break the script connection, so |
715 // there is no privilege leak. | 690 // there is no privilege leak. |
716 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { | 691 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
717 ASSERT_TRUE(LoadExtension( | 692 ASSERT_TRUE(LoadExtension( |
718 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 693 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
719 | 694 |
| 695 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
720 WebContents* newtab; | 696 WebContents* newtab; |
721 ASSERT_NO_FATAL_FAILURE(WindowOpenHelper( | 697 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetSelectedWebContents(), |
722 browser(), | 698 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
723 GURL("about:blank"), | 699 "/newtab.html"), false, &newtab)); |
724 std::string("chrome-extension://") + last_loaded_extension_id_ + | |
725 "/newtab.html", | |
726 &newtab)); | |
727 | 700 |
728 // Extension API should succeed. | 701 // Extension API should succeed. |
729 bool result = false; | 702 bool result = false; |
730 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 703 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
731 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 704 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
732 EXPECT_TRUE(result); | 705 EXPECT_TRUE(result); |
733 } | 706 } |
734 | 707 |
735 #if defined(OS_WIN) && defined(NDEBUG) | 708 #if defined(OS_WIN) && defined(NDEBUG) |
736 #define MAYBE_PluginLoadUnload PluginLoadUnload | 709 #define MAYBE_PluginLoadUnload PluginLoadUnload |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 | 850 |
878 EXPECT_EQ(extension->GetResourceURL("options.html"), | 851 EXPECT_EQ(extension->GetResourceURL("options.html"), |
879 tab_strip->GetTabContentsAt(1)->web_contents()->GetURL()); | 852 tab_strip->GetTabContentsAt(1)->web_contents()->GetURL()); |
880 } | 853 } |
881 | 854 |
882 //============================================================================== | 855 //============================================================================== |
883 // STOP! Please do not add any more random-ass tests here. Create new files for | 856 // STOP! Please do not add any more random-ass tests here. Create new files for |
884 // your tests grouped by functionality. Also, you should strongly consider using | 857 // your tests grouped by functionality. Also, you should strongly consider using |
885 // ExtensionAPITest if possible. | 858 // ExtensionAPITest if possible. |
886 //============================================================================== | 859 //============================================================================== |
OLD | NEW |