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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
11 #include "chrome/browser/extensions/extension_protocols.h" | 12 #include "chrome/browser/extensions/extension_protocols.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "content/public/browser/resource_request_info.h" | 17 #include "content/public/browser/resource_request_info.h" |
17 #include "content/public/test/mock_resource_context.h" | 18 #include "content/public/test/mock_resource_context.h" |
18 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 path = path.AppendASCII("web_store"); | 57 path = path.AppendASCII("web_store"); |
57 | 58 |
58 std::string error; | 59 std::string error; |
59 scoped_refptr<Extension> extension( | 60 scoped_refptr<Extension> extension( |
60 Extension::Create(path, Manifest::COMPONENT, manifest, | 61 Extension::Create(path, Manifest::COMPONENT, manifest, |
61 Extension::NO_FLAGS, &error)); | 62 Extension::NO_FLAGS, &error)); |
62 EXPECT_TRUE(extension.get()) << error; | 63 EXPECT_TRUE(extension.get()) << error; |
63 return extension; | 64 return extension; |
64 } | 65 } |
65 | 66 |
67 scoped_refptr<Extension> CreateTestResponseHeaderExtension() { | |
68 DictionaryValue manifest; | |
69 manifest.SetString("name", "An extension with web-accessible resources"); | |
70 manifest.SetString("version", "2"); | |
71 | |
72 ListValue* web_accessible_list = new ListValue(); | |
73 web_accessible_list->AppendString("test.dat"); | |
74 manifest.Set("web_accessible_resources", web_accessible_list); | |
75 | |
76 base::FilePath path; | |
77 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | |
78 path = path.AppendASCII("extensions").AppendASCII("response_headers"); | |
79 | |
80 std::string error; | |
81 scoped_refptr<Extension> extension( | |
82 Extension::Create(path, Manifest::UNPACKED, manifest, | |
rvargas (doing something else)
2013/06/03 21:12:37
I'm assuming that the extension destructor does cl
jvoung (off chromium)
2013/06/03 22:08:22
It doesn't look like the destructor does anything,
Matt Perry
2013/06/03 22:17:19
Yep, no new files are created by this test.
| |
83 Extension::NO_FLAGS, &error)); | |
84 EXPECT_TRUE(extension.get()) << error; | |
85 return extension; | |
86 } | |
87 | |
66 class ExtensionProtocolTest : public testing::Test { | 88 class ExtensionProtocolTest : public testing::Test { |
67 public: | 89 public: |
68 ExtensionProtocolTest() | 90 ExtensionProtocolTest() |
69 : ui_thread_(BrowserThread::UI, &message_loop_), | 91 : ui_thread_(BrowserThread::UI, &message_loop_), |
70 file_thread_(BrowserThread::FILE, &message_loop_), | 92 file_thread_(BrowserThread::FILE, &message_loop_), |
71 io_thread_(BrowserThread::IO, &message_loop_) {} | 93 io_thread_(BrowserThread::IO, &message_loop_) {} |
72 | 94 |
73 virtual void SetUp() OVERRIDE { | 95 virtual void SetUp() OVERRIDE { |
74 testing::Test::SetUp(); | 96 testing::Test::SetUp(); |
75 extension_info_map_ = new ExtensionInfoMap(); | 97 extension_info_map_ = new ExtensionInfoMap(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 extension_misc::UNLOAD_REASON_DISABLE); | 231 extension_misc::UNLOAD_REASON_DISABLE); |
210 { | 232 { |
211 net::URLRequest request(extension->GetResourceURL("webstore_icon_16.png"), | 233 net::URLRequest request(extension->GetResourceURL("webstore_icon_16.png"), |
212 &test_delegate_, | 234 &test_delegate_, |
213 resource_context_.GetRequestContext()); | 235 resource_context_.GetRequestContext()); |
214 StartRequest(&request, ResourceType::MEDIA); | 236 StartRequest(&request, ResourceType::MEDIA); |
215 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status()); | 237 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status()); |
216 } | 238 } |
217 } | 239 } |
218 | 240 |
241 // Tests that a URL request for resource from an extension returns a few | |
242 // expected response headers. | |
243 TEST_F(ExtensionProtocolTest, ResourceRequestResponseHeaders) { | |
244 // Register a non-incognito extension protocol handler. | |
245 SetProtocolHandler(false); | |
246 | |
247 scoped_refptr<Extension> extension = CreateTestResponseHeaderExtension(); | |
248 extension_info_map_->AddExtension(extension, base::Time::Now(), false); | |
249 | |
250 { | |
251 net::URLRequest request(extension->GetResourceURL("test.dat"), | |
252 &test_delegate_, | |
253 resource_context_.GetRequestContext()); | |
254 StartRequest(&request, ResourceType::MEDIA); | |
255 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status()); | |
256 | |
257 // Check that cache-related headers are set. | |
258 std::string etag; | |
259 request.GetResponseHeaderByName("ETag", &etag); | |
260 EXPECT_TRUE(StartsWithASCII(etag, "\"", false)); | |
261 EXPECT_TRUE(EndsWith(etag, "\"", false)); | |
262 | |
263 std::string revalidation_header; | |
264 request.GetResponseHeaderByName("cache-control", &revalidation_header); | |
265 EXPECT_EQ("no-cache", revalidation_header); | |
266 | |
267 // We set test.dat as web-accessible, so it should have a CORS header. | |
268 std::string access_control; | |
269 request.GetResponseHeaderByName("Access-Control-Allow-Origin", | |
270 &access_control); | |
271 EXPECT_EQ("*", access_control); | |
272 } | |
273 } | |
274 | |
219 } // namespace extensions | 275 } // namespace extensions |
OLD | NEW |