Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 21 matching lines...) Expand all Loading... | |
| 32 using base::DictionaryValue; | 32 using base::DictionaryValue; |
| 33 using base::ListValue; | 33 using base::ListValue; |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 using content::NavigationController; | 35 using content::NavigationController; |
| 36 | 36 |
| 37 namespace extensions { | 37 namespace extensions { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 scoped_refptr<const Extension> CreateTestExtension( | 40 scoped_refptr<const Extension> CreateTestExtension( |
| 41 const std::string& id, | 41 const std::string& id, |
| 42 bool has_active_tab_permission) { | 42 bool has_active_tab_permission, |
| 43 bool has_tab_capture_permission) { | |
| 43 ListBuilder permissions; | 44 ListBuilder permissions; |
| 44 if (has_active_tab_permission) | 45 if (has_active_tab_permission) |
| 45 permissions.Append("activeTab"); | 46 permissions.Append("activeTab"); |
| 47 if (has_tab_capture_permission) | |
| 48 permissions.Append("tabCapture"); | |
| 46 return ExtensionBuilder() | 49 return ExtensionBuilder() |
| 47 .SetManifest(DictionaryBuilder() | 50 .SetManifest(DictionaryBuilder() |
| 48 .Set("name", "Extension with ID " + id) | 51 .Set("name", "Extension with ID " + id) |
| 49 .Set("version", "1.0") | 52 .Set("version", "1.0") |
| 50 .Set("manifest_version", 2) | 53 .Set("manifest_version", 2) |
| 51 .Set("permissions", permissions)) | 54 .Set("permissions", permissions)) |
| 52 .SetID(id) | 55 .SetID(id) |
| 53 .Build(); | 56 .Build(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 class ActiveTabTest : public ChromeRenderViewHostTestHarness { | 59 class ActiveTabTest : public ChromeRenderViewHostTestHarness { |
| 57 protected: | 60 protected: |
| 58 ActiveTabTest() | 61 ActiveTabTest() |
| 59 : extension(CreateTestExtension("deadbeef", true)), | 62 : extension(CreateTestExtension("deadbeef", true, false)), |
| 60 another_extension(CreateTestExtension("feedbeef", true)), | 63 another_extension(CreateTestExtension("feedbeef", true, false)), |
| 61 extension_without_active_tab(CreateTestExtension("badbeef", false)) {} | 64 extension_without_active_tab(CreateTestExtension("badbeef", |
| 65 false, | |
| 66 false)), | |
| 67 extension_with_tab_capture(CreateTestExtension("cafebeef", | |
| 68 true, | |
| 69 true)) {} | |
| 62 | 70 |
| 63 virtual void SetUp() OVERRIDE { | 71 virtual void SetUp() OVERRIDE { |
| 64 ChromeRenderViewHostTestHarness::SetUp(); | 72 ChromeRenderViewHostTestHarness::SetUp(); |
| 65 TabHelper::CreateForWebContents(web_contents()); | 73 TabHelper::CreateForWebContents(web_contents()); |
| 66 } | 74 } |
| 67 | 75 |
| 68 int tab_id() { | 76 int tab_id() { |
| 69 return SessionID::IdForTab(web_contents()); | 77 return SessionID::IdForTab(web_contents()); |
| 70 } | 78 } |
| 71 | 79 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 123 } |
| 116 | 124 |
| 117 // An extension with the activeTab permission. | 125 // An extension with the activeTab permission. |
| 118 scoped_refptr<const Extension> extension; | 126 scoped_refptr<const Extension> extension; |
| 119 | 127 |
| 120 // Another extension with activeTab (for good measure). | 128 // Another extension with activeTab (for good measure). |
| 121 scoped_refptr<const Extension> another_extension; | 129 scoped_refptr<const Extension> another_extension; |
| 122 | 130 |
| 123 // An extension without the activeTab permission. | 131 // An extension without the activeTab permission. |
| 124 scoped_refptr<const Extension> extension_without_active_tab; | 132 scoped_refptr<const Extension> extension_without_active_tab; |
| 133 | |
| 134 // An extension with both the activeTab and tabCapture permission. | |
| 135 scoped_refptr<const Extension> extension_with_tab_capture; | |
| 125 }; | 136 }; |
| 126 | 137 |
| 127 TEST_F(ActiveTabTest, GrantToSinglePage) { | 138 TEST_F(ActiveTabTest, GrantToSinglePage) { |
| 128 GURL google("http://www.google.com"); | 139 GURL google("http://www.google.com"); |
| 129 NavigateAndCommit(google); | 140 NavigateAndCommit(google); |
| 130 | 141 |
| 131 // No access unless it's been granted. | 142 // No access unless it's been granted. |
| 132 EXPECT_TRUE(IsBlocked(extension, google)); | 143 EXPECT_TRUE(IsBlocked(extension, google)); |
| 133 EXPECT_TRUE(IsBlocked(another_extension, google)); | 144 EXPECT_TRUE(IsBlocked(another_extension, google)); |
| 134 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); | 145 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); | 245 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); |
| 235 }; | 246 }; |
| 236 | 247 |
| 237 TEST_F(ActiveTabTest, Uninstalling) { | 248 TEST_F(ActiveTabTest, Uninstalling) { |
| 238 // Some semi-arbitrary setup. | 249 // Some semi-arbitrary setup. |
| 239 GURL google("http://www.google.com"); | 250 GURL google("http://www.google.com"); |
| 240 NavigateAndCommit(google); | 251 NavigateAndCommit(google); |
| 241 | 252 |
| 242 active_tab_permission_granter()->GrantIfRequested(extension.get()); | 253 active_tab_permission_granter()->GrantIfRequested(extension.get()); |
| 243 | 254 |
| 244 EXPECT_TRUE(active_tab_permission_granter()->IsGranted(extension.get())); | 255 EXPECT_TRUE(ActiveTabPermissionGranter::IsGrantedForTab(extension.get(), |
| 256 web_contents())); | |
| 245 EXPECT_TRUE(IsAllowed(extension, google)); | 257 EXPECT_TRUE(IsAllowed(extension, google)); |
| 246 | 258 |
| 247 // Uninstalling the extension should clear its tab permissions. | 259 // Uninstalling the extension should clear its tab permissions. |
| 248 UnloadedExtensionInfo details(extension.get(), | 260 UnloadedExtensionInfo details(extension.get(), |
| 249 extension_misc::UNLOAD_REASON_DISABLE); | 261 extension_misc::UNLOAD_REASON_DISABLE); |
| 250 content::NotificationService::current()->Notify( | 262 content::NotificationService::current()->Notify( |
| 251 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 263 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 252 content::Source<Profile>(Profile::FromBrowserContext( | 264 content::Source<Profile>(Profile::FromBrowserContext( |
| 253 web_contents()->GetBrowserContext())), | 265 web_contents()->GetBrowserContext())), |
| 254 content::Details<UnloadedExtensionInfo>(&details)); | 266 content::Details<UnloadedExtensionInfo>(&details)); |
| 255 | 267 |
| 256 EXPECT_FALSE(active_tab_permission_granter()->IsGranted(extension.get())); | |
| 257 // Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions | 268 // Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions |
| 258 // are just that... considered to be uninstalled, and the manager might | 269 // are just that... considered to be uninstalled, and the manager might |
| 259 // just ignore them from here on. | 270 // just ignore them from here on. |
| 260 | 271 |
| 261 // Granting the extension again should give them back. | 272 // Granting the extension again should give them back. |
| 262 active_tab_permission_granter()->GrantIfRequested(extension.get()); | 273 active_tab_permission_granter()->GrantIfRequested(extension.get()); |
| 263 | 274 |
| 264 EXPECT_TRUE(active_tab_permission_granter()->IsGranted(extension.get())); | 275 EXPECT_TRUE(ActiveTabPermissionGranter::IsGrantedForTab(extension.get(), |
| 276 web_contents())); | |
| 265 EXPECT_TRUE(IsAllowed(extension, google)); | 277 EXPECT_TRUE(IsAllowed(extension, google)); |
| 266 } | 278 } |
| 267 | 279 |
| 268 TEST_F(ActiveTabTest, OnlyActiveTab) { | 280 TEST_F(ActiveTabTest, OnlyActiveTab) { |
| 269 GURL google("http://www.google.com"); | 281 GURL google("http://www.google.com"); |
| 270 NavigateAndCommit(google); | 282 NavigateAndCommit(google); |
| 271 | 283 |
| 272 active_tab_permission_granter()->GrantIfRequested(extension.get()); | 284 active_tab_permission_granter()->GrantIfRequested(extension.get()); |
| 273 | 285 |
| 274 EXPECT_TRUE(IsAllowed(extension, google, tab_id())); | 286 EXPECT_TRUE(IsAllowed(extension, google, tab_id())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 EXPECT_TRUE(IsAllowed(extension, chromium_h1, tab_id())); | 324 EXPECT_TRUE(IsAllowed(extension, chromium_h1, tab_id())); |
| 313 | 325 |
| 314 Reload(); | 326 Reload(); |
| 315 | 327 |
| 316 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); | 328 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); |
| 317 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); | 329 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); |
| 318 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); | 330 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); |
| 319 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); | 331 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); |
| 320 } | 332 } |
| 321 | 333 |
| 334 // TODO(justinlin): Enable when tabCapture API is moved to stable. | |
|
not at google - send to devlin
2013/09/13 22:09:45
could you use ScopedCurrentChannel in feature_chan
justinlin
2013/09/13 22:47:15
Done.
| |
| 335 TEST_F(ActiveTabTest, DISABLED_ChromeUrlGrants) { | |
| 336 GURL internal("chrome://version"); | |
| 337 NavigateAndCommit(internal); | |
| 338 active_tab_permission_granter()->GrantIfRequested( | |
| 339 extension_with_tab_capture.get()); | |
| 340 // Do not grant tabs/hosts permissions for tab. | |
| 341 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id())); | |
| 342 EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab( | |
| 343 extension_with_tab_capture.get(), | |
| 344 tab_id(), | |
| 345 APIPermission::kTabCaptureForTab)); | |
| 346 | |
| 347 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); | |
| 348 EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab( | |
| 349 extension_with_tab_capture.get(), | |
| 350 tab_id() + 1, | |
| 351 APIPermission::kTabCaptureForTab)); | |
| 352 } | |
| 353 | |
| 322 } // namespace | 354 } // namespace |
| 323 } // namespace extensions | 355 } // namespace extensions |
| OLD | NEW |