OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 ASSERT_EQ(0u, warnings.size()); | 304 ASSERT_EQ(0u, warnings.size()); |
305 #else | 305 #else |
306 ASSERT_EQ(1u, warnings.size()); | 306 ASSERT_EQ(1u, warnings.size()); |
307 EXPECT_EQ( | 307 EXPECT_EQ( |
308 "Read and modify all your data on your computer and the websites you " | 308 "Read and modify all your data on your computer and the websites you " |
309 "visit", | 309 "visit", |
310 UTF16ToUTF8(warnings[0])); | 310 UTF16ToUTF8(warnings[0])); |
311 #endif | 311 #endif |
312 } | 312 } |
313 | 313 |
314 // Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage | 314 // Base class for testing the CanAccessPage and CanCaptureVisiblePage |
315 // methods of Extension for extensions with various permissions. | 315 // methods of Extension for extensions with various permissions. |
316 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { | 316 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { |
317 protected: | 317 protected: |
318 ExtensionScriptAndCaptureVisibleTest() | 318 ExtensionScriptAndCaptureVisibleTest() |
319 : http_url("http://www.google.com"), | 319 : http_url("http://www.google.com"), |
320 http_url_with_path("http://www.google.com/index.html"), | 320 http_url_with_path("http://www.google.com/index.html"), |
321 https_url("https://www.google.com"), | 321 https_url("https://www.google.com"), |
322 file_url("file:///foo/bar"), | 322 file_url("file:///foo/bar"), |
323 favicon_url("chrome://favicon/http://www.google.com"), | 323 favicon_url("chrome://favicon/http://www.google.com"), |
324 extension_url("chrome-extension://" + | 324 extension_url("chrome-extension://" + |
(...skipping 13 matching lines...) Expand all Loading... |
338 PermissionsData::SetPolicyDelegate(NULL); | 338 PermissionsData::SetPolicyDelegate(NULL); |
339 } | 339 } |
340 | 340 |
341 bool AllowedScript(const Extension* extension, const GURL& url, | 341 bool AllowedScript(const Extension* extension, const GURL& url, |
342 const GURL& top_url) { | 342 const GURL& top_url) { |
343 return AllowedScript(extension, url, top_url, -1); | 343 return AllowedScript(extension, url, top_url, -1); |
344 } | 344 } |
345 | 345 |
346 bool AllowedScript(const Extension* extension, const GURL& url, | 346 bool AllowedScript(const Extension* extension, const GURL& url, |
347 const GURL& top_url, int tab_id) { | 347 const GURL& top_url, int tab_id) { |
348 return extension->permissions_data()->CanExecuteScriptOnPage( | 348 return extension->permissions_data()->CanAccessPage( |
349 extension, url, top_url, tab_id, NULL, -1, NULL); | 349 extension, url, top_url, tab_id, -1, NULL); |
350 } | 350 } |
351 | 351 |
352 bool BlockedScript(const Extension* extension, const GURL& url, | 352 bool BlockedScript(const Extension* extension, const GURL& url, |
353 const GURL& top_url) { | 353 const GURL& top_url) { |
354 return !extension->permissions_data()->CanExecuteScriptOnPage( | 354 return !extension->permissions_data()->CanAccessPage( |
355 extension, url, top_url, -1, NULL, -1, NULL); | 355 extension, url, top_url, -1, -1, NULL); |
356 } | 356 } |
357 | 357 |
358 bool Allowed(const Extension* extension, const GURL& url) { | 358 bool Allowed(const Extension* extension, const GURL& url) { |
359 return Allowed(extension, url, -1); | 359 return Allowed(extension, url, -1); |
360 } | 360 } |
361 | 361 |
362 bool Allowed(const Extension* extension, const GURL& url, int tab_id) { | 362 bool Allowed(const Extension* extension, const GURL& url, int tab_id) { |
363 return (extension->permissions_data()->CanExecuteScriptOnPage( | 363 return (extension->permissions_data()->CanAccessPage( |
364 extension, url, url, tab_id, NULL, -1, NULL) && | 364 extension, url, url, tab_id, -1, NULL) && |
365 extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL)); | 365 extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL)); |
366 } | 366 } |
367 | 367 |
368 bool CaptureOnly(const Extension* extension, const GURL& url) { | 368 bool CaptureOnly(const Extension* extension, const GURL& url) { |
369 return CaptureOnly(extension, url, -1); | 369 return CaptureOnly(extension, url, -1); |
370 } | 370 } |
371 | 371 |
372 bool CaptureOnly(const Extension* extension, const GURL& url, int tab_id) { | 372 bool CaptureOnly(const Extension* extension, const GURL& url, int tab_id) { |
373 return !extension->permissions_data()->CanExecuteScriptOnPage( | 373 return !extension->permissions_data()->CanAccessPage( |
374 extension, url, url, tab_id, NULL, -1, NULL) && | 374 extension, url, url, tab_id, -1, NULL) && |
375 extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL); | 375 extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL); |
376 } | 376 } |
377 | 377 |
378 bool ScriptOnly(const Extension* extension, const GURL& url, | 378 bool ScriptOnly(const Extension* extension, const GURL& url, |
379 const GURL& top_url) { | 379 const GURL& top_url) { |
380 return ScriptOnly(extension, url, top_url, -1); | 380 return ScriptOnly(extension, url, top_url, -1); |
381 } | 381 } |
382 | 382 |
383 bool ScriptOnly(const Extension* extension, const GURL& url, | 383 bool ScriptOnly(const Extension* extension, const GURL& url, |
384 const GURL& top_url, int tab_id) { | 384 const GURL& top_url, int tab_id) { |
385 return AllowedScript(extension, url, top_url, tab_id) && | 385 return AllowedScript(extension, url, top_url, tab_id) && |
386 !extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL); | 386 !extension->permissions_data()->CanCaptureVisiblePage(tab_id, NULL); |
387 } | 387 } |
388 | 388 |
389 bool Blocked(const Extension* extension, const GURL& url) { | 389 bool Blocked(const Extension* extension, const GURL& url) { |
390 return Blocked(extension, url, -1); | 390 return Blocked(extension, url, -1); |
391 } | 391 } |
392 | 392 |
393 bool Blocked(const Extension* extension, const GURL& url, int tab_id) { | 393 bool Blocked(const Extension* extension, const GURL& url, int tab_id) { |
394 return !(extension->permissions_data()->CanExecuteScriptOnPage( | 394 return !(extension->permissions_data()->CanAccessPage( |
395 extension, url, url, tab_id, NULL, -1, NULL) || | 395 extension, url, url, tab_id, -1, NULL) || |
396 extension->permissions_data()->CanCaptureVisiblePage(tab_id, | 396 extension->permissions_data()->CanCaptureVisiblePage(tab_id, |
397 NULL)); | 397 NULL)); |
398 } | 398 } |
399 | 399 |
400 bool ScriptAllowedExclusivelyOnTab( | 400 bool ScriptAllowedExclusivelyOnTab( |
401 const Extension* extension, | 401 const Extension* extension, |
402 const std::set<GURL>& allowed_urls, | 402 const std::set<GURL>& allowed_urls, |
403 int tab_id) { | 403 int tab_id) { |
404 bool result = true; | 404 bool result = true; |
405 for (std::set<GURL>::iterator it = urls_.begin(); it != urls_.end(); ++it) { | 405 for (std::set<GURL>::iterator it = urls_.begin(); it != urls_.end(); ++it) { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 710 |
711 permissions_data->ClearTabSpecificPermissions(1); | 711 permissions_data->ClearTabSpecificPermissions(1); |
712 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1)); | 712 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1)); |
713 | 713 |
714 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 714 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
715 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 715 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
716 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 716 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
717 } | 717 } |
718 | 718 |
719 } // namespace extensions | 719 } // namespace extensions |
OLD | NEW |