| 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_manager.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 Loading... |
| 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 ActiveTabPermissionManager* granter = |
| 78 tab->extension_tab_helper()->active_tab_permission_manager(); |
| 79 EXPECT_FALSE(granter->IsGranted(extension)); |
| 80 |
| 69 // Activate the shortcut (Ctrl+Shift+F). | 81 // Activate the shortcut (Ctrl+Shift+F). |
| 70 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 82 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 71 browser(), ui::VKEY_F, true, true, false, false)); | 83 browser(), ui::VKEY_F, true, true, false, false)); |
| 72 | 84 |
| 85 // Active tab should now be granted. |
| 86 EXPECT_TRUE(granter->IsGranted(extension)); |
| 87 |
| 73 // Verify the command worked. | 88 // Verify the command worked. |
| 74 WebContents* tab = chrome::GetActiveWebContents(browser()); | |
| 75 bool result = false; | 89 bool result = false; |
| 76 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 90 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 77 tab->GetRenderViewHost(), L"", | 91 tab->web_contents()->GetRenderViewHost(), L"", |
| 78 L"setInterval(function(){" | 92 L"setInterval(function(){" |
| 79 L" if(document.body.bgColor == 'red'){" | 93 L" if(document.body.bgColor == 'red'){" |
| 80 L" window.domAutomationController.send(true)}}, 100)", | 94 L" window.domAutomationController.send(true)}}, 100)", |
| 81 &result)); | 95 &result)); |
| 82 ASSERT_TRUE(result); | 96 ASSERT_TRUE(result); |
| 83 | 97 |
| 84 // Activate the shortcut (Ctrl+Shift+Y). | 98 // Activate the shortcut (Ctrl+Shift+Y). |
| 85 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 99 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 86 browser(), ui::VKEY_Y, true, true, false, false)); | 100 browser(), ui::VKEY_Y, true, true, false, false)); |
| 87 | 101 |
| 88 result = false; | 102 result = false; |
| 89 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 103 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 90 tab->GetRenderViewHost(), L"", | 104 tab->web_contents()->GetRenderViewHost(), L"", |
| 91 L"setInterval(function(){" | 105 L"setInterval(function(){" |
| 92 L" if(document.body.bgColor == 'blue'){" | 106 L" if(document.body.bgColor == 'blue'){" |
| 93 L" window.domAutomationController.send(true)}}, 100)", | 107 L" window.domAutomationController.send(true)}}, 100)", |
| 94 &result)); | 108 &result)); |
| 95 ASSERT_TRUE(result); | 109 ASSERT_TRUE(result); |
| 96 } | 110 } |
| 97 | 111 |
| 98 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { | 112 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { |
| 99 ASSERT_TRUE(test_server()->Start()); | 113 ASSERT_TRUE(test_server()->Start()); |
| 100 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 114 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
| 101 const extensions::Extension* extension = GetSingleLoadedExtension(); | 115 const Extension* extension = GetSingleLoadedExtension(); |
| 102 ASSERT_TRUE(extension) << message_; | 116 ASSERT_TRUE(extension) << message_; |
| 103 | 117 |
| 104 { | 118 { |
| 105 // Load a page, the extension will detect the navigation and request to show | 119 // Load a page, the extension will detect the navigation and request to show |
| 106 // the page action icon. | 120 // the page action icon. |
| 107 ResultCatcher catcher; | 121 ResultCatcher catcher; |
| 108 ui_test_utils::NavigateToURL(browser(), | 122 ui_test_utils::NavigateToURL(browser(), |
| 109 test_server()->GetURL("files/extensions/test_file.txt")); | 123 test_server()->GetURL("files/extensions/test_file.txt")); |
| 110 ASSERT_TRUE(catcher.GetNextResult()); | 124 ASSERT_TRUE(catcher.GetNextResult()); |
| 111 } | 125 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 137 // Checked-in in a disabled state, because the necessary functionality to | 151 // Checked-in in a disabled state, because the necessary functionality to |
| 138 // automatically verify that the test works hasn't been implemented for the | 152 // 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 | 153 // 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 | 154 // 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 | 155 // popup for script badges appear. When bug 140016 has been fixed, the popup |
| 142 // code can signal to the test that the test passed. | 156 // code can signal to the test that the test passed. |
| 143 // TODO(finnur): Enable this test once the bug is fixed. | 157 // TODO(finnur): Enable this test once the bug is fixed. |
| 144 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) { | 158 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) { |
| 145 ASSERT_TRUE(test_server()->Start()); | 159 ASSERT_TRUE(test_server()->Start()); |
| 146 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_; | 160 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_; |
| 147 const extensions::Extension* extension = GetSingleLoadedExtension(); | 161 const Extension* extension = GetSingleLoadedExtension(); |
| 148 ASSERT_TRUE(extension) << message_; | 162 ASSERT_TRUE(extension) << message_; |
| 149 | 163 |
| 150 { | 164 { |
| 151 ResultCatcher catcher; | 165 ResultCatcher catcher; |
| 152 // Tell the extension to update the script badge state. | 166 // Tell the extension to update the script badge state. |
| 153 ui_test_utils::NavigateToURL( | 167 ui_test_utils::NavigateToURL( |
| 154 browser(), GURL(extension->GetResourceURL("show.html"))); | 168 browser(), GURL(extension->GetResourceURL("show.html"))); |
| 155 ASSERT_TRUE(catcher.GetNextResult()); | 169 ASSERT_TRUE(catcher.GetNextResult()); |
| 156 } | 170 } |
| 157 | 171 |
| 158 { | 172 { |
| 159 ResultCatcher catcher; | 173 ResultCatcher catcher; |
| 160 // Activate the shortcut (Ctrl+Shift+F). | 174 // Activate the shortcut (Ctrl+Shift+F). |
| 161 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 175 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 162 browser(), ui::VKEY_F, true, true, false, false)); | 176 browser(), ui::VKEY_F, true, true, false, false)); |
| 163 ASSERT_TRUE(catcher.GetNextResult()); | 177 ASSERT_TRUE(catcher.GetNextResult()); |
| 164 } | 178 } |
| 165 } | 179 } |
| 166 | 180 |
| 181 } // extensions |
| OLD | NEW |