OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 |
| 13 using content::WebContents; |
| 14 |
| 15 class KeybindingApiTest : public ExtensionApiTest { |
| 16 public: |
| 17 KeybindingApiTest() { |
| 18 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 19 switches::kEnableExperimentalExtensionApis); |
| 20 } |
| 21 virtual ~KeybindingApiTest() {} |
| 22 |
| 23 protected: |
| 24 BrowserActionTestUtil GetBrowserActionsBar() { |
| 25 return BrowserActionTestUtil(browser()); |
| 26 } |
| 27 |
| 28 bool OpenPopup(int index) { |
| 29 ResultCatcher catcher; |
| 30 ui_test_utils::WindowedNotificationObserver popup_observer( |
| 31 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 32 content::NotificationService::AllSources()); |
| 33 GetBrowserActionsBar().Press(index); |
| 34 popup_observer.Wait(); |
| 35 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 36 return GetBrowserActionsBar().HasPopup(); |
| 37 } |
| 38 }; |
| 39 |
| 40 #if defined(OS_WIN) // Not implemented on other platforms yet. |
| 41 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) { |
| 42 ASSERT_TRUE(test_server()->Start()); |
| 43 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; |
| 44 const Extension* extension = GetSingleLoadedExtension(); |
| 45 ASSERT_TRUE(extension) << message_; |
| 46 |
| 47 // Test that there is a browser action in the toolbar. |
| 48 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 49 |
| 50 ui_test_utils::NavigateToURL(browser(), |
| 51 test_server()->GetURL("files/extensions/test_file.txt")); |
| 52 |
| 53 // Simulate the browser action being clicked (Ctrl+Shift+F). |
| 54 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 55 browser(), ui::VKEY_F, true, true, false, false)); |
| 56 |
| 57 // Verify the command worked. |
| 58 WebContents* tab = browser()->GetSelectedWebContents(); |
| 59 bool result = false; |
| 60 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 61 tab->GetRenderViewHost(), L"", |
| 62 L"setInterval(function(){" |
| 63 L" if(document.body.bgColor == 'red'){" |
| 64 L" window.domAutomationController.send(true)}}, 100)", |
| 65 &result)); |
| 66 ASSERT_TRUE(result); |
| 67 |
| 68 // Simulate the event being sent (Ctrl+Shift+Y). |
| 69 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 70 browser(), ui::VKEY_Y, true, true, false, false)); |
| 71 |
| 72 result = false; |
| 73 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 74 tab->GetRenderViewHost(), L"", |
| 75 L"setInterval(function(){" |
| 76 L" if(document.body.bgColor == 'blue'){" |
| 77 L" window.domAutomationController.send(true)}}, 100)", |
| 78 &result)); |
| 79 ASSERT_TRUE(result); |
| 80 } |
| 81 #endif // OS_WIN |
OLD | NEW |