| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 10 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_error_reporter.h" | 13 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
| 16 #include "chrome/browser/extensions/extension_tabs_module.h" | 16 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 17 #include "chrome/browser/extensions/extensions_service.h" | 17 #include "chrome/browser/extensions/extensions_service.h" |
| 18 #include "chrome/browser/extensions/extension_updater.h" | 18 #include "chrome/browser/extensions/extension_updater.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/renderer_host/site_instance.h" | 20 #include "chrome/browser/renderer_host/site_instance.h" |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #if defined(TOOLKIT_VIEWS) | 22 #if defined(TOOLKIT_VIEWS) |
| 23 #include "chrome/browser/views/extensions/extension_shelf.h" | |
| 24 #include "chrome/browser/views/frame/browser_view.h" | 23 #include "chrome/browser/views/frame/browser_view.h" |
| 25 #endif | 24 #endif |
| 26 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/extensions/extension_action.h" | 26 #include "chrome/common/extensions/extension_action.h" |
| 28 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/test/ui_test_utils.h" | 29 #include "chrome/test/ui_test_utils.h" |
| 31 #include "net/base/mock_host_resolver.h" | 30 #include "net/base/mock_host_resolver.h" |
| 32 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 33 #include "net/test/test_server.h" | 32 #include "net/test/test_server.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if ((*iter)->GetURL().path() == path) { | 65 if ((*iter)->GetURL().path() == path) { |
| 67 EXPECT_FALSE(host); | 66 EXPECT_FALSE(host); |
| 68 host = *iter; | 67 host = *iter; |
| 69 } | 68 } |
| 70 num_hosts++; | 69 num_hosts++; |
| 71 } | 70 } |
| 72 EXPECT_EQ(expected_hosts, num_hosts); | 71 EXPECT_EQ(expected_hosts, num_hosts); |
| 73 return host; | 72 return host; |
| 74 } | 73 } |
| 75 | 74 |
| 76 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | |
| 77 // See http://crbug.com/30151. | |
| 78 #define Toolstrip DISABLED_Toolstrip | |
| 79 #endif | |
| 80 | |
| 81 // Tests that toolstrips initializes properly and can run basic extension js. | |
| 82 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) { | |
| 83 FilePath extension_test_data_dir = test_data_dir_.AppendASCII("good"). | |
| 84 AppendASCII("Extensions").AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"). | |
| 85 AppendASCII("1.0.0.0"); | |
| 86 ASSERT_TRUE(LoadExtension(extension_test_data_dir)); | |
| 87 | |
| 88 // At this point, there should be three ExtensionHosts loaded because this | |
| 89 // extension has two toolstrips and one background page. Find the one that is | |
| 90 // hosting toolstrip1.html. | |
| 91 ExtensionProcessManager* manager = | |
| 92 browser()->profile()->GetExtensionProcessManager(); | |
| 93 ExtensionHost* host = FindHostWithPath(manager, "/toolstrip1.html", 3); | |
| 94 | |
| 95 // Tell it to run some JavaScript that tests that basic extension code works. | |
| 96 bool result = false; | |
| 97 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 98 host->render_view_host(), L"", L"testTabsAPI()", &result); | |
| 99 EXPECT_TRUE(result); | |
| 100 | |
| 101 // Test for compact language detection API. First navigate to a (static) html | |
| 102 // file with a French sentence. Then, run the test API in toolstrip1.html to | |
| 103 // actually call the language detection API through the existing extension, | |
| 104 // and verify that the language returned is indeed French. | |
| 105 FilePath language_url = extension_test_data_dir.AppendASCII( | |
| 106 "french_sentence.html"); | |
| 107 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(language_url)); | |
| 108 | |
| 109 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 110 host->render_view_host(), L"", L"testTabsLanguageAPI()", &result); | |
| 111 EXPECT_TRUE(result); | |
| 112 } | |
| 113 | |
| 114 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ExtensionViews) { | |
| 115 FilePath extension_test_data_dir = test_data_dir_.AppendASCII("good"). | |
| 116 AppendASCII("Extensions").AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"). | |
| 117 AppendASCII("1.0.0.0"); | |
| 118 ASSERT_TRUE(LoadExtension(extension_test_data_dir)); | |
| 119 | |
| 120 // At this point, there should be three ExtensionHosts loaded because this | |
| 121 // extension has two toolstrips and one background page. Find the one that is | |
| 122 // hosting toolstrip1.html. | |
| 123 ExtensionProcessManager* manager = | |
| 124 browser()->profile()->GetExtensionProcessManager(); | |
| 125 ExtensionHost* host = FindHostWithPath(manager, "/toolstrip1.html", 3); | |
| 126 | |
| 127 FilePath gettabs_url = extension_test_data_dir.AppendASCII( | |
| 128 "test_gettabs.html"); | |
| 129 ui_test_utils::NavigateToURL( | |
| 130 browser(), | |
| 131 GURL(gettabs_url.value())); | |
| 132 | |
| 133 bool result = false; | |
| 134 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 135 host->render_view_host(), L"", L"testgetToolstripsAPI()", &result); | |
| 136 EXPECT_TRUE(result); | |
| 137 | |
| 138 result = false; | |
| 139 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 140 host->render_view_host(), L"", L"testgetBackgroundPageAPI()", &result); | |
| 141 EXPECT_TRUE(result); | |
| 142 | |
| 143 ui_test_utils::NavigateToURL( | |
| 144 browser(), | |
| 145 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 146 "test_gettabs.html")); | |
| 147 result = false; | |
| 148 ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 149 host->render_view_host(), L"", L"testgetExtensionTabsAPI()", &result); | |
| 150 EXPECT_TRUE(result); | |
| 151 } | |
| 152 | |
| 153 #if defined(TOOLKIT_VIEWS) | |
| 154 // http://crbug.com/29897 - for other UI toolkits? | |
| 155 | |
| 156 // Tests that the ExtensionShelf initializes properly, notices that | |
| 157 // an extension loaded and has a view available, and then sets that up | |
| 158 // properly. | |
| 159 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Shelf) { | |
| 160 // When initialized, there are no extension views and the preferred height | |
| 161 // should be zero. | |
| 162 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | |
| 163 ExtensionShelf* shelf = browser_view->extension_shelf(); | |
| 164 ASSERT_TRUE(shelf); | |
| 165 EXPECT_EQ(shelf->GetChildViewCount(), 0); | |
| 166 EXPECT_EQ(shelf->GetPreferredSize().height(), 0); | |
| 167 | |
| 168 ASSERT_TRUE(LoadExtension( | |
| 169 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 170 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 171 .AppendASCII("1.0.0.0"))); | |
| 172 | |
| 173 // There should now be two extension views and preferred height of the view | |
| 174 // should be non-zero. | |
| 175 EXPECT_EQ(shelf->GetChildViewCount(), 2); | |
| 176 EXPECT_NE(shelf->GetPreferredSize().height(), 0); | |
| 177 } | |
| 178 #endif // defined(TOOLKIT_VIEWS) | |
| 179 | |
| 180 // Tests that extension resources can be loaded from origins which the | 75 // Tests that extension resources can be loaded from origins which the |
| 181 // extension specifies in permissions but not from others. | 76 // extension specifies in permissions but not from others. |
| 182 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) { | 77 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) { |
| 183 host_resolver()->AddRule("*", "127.0.0.1"); | 78 host_resolver()->AddRule("*", "127.0.0.1"); |
| 184 ASSERT_TRUE(StartHTTPServer()); | 79 ASSERT_TRUE(StartHTTPServer()); |
| 185 ASSERT_TRUE(LoadExtension(test_data_dir_ | 80 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 186 .AppendASCII("origin_privileges").AppendASCII("extension"))); | 81 .AppendASCII("origin_privileges").AppendASCII("extension"))); |
| 187 | 82 |
| 188 // A web host that has permission. | 83 // A web host that has permission. |
| 189 ui_test_utils::NavigateToURL(browser(), | 84 ui_test_utils::NavigateToURL(browser(), |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 588 |
| 694 // Tests that an error raised during an async function still fires | 589 // Tests that an error raised during an async function still fires |
| 695 // the callback, but sets chrome.extension.lastError. | 590 // the callback, but sets chrome.extension.lastError. |
| 696 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { | 591 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { |
| 697 ASSERT_TRUE(LoadExtension( | 592 ASSERT_TRUE(LoadExtension( |
| 698 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); | 593 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); |
| 699 | 594 |
| 700 // Get the ExtensionHost that is hosting our toolstrip page. | 595 // Get the ExtensionHost that is hosting our toolstrip page. |
| 701 ExtensionProcessManager* manager = | 596 ExtensionProcessManager* manager = |
| 702 browser()->profile()->GetExtensionProcessManager(); | 597 browser()->profile()->GetExtensionProcessManager(); |
| 703 ExtensionHost* host = FindHostWithPath(manager, "/toolstrip.html", 1); | 598 ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); |
| 704 | 599 |
| 705 bool result = false; | 600 bool result = false; |
| 706 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 601 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 707 host->render_view_host(), L"", L"testLastError()", &result); | 602 host->render_view_host(), L"", L"testLastError()", &result); |
| 708 EXPECT_TRUE(result); | 603 EXPECT_TRUE(result); |
| 709 } | 604 } |
| 710 | 605 |
| 711 // Helper function for common code shared by the 3 WindowOpen tests below. | 606 // Helper function for common code shared by the 3 WindowOpen tests below. |
| 712 static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url, | 607 static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url, |
| 713 const std::string& newtab_url) { | 608 const std::string& newtab_url) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 773 |
| 879 // If the options page hasn't already come up, wait for it. | 774 // If the options page hasn't already come up, wait for it. |
| 880 if (tab_strip->count() == 1) { | 775 if (tab_strip->count() == 1) { |
| 881 ui_test_utils::WaitForNewTab(browser()); | 776 ui_test_utils::WaitForNewTab(browser()); |
| 882 } | 777 } |
| 883 ASSERT_EQ(2, tab_strip->count()); | 778 ASSERT_EQ(2, tab_strip->count()); |
| 884 | 779 |
| 885 EXPECT_EQ(extension->GetResourceURL("options.html"), | 780 EXPECT_EQ(extension->GetResourceURL("options.html"), |
| 886 tab_strip->GetTabContentsAt(1)->GetURL()); | 781 tab_strip->GetTabContentsAt(1)->GetURL()); |
| 887 } | 782 } |
| OLD | NEW |