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

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

Issue 140433003: tab capture: Change the permissions for tabs.captureVisibleTab(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 | Annotate | Revision Log
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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 int tab_id() { 78 int tab_id() {
79 return SessionID::IdForTab(web_contents()); 79 return SessionID::IdForTab(web_contents());
80 } 80 }
81 81
82 ActiveTabPermissionGranter* active_tab_permission_granter() { 82 ActiveTabPermissionGranter* active_tab_permission_granter() {
83 return extensions::TabHelper::FromWebContents(web_contents())-> 83 return extensions::TabHelper::FromWebContents(web_contents())->
84 active_tab_permission_granter(); 84 active_tab_permission_granter();
85 } 85 }
86 86
87 bool IsAllowed(const scoped_refptr<const Extension>& extension, 87 bool IsScriptAllowed(const scoped_refptr<const Extension>& extension,
not at google - send to devlin 2014/01/21 21:44:21 Comment for whole file: this is a pretty severe ch
sadrul 2014/01/23 20:11:14 Done.
88 const GURL& url) { 88 const GURL& url) {
89 return IsAllowed(extension, url, tab_id()); 89 return IsScriptAllowed(extension, url, tab_id());
90 } 90 }
91 91
92 bool IsAllowed(const scoped_refptr<const Extension>& extension, 92 bool IsScriptAllowed(const scoped_refptr<const Extension>& extension,
93 const GURL& url, 93 const GURL& url,
94 int tab_id) { 94 int tab_id) {
95 return PermissionsData::CanExecuteScriptOnPage( 95 return PermissionsData::CanExecuteScriptOnPage(
96 extension.get(), url, url, tab_id, NULL, -1, NULL) && 96 extension.get(), url, url, tab_id, NULL, -1, NULL);
97 PermissionsData::CanCaptureVisiblePage(
98 extension.get(), url, tab_id, NULL) &&
99 HasTabsPermission(extension, tab_id);
100 } 97 }
101 98
102 bool IsBlocked(const scoped_refptr<const Extension>& extension, 99 bool IsCaptureAllowed(const scoped_refptr<const Extension>& extension) {
103 const GURL& url) { 100 return HasTabsPermission(extension, tab_id()) &&
104 return IsBlocked(extension, url, tab_id()); 101 PermissionsData::CanCaptureVisiblePage(extension.get(), tab_id(), NULL);
105 } 102 }
106 103
107 bool IsBlocked(const scoped_refptr<const Extension>& extension, 104 bool IsBothBlocked(const scoped_refptr<const Extension>& extension,
108 const GURL& url, 105 const GURL& url) {
109 int tab_id) { 106 return IsBothBlocked(extension, url, tab_id());
107 }
108
109 bool IsBothBlocked(const scoped_refptr<const Extension>& extension,
110 const GURL& url,
111 int tab_id) {
110 // Note: can't check HasTabsPermission because it isn't URL specific. 112 // Note: can't check HasTabsPermission because it isn't URL specific.
111 return !PermissionsData::CanExecuteScriptOnPage( 113 return !PermissionsData::CanExecuteScriptOnPage(
112 extension.get(), url, url, tab_id, NULL, -1, NULL) && 114 extension.get(), url, url, tab_id, NULL, -1, NULL) &&
113 !PermissionsData::CanCaptureVisiblePage( 115 !PermissionsData::CanCaptureVisiblePage(
114 extension.get(), url, tab_id, NULL); 116 extension.get(), tab_id, NULL);
not at google - send to devlin 2014/01/21 21:44:21 indentation around here needs updating
115 } 117 }
116 118
117 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { 119 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) {
118 return HasTabsPermission(extension, tab_id()); 120 return HasTabsPermission(extension, tab_id());
119 } 121 }
120 122
121 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, 123 bool HasTabsPermission(const scoped_refptr<const Extension>& extension,
122 int tab_id) { 124 int tab_id) {
123 return PermissionsData::HasAPIPermissionForTab( 125 return PermissionsData::HasAPIPermissionForTab(
124 extension.get(), tab_id, APIPermission::kTab); 126 extension.get(), tab_id, APIPermission::kTab);
(...skipping 21 matching lines...) Expand all
146 148
147 // An extension with both the activeTab and tabCapture permission. 149 // An extension with both the activeTab and tabCapture permission.
148 scoped_refptr<const Extension> extension_with_tab_capture; 150 scoped_refptr<const Extension> extension_with_tab_capture;
149 }; 151 };
150 152
151 TEST_F(ActiveTabTest, GrantToSinglePage) { 153 TEST_F(ActiveTabTest, GrantToSinglePage) {
152 GURL google("http://www.google.com"); 154 GURL google("http://www.google.com");
153 NavigateAndCommit(google); 155 NavigateAndCommit(google);
154 156
155 // No access unless it's been granted. 157 // No access unless it's been granted.
156 EXPECT_TRUE(IsBlocked(extension, google)); 158 EXPECT_TRUE(IsBothBlocked(extension, google));
157 EXPECT_TRUE(IsBlocked(another_extension, google)); 159 EXPECT_TRUE(IsBothBlocked(another_extension, google));
158 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 160 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
159 161
160 EXPECT_FALSE(HasTabsPermission(extension)); 162 EXPECT_FALSE(HasTabsPermission(extension));
161 EXPECT_FALSE(HasTabsPermission(another_extension)); 163 EXPECT_FALSE(HasTabsPermission(another_extension));
162 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab)); 164 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab));
163 165
164 active_tab_permission_granter()->GrantIfRequested(extension.get()); 166 active_tab_permission_granter()->GrantIfRequested(extension.get());
165 active_tab_permission_granter()->GrantIfRequested( 167 active_tab_permission_granter()->GrantIfRequested(
166 extension_without_active_tab.get()); 168 extension_without_active_tab.get());
167 169
170 EXPECT_TRUE(IsCaptureAllowed(extension));
171 EXPECT_FALSE(IsCaptureAllowed(another_extension));
172 EXPECT_FALSE(IsCaptureAllowed(extension_without_active_tab));
173
168 // Granted to extension and extension_without_active_tab, but the latter 174 // Granted to extension and extension_without_active_tab, but the latter
169 // doesn't have the activeTab permission so not granted. 175 // doesn't have the activeTab permission so not granted.
170 EXPECT_TRUE(IsAllowed(extension, google)); 176 EXPECT_TRUE(IsScriptAllowed(extension, google));
171 EXPECT_TRUE(IsBlocked(another_extension, google)); 177 EXPECT_TRUE(IsBothBlocked(another_extension, google));
172 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 178 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
173 179
174 // Other subdomains shouldn't be given access. 180 // Other subdomains shouldn't be given access.
175 GURL mail_google("http://mail.google.com"); 181 GURL mail_google("http://mail.google.com");
176 EXPECT_TRUE(IsBlocked(extension, mail_google)); 182 EXPECT_FALSE(IsScriptAllowed(extension, mail_google));
177 EXPECT_TRUE(IsBlocked(another_extension, mail_google)); 183 EXPECT_FALSE(IsScriptAllowed(another_extension, mail_google));
178 EXPECT_TRUE(IsBlocked(extension_without_active_tab, mail_google)); 184 EXPECT_FALSE(IsScriptAllowed(extension_without_active_tab, mail_google));
179 185
180 // Reloading the page should clear the active permissions. 186 // Reloading the page should clear the active permissions.
181 Reload(); 187 Reload();
182 188
183 EXPECT_TRUE(IsBlocked(extension, google)); 189 EXPECT_TRUE(IsBothBlocked(extension, google));
184 EXPECT_TRUE(IsBlocked(another_extension, google)); 190 EXPECT_TRUE(IsBothBlocked(another_extension, google));
185 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 191 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
186 192
187 EXPECT_FALSE(HasTabsPermission(extension)); 193 EXPECT_FALSE(HasTabsPermission(extension));
188 EXPECT_FALSE(HasTabsPermission(another_extension)); 194 EXPECT_FALSE(HasTabsPermission(another_extension));
189 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab)); 195 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab));
190 196
191 // But they should still be able to be granted again. 197 // But they should still be able to be granted again.
192 active_tab_permission_granter()->GrantIfRequested(extension.get()); 198 active_tab_permission_granter()->GrantIfRequested(extension.get());
193 199
194 EXPECT_TRUE(IsAllowed(extension, google)); 200 EXPECT_TRUE(IsCaptureAllowed(extension));
195 EXPECT_TRUE(IsBlocked(another_extension, google)); 201
196 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 202 EXPECT_TRUE(IsScriptAllowed(extension, google));
203 EXPECT_TRUE(IsBothBlocked(another_extension, google));
204 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
197 205
198 // And grant a few more times redundantly for good measure. 206 // And grant a few more times redundantly for good measure.
199 active_tab_permission_granter()->GrantIfRequested(extension.get()); 207 active_tab_permission_granter()->GrantIfRequested(extension.get());
200 active_tab_permission_granter()->GrantIfRequested(extension.get()); 208 active_tab_permission_granter()->GrantIfRequested(extension.get());
201 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 209 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
202 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 210 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
203 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 211 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
204 active_tab_permission_granter()->GrantIfRequested(extension.get()); 212 active_tab_permission_granter()->GrantIfRequested(extension.get());
205 active_tab_permission_granter()->GrantIfRequested(extension.get()); 213 active_tab_permission_granter()->GrantIfRequested(extension.get());
206 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 214 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
207 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 215 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
208 216
209 EXPECT_TRUE(IsAllowed(extension, google)); 217 EXPECT_TRUE(IsCaptureAllowed(extension));
210 EXPECT_TRUE(IsAllowed(another_extension, google)); 218 EXPECT_TRUE(IsCaptureAllowed(another_extension));
211 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 219
220 EXPECT_TRUE(IsScriptAllowed(extension, google));
221 EXPECT_TRUE(IsScriptAllowed(another_extension, google));
222 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
212 223
213 // Navigating to a new URL should clear the active permissions. 224 // Navigating to a new URL should clear the active permissions.
214 GURL chromium("http://www.chromium.org"); 225 GURL chromium("http://www.chromium.org");
215 NavigateAndCommit(chromium); 226 NavigateAndCommit(chromium);
216 227
217 EXPECT_TRUE(IsBlocked(extension, google)); 228 EXPECT_TRUE(IsBothBlocked(extension, google));
218 EXPECT_TRUE(IsBlocked(another_extension, google)); 229 EXPECT_TRUE(IsBothBlocked(another_extension, google));
219 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); 230 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
220 231
221 EXPECT_TRUE(IsBlocked(extension, chromium)); 232 EXPECT_TRUE(IsBothBlocked(extension, chromium));
222 EXPECT_TRUE(IsBlocked(another_extension, chromium)); 233 EXPECT_TRUE(IsBothBlocked(another_extension, chromium));
223 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); 234 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
224 235
225 EXPECT_FALSE(HasTabsPermission(extension)); 236 EXPECT_FALSE(HasTabsPermission(extension));
226 EXPECT_FALSE(HasTabsPermission(another_extension)); 237 EXPECT_FALSE(HasTabsPermission(another_extension));
227 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab)); 238 EXPECT_FALSE(HasTabsPermission(extension_without_active_tab));
228 239
229 // Should be able to grant to multiple extensions at the same time (if they 240 // Should be able to grant to multiple extensions at the same time (if they
230 // have the activeTab permission, of course). 241 // have the activeTab permission, of course).
231 active_tab_permission_granter()->GrantIfRequested(extension.get()); 242 active_tab_permission_granter()->GrantIfRequested(extension.get());
232 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 243 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
233 active_tab_permission_granter()->GrantIfRequested( 244 active_tab_permission_granter()->GrantIfRequested(
234 extension_without_active_tab.get()); 245 extension_without_active_tab.get());
235 246
236 EXPECT_TRUE(IsBlocked(extension, google)); 247 EXPECT_TRUE(IsCaptureAllowed(extension));
237 EXPECT_TRUE(IsBlocked(another_extension, google)); 248 EXPECT_TRUE(IsCaptureAllowed(another_extension));
238 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
239 249
240 EXPECT_TRUE(IsAllowed(extension, chromium)); 250 EXPECT_FALSE(IsScriptAllowed(extension, google));
241 EXPECT_TRUE(IsAllowed(another_extension, chromium)); 251 EXPECT_FALSE(IsScriptAllowed(another_extension, google));
242 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); 252 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
253
254 EXPECT_TRUE(IsScriptAllowed(extension, chromium));
255 EXPECT_TRUE(IsScriptAllowed(another_extension, chromium));
256 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
243 257
244 // Should be able to go back to URLs that were previously cleared. 258 // Should be able to go back to URLs that were previously cleared.
245 NavigateAndCommit(google); 259 NavigateAndCommit(google);
246 260
247 active_tab_permission_granter()->GrantIfRequested(extension.get()); 261 active_tab_permission_granter()->GrantIfRequested(extension.get());
248 active_tab_permission_granter()->GrantIfRequested(another_extension.get()); 262 active_tab_permission_granter()->GrantIfRequested(another_extension.get());
249 active_tab_permission_granter()->GrantIfRequested( 263 active_tab_permission_granter()->GrantIfRequested(
250 extension_without_active_tab.get()); 264 extension_without_active_tab.get());
251 265
252 EXPECT_TRUE(IsAllowed(extension, google)); 266 EXPECT_TRUE(IsCaptureAllowed(extension));
253 EXPECT_TRUE(IsAllowed(another_extension, google)); 267 EXPECT_TRUE(IsCaptureAllowed(another_extension));
254 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
255 268
256 EXPECT_TRUE(IsBlocked(extension, chromium)); 269 EXPECT_TRUE(IsScriptAllowed(extension, google));
257 EXPECT_TRUE(IsBlocked(another_extension, chromium)); 270 EXPECT_TRUE(IsScriptAllowed(another_extension, google));
258 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); 271 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
272
273 EXPECT_FALSE(IsScriptAllowed(extension, chromium));
274 EXPECT_FALSE(IsScriptAllowed(another_extension, chromium));
275 EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
259 }; 276 };
260 277
261 TEST_F(ActiveTabTest, Uninstalling) { 278 TEST_F(ActiveTabTest, Uninstalling) {
262 // Some semi-arbitrary setup. 279 // Some semi-arbitrary setup.
263 GURL google("http://www.google.com"); 280 GURL google("http://www.google.com");
264 NavigateAndCommit(google); 281 NavigateAndCommit(google);
265 282
266 active_tab_permission_granter()->GrantIfRequested(extension.get()); 283 active_tab_permission_granter()->GrantIfRequested(extension.get());
267 284
268 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents())); 285 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
269 EXPECT_TRUE(IsAllowed(extension, google)); 286 EXPECT_TRUE(IsScriptAllowed(extension, google));
270 287
271 // Uninstalling the extension should clear its tab permissions. 288 // Uninstalling the extension should clear its tab permissions.
272 UnloadedExtensionInfo details(extension.get(), 289 UnloadedExtensionInfo details(extension.get(),
273 UnloadedExtensionInfo::REASON_DISABLE); 290 UnloadedExtensionInfo::REASON_DISABLE);
274 content::NotificationService::current()->Notify( 291 content::NotificationService::current()->Notify(
275 chrome::NOTIFICATION_EXTENSION_UNLOADED, 292 chrome::NOTIFICATION_EXTENSION_UNLOADED,
276 content::Source<Profile>(Profile::FromBrowserContext( 293 content::Source<Profile>(Profile::FromBrowserContext(
277 web_contents()->GetBrowserContext())), 294 web_contents()->GetBrowserContext())),
278 content::Details<UnloadedExtensionInfo>(&details)); 295 content::Details<UnloadedExtensionInfo>(&details));
279 296
280 // Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions 297 // Note: can't EXPECT_FALSE(IsScriptAllowed) here because uninstalled
281 // are just that... considered to be uninstalled, and the manager might 298 // extensions are just that... considered to be uninstalled, and the manager
282 // just ignore them from here on. 299 // might just ignore them from here on.
283 300
284 // Granting the extension again should give them back. 301 // Granting the extension again should give them back.
285 active_tab_permission_granter()->GrantIfRequested(extension.get()); 302 active_tab_permission_granter()->GrantIfRequested(extension.get());
286 303
287 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents())); 304 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
288 EXPECT_TRUE(IsAllowed(extension, google)); 305 EXPECT_TRUE(IsScriptAllowed(extension, google));
289 } 306 }
290 307
291 TEST_F(ActiveTabTest, OnlyActiveTab) { 308 TEST_F(ActiveTabTest, OnlyActiveTab) {
292 GURL google("http://www.google.com"); 309 GURL google("http://www.google.com");
293 NavigateAndCommit(google); 310 NavigateAndCommit(google);
294 311
295 active_tab_permission_granter()->GrantIfRequested(extension.get()); 312 active_tab_permission_granter()->GrantIfRequested(extension.get());
296 313
297 EXPECT_TRUE(IsAllowed(extension, google, tab_id())); 314 EXPECT_TRUE(IsScriptAllowed(extension, google, tab_id()));
298 EXPECT_TRUE(IsBlocked(extension, google, tab_id() + 1)); 315 EXPECT_TRUE(IsBothBlocked(extension, google, tab_id() + 1));
299 EXPECT_FALSE(HasTabsPermission(extension, tab_id() + 1)); 316 EXPECT_FALSE(HasTabsPermission(extension, tab_id() + 1));
300 } 317 }
301 318
302 TEST_F(ActiveTabTest, NavigateInPage) { 319 TEST_F(ActiveTabTest, NavigateInPage) {
303 GURL google("http://www.google.com"); 320 GURL google("http://www.google.com");
304 NavigateAndCommit(google); 321 NavigateAndCommit(google);
305 322
306 active_tab_permission_granter()->GrantIfRequested(extension.get()); 323 active_tab_permission_granter()->GrantIfRequested(extension.get());
307 324
308 // Perform an in-page navigation. The extension should not lose the temporary 325 // Perform an in-page navigation. The extension should not lose the temporary
309 // permission. 326 // permission.
310 GURL google_h1("http://www.google.com#h1"); 327 GURL google_h1("http://www.google.com#h1");
311 NavigateAndCommit(google_h1); 328 NavigateAndCommit(google_h1);
312 329
313 EXPECT_TRUE(IsAllowed(extension, google, tab_id())); 330 EXPECT_TRUE(IsScriptAllowed(extension, google, tab_id()));
314 EXPECT_TRUE(IsAllowed(extension, google_h1, tab_id())); 331 EXPECT_TRUE(IsScriptAllowed(extension, google_h1, tab_id()));
315 332
316 GURL chromium("http://www.chromium.org"); 333 GURL chromium("http://www.chromium.org");
317 NavigateAndCommit(chromium); 334 NavigateAndCommit(chromium);
318 335
319 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); 336 EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
320 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); 337 EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
321 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); 338 EXPECT_FALSE(IsScriptAllowed(extension, chromium, tab_id()));
322 339
323 active_tab_permission_granter()->GrantIfRequested(extension.get()); 340 active_tab_permission_granter()->GrantIfRequested(extension.get());
324 341
325 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); 342 EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
326 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); 343 EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
327 EXPECT_TRUE(IsAllowed(extension, chromium, tab_id())); 344 EXPECT_TRUE(IsScriptAllowed(extension, chromium, tab_id()));
328 345
329 GURL chromium_h1("http://www.chromium.org#h1"); 346 GURL chromium_h1("http://www.chromium.org#h1");
330 NavigateAndCommit(chromium_h1); 347 NavigateAndCommit(chromium_h1);
331 348
332 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); 349 EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
333 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); 350 EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
334 EXPECT_TRUE(IsAllowed(extension, chromium, tab_id())); 351 EXPECT_TRUE(IsScriptAllowed(extension, chromium, tab_id()));
335 EXPECT_TRUE(IsAllowed(extension, chromium_h1, tab_id())); 352 EXPECT_TRUE(IsScriptAllowed(extension, chromium_h1, tab_id()));
336 353
337 Reload(); 354 Reload();
338 355
339 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); 356 EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
340 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); 357 EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
341 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); 358 EXPECT_FALSE(IsScriptAllowed(extension, chromium, tab_id()));
342 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); 359 EXPECT_FALSE(IsScriptAllowed(extension, chromium_h1, tab_id()));
343 } 360 }
344 361
345 TEST_F(ActiveTabTest, ChromeUrlGrants) { 362 TEST_F(ActiveTabTest, ChromeUrlGrants) {
346 GURL internal("chrome://version"); 363 GURL internal("chrome://version");
347 NavigateAndCommit(internal); 364 NavigateAndCommit(internal);
348 active_tab_permission_granter()->GrantIfRequested( 365 active_tab_permission_granter()->GrantIfRequested(
349 extension_with_tab_capture.get()); 366 extension_with_tab_capture.get());
350 // Do not grant tabs/hosts permissions for tab. 367 // Do not grant tabs/hosts permissions for tab.
351 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id())); 368 EXPECT_TRUE(IsCaptureAllowed(extension_with_tab_capture));
369 EXPECT_FALSE(IsScriptAllowed(extension_with_tab_capture, internal, tab_id()));
352 EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab( 370 EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab(
353 extension_with_tab_capture.get(), 371 extension_with_tab_capture.get(),
354 tab_id(), 372 tab_id(),
355 APIPermission::kTabCaptureForTab)); 373 APIPermission::kTabCaptureForTab));
356 374
357 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); 375 EXPECT_TRUE(
376 IsBothBlocked(extension_with_tab_capture, internal, tab_id() + 1));
358 EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab( 377 EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab(
359 extension_with_tab_capture.get(), 378 extension_with_tab_capture.get(),
360 tab_id() + 1, 379 tab_id() + 1,
361 APIPermission::kTabCaptureForTab)); 380 APIPermission::kTabCaptureForTab));
362 } 381 }
363 382
364 } // namespace 383 } // namespace
365 } // namespace extensions 384 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_api.cc » ('j') | extensions/common/manifest_constants.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698