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

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

Issue 9693047: Add Extension Keybinding test for page actions. This is to facilitate an upcoming port of the PageA… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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/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/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
8 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_action.h"
9 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
10 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
12 16
13 using content::WebContents; 17 using content::WebContents;
14 18
15 class KeybindingApiTest : public ExtensionApiTest { 19 class KeybindingApiTest : public ExtensionApiTest {
16 public: 20 public:
17 KeybindingApiTest() { 21 KeybindingApiTest() {
18 CommandLine::ForCurrentProcess()->AppendSwitch( 22 CommandLine::ForCurrentProcess()->AppendSwitch(
19 switches::kEnableExperimentalExtensionApis); 23 switches::kEnableExperimentalExtensionApis);
20 } 24 }
21 virtual ~KeybindingApiTest() {} 25 virtual ~KeybindingApiTest() {}
22 26
23 protected: 27 protected:
24 BrowserActionTestUtil GetBrowserActionsBar() { 28 BrowserActionTestUtil GetBrowserActionsBar() {
25 return BrowserActionTestUtil(browser()); 29 return BrowserActionTestUtil(browser());
26 } 30 }
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 }; 31 };
39 32
40 #if !defined(OS_MACOSX) 33 #if !defined(OS_MACOSX)
41 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) { 34 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) {
42 ASSERT_TRUE(test_server()->Start()); 35 ASSERT_TRUE(test_server()->Start());
43 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; 36 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_;
44 const Extension* extension = GetSingleLoadedExtension(); 37 const Extension* extension = GetSingleLoadedExtension();
45 ASSERT_TRUE(extension) << message_; 38 ASSERT_TRUE(extension) << message_;
46 39
47 // Test that there is a browser action in the toolbar. 40 // Test that there is a browser action in the toolbar.
48 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 41 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
49 42
50 ui_test_utils::NavigateToURL(browser(), 43 ui_test_utils::NavigateToURL(browser(),
51 test_server()->GetURL("files/extensions/test_file.txt")); 44 test_server()->GetURL("files/extensions/test_file.txt"));
52 45
53 // Simulate the browser action being clicked (Ctrl+Shift+F). 46 // Activate the shortcut (Ctrl+Shift+F).
54 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 47 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
55 browser(), ui::VKEY_F, true, true, false, false)); 48 browser(), ui::VKEY_F, true, true, false, false));
56 49
57 // Verify the command worked. 50 // Verify the command worked.
58 WebContents* tab = browser()->GetSelectedWebContents(); 51 WebContents* tab = browser()->GetSelectedWebContents();
59 bool result = false; 52 bool result = false;
60 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 53 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
61 tab->GetRenderViewHost(), L"", 54 tab->GetRenderViewHost(), L"",
62 L"setInterval(function(){" 55 L"setInterval(function(){"
63 L" if(document.body.bgColor == 'red'){" 56 L" if(document.body.bgColor == 'red'){"
64 L" window.domAutomationController.send(true)}}, 100)", 57 L" window.domAutomationController.send(true)}}, 100)",
65 &result)); 58 &result));
66 ASSERT_TRUE(result); 59 ASSERT_TRUE(result);
67 60
68 // Simulate the event being sent (Ctrl+Shift+Y). 61 // Activate the shortcut (Ctrl+Shift+Y).
69 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 62 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
70 browser(), ui::VKEY_Y, true, true, false, false)); 63 browser(), ui::VKEY_Y, true, true, false, false));
71 64
72 result = false; 65 result = false;
73 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 66 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
74 tab->GetRenderViewHost(), L"", 67 tab->GetRenderViewHost(), L"",
75 L"setInterval(function(){" 68 L"setInterval(function(){"
76 L" if(document.body.bgColor == 'blue'){" 69 L" if(document.body.bgColor == 'blue'){"
77 L" window.domAutomationController.send(true)}}, 100)", 70 L" window.domAutomationController.send(true)}}, 100)",
78 &result)); 71 &result));
79 ASSERT_TRUE(result); 72 ASSERT_TRUE(result);
80 } 73 }
74
75 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, PageAction) {
76 ASSERT_TRUE(test_server()->Start());
77 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_;
78 const Extension* extension = GetSingleLoadedExtension();
79 ASSERT_TRUE(extension) << message_;
80
81 {
82 // Load a page, the extension will detect the navigation and request to show
83 // the page action icon.
84 ResultCatcher catcher;
85 ui_test_utils::NavigateToURL(browser(),
86 test_server()->GetURL("files/extensions/test_file.txt"));
87 ASSERT_TRUE(catcher.GetNextResult());
88 }
89
90 // Make sure it appears and is the right one.
91 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
92 int tab_id = browser()->GetSelectedTabContentsWrapper()->
93 restore_tab_helper()->session_id().id();
94 ExtensionAction* action = extension->page_action();
95 ASSERT_TRUE(action);
96 EXPECT_EQ("Make this page red", action->GetTitle(tab_id));
97
98 // Activate the shortcut (Ctrl+Shift+F).
99 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
100 browser(), ui::VKEY_F, true, true, false, false));
101
102 // Verify the command worked (the page action turns the page red).
103 WebContents* tab = browser()->GetSelectedWebContents();
104 bool result = false;
105 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
106 tab->GetRenderViewHost(), L"",
107 L"setInterval(function(){"
108 L" if(document.body.bgColor == 'red'){"
109 L" window.domAutomationController.send(true)}}, 100)",
110 &result));
111 ASSERT_TRUE(result);
112 }
113
81 #endif // !OS_MACOSX 114 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | chrome/browser/ui/gtk/location_bar_view_gtk.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698