| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { | 25 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { |
| 26 protected: | 26 protected: |
| 27 void SetUpCommandLine(base::CommandLine* command_line) override { | 27 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 28 ExtensionApiTest::SetUpCommandLine(command_line); | 28 ExtensionApiTest::SetUpCommandLine(command_line); |
| 29 command_line->AppendSwitch( | 29 command_line->AppendSwitch( |
| 30 extensions::switches::kAllowLegacyExtensionManifests); | 30 extensions::switches::kAllowLegacyExtensionManifests); |
| 31 } | 31 } |
| 32 |
| 33 void SetUpOnMainThread() override { |
| 34 ExtensionApiTest::SetUpOnMainThread(); |
| 35 host_resolver()->AddRule("*", "127.0.0.1"); |
| 36 ASSERT_TRUE(embedded_test_server()->Start()); |
| 37 } |
| 32 }; | 38 }; |
| 33 | 39 |
| 34 // Note, this mostly tests the logic of chrome/renderer/extensions/ | 40 // Note, this mostly tests the logic of chrome/renderer/extensions/ |
| 35 // extension_resource_request_policy.*, but we have it as a browser test so that | 41 // extension_resource_request_policy.*, but we have it as a browser test so that |
| 36 // can make sure it works end-to-end. | 42 // can make sure it works end-to-end. |
| 37 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) { | 43 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) { |
| 38 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 39 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 40 ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_ | 44 ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_ |
| 41 .AppendASCII("extension_resource_request_policy") | 45 .AppendASCII("extension_resource_request_policy") |
| 42 .AppendASCII("extension"), | 46 .AppendASCII("extension"), |
| 43 // Tests manifest_version 1 behavior, so warnings are expected. | 47 // Tests manifest_version 1 behavior, so warnings are expected. |
| 44 ExtensionBrowserTest::kFlagIgnoreManifestWarnings)); | 48 ExtensionBrowserTest::kFlagIgnoreManifestWarnings)); |
| 45 | 49 |
| 46 GURL web_resource(embedded_test_server()->GetURL( | 50 GURL web_resource(embedded_test_server()->GetURL( |
| 47 "/extensions/api_test/extension_resource_request_policy/" | 51 "/extensions/api_test/extension_resource_request_policy/" |
| 48 "index.html")); | 52 "index.html")); |
| 49 | 53 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 153 |
| 150 // This test times out regularly on win_rel trybots. See http://crbug.com/122154 | 154 // This test times out regularly on win_rel trybots. See http://crbug.com/122154 |
| 151 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
| 152 #define MAYBE_WebAccessibleResources DISABLED_WebAccessibleResources | 156 #define MAYBE_WebAccessibleResources DISABLED_WebAccessibleResources |
| 153 #else | 157 #else |
| 154 #define MAYBE_WebAccessibleResources WebAccessibleResources | 158 #define MAYBE_WebAccessibleResources WebAccessibleResources |
| 155 #endif | 159 #endif |
| 156 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 160 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
| 157 MAYBE_WebAccessibleResources) { | 161 MAYBE_WebAccessibleResources) { |
| 158 std::string result; | 162 std::string result; |
| 159 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 160 ASSERT_TRUE(LoadExtension(test_data_dir_ | 163 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 161 .AppendASCII("extension_resource_request_policy") | 164 .AppendASCII("extension_resource_request_policy") |
| 162 .AppendASCII("web_accessible"))); | 165 .AppendASCII("web_accessible"))); |
| 163 | 166 |
| 164 GURL accessible_resource(embedded_test_server()->GetURL( | 167 GURL accessible_resource(embedded_test_server()->GetURL( |
| 165 "/extensions/api_test/extension_resource_request_policy/" | 168 "/extensions/api_test/extension_resource_request_policy/" |
| 166 "web_accessible/accessible_resource.html")); | 169 "web_accessible/accessible_resource.html")); |
| 167 ui_test_utils::NavigateToURL(browser(), accessible_resource); | 170 ui_test_utils::NavigateToURL(browser(), accessible_resource); |
| 168 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 171 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 169 browser()->tab_strip_model()->GetActiveWebContents(), | 172 browser()->tab_strip_model()->GetActiveWebContents(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 226 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 224 browser()->tab_strip_model()->GetActiveWebContents(), | 227 browser()->tab_strip_model()->GetActiveWebContents(), |
| 225 "window.domAutomationController.send(document.title)", | 228 "window.domAutomationController.send(document.title)", |
| 226 &result)); | 229 &result)); |
| 227 EXPECT_EQ("New Tab Page Loaded Successfully", result); | 230 EXPECT_EQ("New Tab Page Loaded Successfully", result); |
| 228 } | 231 } |
| 229 | 232 |
| 230 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 233 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
| 231 LinkToWebAccessibleResources) { | 234 LinkToWebAccessibleResources) { |
| 232 std::string result; | 235 std::string result; |
| 233 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 234 const extensions::Extension* extension = LoadExtension( | 236 const extensions::Extension* extension = LoadExtension( |
| 235 test_data_dir_.AppendASCII("extension_resource_request_policy") | 237 test_data_dir_.AppendASCII("extension_resource_request_policy") |
| 236 .AppendASCII("web_accessible")); | 238 .AppendASCII("web_accessible")); |
| 237 ASSERT_TRUE(extension); | 239 ASSERT_TRUE(extension); |
| 238 | 240 |
| 239 GURL accessible_linked_resource(embedded_test_server()->GetURL( | 241 GURL accessible_linked_resource(embedded_test_server()->GetURL( |
| 240 "/extensions/api_test/extension_resource_request_policy/" | 242 "/extensions/api_test/extension_resource_request_policy/" |
| 241 "web_accessible/accessible_link_resource.html")); | 243 "web_accessible/accessible_link_resource.html")); |
| 242 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 244 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 243 browser(), accessible_linked_resource, 1); | 245 browser(), accessible_linked_resource, 1); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 nonaccessible_observer.Wait(); | 289 nonaccessible_observer.Wait(); |
| 288 EXPECT_EQ(GURL("about:blank"), browser() | 290 EXPECT_EQ(GURL("about:blank"), browser() |
| 289 ->tab_strip_model() | 291 ->tab_strip_model() |
| 290 ->GetActiveWebContents() | 292 ->GetActiveWebContents() |
| 291 ->GetLastCommittedURL()); | 293 ->GetLastCommittedURL()); |
| 292 } | 294 } |
| 293 | 295 |
| 294 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 296 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
| 295 WebAccessibleResourcesWithCSP) { | 297 WebAccessibleResourcesWithCSP) { |
| 296 std::string result; | 298 std::string result; |
| 297 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 298 ASSERT_TRUE(LoadExtension(test_data_dir_ | 299 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 299 .AppendASCII("extension_resource_request_policy") | 300 .AppendASCII("extension_resource_request_policy") |
| 300 .AppendASCII("web_accessible"))); | 301 .AppendASCII("web_accessible"))); |
| 301 | 302 |
| 302 GURL accessible_resource_with_csp(embedded_test_server()->GetURL( | 303 GURL accessible_resource_with_csp(embedded_test_server()->GetURL( |
| 303 "/extensions/api_test/extension_resource_request_policy/" | 304 "/extensions/api_test/extension_resource_request_policy/" |
| 304 "web_accessible/accessible_resource_with_csp.html")); | 305 "web_accessible/accessible_resource_with_csp.html")); |
| 305 ui_test_utils::NavigateToURL(browser(), accessible_resource_with_csp); | 306 ui_test_utils::NavigateToURL(browser(), accessible_resource_with_csp); |
| 306 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 307 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 307 browser()->tab_strip_model()->GetActiveWebContents(), | 308 browser()->tab_strip_model()->GetActiveWebContents(), |
| 308 "window.domAutomationController.send(document.title)", | 309 "window.domAutomationController.send(document.title)", |
| 309 &result)); | 310 &result)); |
| 310 EXPECT_EQ("Loaded", result); | 311 EXPECT_EQ("Loaded", result); |
| 311 } | 312 } |
| 312 | 313 |
| 313 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Iframe) { | 314 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Iframe) { |
| 314 // Load another extension, which the test one shouldn't be able to get | 315 // Load another extension, which the test one shouldn't be able to get |
| 315 // resources from. | 316 // resources from. |
| 316 ASSERT_TRUE(LoadExtension(test_data_dir_ | 317 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 317 .AppendASCII("extension_resource_request_policy") | 318 .AppendASCII("extension_resource_request_policy") |
| 318 .AppendASCII("inaccessible"))); | 319 .AppendASCII("inaccessible"))); |
| 319 EXPECT_TRUE(RunExtensionSubtest( | 320 EXPECT_TRUE(RunExtensionSubtest( |
| 320 "extension_resource_request_policy/web_accessible", | 321 "extension_resource_request_policy/web_accessible", |
| 321 "iframe.html")) << message_; | 322 "iframe.html")) << message_; |
| 322 } | 323 } |
| 323 | 324 |
| 324 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 325 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
| 325 IframeNavigateToInaccessible) { | 326 IframeNavigateToInaccessible) { |
| 326 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 327 ASSERT_TRUE(LoadExtension( | 327 ASSERT_TRUE(LoadExtension( |
| 328 test_data_dir_.AppendASCII("extension_resource_request_policy") | 328 test_data_dir_.AppendASCII("extension_resource_request_policy") |
| 329 .AppendASCII("some_accessible"))); | 329 .AppendASCII("some_accessible"))); |
| 330 | 330 |
| 331 GURL iframe_navigate_url(embedded_test_server()->GetURL( | 331 GURL iframe_navigate_url(embedded_test_server()->GetURL( |
| 332 "/extensions/api_test/extension_resource_request_policy/" | 332 "/extensions/api_test/extension_resource_request_policy/" |
| 333 "iframe_navigate.html")); | 333 "iframe_navigate.html")); |
| 334 | 334 |
| 335 ui_test_utils::NavigateToURL(browser(), iframe_navigate_url); | 335 ui_test_utils::NavigateToURL(browser(), iframe_navigate_url); |
| 336 | 336 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 350 // The iframe should not load |private_page|, which is not web-accessible. | 350 // The iframe should not load |private_page|, which is not web-accessible. |
| 351 // | 351 // |
| 352 // TODO(alexmos): The failure mode differs on whether or not | 352 // TODO(alexmos): The failure mode differs on whether or not |
| 353 // --isolate-extensions is used: if it is on, the request is canceled and we | 353 // --isolate-extensions is used: if it is on, the request is canceled and we |
| 354 // stay on public.html (see https://crbug.com/656752), and if it's off, the | 354 // stay on public.html (see https://crbug.com/656752), and if it's off, the |
| 355 // request is blocked in ExtensionNavigationThrottle, which loads an error | 355 // request is blocked in ExtensionNavigationThrottle, which loads an error |
| 356 // page into the iframe. This check handles both cases, but we should make | 356 // page into the iframe. This check handles both cases, but we should make |
| 357 // the check stricter once --isolate-extensions is on by default. | 357 // the check stricter once --isolate-extensions is on by default. |
| 358 EXPECT_NE("Private", content); | 358 EXPECT_NE("Private", content); |
| 359 } | 359 } |
| OLD | NEW |