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

Unified Diff: chrome/browser/extensions/active_tab_unittest.cc

Issue 17298002: Allow tabCapture API to be granted for chrome:// pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests.. how did it even work before? Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/active_tab_unittest.cc
diff --git a/chrome/browser/extensions/active_tab_unittest.cc b/chrome/browser/extensions/active_tab_unittest.cc
index 93bd889d4ab37ede451f9ac9847d4cc4a0731352..ae16beb23525195c79b41400b697868560fbbc40 100644
--- a/chrome/browser/extensions/active_tab_unittest.cc
+++ b/chrome/browser/extensions/active_tab_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/sessions/session_id.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_builder.h"
+#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/extensions/permissions/permissions_data.h"
#include "chrome/common/extensions/value_builder.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
@@ -39,10 +40,13 @@ namespace {
scoped_refptr<const Extension> CreateTestExtension(
const std::string& id,
- bool has_active_tab_permission) {
+ bool has_active_tab_permission,
+ bool has_tab_capture_permission) {
ListBuilder permissions;
if (has_active_tab_permission)
permissions.Append("activeTab");
+ if (has_tab_capture_permission)
+ permissions.Append("tabCapture");
return ExtensionBuilder()
.SetManifest(DictionaryBuilder()
.Set("name", "Extension with ID " + id)
@@ -56,9 +60,15 @@ scoped_refptr<const Extension> CreateTestExtension(
class ActiveTabTest : public ChromeRenderViewHostTestHarness {
protected:
ActiveTabTest()
- : extension(CreateTestExtension("deadbeef", true)),
- another_extension(CreateTestExtension("feedbeef", true)),
- extension_without_active_tab(CreateTestExtension("badbeef", false)) {}
+ : current_channel(chrome::VersionInfo::CHANNEL_DEV),
+ extension(CreateTestExtension("deadbeef", true, false)),
+ another_extension(CreateTestExtension("feedbeef", true, false)),
+ extension_without_active_tab(CreateTestExtension("badbeef",
+ false,
+ false)),
+ extension_with_tab_capture(CreateTestExtension("cafebeef",
+ true,
+ true)) {}
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
@@ -114,6 +124,17 @@ class ActiveTabTest : public ChromeRenderViewHostTestHarness {
extension.get(), tab_id, APIPermission::kTab);
}
+ bool IsGrantedForTab(const Extension* extension,
+ const content::WebContents* web_contents) {
+ return PermissionsData::HasAPIPermissionForTab(
+ extension,
+ SessionID::IdForTab(web_contents),
+ APIPermission::kTab);
+ }
+
+ // TODO(justinlin): Remove when tabCapture is moved to stable.
+ ScopedCurrentChannel current_channel;
+
// An extension with the activeTab permission.
scoped_refptr<const Extension> extension;
@@ -122,6 +143,9 @@ class ActiveTabTest : public ChromeRenderViewHostTestHarness {
// An extension without the activeTab permission.
scoped_refptr<const Extension> extension_without_active_tab;
+
+ // An extension with both the activeTab and tabCapture permission.
+ scoped_refptr<const Extension> extension_with_tab_capture;
};
TEST_F(ActiveTabTest, GrantToSinglePage) {
@@ -241,7 +265,7 @@ TEST_F(ActiveTabTest, Uninstalling) {
active_tab_permission_granter()->GrantIfRequested(extension.get());
- EXPECT_TRUE(active_tab_permission_granter()->IsGranted(extension.get()));
+ EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
EXPECT_TRUE(IsAllowed(extension, google));
// Uninstalling the extension should clear its tab permissions.
@@ -253,7 +277,6 @@ TEST_F(ActiveTabTest, Uninstalling) {
web_contents()->GetBrowserContext())),
content::Details<UnloadedExtensionInfo>(&details));
- EXPECT_FALSE(active_tab_permission_granter()->IsGranted(extension.get()));
// Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions
// are just that... considered to be uninstalled, and the manager might
// just ignore them from here on.
@@ -261,7 +284,7 @@ TEST_F(ActiveTabTest, Uninstalling) {
// Granting the extension again should give them back.
active_tab_permission_granter()->GrantIfRequested(extension.get());
- EXPECT_TRUE(active_tab_permission_granter()->IsGranted(extension.get()));
+ EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
EXPECT_TRUE(IsAllowed(extension, google));
}
@@ -319,5 +342,24 @@ TEST_F(ActiveTabTest, NavigateInPage) {
EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id()));
}
+TEST_F(ActiveTabTest, ChromeUrlGrants) {
+ GURL internal("chrome://version");
+ NavigateAndCommit(internal);
+ active_tab_permission_granter()->GrantIfRequested(
+ extension_with_tab_capture.get());
+ // Do not grant tabs/hosts permissions for tab.
+ EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id()));
+ EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab(
+ extension_with_tab_capture.get(),
+ tab_id(),
+ APIPermission::kTabCaptureForTab));
+
+ EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1));
+ EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab(
+ extension_with_tab_capture.get(),
+ tab_id() + 1,
+ APIPermission::kTabCaptureForTab));
+}
+
} // namespace
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698