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

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

Issue 9705097: Revert 127146 - Add Extension Keybinding test for page actions and port the PageAction keybindings … (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
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
8 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_action.h"
13 #include "chrome/test/base/ui_test_utils.h" 9 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
16 12
17 using content::WebContents; 13 using content::WebContents;
18 14
19 class KeybindingApiTest : public ExtensionApiTest { 15 class KeybindingApiTest : public ExtensionApiTest {
20 public: 16 public:
21 KeybindingApiTest() { 17 KeybindingApiTest() {
22 CommandLine::ForCurrentProcess()->AppendSwitch( 18 CommandLine::ForCurrentProcess()->AppendSwitch(
23 switches::kEnableExperimentalExtensionApis); 19 switches::kEnableExperimentalExtensionApis);
24 } 20 }
25 virtual ~KeybindingApiTest() {} 21 virtual ~KeybindingApiTest() {}
26 22
27 protected: 23 protected:
28 BrowserActionTestUtil GetBrowserActionsBar() { 24 BrowserActionTestUtil GetBrowserActionsBar() {
29 return BrowserActionTestUtil(browser()); 25 return BrowserActionTestUtil(browser());
30 } 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 }
31 }; 38 };
32 39
33 #if !defined(OS_MACOSX) 40 #if !defined(OS_MACOSX)
34 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) { 41 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) {
35 ASSERT_TRUE(test_server()->Start()); 42 ASSERT_TRUE(test_server()->Start());
36 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; 43 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_;
37 const Extension* extension = GetSingleLoadedExtension(); 44 const Extension* extension = GetSingleLoadedExtension();
38 ASSERT_TRUE(extension) << message_; 45 ASSERT_TRUE(extension) << message_;
39 46
40 // Test that there is a browser action in the toolbar. 47 // Test that there is a browser action in the toolbar.
41 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); 48 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
42 49
43 ui_test_utils::NavigateToURL(browser(), 50 ui_test_utils::NavigateToURL(browser(),
44 test_server()->GetURL("files/extensions/test_file.txt")); 51 test_server()->GetURL("files/extensions/test_file.txt"));
45 52
46 // Activate the shortcut (Ctrl+Shift+F). 53 // Simulate the browser action being clicked (Ctrl+Shift+F).
47 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 54 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
48 browser(), ui::VKEY_F, true, true, false, false)); 55 browser(), ui::VKEY_F, true, true, false, false));
49 56
50 // Verify the command worked. 57 // Verify the command worked.
51 WebContents* tab = browser()->GetSelectedWebContents(); 58 WebContents* tab = browser()->GetSelectedWebContents();
52 bool result = false; 59 bool result = false;
53 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 60 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
54 tab->GetRenderViewHost(), L"", 61 tab->GetRenderViewHost(), L"",
55 L"setInterval(function(){" 62 L"setInterval(function(){"
56 L" if(document.body.bgColor == 'red'){" 63 L" if(document.body.bgColor == 'red'){"
57 L" window.domAutomationController.send(true)}}, 100)", 64 L" window.domAutomationController.send(true)}}, 100)",
58 &result)); 65 &result));
59 ASSERT_TRUE(result); 66 ASSERT_TRUE(result);
60 67
61 // Activate the shortcut (Ctrl+Shift+Y). 68 // Simulate the event being sent (Ctrl+Shift+Y).
62 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 69 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
63 browser(), ui::VKEY_Y, true, true, false, false)); 70 browser(), ui::VKEY_Y, true, true, false, false));
64 71
65 result = false; 72 result = false;
66 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 73 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
67 tab->GetRenderViewHost(), L"", 74 tab->GetRenderViewHost(), L"",
68 L"setInterval(function(){" 75 L"setInterval(function(){"
69 L" if(document.body.bgColor == 'blue'){" 76 L" if(document.body.bgColor == 'blue'){"
70 L" window.domAutomationController.send(true)}}, 100)", 77 L" window.domAutomationController.send(true)}}, 100)",
71 &result)); 78 &result));
72 ASSERT_TRUE(result); 79 ASSERT_TRUE(result);
73 } 80 }
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
114 #endif // !OS_MACOSX 81 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698