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

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

Issue 306044: Refactor implementation of BrowserActions, and add support for (Closed)
Patch Set: Make it work on linux too Created 11 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_browser_actions_api.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser.h" 5 #include "chrome/browser/browser.h"
6 #include "chrome/browser/browser_window.h" 6 #include "chrome/browser/browser_window.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_browser_event_router.h" 8 #include "chrome/browser/extensions/extension_browser_event_router.h"
9 #include "chrome/browser/extensions/extension_tabs_module.h" 9 #include "chrome/browser/extensions/extension_tabs_module.h"
10 #include "chrome/browser/extensions/extensions_service.h" 10 #include "chrome/browser/extensions/extensions_service.h"
11 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 12 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/views/browser_actions_container.h" 13 #include "chrome/browser/views/browser_actions_container.h"
14 #include "chrome/browser/views/extensions/extension_popup.h" 14 #include "chrome/browser/views/extensions/extension_popup.h"
15 #include "chrome/browser/views/toolbar_view.h" 15 #include "chrome/browser/views/toolbar_view.h"
16 #include "chrome/common/extensions/extension_action.h" 16 #include "chrome/common/extensions/extension_action2.h"
17 #include "chrome/test/ui_test_utils.h" 17 #include "chrome/test/ui_test_utils.h"
18 18
19 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserAction) { 19 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserAction) {
20 StartHTTPServer(); 20 StartHTTPServer();
21 ASSERT_TRUE(RunExtensionTest("browser_action")) << message_; 21 ASSERT_TRUE(RunExtensionTest("browser_action")) << message_;
22 22
23 // Test that there is a browser action in the toolbar. 23 // Test that there is a browser action in the toolbar.
24 BrowserActionsContainer* browser_actions = 24 BrowserActionsContainer* browser_actions =
25 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> 25 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
26 browser_actions(); 26 browser_actions();
27 ASSERT_EQ(1, browser_actions->num_browser_actions()); 27 ASSERT_EQ(1, browser_actions->num_browser_actions());
28 28
29 // Tell the extension to update the browser action state. 29 // Tell the extension to update the browser action state.
30 ResultCatcher catcher; 30 ResultCatcher catcher;
31 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 31 ExtensionsService* service = browser()->profile()->GetExtensionsService();
32 Extension* extension = service->extensions()->at(0); 32 Extension* extension = service->extensions()->at(0);
33 ui_test_utils::NavigateToURL(browser(), 33 ui_test_utils::NavigateToURL(browser(),
34 GURL(extension->GetResourceURL("update.html"))); 34 GURL(extension->GetResourceURL("update.html")));
35 ASSERT_TRUE(catcher.GetNextResult()); 35 ASSERT_TRUE(catcher.GetNextResult());
36 36
37 // Test that we received the changes. 37 // Test that we received the changes.
38 ExtensionActionState* action_state = extension->browser_action_state(); 38 ExtensionAction2* action = extension->browser_action();
39 ASSERT_EQ("Modified", action_state->title()); 39 ASSERT_EQ("Modified", action->GetTitle(ExtensionAction2::kDefaultTabId));
40 ASSERT_EQ("badge", action_state->badge_text()); 40 ASSERT_EQ("badge", action->GetBadgeText(ExtensionAction2::kDefaultTabId));
41 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), 41 ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
42 action_state->badge_background_color()); 42 action->GetBadgeBackgroundColor(ExtensionAction2::kDefaultTabId));
43 43
44 // Simulate the browser action being clicked. 44 // Simulate the browser action being clicked.
45 ui_test_utils::NavigateToURL(browser(), 45 ui_test_utils::NavigateToURL(browser(),
46 GURL("http://localhost:1337/files/extensions/test_file.txt")); 46 GURL("http://localhost:1337/files/extensions/test_file.txt"));
47 47
48 ExtensionAction* browser_action = service->GetBrowserActions(false)[0];
49 int window_id = ExtensionTabUtil::GetWindowId(browser()); 48 int window_id = ExtensionTabUtil::GetWindowId(browser());
50 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( 49 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
51 browser()->profile(), browser_action->extension_id(), browser()); 50 browser()->profile(), action->extension_id(), browser());
52 51
53 // Verify the command worked. 52 // Verify the command worked.
54 TabContents* tab = browser()->GetSelectedTabContents(); 53 TabContents* tab = browser()->GetSelectedTabContents();
55 bool result = false; 54 bool result = false;
56 ui_test_utils::ExecuteJavaScriptAndExtractBool( 55 ui_test_utils::ExecuteJavaScriptAndExtractBool(
57 tab->render_view_host(), L"", 56 tab->render_view_host(), L"",
58 L"setInterval(function(){" 57 L"setInterval(function(){"
59 L" if(document.body.bgColor == 'red'){" 58 L" if(document.body.bgColor == 'red'){"
60 L" window.domAutomationController.send(true)}}, 100)", 59 L" window.domAutomationController.send(true)}}, 100)",
61 &result); 60 &result);
(...skipping 28 matching lines...) Expand all
90 GURL(extension->GetResourceURL("update2.html"))); 89 GURL(extension->GetResourceURL("update2.html")));
91 ASSERT_TRUE(catcher.GetNextResult()); 90 ASSERT_TRUE(catcher.GetNextResult());
92 91
93 // Test that we received the changes. 92 // Test that we received the changes.
94 ASSERT_FALSE(browser_actions->GetBrowserActionViewAt(0)->button()->icon() 93 ASSERT_FALSE(browser_actions->GetBrowserActionViewAt(0)->button()->icon()
95 .empty()); 94 .empty());
96 95
97 // TODO(aa): Would be nice here to actually compare that the pixels change. 96 // TODO(aa): Would be nice here to actually compare that the pixels change.
98 } 97 }
99 98
99 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabSpecificBrowserActionState) {
100 ASSERT_TRUE(RunExtensionTest("browser_action_tab_specific_state"))
101 << message_;
102
103 // Test that there is a browser action in the toolbar and that it has no icon.
104 BrowserActionsContainer* browser_actions =
105 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
106 browser_actions();
107 ASSERT_EQ(1, browser_actions->num_browser_actions());
108 ASSERT_FALSE(browser_actions->GetBrowserActionViewAt(0)->button()->icon()
109 .empty());
110
111 // Execute the action, its title should change
112 std::wstring text;
113 ResultCatcher catcher;
114 browser_actions->TestExecuteBrowserAction(0);
115 ASSERT_TRUE(catcher.GetNextResult());
116 ASSERT_TRUE(
117 browser_actions->GetBrowserActionViewAt(0)->button()->GetTooltipText(
118 0, 0, &text));
119 ASSERT_EQ(L"Showing icon 2", text);
120
121 // open a new tab, the title should go back
122 browser()->NewTab();
123 ASSERT_TRUE(
124 browser_actions->GetBrowserActionViewAt(0)->button()->GetTooltipText(
125 0, 0, &text));
126 ASSERT_EQ(L"hi!", text);
127
128 // go back to first tab, changed title should reappear
129 browser()->SelectTabContentsAt(0, true);
130 ASSERT_TRUE(
131 browser_actions->GetBrowserActionViewAt(0)->button()->GetTooltipText(
132 0, 0, &text));
133 ASSERT_EQ(L"Showing icon 2", text);
134
135 // reload that tab, default title should come back
136 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
137 ASSERT_TRUE(
138 browser_actions->GetBrowserActionViewAt(0)->button()->GetTooltipText(
139 0, 0, &text));
140 ASSERT_EQ(L"hi!", text);
141 }
142
100 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserActionPopup) { 143 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserActionPopup) {
101 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("popup"))); 144 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("popup")));
102 145
103 ResultCatcher catcher; 146 ResultCatcher catcher;
104 BrowserActionsContainer* browser_actions = 147 BrowserActionsContainer* browser_actions =
105 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> 148 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
106 browser_actions(); 149 browser_actions();
107 150
108 // Simulate a click on the browser action and verify the size of the resulting 151 // Simulate a click on the browser action and verify the size of the resulting
109 // popup. 152 // popup.
(...skipping 10 matching lines...) Expand all
120 // opened). 163 // opened).
121 browser_actions->TestExecuteBrowserAction(0); 164 browser_actions->TestExecuteBrowserAction(0);
122 EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); 165 EXPECT_TRUE(browser_actions->TestGetPopup() != NULL);
123 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 166 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
124 bounds = browser_actions->TestGetPopup()->view()->bounds(); 167 bounds = browser_actions->TestGetPopup()->view()->bounds();
125 EXPECT_EQ(200, bounds.width()); 168 EXPECT_EQ(200, bounds.width());
126 EXPECT_EQ(200, bounds.height()); 169 EXPECT_EQ(200, bounds.height());
127 browser_actions->HidePopup(); 170 browser_actions->HidePopup();
128 EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); 171 EXPECT_TRUE(browser_actions->TestGetPopup() == NULL);
129 } 172 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_browser_actions_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698