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

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

Issue 545068: Allow extensions to add, remove, or change their page action popup. (Closed)
Patch Set: Rebase, to run trybots with test data in place. Created 10 years, 11 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
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/location_bar.h" 12 #include "chrome/browser/location_bar.h"
13 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "chrome/common/extensions/extension_action.h" 14 #include "chrome/common/extensions/extension_action.h"
15 #include "chrome/test/ui_test_utils.h" 15 #include "chrome/test/ui_test_utils.h"
16 16
17 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { 17 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) {
18 StartHTTPServer(); 18 StartHTTPServer();
19 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; 19 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_;
20 20
21 // TODO(skerner): Move the next four lines into a helper method.
21 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 22 ExtensionsService* service = browser()->profile()->GetExtensionsService();
22 ASSERT_EQ(1u, service->extensions()->size()); 23 ASSERT_EQ(1u, service->extensions()->size());
23 Extension* extension = service->extensions()->at(0); 24 Extension* extension = service->extensions()->at(0);
24 ASSERT_TRUE(extension); 25 ASSERT_TRUE(extension);
25 26
26 { 27 {
27 // Tell the extension to update the page action state. 28 // Tell the extension to update the page action state.
28 ResultCatcher catcher; 29 ResultCatcher catcher;
29 ui_test_utils::NavigateToURL(browser(), 30 ui_test_utils::NavigateToURL(browser(),
30 GURL(extension->GetResourceURL("update.html"))); 31 GURL(extension->GetResourceURL("update.html")));
(...skipping 23 matching lines...) Expand all
54 ui_test_utils::NavigateToURL(browser(), 55 ui_test_utils::NavigateToURL(browser(),
55 GURL(extension->GetResourceURL("update2.html"))); 56 GURL(extension->GetResourceURL("update2.html")));
56 ASSERT_TRUE(catcher.GetNextResult()); 57 ASSERT_TRUE(catcher.GetNextResult());
57 } 58 }
58 59
59 // Test that we received the changes. 60 // Test that we received the changes.
60 tab_id = browser()->GetSelectedTabContents()->controller().session_id().id(); 61 tab_id = browser()->GetSelectedTabContents()->controller().session_id().id();
61 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); 62 EXPECT_FALSE(action->GetIcon(tab_id).isNull());
62 } 63 }
63 64
65 // Test that calling chrome.pageAction.setPopup() can enable a popup.
66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) {
67 // Load the extension, which has no default popup.
68 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_;
69
70 ExtensionsService* service = browser()->profile()->GetExtensionsService();
71 ASSERT_EQ(1u, service->extensions()->size());
72 Extension* extension = service->extensions()->at(0);
73 ASSERT_TRUE(extension);
74
75 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents());
76
77 ExtensionAction* page_action = extension->page_action();
78 ASSERT_TRUE(page_action)
79 << "Page action test extension should have a page action.";
80
81 ASSERT_FALSE(page_action->HasPopup(tab_id));
82
83 // Simulate the page action being clicked. The resulting event should
84 // install a page action popup.
85 {
86 ResultCatcher catcher;
87 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted(
88 browser()->profile(), extension->id(), "action", tab_id, "", 1);
89 ASSERT_TRUE(catcher.GetNextResult());
90 }
91
92 ASSERT_TRUE(page_action->HasPopup(tab_id))
93 << "Clicking on the page action should have caused a popup to be added.";
94
95 ASSERT_STREQ("/a_popup.html",
96 page_action->GetPopupUrl(tab_id).path().c_str());
97
98 // Now change the popup from a_popup.html to a_second_popup.html .
99 // Load a page which removes the popup using chrome.pageAction.setPopup().
100 {
101 ResultCatcher catcher;
102 ui_test_utils::NavigateToURL(
103 browser(),
104 GURL(extension->GetResourceURL("change_popup.html")));
105 ASSERT_TRUE(catcher.GetNextResult());
106 }
107
108 ASSERT_TRUE(page_action->HasPopup(tab_id));
109 ASSERT_STREQ("/another_popup.html",
110 page_action->GetPopupUrl(tab_id).path().c_str());
111 }
112
113 // Test that calling chrome.pageAction.setPopup() can remove a popup.
114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) {
115 // Load the extension, which has a page action with a default popup.
116 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_;
117
118 ExtensionsService* service = browser()->profile()->GetExtensionsService();
119 ASSERT_EQ(1u, service->extensions()->size());
120 Extension* extension = service->extensions()->at(0);
121 ASSERT_TRUE(extension);
122
123 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents());
124
125 ExtensionAction* page_action = extension->page_action();
126 ASSERT_TRUE(page_action)
127 << "Page action test extension should have a page action.";
128
129 ASSERT_TRUE(page_action->HasPopup(tab_id))
130 << "Expect a page action popup before the test removes it.";
131
132 // Load a page which removes the popup using chrome.pageAction.setPopup().
133 {
134 ResultCatcher catcher;
135 ui_test_utils::NavigateToURL(
136 browser(),
137 GURL(extension->GetResourceURL("remove_popup.html")));
138 ASSERT_TRUE(catcher.GetNextResult());
139 }
140
141 ASSERT_FALSE(page_action->HasPopup(tab_id))
142 << "Page action popup should have been removed.";
143 }
144
64 // Tests old-style pageActions API that is deprecated but we don't want to 145 // Tests old-style pageActions API that is deprecated but we don't want to
65 // break. 146 // break.
66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) { 147 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) {
67 ASSERT_TRUE(RunExtensionTest("page_action/old_api")) << message_; 148 ASSERT_TRUE(RunExtensionTest("page_action/old_api")) << message_;
68 149
69 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 150 ExtensionsService* service = browser()->profile()->GetExtensionsService();
70 ASSERT_EQ(1u, service->extensions()->size()); 151 ASSERT_EQ(1u, service->extensions()->size());
71 Extension* extension = service->extensions()->at(0); 152 Extension* extension = service->extensions()->at(0);
72 ASSERT_TRUE(extension); 153 ASSERT_TRUE(extension);
73 154
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ASSERT_EQ(1, location_bar->PageActionVisibleCount()); 247 ASSERT_EQ(1, location_bar->PageActionVisibleCount());
167 ExtensionAction* action = location_bar->GetVisiblePageAction(0); 248 ExtensionAction* action = location_bar->GetVisiblePageAction(0);
168 EXPECT_EQ(action, last_action_); 249 EXPECT_EQ(action, last_action_);
169 250
170 { 251 {
171 ResultCatcher catcher; 252 ResultCatcher catcher;
172 location_bar->TestPageActionPressed(0); 253 location_bar->TestPageActionPressed(0);
173 ASSERT_TRUE(catcher.GetNextResult()); 254 ASSERT_TRUE(catcher.GetNextResult());
174 } 255 }
175 } 256 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_page_actions_module.cc ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698