OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
13 | 13 |
14 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { | 14 class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { |
15 protected: | 15 protected: |
16 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 16 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
17 ExtensionApiTest::SetUpCommandLine(command_line); | 17 ExtensionApiTest::SetUpCommandLine(command_line); |
18 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); | 18 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); |
19 } | 19 } |
20 }; | 20 }; |
(...skipping 19 matching lines...) Expand all Loading... |
40 | 40 |
41 std::string host_b("b.com"); | 41 std::string host_b("b.com"); |
42 GURL::Replacements make_host_b_com; | 42 GURL::Replacements make_host_b_com; |
43 make_host_b_com.SetHostStr(host_b); | 43 make_host_b_com.SetHostStr(host_b); |
44 | 44 |
45 // A web host that has permission. | 45 // A web host that has permission. |
46 ui_test_utils::NavigateToURL( | 46 ui_test_utils::NavigateToURL( |
47 browser(), web_resource.ReplaceComponents(make_host_a_com)); | 47 browser(), web_resource.ReplaceComponents(make_host_a_com)); |
48 std::string result; | 48 std::string result; |
49 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 49 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
50 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 50 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
51 L"window.domAutomationController.send(document.title)", | 51 L"window.domAutomationController.send(document.title)", |
52 &result)); | 52 &result)); |
53 EXPECT_EQ(result, "Loaded"); | 53 EXPECT_EQ(result, "Loaded"); |
54 | 54 |
55 // A web host that loads a non-existent extension. | 55 // A web host that loads a non-existent extension. |
56 GURL non_existent_extension( | 56 GURL non_existent_extension( |
57 test_server()->GetURL( | 57 test_server()->GetURL( |
58 "files/extensions/api_test/extension_resource_request_policy/" | 58 "files/extensions/api_test/extension_resource_request_policy/" |
59 "non_existent_extension.html")); | 59 "non_existent_extension.html")); |
60 ui_test_utils::NavigateToURL(browser(), non_existent_extension); | 60 ui_test_utils::NavigateToURL(browser(), non_existent_extension); |
61 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 61 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
62 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 62 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
63 L"window.domAutomationController.send(document.title)", | 63 L"window.domAutomationController.send(document.title)", |
64 &result)); | 64 &result)); |
65 EXPECT_EQ(result, "Image failed to load"); | 65 EXPECT_EQ(result, "Image failed to load"); |
66 | 66 |
67 // A data URL. Data URLs should always be able to load chrome-extension:// | 67 // A data URL. Data URLs should always be able to load chrome-extension:// |
68 // resources. | 68 // resources. |
69 std::string file_source; | 69 std::string file_source; |
70 ASSERT_TRUE(file_util::ReadFileToString( | 70 ASSERT_TRUE(file_util::ReadFileToString( |
71 test_data_dir_.AppendASCII("extension_resource_request_policy") | 71 test_data_dir_.AppendASCII("extension_resource_request_policy") |
72 .AppendASCII("index.html"), &file_source)); | 72 .AppendASCII("index.html"), &file_source)); |
73 ui_test_utils::NavigateToURL(browser(), | 73 ui_test_utils::NavigateToURL(browser(), |
74 GURL(std::string("data:text/html;charset=utf-8,") + file_source)); | 74 GURL(std::string("data:text/html;charset=utf-8,") + file_source)); |
75 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 75 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
76 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 76 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
77 L"window.domAutomationController.send(document.title)", | 77 L"window.domAutomationController.send(document.title)", |
78 &result)); | 78 &result)); |
79 EXPECT_EQ(result, "Loaded"); | 79 EXPECT_EQ(result, "Loaded"); |
80 | 80 |
81 // A different extension. Extensions should always be able to load each | 81 // A different extension. Extensions should always be able to load each |
82 // other's resources. | 82 // other's resources. |
83 ASSERT_TRUE(LoadExtension(test_data_dir_ | 83 ASSERT_TRUE(LoadExtension(test_data_dir_ |
84 .AppendASCII("extension_resource_request_policy") | 84 .AppendASCII("extension_resource_request_policy") |
85 .AppendASCII("extension2"))); | 85 .AppendASCII("extension2"))); |
86 ui_test_utils::NavigateToURL( | 86 ui_test_utils::NavigateToURL( |
87 browser(), | 87 browser(), |
88 GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html")); | 88 GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html")); |
89 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 89 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
90 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 90 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
91 L"window.domAutomationController.send(document.title)", | 91 L"window.domAutomationController.send(document.title)", |
92 &result)); | 92 &result)); |
93 EXPECT_EQ(result, "Loaded"); | 93 EXPECT_EQ(result, "Loaded"); |
94 } | 94 } |
95 | 95 |
96 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, | 96 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, |
97 ExtensionCanLoadHostedAppIcons) { | 97 ExtensionCanLoadHostedAppIcons) { |
98 ASSERT_TRUE(LoadExtension(test_data_dir_ | 98 ASSERT_TRUE(LoadExtension(test_data_dir_ |
99 .AppendASCII("extension_resource_request_policy") | 99 .AppendASCII("extension_resource_request_policy") |
100 .AppendASCII("extension"))); | 100 .AppendASCII("extension"))); |
(...skipping 29 matching lines...) Expand all Loading... |
130 ASSERT_TRUE(LoadExtension(test_data_dir_ | 130 ASSERT_TRUE(LoadExtension(test_data_dir_ |
131 .AppendASCII("extension_resource_request_policy") | 131 .AppendASCII("extension_resource_request_policy") |
132 .AppendASCII("web_accessible"))); | 132 .AppendASCII("web_accessible"))); |
133 | 133 |
134 GURL accessible_resource( | 134 GURL accessible_resource( |
135 test_server()->GetURL( | 135 test_server()->GetURL( |
136 "files/extensions/api_test/extension_resource_request_policy/" | 136 "files/extensions/api_test/extension_resource_request_policy/" |
137 "web_accessible/accessible_resource.html")); | 137 "web_accessible/accessible_resource.html")); |
138 ui_test_utils::NavigateToURL(browser(), accessible_resource); | 138 ui_test_utils::NavigateToURL(browser(), accessible_resource); |
139 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 139 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
140 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 140 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
141 L"window.domAutomationController.send(document.title)", | 141 L"window.domAutomationController.send(document.title)", |
142 &result)); | 142 &result)); |
143 EXPECT_EQ("Loaded", result); | 143 EXPECT_EQ("Loaded", result); |
144 | 144 |
145 GURL nonaccessible_resource( | 145 GURL nonaccessible_resource( |
146 test_server()->GetURL( | 146 test_server()->GetURL( |
147 "files/extensions/api_test/extension_resource_request_policy/" | 147 "files/extensions/api_test/extension_resource_request_policy/" |
148 "web_accessible/nonaccessible_resource.html")); | 148 "web_accessible/nonaccessible_resource.html")); |
149 ui_test_utils::NavigateToURL(browser(), nonaccessible_resource); | 149 ui_test_utils::NavigateToURL(browser(), nonaccessible_resource); |
150 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 150 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
151 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 151 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
152 L"window.domAutomationController.send(document.title)", | 152 L"window.domAutomationController.send(document.title)", |
153 &result)); | 153 &result)); |
154 EXPECT_EQ("Image failed to load", result); | 154 EXPECT_EQ("Image failed to load", result); |
155 | 155 |
156 GURL nonexistent_resource( | 156 GURL nonexistent_resource( |
157 test_server()->GetURL( | 157 test_server()->GetURL( |
158 "files/extensions/api_test/extension_resource_request_policy/" | 158 "files/extensions/api_test/extension_resource_request_policy/" |
159 "web_accessible/nonexistent_resource.html")); | 159 "web_accessible/nonexistent_resource.html")); |
160 ui_test_utils::NavigateToURL(browser(), nonexistent_resource); | 160 ui_test_utils::NavigateToURL(browser(), nonexistent_resource); |
161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 161 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
162 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", | 162 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
163 L"window.domAutomationController.send(document.title)", | 163 L"window.domAutomationController.send(document.title)", |
164 &result)); | 164 &result)); |
165 EXPECT_EQ("Image failed to load", result); | 165 EXPECT_EQ("Image failed to load", result); |
166 } | 166 } |
167 | 167 |
OLD | NEW |