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

Unified 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 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 150ba607c9a350b550c8b84122d46c9cda5bb701..533f370b8d430d2225c5fe9203e6db472da3acee 100644
--- a/chrome/browser/extensions/active_tab_unittest.cc
+++ b/chrome/browser/extensions/active_tab_unittest.cc
@@ -84,34 +84,36 @@ class ActiveTabTest : public ChromeRenderViewHostTestHarness {
active_tab_permission_granter();
}
- bool IsAllowed(const scoped_refptr<const Extension>& extension,
+ 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.
const GURL& url) {
- return IsAllowed(extension, url, tab_id());
+ return IsScriptAllowed(extension, url, tab_id());
}
- bool IsAllowed(const scoped_refptr<const Extension>& extension,
+ bool IsScriptAllowed(const scoped_refptr<const Extension>& extension,
const GURL& url,
int tab_id) {
return PermissionsData::CanExecuteScriptOnPage(
- extension.get(), url, url, tab_id, NULL, -1, NULL) &&
- PermissionsData::CanCaptureVisiblePage(
- extension.get(), url, tab_id, NULL) &&
- HasTabsPermission(extension, tab_id);
+ extension.get(), url, url, tab_id, NULL, -1, NULL);
+ }
+
+ bool IsCaptureAllowed(const scoped_refptr<const Extension>& extension) {
+ return HasTabsPermission(extension, tab_id()) &&
+ PermissionsData::CanCaptureVisiblePage(extension.get(), tab_id(), NULL);
}
- bool IsBlocked(const scoped_refptr<const Extension>& extension,
+ bool IsBothBlocked(const scoped_refptr<const Extension>& extension,
const GURL& url) {
- return IsBlocked(extension, url, tab_id());
+ return IsBothBlocked(extension, url, tab_id());
}
- bool IsBlocked(const scoped_refptr<const Extension>& extension,
- const GURL& url,
- int tab_id) {
+ bool IsBothBlocked(const scoped_refptr<const Extension>& extension,
+ const GURL& url,
+ int tab_id) {
// Note: can't check HasTabsPermission because it isn't URL specific.
return !PermissionsData::CanExecuteScriptOnPage(
extension.get(), url, url, tab_id, NULL, -1, NULL) &&
!PermissionsData::CanCaptureVisiblePage(
- extension.get(), url, tab_id, NULL);
+ extension.get(), tab_id, NULL);
not at google - send to devlin 2014/01/21 21:44:21 indentation around here needs updating
}
bool HasTabsPermission(const scoped_refptr<const Extension>& extension) {
@@ -153,9 +155,9 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
NavigateAndCommit(google);
// No access unless it's been granted.
- EXPECT_TRUE(IsBlocked(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsBothBlocked(extension, google));
+ EXPECT_TRUE(IsBothBlocked(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
EXPECT_FALSE(HasTabsPermission(extension));
EXPECT_FALSE(HasTabsPermission(another_extension));
@@ -165,24 +167,28 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
active_tab_permission_granter()->GrantIfRequested(
extension_without_active_tab.get());
+ EXPECT_TRUE(IsCaptureAllowed(extension));
+ EXPECT_FALSE(IsCaptureAllowed(another_extension));
+ EXPECT_FALSE(IsCaptureAllowed(extension_without_active_tab));
+
// Granted to extension and extension_without_active_tab, but the latter
// doesn't have the activeTab permission so not granted.
- EXPECT_TRUE(IsAllowed(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
+ EXPECT_TRUE(IsBothBlocked(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
// Other subdomains shouldn't be given access.
GURL mail_google("http://mail.google.com");
- EXPECT_TRUE(IsBlocked(extension, mail_google));
- EXPECT_TRUE(IsBlocked(another_extension, mail_google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, mail_google));
+ EXPECT_FALSE(IsScriptAllowed(extension, mail_google));
+ EXPECT_FALSE(IsScriptAllowed(another_extension, mail_google));
+ EXPECT_FALSE(IsScriptAllowed(extension_without_active_tab, mail_google));
// Reloading the page should clear the active permissions.
Reload();
- EXPECT_TRUE(IsBlocked(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsBothBlocked(extension, google));
+ EXPECT_TRUE(IsBothBlocked(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
EXPECT_FALSE(HasTabsPermission(extension));
EXPECT_FALSE(HasTabsPermission(another_extension));
@@ -191,9 +197,11 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
// But they should still be able to be granted again.
active_tab_permission_granter()->GrantIfRequested(extension.get());
- EXPECT_TRUE(IsAllowed(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsCaptureAllowed(extension));
+
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
+ EXPECT_TRUE(IsBothBlocked(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
// And grant a few more times redundantly for good measure.
active_tab_permission_granter()->GrantIfRequested(extension.get());
@@ -206,21 +214,24 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
active_tab_permission_granter()->GrantIfRequested(another_extension.get());
active_tab_permission_granter()->GrantIfRequested(another_extension.get());
- EXPECT_TRUE(IsAllowed(extension, google));
- EXPECT_TRUE(IsAllowed(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsCaptureAllowed(extension));
+ EXPECT_TRUE(IsCaptureAllowed(another_extension));
+
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
+ EXPECT_TRUE(IsScriptAllowed(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
// Navigating to a new URL should clear the active permissions.
GURL chromium("http://www.chromium.org");
NavigateAndCommit(chromium);
- EXPECT_TRUE(IsBlocked(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsBothBlocked(extension, google));
+ EXPECT_TRUE(IsBothBlocked(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
- EXPECT_TRUE(IsBlocked(extension, chromium));
- EXPECT_TRUE(IsBlocked(another_extension, chromium));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium));
+ EXPECT_TRUE(IsBothBlocked(extension, chromium));
+ EXPECT_TRUE(IsBothBlocked(another_extension, chromium));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
EXPECT_FALSE(HasTabsPermission(extension));
EXPECT_FALSE(HasTabsPermission(another_extension));
@@ -233,13 +244,16 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
active_tab_permission_granter()->GrantIfRequested(
extension_without_active_tab.get());
- EXPECT_TRUE(IsBlocked(extension, google));
- EXPECT_TRUE(IsBlocked(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsCaptureAllowed(extension));
+ EXPECT_TRUE(IsCaptureAllowed(another_extension));
- EXPECT_TRUE(IsAllowed(extension, chromium));
- EXPECT_TRUE(IsAllowed(another_extension, chromium));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium));
+ EXPECT_FALSE(IsScriptAllowed(extension, google));
+ EXPECT_FALSE(IsScriptAllowed(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
+
+ EXPECT_TRUE(IsScriptAllowed(extension, chromium));
+ EXPECT_TRUE(IsScriptAllowed(another_extension, chromium));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
// Should be able to go back to URLs that were previously cleared.
NavigateAndCommit(google);
@@ -249,13 +263,16 @@ TEST_F(ActiveTabTest, GrantToSinglePage) {
active_tab_permission_granter()->GrantIfRequested(
extension_without_active_tab.get());
- EXPECT_TRUE(IsAllowed(extension, google));
- EXPECT_TRUE(IsAllowed(another_extension, google));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, google));
+ EXPECT_TRUE(IsCaptureAllowed(extension));
+ EXPECT_TRUE(IsCaptureAllowed(another_extension));
+
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
+ EXPECT_TRUE(IsScriptAllowed(another_extension, google));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, google));
- EXPECT_TRUE(IsBlocked(extension, chromium));
- EXPECT_TRUE(IsBlocked(another_extension, chromium));
- EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium));
+ EXPECT_FALSE(IsScriptAllowed(extension, chromium));
+ EXPECT_FALSE(IsScriptAllowed(another_extension, chromium));
+ EXPECT_TRUE(IsBothBlocked(extension_without_active_tab, chromium));
};
TEST_F(ActiveTabTest, Uninstalling) {
@@ -266,7 +283,7 @@ TEST_F(ActiveTabTest, Uninstalling) {
active_tab_permission_granter()->GrantIfRequested(extension.get());
EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
- EXPECT_TRUE(IsAllowed(extension, google));
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
// Uninstalling the extension should clear its tab permissions.
UnloadedExtensionInfo details(extension.get(),
@@ -277,15 +294,15 @@ TEST_F(ActiveTabTest, Uninstalling) {
web_contents()->GetBrowserContext())),
content::Details<UnloadedExtensionInfo>(&details));
- // 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.
+ // Note: can't EXPECT_FALSE(IsScriptAllowed) here because uninstalled
+ // extensions are just that... considered to be uninstalled, and the manager
+ // might just ignore them from here on.
// Granting the extension again should give them back.
active_tab_permission_granter()->GrantIfRequested(extension.get());
EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents()));
- EXPECT_TRUE(IsAllowed(extension, google));
+ EXPECT_TRUE(IsScriptAllowed(extension, google));
}
TEST_F(ActiveTabTest, OnlyActiveTab) {
@@ -294,8 +311,8 @@ TEST_F(ActiveTabTest, OnlyActiveTab) {
active_tab_permission_granter()->GrantIfRequested(extension.get());
- EXPECT_TRUE(IsAllowed(extension, google, tab_id()));
- EXPECT_TRUE(IsBlocked(extension, google, tab_id() + 1));
+ EXPECT_TRUE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_TRUE(IsBothBlocked(extension, google, tab_id() + 1));
EXPECT_FALSE(HasTabsPermission(extension, tab_id() + 1));
}
@@ -310,36 +327,36 @@ TEST_F(ActiveTabTest, NavigateInPage) {
GURL google_h1("http://www.google.com#h1");
NavigateAndCommit(google_h1);
- EXPECT_TRUE(IsAllowed(extension, google, tab_id()));
- EXPECT_TRUE(IsAllowed(extension, google_h1, tab_id()));
+ EXPECT_TRUE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_TRUE(IsScriptAllowed(extension, google_h1, tab_id()));
GURL chromium("http://www.chromium.org");
NavigateAndCommit(chromium);
- EXPECT_FALSE(IsAllowed(extension, google, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, chromium, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, chromium, tab_id()));
active_tab_permission_granter()->GrantIfRequested(extension.get());
- EXPECT_FALSE(IsAllowed(extension, google, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id()));
- EXPECT_TRUE(IsAllowed(extension, chromium, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
+ EXPECT_TRUE(IsScriptAllowed(extension, chromium, tab_id()));
GURL chromium_h1("http://www.chromium.org#h1");
NavigateAndCommit(chromium_h1);
- EXPECT_FALSE(IsAllowed(extension, google, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id()));
- EXPECT_TRUE(IsAllowed(extension, chromium, tab_id()));
- EXPECT_TRUE(IsAllowed(extension, chromium_h1, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
+ EXPECT_TRUE(IsScriptAllowed(extension, chromium, tab_id()));
+ EXPECT_TRUE(IsScriptAllowed(extension, chromium_h1, tab_id()));
Reload();
- EXPECT_FALSE(IsAllowed(extension, google, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, chromium, tab_id()));
- EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, google_h1, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, chromium, tab_id()));
+ EXPECT_FALSE(IsScriptAllowed(extension, chromium_h1, tab_id()));
}
TEST_F(ActiveTabTest, ChromeUrlGrants) {
@@ -348,13 +365,15 @@ TEST_F(ActiveTabTest, ChromeUrlGrants) {
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(IsCaptureAllowed(extension_with_tab_capture));
+ EXPECT_FALSE(IsScriptAllowed(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_TRUE(
+ IsBothBlocked(extension_with_tab_capture, internal, tab_id() + 1));
EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab(
extension_with_tab_capture.get(),
tab_id() + 1,
« 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