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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "chrome/common/extensions/extension_test_util.h" | 11 #include "chrome/common/extensions/extension_test_util.h" |
12 #include "chromeos/login/login_state.h" | 12 #include "chromeos/login/login_state.h" |
13 #include "content/public/browser/resource_request_info.h" | 13 #include "content/public/browser/resource_request_info.h" |
| 14 #include "content/public/common/previews_state.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "extensions/browser/api/web_request/web_request_permissions.h" | 16 #include "extensions/browser/api/web_request/web_request_permissions.h" |
16 #include "extensions/browser/info_map.h" | 17 #include "extensions/browser/info_map.h" |
17 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
18 #include "extensions/common/permissions/permissions_data.h" | 19 #include "extensions/common/permissions/permissions_data.h" |
19 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 context.CreateRequest(non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); | 145 context.CreateRequest(non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
145 EXPECT_FALSE(WebRequestPermissions::HideRequest( | 146 EXPECT_FALSE(WebRequestPermissions::HideRequest( |
146 extension_info_map_.get(), non_sensitive_request.get(), nullptr)); | 147 extension_info_map_.get(), non_sensitive_request.get(), nullptr)); |
147 // If the origin is labeled by the WebStoreAppId, it becomes protected. | 148 // If the origin is labeled by the WebStoreAppId, it becomes protected. |
148 { | 149 { |
149 int process_id = 42; | 150 int process_id = 42; |
150 int site_instance_id = 23; | 151 int site_instance_id = 23; |
151 int view_id = 17; | 152 int view_id = 17; |
152 std::unique_ptr<net::URLRequest> sensitive_request( | 153 std::unique_ptr<net::URLRequest> sensitive_request( |
153 context.CreateRequest(non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); | 154 context.CreateRequest(non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
154 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), | 155 ResourceRequestInfo::AllocateForTesting( |
155 content::RESOURCE_TYPE_SCRIPT, | 156 sensitive_request.get(), content::RESOURCE_TYPE_SCRIPT, NULL, |
156 NULL, | 157 process_id, view_id, MSG_ROUTING_NONE, |
157 process_id, | 158 /*is_main_frame=*/false, |
158 view_id, | 159 /*parent_is_main_frame=*/false, |
159 MSG_ROUTING_NONE, | 160 /*allow_download=*/true, |
160 false, // is_main_frame | 161 /*is_async=*/false, content::PREVIEWS_OFF); |
161 false, // parent_is_main_frame | 162 extension_info_map_->RegisterExtensionProcess(extensions::kWebStoreAppId, |
162 true, // allow_download | 163 process_id, site_instance_id); |
163 false, // is_async | |
164 false); // is_using_lofi | |
165 extension_info_map_->RegisterExtensionProcess( | |
166 extensions::kWebStoreAppId, process_id, site_instance_id); | |
167 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 164 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
168 extension_info_map_.get(), sensitive_request.get(), nullptr)); | 165 extension_info_map_.get(), sensitive_request.get(), nullptr)); |
169 } | 166 } |
170 } | 167 } |
171 | 168 |
172 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, | 169 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, |
173 TestCanExtensionAccessURL_HostPermissions) { | 170 TestCanExtensionAccessURL_HostPermissions) { |
174 std::unique_ptr<net::URLRequest> request(context.CreateRequest( | 171 std::unique_ptr<net::URLRequest> request(context.CreateRequest( |
175 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL)); | 172 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL)); |
176 | 173 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 242 |
246 EXPECT_EQ(PermissionsData::ACCESS_DENIED, | 243 EXPECT_EQ(PermissionsData::ACCESS_DENIED, |
247 WebRequestPermissions::CanExtensionAccessURL( | 244 WebRequestPermissions::CanExtensionAccessURL( |
248 extension_info_map_.get(), com_policy_extension_->id(), | 245 extension_info_map_.get(), com_policy_extension_->id(), |
249 chrome_request->url(), | 246 chrome_request->url(), |
250 -1, // No tab id. | 247 -1, // No tab id. |
251 false, // crosses_incognito | 248 false, // crosses_incognito |
252 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 249 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
253 #endif | 250 #endif |
254 } | 251 } |
OLD | NEW |