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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 | 28 |
29 scoped_refptr<Extension> CreateTestExtension(const std::string& name, | 29 scoped_refptr<Extension> CreateTestExtension(const std::string& name, |
30 bool incognito_split_mode) { | 30 bool incognito_split_mode) { |
31 DictionaryValue manifest; | 31 DictionaryValue manifest; |
32 manifest.SetString("name", name); | 32 manifest.SetString("name", name); |
33 manifest.SetString("version", "1"); | 33 manifest.SetString("version", "1"); |
| 34 manifest.SetInteger("manifest_version", 2); |
34 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning"); | 35 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning"); |
35 | 36 |
36 base::FilePath path; | 37 base::FilePath path; |
37 EXPECT_TRUE(file_util::GetCurrentDirectory(&path)); | 38 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 39 path = path.AppendASCII("extensions").AppendASCII("response_headers"); |
38 | 40 |
39 std::string error; | 41 std::string error; |
40 scoped_refptr<Extension> extension( | 42 scoped_refptr<Extension> extension( |
41 Extension::Create(path, Manifest::INTERNAL, manifest, | 43 Extension::Create(path, Manifest::INTERNAL, manifest, |
42 Extension::NO_FLAGS, &error)); | 44 Extension::NO_FLAGS, &error)); |
43 EXPECT_TRUE(extension.get()) << error; | 45 EXPECT_TRUE(extension.get()) << error; |
44 return extension; | 46 return extension; |
45 } | 47 } |
46 | 48 |
47 scoped_refptr<Extension> CreateWebStoreExtension() { | 49 scoped_refptr<Extension> CreateWebStoreExtension() { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 EXPECT_EQ("no-cache", revalidation_header); | 274 EXPECT_EQ("no-cache", revalidation_header); |
273 | 275 |
274 // We set test.dat as web-accessible, so it should have a CORS header. | 276 // We set test.dat as web-accessible, so it should have a CORS header. |
275 std::string access_control; | 277 std::string access_control; |
276 request.GetResponseHeaderByName("Access-Control-Allow-Origin", | 278 request.GetResponseHeaderByName("Access-Control-Allow-Origin", |
277 &access_control); | 279 &access_control); |
278 EXPECT_EQ("*", access_control); | 280 EXPECT_EQ("*", access_control); |
279 } | 281 } |
280 } | 282 } |
281 | 283 |
| 284 // Tests that a URL request for main frame or subframe from an extension |
| 285 // succeeds, but subresources fail. See http://crbug.com/312269. |
| 286 TEST_F(ExtensionProtocolTest, AllowFrameRequests) { |
| 287 // Register a non-incognito extension protocol handler. |
| 288 SetProtocolHandler(false); |
| 289 |
| 290 scoped_refptr<Extension> extension = CreateTestExtension("foo", false); |
| 291 extension_info_map_->AddExtension(extension.get(), base::Time::Now(), false); |
| 292 |
| 293 // All MAIN_FRAME and SUB_FRAME requests should succeed. |
| 294 { |
| 295 net::URLRequest request(extension->GetResourceURL("test.dat"), |
| 296 &test_delegate_, |
| 297 resource_context_.GetRequestContext()); |
| 298 StartRequest(&request, ResourceType::MAIN_FRAME); |
| 299 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status()); |
| 300 } |
| 301 { |
| 302 net::URLRequest request(extension->GetResourceURL("test.dat"), |
| 303 &test_delegate_, |
| 304 resource_context_.GetRequestContext()); |
| 305 StartRequest(&request, ResourceType::SUB_FRAME); |
| 306 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status()); |
| 307 } |
| 308 |
| 309 // And subresource types, such as media, should fail. |
| 310 { |
| 311 net::URLRequest request(extension->GetResourceURL("test.dat"), |
| 312 &test_delegate_, |
| 313 resource_context_.GetRequestContext()); |
| 314 StartRequest(&request, ResourceType::MEDIA); |
| 315 EXPECT_EQ(net::URLRequestStatus::FAILED, request.status().status()); |
| 316 } |
| 317 } |
| 318 |
282 } // namespace extensions | 319 } // namespace extensions |
OLD | NEW |