| 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 "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/autoupdate_interceptor.h" | 9 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 #endif // defined(TOOLKIT_VIEWS) | 177 #endif // defined(TOOLKIT_VIEWS) |
| 178 | 178 |
| 179 // Tests that extension resources can be loaded from origins which the | 179 // Tests that extension resources can be loaded from origins which the |
| 180 // extension specifies in permissions but not from others. | 180 // extension specifies in permissions but not from others. |
| 181 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) { | 181 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) { |
| 182 host_resolver()->AddRule("*", "127.0.0.1"); | 182 host_resolver()->AddRule("*", "127.0.0.1"); |
| 183 ASSERT_TRUE(StartHTTPServer()); | 183 ASSERT_TRUE(StartHTTPServer()); |
| 184 ASSERT_TRUE(LoadExtension(test_data_dir_ | 184 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 185 .AppendASCII("origin_privileges").AppendASCII("extension"))); | 185 .AppendASCII("origin_privileges").AppendASCII("extension"))); |
| 186 | 186 |
| 187 // A web host that has permission. |
| 187 ui_test_utils::NavigateToURL(browser(), | 188 ui_test_utils::NavigateToURL(browser(), |
| 188 GURL("http://a.com:1337/files/extensions/origin_privileges/index.html")); | 189 GURL("http://a.com:1337/files/extensions/origin_privileges/index.html")); |
| 189 std::string result; | 190 std::string result; |
| 190 ui_test_utils::ExecuteJavaScriptAndExtractString( | 191 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 191 browser()->GetSelectedTabContents()->render_view_host(), L"", | 192 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 192 L"window.domAutomationController.send(document.title)", | 193 L"window.domAutomationController.send(document.title)", |
| 193 &result); | 194 &result); |
| 194 EXPECT_EQ(result, "Loaded"); | 195 EXPECT_EQ(result, "Loaded"); |
| 195 | 196 |
| 197 // A web host that does not have permission. |
| 196 ui_test_utils::NavigateToURL(browser(), | 198 ui_test_utils::NavigateToURL(browser(), |
| 197 GURL("http://b.com:1337/files/extensions/origin_privileges/index.html")); | 199 GURL("http://b.com:1337/files/extensions/origin_privileges/index.html")); |
| 198 ui_test_utils::ExecuteJavaScriptAndExtractString( | 200 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 199 browser()->GetSelectedTabContents()->render_view_host(), L"", | 201 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 200 L"window.domAutomationController.send(document.title)", | 202 L"window.domAutomationController.send(document.title)", |
| 201 &result); | 203 &result); |
| 202 EXPECT_EQ(result, "Image failed to load"); | 204 EXPECT_EQ(result, "Image failed to load"); |
| 205 |
| 206 // A different extension. Extensions should always be able to load each |
| 207 // other's resources. |
| 208 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 209 .AppendASCII("origin_privileges").AppendASCII("extension2"))); |
| 210 ui_test_utils::NavigateToURL( |
| 211 browser(), |
| 212 GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html")); |
| 213 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 214 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 215 L"window.domAutomationController.send(document.title)", |
| 216 &result); |
| 217 EXPECT_EQ(result, "Loaded"); |
| 203 } | 218 } |
| 204 | 219 |
| 205 // Tests that we can load extension pages into the tab area and they can call | 220 // Tests that we can load extension pages into the tab area and they can call |
| 206 // extension APIs. | 221 // extension APIs. |
| 207 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { | 222 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { |
| 208 ASSERT_TRUE(LoadExtension( | 223 ASSERT_TRUE(LoadExtension( |
| 209 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 224 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 210 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 225 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 211 .AppendASCII("1.0.0.0"))); | 226 .AppendASCII("1.0.0.0"))); |
| 212 | 227 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 876 |
| 862 // If the options page hasn't already come up, wait for it. | 877 // If the options page hasn't already come up, wait for it. |
| 863 if (tab_strip->count() == 1) { | 878 if (tab_strip->count() == 1) { |
| 864 ui_test_utils::WaitForNewTab(browser()); | 879 ui_test_utils::WaitForNewTab(browser()); |
| 865 } | 880 } |
| 866 ASSERT_EQ(2, tab_strip->count()); | 881 ASSERT_EQ(2, tab_strip->count()); |
| 867 | 882 |
| 868 EXPECT_EQ(extension->GetResourceURL("options.html"), | 883 EXPECT_EQ(extension->GetResourceURL("options.html"), |
| 869 tab_strip->GetTabContentsAt(1)->GetURL()); | 884 tab_strip->GetTabContentsAt(1)->GetURL()); |
| 870 } | 885 } |
| OLD | NEW |