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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 .SetManifest(DictionaryBuilder() | 47 .SetManifest(DictionaryBuilder() |
48 .Set("name", "Extension with ID " + id) | 48 .Set("name", "Extension with ID " + id) |
49 .Set("version", "1.0") | 49 .Set("version", "1.0") |
50 .Set("manifest_version", 2) | 50 .Set("manifest_version", 2) |
51 .Set("permissions", permissions)) | 51 .Set("permissions", permissions)) |
52 .SetID(id) | 52 .SetID(id) |
53 .Build(); | 53 .Build(); |
54 } | 54 } |
55 | 55 |
56 class ActiveTabTest : public ChromeRenderViewHostTestHarness { | 56 class ActiveTabTest : public ChromeRenderViewHostTestHarness { |
57 public: | 57 protected: |
58 ActiveTabTest() | 58 ActiveTabTest() |
59 : extension(CreateTestExtension("deadbeef", true)), | 59 : extension(CreateTestExtension("deadbeef", true)), |
60 another_extension(CreateTestExtension("feedbeef", true)), | 60 another_extension(CreateTestExtension("feedbeef", true)), |
61 extension_without_active_tab(CreateTestExtension("badbeef", false)), | 61 extension_without_active_tab(CreateTestExtension("badbeef", false)) {} |
62 ui_thread_(BrowserThread::UI, base::MessageLoop::current()) {} | |
63 | 62 |
64 protected: | |
65 virtual void SetUp() OVERRIDE { | 63 virtual void SetUp() OVERRIDE { |
66 ChromeRenderViewHostTestHarness::SetUp(); | 64 ChromeRenderViewHostTestHarness::SetUp(); |
67 TabHelper::CreateForWebContents(web_contents()); | 65 TabHelper::CreateForWebContents(web_contents()); |
68 } | 66 } |
69 | 67 |
70 int tab_id() { | 68 int tab_id() { |
71 return SessionID::IdForTab(web_contents()); | 69 return SessionID::IdForTab(web_contents()); |
72 } | 70 } |
73 | 71 |
74 ActiveTabPermissionGranter* active_tab_permission_granter() { | 72 ActiveTabPermissionGranter* active_tab_permission_granter() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 115 } |
118 | 116 |
119 // An extension with the activeTab permission. | 117 // An extension with the activeTab permission. |
120 scoped_refptr<const Extension> extension; | 118 scoped_refptr<const Extension> extension; |
121 | 119 |
122 // Another extension with activeTab (for good measure). | 120 // Another extension with activeTab (for good measure). |
123 scoped_refptr<const Extension> another_extension; | 121 scoped_refptr<const Extension> another_extension; |
124 | 122 |
125 // An extension without the activeTab permission. | 123 // An extension without the activeTab permission. |
126 scoped_refptr<const Extension> extension_without_active_tab; | 124 scoped_refptr<const Extension> extension_without_active_tab; |
127 | |
128 private: | |
129 content::TestBrowserThread ui_thread_; | |
130 }; | 125 }; |
131 | 126 |
132 TEST_F(ActiveTabTest, GrantToSinglePage) { | 127 TEST_F(ActiveTabTest, GrantToSinglePage) { |
133 GURL google("http://www.google.com"); | 128 GURL google("http://www.google.com"); |
134 NavigateAndCommit(google); | 129 NavigateAndCommit(google); |
135 | 130 |
136 // No access unless it's been granted. | 131 // No access unless it's been granted. |
137 EXPECT_TRUE(IsBlocked(extension, google)); | 132 EXPECT_TRUE(IsBlocked(extension, google)); |
138 EXPECT_TRUE(IsBlocked(another_extension, google)); | 133 EXPECT_TRUE(IsBlocked(another_extension, google)); |
139 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); | 134 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 Reload(); | 315 Reload(); |
321 | 316 |
322 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); | 317 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); |
323 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); | 318 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); |
324 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); | 319 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); |
325 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); | 320 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); |
326 } | 321 } |
327 | 322 |
328 } // namespace | 323 } // namespace |
329 } // namespace extensions | 324 } // namespace extensions |
OLD | NEW |