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

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

Issue 10880064: Make extension commands grant the activeTab permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 3 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 "chrome/browser/extensions/active_tab_permission_granter.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h"
5 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h" 8 #include "chrome/browser/extensions/tab_helper.h"
7 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
8 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_tabstrip.h" 11 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_action.h" 15 #include "chrome/common/extensions/extension_action.h"
14 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
18 20
19 using content::WebContents; 21 using content::WebContents;
20 22
23 namespace extensions {
24
21 class CommandsApiTest : public ExtensionApiTest { 25 class CommandsApiTest : public ExtensionApiTest {
22 public: 26 public:
23 CommandsApiTest() {} 27 CommandsApiTest() {}
24 virtual ~CommandsApiTest() {} 28 virtual ~CommandsApiTest() {}
25 29
26 protected: 30 protected:
27 BrowserActionTestUtil GetBrowserActionsBar() { 31 BrowserActionTestUtil GetBrowserActionsBar() {
28 return BrowserActionTestUtil(browser()); 32 return BrowserActionTestUtil(browser());
29 } 33 }
30 }; 34 };
(...skipping 13 matching lines...) Expand all
44 48
45 // Test the basic functionality of the Keybinding API: 49 // Test the basic functionality of the Keybinding API:
46 // - That pressing the shortcut keys should perform actions (activate the 50 // - That pressing the shortcut keys should perform actions (activate the
47 // browser action or send an event). 51 // browser action or send an event).
48 // - Note: Page action keybindings are tested in PageAction test below. 52 // - Note: Page action keybindings are tested in PageAction test below.
49 // - The shortcut keys taken by one extension are not overwritten by the last 53 // - The shortcut keys taken by one extension are not overwritten by the last
50 // installed extension. 54 // installed extension.
51 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { 55 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) {
52 ASSERT_TRUE(test_server()->Start()); 56 ASSERT_TRUE(test_server()->Start());
53 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; 57 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_;
54 const extensions::Extension* extension = GetSingleLoadedExtension(); 58 const Extension* extension = GetSingleLoadedExtension();
55 ASSERT_TRUE(extension) << message_; 59 ASSERT_TRUE(extension) << message_;
56 60
57 // Load this extension, which uses the same keybindings but sets the page 61 // Load this extension, which uses the same keybindings but sets the page
58 // to different colors. This is so we can see that it doesn't interfere. We 62 // to different colors. This is so we can see that it doesn't interfere. We
59 // don't test this extension in any other way (it should otherwise be 63 // don't test this extension in any other way (it should otherwise be
60 // immaterial to this test). 64 // immaterial to this test).
61 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; 65 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_;
62 66
63 // Test that there are two browser actions in the toolbar. 67 // Test that there are two browser actions in the toolbar.
64 ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions()); 68 ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions());
65 69
66 ui_test_utils::NavigateToURL(browser(), 70 ui_test_utils::NavigateToURL(browser(),
67 test_server()->GetURL("files/extensions/test_file.txt")); 71 test_server()->GetURL("files/extensions/test_file.txt"));
68 72
73 // activeTab shouldn't have been granted yet.
74 TabContents* tab = chrome::GetActiveTabContents(browser());
75 ASSERT_TRUE(tab);
76
77 ActiveTabPermissionGranter* granter =
78 TabHelper::FromWebContents(tab->web_contents())->
79 active_tab_permission_granter();
80 EXPECT_FALSE(granter->IsGranted(extension));
81
69 // Activate the shortcut (Ctrl+Shift+F). 82 // Activate the shortcut (Ctrl+Shift+F).
70 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 83 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
71 browser(), ui::VKEY_F, true, true, false, false)); 84 browser(), ui::VKEY_F, true, true, false, false));
72 85
86 // activeTab should now be granted.
87 EXPECT_TRUE(granter->IsGranted(extension));
88
73 // Verify the command worked. 89 // Verify the command worked.
74 WebContents* tab = chrome::GetActiveWebContents(browser());
75 bool result = false; 90 bool result = false;
76 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 91 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
77 tab->GetRenderViewHost(), L"", 92 tab->web_contents()->GetRenderViewHost(), L"",
78 L"setInterval(function(){" 93 L"setInterval(function(){"
79 L" if(document.body.bgColor == 'red'){" 94 L" if(document.body.bgColor == 'red'){"
80 L" window.domAutomationController.send(true)}}, 100)", 95 L" window.domAutomationController.send(true)}}, 100)",
81 &result)); 96 &result));
82 ASSERT_TRUE(result); 97 ASSERT_TRUE(result);
83 98
84 // Activate the shortcut (Ctrl+Shift+Y). 99 // Activate the shortcut (Ctrl+Shift+Y).
85 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 100 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
86 browser(), ui::VKEY_Y, true, true, false, false)); 101 browser(), ui::VKEY_Y, true, true, false, false));
87 102
88 result = false; 103 result = false;
89 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 104 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
90 tab->GetRenderViewHost(), L"", 105 tab->web_contents()->GetRenderViewHost(), L"",
91 L"setInterval(function(){" 106 L"setInterval(function(){"
92 L" if(document.body.bgColor == 'blue'){" 107 L" if(document.body.bgColor == 'blue'){"
93 L" window.domAutomationController.send(true)}}, 100)", 108 L" window.domAutomationController.send(true)}}, 100)",
94 &result)); 109 &result));
95 ASSERT_TRUE(result); 110 ASSERT_TRUE(result);
96 } 111 }
97 112
98 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { 113 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) {
99 ASSERT_TRUE(test_server()->Start()); 114 ASSERT_TRUE(test_server()->Start());
100 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; 115 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_;
101 const extensions::Extension* extension = GetSingleLoadedExtension(); 116 const Extension* extension = GetSingleLoadedExtension();
102 ASSERT_TRUE(extension) << message_; 117 ASSERT_TRUE(extension) << message_;
103 118
104 { 119 {
105 // Load a page, the extension will detect the navigation and request to show 120 // Load a page, the extension will detect the navigation and request to show
106 // the page action icon. 121 // the page action icon.
107 ResultCatcher catcher; 122 ResultCatcher catcher;
108 ui_test_utils::NavigateToURL(browser(), 123 ui_test_utils::NavigateToURL(browser(),
109 test_server()->GetURL("files/extensions/test_file.txt")); 124 test_server()->GetURL("files/extensions/test_file.txt"));
110 ASSERT_TRUE(catcher.GetNextResult()); 125 ASSERT_TRUE(catcher.GetNextResult());
111 } 126 }
(...skipping 25 matching lines...) Expand all
137 // Checked-in in a disabled state, because the necessary functionality to 152 // Checked-in in a disabled state, because the necessary functionality to
138 // automatically verify that the test works hasn't been implemented for the 153 // automatically verify that the test works hasn't been implemented for the
139 // script badges yet (see http://crbug.com/140016). The test results, can be 154 // script badges yet (see http://crbug.com/140016). The test results, can be
140 // verified manually by running the test and verifying that the synthesized 155 // verified manually by running the test and verifying that the synthesized
141 // popup for script badges appear. When bug 140016 has been fixed, the popup 156 // popup for script badges appear. When bug 140016 has been fixed, the popup
142 // code can signal to the test that the test passed. 157 // code can signal to the test that the test passed.
143 // TODO(finnur): Enable this test once the bug is fixed. 158 // TODO(finnur): Enable this test once the bug is fixed.
144 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) { 159 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) {
145 ASSERT_TRUE(test_server()->Start()); 160 ASSERT_TRUE(test_server()->Start());
146 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_; 161 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_;
147 const extensions::Extension* extension = GetSingleLoadedExtension(); 162 const Extension* extension = GetSingleLoadedExtension();
148 ASSERT_TRUE(extension) << message_; 163 ASSERT_TRUE(extension) << message_;
149 164
150 { 165 {
151 ResultCatcher catcher; 166 ResultCatcher catcher;
152 // Tell the extension to update the script badge state. 167 // Tell the extension to update the script badge state.
153 ui_test_utils::NavigateToURL( 168 ui_test_utils::NavigateToURL(
154 browser(), GURL(extension->GetResourceURL("show.html"))); 169 browser(), GURL(extension->GetResourceURL("show.html")));
155 ASSERT_TRUE(catcher.GetNextResult()); 170 ASSERT_TRUE(catcher.GetNextResult());
156 } 171 }
157 172
158 { 173 {
159 ResultCatcher catcher; 174 ResultCatcher catcher;
160 // Activate the shortcut (Ctrl+Shift+F). 175 // Activate the shortcut (Ctrl+Shift+F).
161 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 176 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
162 browser(), ui::VKEY_F, true, true, false, false)); 177 browser(), ui::VKEY_F, true, true, false, false));
163 ASSERT_TRUE(catcher.GetNextResult()); 178 ASSERT_TRUE(catcher.GetNextResult());
164 } 179 }
165 } 180 }
166 181
182 } // extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/omnibox/omnibox_api.cc ('k') | chrome/browser/extensions/extension_keybinding_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698