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 "chrome/browser/extensions/active_tab_permission_granter.h" | 5 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
11 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/permissions/permissions_data.h" |
16 #include "chrome/test/base/interactive_test_utils.h" | 17 #include "chrome/test/base/interactive_test_utils.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
21 | 22 |
22 using content::WebContents; | 23 using content::WebContents; |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 class CommandsApiTest : public ExtensionApiTest { | 27 class CommandsApiTest : public ExtensionApiTest { |
27 public: | 28 public: |
28 CommandsApiTest() {} | 29 CommandsApiTest() {} |
29 virtual ~CommandsApiTest() {} | 30 virtual ~CommandsApiTest() {} |
30 | 31 |
31 protected: | 32 protected: |
32 BrowserActionTestUtil GetBrowserActionsBar() { | 33 BrowserActionTestUtil GetBrowserActionsBar() { |
33 return BrowserActionTestUtil(browser()); | 34 return BrowserActionTestUtil(browser()); |
34 } | 35 } |
| 36 |
| 37 bool IsGrantedForTab(const Extension* extension, |
| 38 const content::WebContents* web_contents) { |
| 39 return PermissionsData::HasAPIPermissionForTab( |
| 40 extension, |
| 41 SessionID::IdForTab(web_contents), |
| 42 APIPermission::kTab); |
| 43 } |
35 }; | 44 }; |
36 | 45 |
37 class ScriptBadgesCommandsApiTest : public ExtensionApiTest { | 46 class ScriptBadgesCommandsApiTest : public ExtensionApiTest { |
38 public: | 47 public: |
39 ScriptBadgesCommandsApiTest() { | 48 ScriptBadgesCommandsApiTest() { |
40 // We cannot add this to CommandsApiTest because then PageActions get | 49 // We cannot add this to CommandsApiTest because then PageActions get |
41 // treated like BrowserActions and the PageAction test starts failing. | 50 // treated like BrowserActions and the PageAction test starts failing. |
42 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 51 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
43 switches::kScriptBadges, "1"); | 52 switches::kScriptBadges, "1"); |
44 } | 53 } |
(...skipping 21 matching lines...) Expand all Loading... |
66 // Test that there are two browser actions in the toolbar. | 75 // Test that there are two browser actions in the toolbar. |
67 ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions()); | 76 ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions()); |
68 | 77 |
69 ui_test_utils::NavigateToURL(browser(), | 78 ui_test_utils::NavigateToURL(browser(), |
70 test_server()->GetURL("files/extensions/test_file.txt")); | 79 test_server()->GetURL("files/extensions/test_file.txt")); |
71 | 80 |
72 // activeTab shouldn't have been granted yet. | 81 // activeTab shouldn't have been granted yet. |
73 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 82 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
74 ASSERT_TRUE(tab); | 83 ASSERT_TRUE(tab); |
75 | 84 |
76 ActiveTabPermissionGranter* granter = | 85 EXPECT_FALSE(IsGrantedForTab(extension, tab)); |
77 TabHelper::FromWebContents(tab)->active_tab_permission_granter(); | |
78 EXPECT_FALSE(granter->IsGranted(extension)); | |
79 | 86 |
80 // Activate the shortcut (Ctrl+Shift+F). | 87 // Activate the shortcut (Ctrl+Shift+F). |
81 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 88 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
82 browser(), ui::VKEY_F, true, true, false, false)); | 89 browser(), ui::VKEY_F, true, true, false, false)); |
83 | 90 |
84 // activeTab should now be granted. | 91 // activeTab should now be granted. |
85 EXPECT_TRUE(granter->IsGranted(extension)); | 92 EXPECT_TRUE(IsGrantedForTab(extension, tab)); |
86 | 93 |
87 // Verify the command worked. | 94 // Verify the command worked. |
88 bool result = false; | 95 bool result = false; |
89 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 96 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
90 tab, | 97 tab, |
91 "setInterval(function(){" | 98 "setInterval(function(){" |
92 " if(document.body.bgColor == 'red'){" | 99 " if(document.body.bgColor == 'red'){" |
93 " window.domAutomationController.send(true)}}, 100)", | 100 " window.domAutomationController.send(true)}}, 100)", |
94 &result)); | 101 &result)); |
95 ASSERT_TRUE(result); | 102 ASSERT_TRUE(result); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 241 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
235 tab, | 242 tab, |
236 "setInterval(function() {" | 243 "setInterval(function() {" |
237 " if (document.body.bgColor == 'blue') {" | 244 " if (document.body.bgColor == 'blue') {" |
238 " window.domAutomationController.send(true)}}, 100)", | 245 " window.domAutomationController.send(true)}}, 100)", |
239 &result)); | 246 &result)); |
240 ASSERT_TRUE(result); | 247 ASSERT_TRUE(result); |
241 } | 248 } |
242 | 249 |
243 } // namespace extensions | 250 } // namespace extensions |
OLD | NEW |