| 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/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.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/sessions/restore_tab_helper.h" | 7 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | 9 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_action.h" | 13 #include "chrome/common/extensions/extension_action.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" |
| 17 | 18 |
| 18 using content::WebContents; | 19 using content::WebContents; |
| 19 | 20 |
| 20 class KeybindingApiTest : public ExtensionApiTest { | 21 class KeybindingApiTest : public ExtensionApiTest { |
| 21 public: | 22 public: |
| 22 KeybindingApiTest() { | 23 KeybindingApiTest() { |
| 23 CommandLine::ForCurrentProcess()->AppendSwitch( | 24 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 24 switches::kEnableExperimentalExtensionApis); | 25 switches::kEnableExperimentalExtensionApis); |
| 25 } | 26 } |
| 26 virtual ~KeybindingApiTest() {} | 27 virtual ~KeybindingApiTest() {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 56 ui_test_utils::NavigateToURL(browser(), | 57 ui_test_utils::NavigateToURL(browser(), |
| 57 test_server()->GetURL("files/extensions/test_file.txt")); | 58 test_server()->GetURL("files/extensions/test_file.txt")); |
| 58 | 59 |
| 59 // Activate the shortcut (Ctrl+Shift+F). | 60 // Activate the shortcut (Ctrl+Shift+F). |
| 60 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 61 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 61 browser(), ui::VKEY_F, true, true, false, false)); | 62 browser(), ui::VKEY_F, true, true, false, false)); |
| 62 | 63 |
| 63 // Verify the command worked. | 64 // Verify the command worked. |
| 64 WebContents* tab = chrome::GetActiveWebContents(browser()); | 65 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 65 bool result = false; | 66 bool result = false; |
| 66 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 67 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 67 tab->GetRenderViewHost(), L"", | 68 tab->GetRenderViewHost(), L"", |
| 68 L"setInterval(function(){" | 69 L"setInterval(function(){" |
| 69 L" if(document.body.bgColor == 'red'){" | 70 L" if(document.body.bgColor == 'red'){" |
| 70 L" window.domAutomationController.send(true)}}, 100)", | 71 L" window.domAutomationController.send(true)}}, 100)", |
| 71 &result)); | 72 &result)); |
| 72 ASSERT_TRUE(result); | 73 ASSERT_TRUE(result); |
| 73 | 74 |
| 74 // Activate the shortcut (Ctrl+Shift+Y). | 75 // Activate the shortcut (Ctrl+Shift+Y). |
| 75 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 76 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 76 browser(), ui::VKEY_Y, true, true, false, false)); | 77 browser(), ui::VKEY_Y, true, true, false, false)); |
| 77 | 78 |
| 78 result = false; | 79 result = false; |
| 79 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 80 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 80 tab->GetRenderViewHost(), L"", | 81 tab->GetRenderViewHost(), L"", |
| 81 L"setInterval(function(){" | 82 L"setInterval(function(){" |
| 82 L" if(document.body.bgColor == 'blue'){" | 83 L" if(document.body.bgColor == 'blue'){" |
| 83 L" window.domAutomationController.send(true)}}, 100)", | 84 L" window.domAutomationController.send(true)}}, 100)", |
| 84 &result)); | 85 &result)); |
| 85 ASSERT_TRUE(result); | 86 ASSERT_TRUE(result); |
| 86 } | 87 } |
| 87 | 88 |
| 88 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, PageAction) { | 89 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, PageAction) { |
| 89 ASSERT_TRUE(test_server()->Start()); | 90 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 108 ASSERT_TRUE(action); | 109 ASSERT_TRUE(action); |
| 109 EXPECT_EQ("Make this page red", action->GetTitle(tab_id)); | 110 EXPECT_EQ("Make this page red", action->GetTitle(tab_id)); |
| 110 | 111 |
| 111 // Activate the shortcut (Ctrl+Shift+F). | 112 // Activate the shortcut (Ctrl+Shift+F). |
| 112 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 113 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 113 browser(), ui::VKEY_F, true, true, false, false)); | 114 browser(), ui::VKEY_F, true, true, false, false)); |
| 114 | 115 |
| 115 // Verify the command worked (the page action turns the page red). | 116 // Verify the command worked (the page action turns the page red). |
| 116 WebContents* tab = chrome::GetActiveWebContents(browser()); | 117 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 117 bool result = false; | 118 bool result = false; |
| 118 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 119 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 119 tab->GetRenderViewHost(), L"", | 120 tab->GetRenderViewHost(), L"", |
| 120 L"setInterval(function(){" | 121 L"setInterval(function(){" |
| 121 L" if(document.body.bgColor == 'red'){" | 122 L" if(document.body.bgColor == 'red'){" |
| 122 L" window.domAutomationController.send(true)}}, 100)", | 123 L" window.domAutomationController.send(true)}}, 100)", |
| 123 &result)); | 124 &result)); |
| 124 ASSERT_TRUE(result); | 125 ASSERT_TRUE(result); |
| 125 } | 126 } |
| 126 | 127 |
| 127 #endif // !OS_MACOSX | 128 #endif // !OS_MACOSX |
| OLD | NEW |