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 "extensions/browser/api/web_request/web_request_permissions.h" | 5 #include "extensions/browser/api/web_request/web_request_permissions.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/common/extensions/extension_test_util.h" | 9 #include "chrome/common/extensions/extension_test_util.h" |
10 #include "content/public/browser/resource_request_info.h" | 10 #include "content/public/browser/resource_request_info.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 "http://www.gstatic.com/chrome/extensions/blacklist", | 88 "http://www.gstatic.com/chrome/extensions/blacklist", |
89 "https://www.gstatic.com/chrome/extensions/blacklist", | 89 "https://www.gstatic.com/chrome/extensions/blacklist", |
90 "notregisteredscheme://www.foobar.com", | 90 "notregisteredscheme://www.foobar.com", |
91 "https://chrome.google.com/webstore/", | 91 "https://chrome.google.com/webstore/", |
92 "https://chrome.google.com/webstore/" | 92 "https://chrome.google.com/webstore/" |
93 "inlineinstall/detail/kcnhkahnjcbndmmehfkdnkjomaanaooo" | 93 "inlineinstall/detail/kcnhkahnjcbndmmehfkdnkjomaanaooo" |
94 }; | 94 }; |
95 const char* const non_sensitive_urls[] = { | 95 const char* const non_sensitive_urls[] = { |
96 "http://www.google.com/" | 96 "http://www.google.com/" |
97 }; | 97 }; |
98 const int kSigninProcessId = 99; | |
99 extension_info_map_->SetSigninProcess(kSigninProcessId); | |
100 | 98 |
101 // Check that requests are rejected based on the destination | 99 // Check that requests are rejected based on the destination |
102 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { | 100 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { |
103 GURL sensitive_url(sensitive_urls[i]); | 101 GURL sensitive_url(sensitive_urls[i]); |
104 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 102 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
105 sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 103 sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); |
106 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 104 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
107 extension_info_map_.get(), request.get())) << sensitive_urls[i]; | 105 extension_info_map_.get(), request.get())) << sensitive_urls[i]; |
108 } | 106 } |
109 // Check that requests are accepted if they don't touch sensitive urls. | 107 // Check that requests are accepted if they don't touch sensitive urls. |
(...skipping 28 matching lines...) Expand all Loading... |
138 MSG_ROUTING_NONE, | 136 MSG_ROUTING_NONE, |
139 false, // is_main_frame | 137 false, // is_main_frame |
140 false, // parent_is_main_frame | 138 false, // parent_is_main_frame |
141 true, // allow_download | 139 true, // allow_download |
142 false); // is_async | 140 false); // is_async |
143 extension_info_map_->RegisterExtensionProcess( | 141 extension_info_map_->RegisterExtensionProcess( |
144 extensions::kWebStoreAppId, process_id, site_instance_id); | 142 extensions::kWebStoreAppId, process_id, site_instance_id); |
145 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 143 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
146 extension_info_map_.get(), sensitive_request.get())); | 144 extension_info_map_.get(), sensitive_request.get())); |
147 } | 145 } |
148 // If the process is the signin process, it becomes protected. | |
149 { | |
150 int process_id = kSigninProcessId; | |
151 int view_id = 19; | |
152 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( | |
153 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | |
154 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), | |
155 content::RESOURCE_TYPE_SCRIPT, | |
156 NULL, | |
157 process_id, | |
158 view_id, | |
159 MSG_ROUTING_NONE, | |
160 false, // is_main_frame | |
161 false, // parent_is_main_frame | |
162 true, // allow_download | |
163 false); // is_async | |
164 EXPECT_TRUE(WebRequestPermissions::HideRequest( | |
165 extension_info_map_.get(), sensitive_request.get())); | |
166 } | |
167 } | 146 } |
168 | 147 |
169 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, | 148 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, |
170 TestCanExtensionAccessURL_HostPermissions) { | 149 TestCanExtensionAccessURL_HostPermissions) { |
171 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 150 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
172 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); | 151 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); |
173 | 152 |
174 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( | 153 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( |
175 extension_info_map_.get(), | 154 extension_info_map_.get(), |
176 permissionless_extension_->id(), | 155 permissionless_extension_->id(), |
(...skipping 12 matching lines...) Expand all Loading... |
189 request->url(), | 168 request->url(), |
190 false /*crosses_incognito*/, | 169 false /*crosses_incognito*/, |
191 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 170 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
192 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( | 171 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( |
193 extension_info_map_.get(), | 172 extension_info_map_.get(), |
194 com_extension_->id(), | 173 com_extension_->id(), |
195 request->url(), | 174 request->url(), |
196 false /*crosses_incognito*/, | 175 false /*crosses_incognito*/, |
197 WebRequestPermissions::REQUIRE_ALL_URLS)); | 176 WebRequestPermissions::REQUIRE_ALL_URLS)); |
198 } | 177 } |
OLD | NEW |