1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "net/base/mock_host_resolver.h"
class ExtensionResourceRequestPolicyTest : public ExtensionApiTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests);
}
};
// Note, this mostly tests the logic of chrome/renderer/extensions/
// extension_resource_request_policy.*, but we have it as a browser test so that
// can make sure it works end-to-end.
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
GURL web_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"index.html"));
std::string host_a("a.com");
GURL::Replacements make_host_a_com;
make_host_a_com.SetHostStr(host_a);
std::string host_b("b.com");
GURL::Replacements make_host_b_com;
make_host_b_com.SetHostStr(host_b);
// A web host that has permission.
ui_test_utils::NavigateToURL(
browser(), web_resource.ReplaceComponents(make_host_a_com));
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ(result, "Loaded");
// A web host that loads a non-existent extension.
GURL non_existent_extension(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"non_existent_extension.html"));
ui_test_utils::NavigateToURL(browser(), non_existent_extension);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ(result, "Image failed to load");
// A data URL. Data URLs should always be able to load chrome-extension://
// resources.
std::string file_source;
ASSERT_TRUE(file_util::ReadFileToString(
test_data_dir_.AppendASCII("extension_resource_request_policy")
.AppendASCII("index.html"), &file_source));
ui_test_utils::NavigateToURL(browser(),
GURL(std::string("data:text/html;charset=utf-8,") + file_source));
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ(result, "Loaded");
// A different extension. Legacy (manifest_version 1) extensions should always
// be able to load each other's resources.
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension2"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
ui_test_utils::NavigateToURL(
browser(),
GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html"));
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ(result, "Loaded");
}
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
ExtensionCanLoadHostedAppIcons) {
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
ASSERT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2/",
"can_load_icons_from_hosted_apps.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Audio) {
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2",
"audio.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
#if defined(OS_MACOSX)
// http://crbug.com/95274 - Video is flaky on Mac.
#define MAYBE_Video DISABLED_Video
#else
#define MAYBE_Video Video
#endif
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, MAYBE_Video) {
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2",
"video.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
// This test times out regularly on win_rel trybots. See http://crbug.com/122154
#if defined(OS_WIN)
#define MAYBE_WebAccessibleResources DISABLED_WebAccessibleResources
#else
#define MAYBE_WebAccessibleResources WebAccessibleResources
#endif
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
MAYBE_WebAccessibleResources) {
std::string result;
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("web_accessible")));
GURL accessible_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/accessible_resource.html"));
ui_test_utils::NavigateToURL(browser(), accessible_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("Loaded", result);
GURL xhr_accessible_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/xhr_accessible_resource.html"));
ui_test_utils::NavigateToURL(
browser(), xhr_accessible_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("XHR completed with status: 200", result);
GURL xhr_inaccessible_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/xhr_inaccessible_resource.html"));
ui_test_utils::NavigateToURL(
browser(), xhr_inaccessible_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("XHR failed to load resource", result);
GURL nonaccessible_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/nonaccessible_resource.html"));
ui_test_utils::NavigateToURL(browser(), nonaccessible_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("Image failed to load", result);
GURL nonexistent_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/nonexistent_resource.html"));
ui_test_utils::NavigateToURL(browser(), nonexistent_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("Image failed to load", result);
GURL nonaccessible_cer_resource(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/nonaccessible_chrome_resource_scheme.html"));
ui_test_utils::NavigateToURL(browser(), nonaccessible_cer_resource);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("Loading CER:// failed.", result);
GURL newtab_page("chrome://newtab");
GURL accessible_newtab_override(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/accessible_history_navigation.html"));
ui_test_utils::NavigateToURL(browser(), newtab_page);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), accessible_newtab_override, 2);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("New Tab Page Loaded Successfully", result);
}
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
WebAccessibleResourcesWithCSP) {
std::string result;
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("web_accessible")));
GURL accessible_resource_with_csp(
test_server()->GetURL(
"files/extensions/api_test/extension_resource_request_policy/"
"web_accessible/accessible_resource_with_csp.html"));
ui_test_utils::NavigateToURL(browser(), accessible_resource_with_csp);
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.title)",
&result));
EXPECT_EQ("Loaded", result);
}
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Iframe) {
// Load another extension, which the test one shouldn't be able to get
// resources from.
ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("inaccessible")));
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/web_accessible",
"iframe.html")) << message_;
}
#if defined(OS_MACOSX)
#define MAYBE_ExtensionAccessibleResources DISABLED_ExtensionAccessibleResources
#else
#define MAYBE_ExtensionAccessibleResources ExtensionAccessibleResources
#endif
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
MAYBE_ExtensionAccessibleResources) {
ASSERT_TRUE(RunExtensionSubtest("accessible_cer", "main.html")) << message_;
}
|