Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/browser/extensions/extension_protocols_unittest.cc

Issue 55163006: Allow navigations performed by extensions to pass through AllowExtensionResourceLoad. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix webview case. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_protocols.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 #include "net/url_request/url_request_test_util.h" 25 #include "net/url_request/url_request_test_util.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace extensions { 28 namespace extensions {
29 29
30 scoped_refptr<Extension> CreateTestExtension(const std::string& name, 30 scoped_refptr<Extension> CreateTestExtension(const std::string& name,
31 bool incognito_split_mode) { 31 bool incognito_split_mode) {
32 DictionaryValue manifest; 32 DictionaryValue manifest;
33 manifest.SetString("name", name); 33 manifest.SetString("name", name);
34 manifest.SetString("version", "1"); 34 manifest.SetString("version", "1");
35 manifest.SetInteger("manifest_version", 2);
35 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning"); 36 manifest.SetString("incognito", incognito_split_mode ? "split" : "spanning");
36 37
37 base::FilePath path; 38 base::FilePath path;
38 EXPECT_TRUE(file_util::GetCurrentDirectory(&path)); 39 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
40 path = path.AppendASCII("extensions").AppendASCII("response_headers");
39 41
40 std::string error; 42 std::string error;
41 scoped_refptr<Extension> extension( 43 scoped_refptr<Extension> extension(
42 Extension::Create(path, Manifest::INTERNAL, manifest, 44 Extension::Create(path, Manifest::INTERNAL, manifest,
43 Extension::NO_FLAGS, &error)); 45 Extension::NO_FLAGS, &error));
44 EXPECT_TRUE(extension.get()) << error; 46 EXPECT_TRUE(extension.get()) << error;
45 return extension; 47 return extension;
46 } 48 }
47 49
48 scoped_refptr<Extension> CreateWebStoreExtension() { 50 scoped_refptr<Extension> CreateWebStoreExtension() {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_EQ("no-cache", revalidation_header); 280 EXPECT_EQ("no-cache", revalidation_header);
279 281
280 // We set test.dat as web-accessible, so it should have a CORS header. 282 // We set test.dat as web-accessible, so it should have a CORS header.
281 std::string access_control; 283 std::string access_control;
282 request.GetResponseHeaderByName("Access-Control-Allow-Origin", 284 request.GetResponseHeaderByName("Access-Control-Allow-Origin",
283 &access_control); 285 &access_control);
284 EXPECT_EQ("*", access_control); 286 EXPECT_EQ("*", access_control);
285 } 287 }
286 } 288 }
287 289
290 // Tests that a URL request for main frame or subframe from an extension
291 // succeeds, but subresources fail. See http://crbug.com/312269.
292 TEST_F(ExtensionProtocolTest, AllowFrameRequests) {
293 // Register a non-incognito extension protocol handler.
294 SetProtocolHandler(false);
295
296 scoped_refptr<Extension> extension = CreateTestExtension("foo", false);
297 extension_info_map_->AddExtension(extension.get(), base::Time::Now(), false);
298
299 // All MAIN_FRAME and SUB_FRAME requests should succeed.
300 {
301 net::URLRequest request(extension->GetResourceURL("test.dat"),
302 net::DEFAULT_PRIORITY,
303 &test_delegate_,
304 resource_context_.GetRequestContext());
305 StartRequest(&request, ResourceType::MAIN_FRAME);
306 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status());
307 }
308 {
309 net::URLRequest request(extension->GetResourceURL("test.dat"),
310 net::DEFAULT_PRIORITY,
311 &test_delegate_,
312 resource_context_.GetRequestContext());
313 StartRequest(&request, ResourceType::SUB_FRAME);
314 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status());
315 }
316
317 // And subresource types, such as media, should fail.
318 {
319 net::URLRequest request(extension->GetResourceURL("test.dat"),
320 net::DEFAULT_PRIORITY,
321 &test_delegate_,
322 resource_context_.GetRequestContext());
323 StartRequest(&request, ResourceType::MEDIA);
324 EXPECT_EQ(net::URLRequestStatus::FAILED, request.status().status());
325 }
326 }
327
288 } // namespace extensions 328 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_protocols.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698