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

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

Issue 309533007: Refactor PermissionsData pt1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 bool IsAllowed(const scoped_refptr<const Extension>& extension, 100 bool IsAllowed(const scoped_refptr<const Extension>& extension,
101 const GURL& url, 101 const GURL& url,
102 PermittedFeature feature) { 102 PermittedFeature feature) {
103 return IsAllowed(extension, url, feature, tab_id()); 103 return IsAllowed(extension, url, feature, tab_id());
104 } 104 }
105 105
106 bool IsAllowed(const scoped_refptr<const Extension>& extension, 106 bool IsAllowed(const scoped_refptr<const Extension>& extension,
107 const GURL& url, 107 const GURL& url,
108 PermittedFeature feature, 108 PermittedFeature feature,
109 int tab_id) { 109 int tab_id) {
110 bool script = PermissionsData::CanExecuteScriptOnPage( 110 bool script =
111 extension.get(), url, url, tab_id, NULL, -1, NULL); 111 PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage(
112 extension, url, url, tab_id, NULL, -1, NULL);
112 bool capture = HasTabsPermission(extension, tab_id) && 113 bool capture = HasTabsPermission(extension, tab_id) &&
113 PermissionsData::CanCaptureVisiblePage(extension.get(), tab_id, NULL); 114 PermissionsData::ForExtension(extension)
not at google - send to devlin 2014/06/02 23:20:06 here
Devlin 2014/06/03 15:28:21 Done.
115 ->CanCaptureVisiblePage(tab_id, NULL);
114 switch (feature) { 116 switch (feature) {
115 case PERMITTED_SCRIPT_ONLY: 117 case PERMITTED_SCRIPT_ONLY:
116 return script && !capture; 118 return script && !capture;
117 case PERMITTED_CAPTURE_ONLY: 119 case PERMITTED_CAPTURE_ONLY:
118 return capture && !script; 120 return capture && !script;
119 case PERMITTED_BOTH: 121 case PERMITTED_BOTH:
120 return script && capture; 122 return script && capture;
121 case PERMITTED_NONE: 123 case PERMITTED_NONE:
122 return !script && !capture; 124 return !script && !capture;
123 } 125 }
(...skipping 11 matching lines...) Expand all
135 int tab_id) { 137 int tab_id) {
136 return IsAllowed(extension, url, PERMITTED_NONE, tab_id); 138 return IsAllowed(extension, url, PERMITTED_NONE, tab_id);
137 } 139 }
138 140
139 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { 141 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) {
140 return HasTabsPermission(extension, tab_id()); 142 return HasTabsPermission(extension, tab_id());
141 } 143 }
142 144
143 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, 145 bool HasTabsPermission(const scoped_refptr<const Extension>& extension,
144 int tab_id) { 146 int tab_id) {
145 return PermissionsData::HasAPIPermissionForTab( 147 return PermissionsData::ForExtension(extension)
146 extension.get(), tab_id, APIPermission::kTab); 148 ->HasAPIPermissionForTab(tab_id, APIPermission::kTab);
147 } 149 }
148 150
149 bool IsGrantedForTab(const Extension* extension, 151 bool IsGrantedForTab(const Extension* extension,
150 const content::WebContents* web_contents) { 152 const content::WebContents* web_contents) {
151 return PermissionsData::HasAPIPermissionForTab( 153 return PermissionsData::ForExtension(extension)->HasAPIPermissionForTab(
152 extension, 154 SessionID::IdForTab(web_contents), APIPermission::kTab);
153 SessionID::IdForTab(web_contents),
154 APIPermission::kTab);
155 } 155 }
156 156
157 // TODO(justinlin): Remove when tabCapture is moved to stable. 157 // TODO(justinlin): Remove when tabCapture is moved to stable.
158 ScopedCurrentChannel current_channel; 158 ScopedCurrentChannel current_channel;
159 159
160 // An extension with the activeTab permission. 160 // An extension with the activeTab permission.
161 scoped_refptr<const Extension> extension; 161 scoped_refptr<const Extension> extension;
162 162
163 // Another extension with activeTab (for good measure). 163 // Another extension with activeTab (for good measure).
164 scoped_refptr<const Extension> another_extension; 164 scoped_refptr<const Extension> another_extension;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 362 }
363 363
364 TEST_F(ActiveTabTest, ChromeUrlGrants) { 364 TEST_F(ActiveTabTest, ChromeUrlGrants) {
365 GURL internal("chrome://version"); 365 GURL internal("chrome://version");
366 NavigateAndCommit(internal); 366 NavigateAndCommit(internal);
367 active_tab_permission_granter()->GrantIfRequested( 367 active_tab_permission_granter()->GrantIfRequested(
368 extension_with_tab_capture.get()); 368 extension_with_tab_capture.get());
369 // Do not grant tabs/hosts permissions for tab. 369 // Do not grant tabs/hosts permissions for tab.
370 EXPECT_TRUE(IsAllowed(extension_with_tab_capture, internal, 370 EXPECT_TRUE(IsAllowed(extension_with_tab_capture, internal,
371 PERMITTED_CAPTURE_ONLY)); 371 PERMITTED_CAPTURE_ONLY));
372 EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab( 372 EXPECT_TRUE(
373 extension_with_tab_capture.get(), 373 PermissionsData::ForExtension(extension_with_tab_capture)
374 tab_id(), 374 ->HasAPIPermissionForTab(tab_id(), APIPermission::kTabCaptureForTab));
375 APIPermission::kTabCaptureForTab));
376 375
377 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); 376 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1));
378 EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab( 377 EXPECT_FALSE(PermissionsData::ForExtension(extension_with_tab_capture)
379 extension_with_tab_capture.get(), 378 ->HasAPIPermissionForTab(tab_id() + 1,
380 tab_id() + 1, 379 APIPermission::kTabCaptureForTab));
381 APIPermission::kTabCaptureForTab));
382 } 380 }
383 381
384 } // namespace 382 } // namespace
385 } // namespace extensions 383 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698