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

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

Issue 2007133004: Disallow navigation to documents not explicitly listed as web accessible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix up subframe cases. Created 4 years, 6 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 std::string name; 191 std::string name;
192 bool incognito_split_mode; 192 bool incognito_split_mode;
193 bool incognito_enabled; 193 bool incognito_enabled;
194 194
195 // Expected results. 195 // Expected results.
196 bool should_allow_main_frame_load; 196 bool should_allow_main_frame_load;
197 bool should_allow_sub_frame_load; 197 bool should_allow_sub_frame_load;
198 } cases[] = { 198 } cases[] = {
199 {"spanning disabled", false, false, false, false}, 199 {"spanning disabled", false, false, false, false},
200 {"split disabled", true, false, false, false}, 200 {"split disabled", true, false, false, false},
201 {"spanning enabled", false, true, false, true}, 201 {"spanning enabled", false, true, false, false},
202 {"split enabled", true, true, true, true}, 202 {"split enabled", true, true, true, false},
203 }; 203 };
204 204
205 for (size_t i = 0; i < arraysize(cases); ++i) { 205 for (size_t i = 0; i < arraysize(cases); ++i) {
206 scoped_refptr<Extension> extension = 206 scoped_refptr<Extension> extension =
207 CreateTestExtension(cases[i].name, cases[i].incognito_split_mode); 207 CreateTestExtension(cases[i].name, cases[i].incognito_split_mode);
208 extension_info_map_->AddExtension( 208 extension_info_map_->AddExtension(
209 extension.get(), base::Time::Now(), cases[i].incognito_enabled, false); 209 extension.get(), base::Time::Now(), cases[i].incognito_enabled, false);
210 210
211 // First test a main frame request. 211 // First test a main frame request.
212 { 212 {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 TEST_F(ExtensionProtocolTest, AllowFrameRequests) { 339 TEST_F(ExtensionProtocolTest, AllowFrameRequests) {
340 // Register a non-incognito extension protocol handler. 340 // Register a non-incognito extension protocol handler.
341 SetProtocolHandler(false); 341 SetProtocolHandler(false);
342 342
343 scoped_refptr<Extension> extension = CreateTestExtension("foo", false); 343 scoped_refptr<Extension> extension = CreateTestExtension("foo", false);
344 extension_info_map_->AddExtension(extension.get(), 344 extension_info_map_->AddExtension(extension.get(),
345 base::Time::Now(), 345 base::Time::Now(),
346 false, 346 false,
347 false); 347 false);
348 348
349 // All MAIN_FRAME and SUB_FRAME requests should succeed. 349 // All MAIN_FRAME and SUB_FRAME requests should succeed.
asargent_no_longer_on_chrome 2016/05/31 18:17:38 nit: mind updating this comment? Something like "A
nasko 2016/05/31 23:16:17 Done.
350 { 350 {
351 std::unique_ptr<net::URLRequest> request( 351 std::unique_ptr<net::URLRequest> request(
352 resource_context_.GetRequestContext()->CreateRequest( 352 resource_context_.GetRequestContext()->CreateRequest(
353 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY, 353 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY,
354 &test_delegate_)); 354 &test_delegate_));
355 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME); 355 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME);
356 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 356 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
357 } 357 }
358 { 358 {
359 std::unique_ptr<net::URLRequest> request( 359 std::unique_ptr<net::URLRequest> request(
360 resource_context_.GetRequestContext()->CreateRequest( 360 resource_context_.GetRequestContext()->CreateRequest(
361 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY, 361 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY,
362 &test_delegate_)); 362 &test_delegate_));
363 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME); 363 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
364 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 364 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
365 } 365 }
366 366
367 // And subresource types, such as media, should fail. 367 // And subresource types, such as media, should fail.
368 { 368 {
369 std::unique_ptr<net::URLRequest> request( 369 std::unique_ptr<net::URLRequest> request(
370 resource_context_.GetRequestContext()->CreateRequest( 370 resource_context_.GetRequestContext()->CreateRequest(
371 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY, 371 extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY,
372 &test_delegate_)); 372 &test_delegate_));
373 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA); 373 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA);
374 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 374 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
(...skipping 22 matching lines...) Expand all
397 DoRequest(*extension, relative_path.AsUTF8Unsafe())); 397 DoRequest(*extension, relative_path.AsUTF8Unsafe()));
398 398
399 // Loading "/_metadata/a.txt" should also fail. 399 // Loading "/_metadata/a.txt" should also fail.
400 relative_path = base::FilePath(kMetadataFolder).AppendASCII("a.txt"); 400 relative_path = base::FilePath(kMetadataFolder).AppendASCII("a.txt");
401 EXPECT_TRUE(base::PathExists(extension_dir.Append(relative_path))); 401 EXPECT_TRUE(base::PathExists(extension_dir.Append(relative_path)));
402 EXPECT_EQ(net::URLRequestStatus::FAILED, 402 EXPECT_EQ(net::URLRequestStatus::FAILED,
403 DoRequest(*extension, relative_path.AsUTF8Unsafe())); 403 DoRequest(*extension, relative_path.AsUTF8Unsafe()));
404 } 404 }
405 405
406 } // namespace extensions 406 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698