| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 11 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 12 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_builder.h" | 17 #include "chrome/common/extensions/extension_builder.h" |
| 18 #include "chrome/common/extensions/features/feature.h" | 18 #include "chrome/common/extensions/features/feature.h" |
| 19 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" | |
| 20 #include "chrome/common/extensions/permissions/scoped_testing_permissions_info.h
" | |
| 21 #include "chrome/common/extensions/value_builder.h" | 19 #include "chrome/common/extensions/value_builder.h" |
| 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 23 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/frame_navigate_params.h" | 27 #include "content/public/common/frame_navigate_params.h" |
| 30 #include "content/public/common/page_transition_types.h" | 28 #include "content/public/common/page_transition_types.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 .Set("version", "1.0") | 48 .Set("version", "1.0") |
| 51 .Set("manifest_version", 2) | 49 .Set("manifest_version", 2) |
| 52 .Set("permissions", permissions)) | 50 .Set("permissions", permissions)) |
| 53 .SetID(id) | 51 .SetID(id) |
| 54 .Build(); | 52 .Build(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 class ActiveTabTest : public ChromeRenderViewHostTestHarness { | 55 class ActiveTabTest : public ChromeRenderViewHostTestHarness { |
| 58 public: | 56 public: |
| 59 ActiveTabTest() | 57 ActiveTabTest() |
| 60 : permissions_info_(ChromeAPIPermissions()), | 58 : extension(CreateTestExtension("deadbeef", true)), |
| 61 extension(CreateTestExtension("deadbeef", true)), | |
| 62 another_extension(CreateTestExtension("feedbeef", true)), | 59 another_extension(CreateTestExtension("feedbeef", true)), |
| 63 extension_without_active_tab(CreateTestExtension("badbeef", false)), | 60 extension_without_active_tab(CreateTestExtension("badbeef", false)), |
| 64 ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 61 ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
| 65 | 62 |
| 66 protected: | 63 protected: |
| 67 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
| 68 ChromeRenderViewHostTestHarness::SetUp(); | 65 ChromeRenderViewHostTestHarness::SetUp(); |
| 69 TabHelper::CreateForWebContents(web_contents()); | 66 TabHelper::CreateForWebContents(web_contents()); |
| 70 } | 67 } |
| 71 | 68 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 103 |
| 107 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { | 104 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { |
| 108 return HasTabsPermission(extension, tab_id()); | 105 return HasTabsPermission(extension, tab_id()); |
| 109 } | 106 } |
| 110 | 107 |
| 111 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, | 108 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, |
| 112 int tab_id) { | 109 int tab_id) { |
| 113 return extension->HasAPIPermissionForTab(tab_id, APIPermission::kTab); | 110 return extension->HasAPIPermissionForTab(tab_id, APIPermission::kTab); |
| 114 } | 111 } |
| 115 | 112 |
| 116 ScopedTestingPermissionsInfo permissions_info_; | |
| 117 | |
| 118 // An extension with the activeTab permission. | 113 // An extension with the activeTab permission. |
| 119 scoped_refptr<const Extension> extension; | 114 scoped_refptr<const Extension> extension; |
| 120 | 115 |
| 121 // Another extension with activeTab (for good measure). | 116 // Another extension with activeTab (for good measure). |
| 122 scoped_refptr<const Extension> another_extension; | 117 scoped_refptr<const Extension> another_extension; |
| 123 | 118 |
| 124 // An extension without the activeTab permission. | 119 // An extension without the activeTab permission. |
| 125 scoped_refptr<const Extension> extension_without_active_tab; | 120 scoped_refptr<const Extension> extension_without_active_tab; |
| 126 | 121 |
| 127 private: | 122 private: |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 Reload(); | 314 Reload(); |
| 320 | 315 |
| 321 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); | 316 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); |
| 322 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); | 317 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); |
| 323 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); | 318 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); |
| 324 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); | 319 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); |
| 325 } | 320 } |
| 326 | 321 |
| 327 } // namespace | 322 } // namespace |
| 328 } // namespace extensions | 323 } // namespace extensions |
| OLD | NEW |