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

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

Issue 496863003: Consolidate ExtensionAction execution code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/api/extension_action/extension_action_api.h" 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
6 #include "chrome/browser/extensions/extension_action.h" 6 #include "chrome/browser/extensions/extension_action.h"
7 #include "chrome/browser/extensions/extension_action_icon_factory.h" 7 #include "chrome/browser/extensions/extension_action_icon_factory.h"
8 #include "chrome/browser/extensions/extension_action_manager.h" 8 #include "chrome/browser/extensions/extension_action_manager.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Test that we received the changes. 51 // Test that we received the changes.
52 int tab_id = SessionTabHelper::FromWebContents( 52 int tab_id = SessionTabHelper::FromWebContents(
53 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); 53 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
54 ExtensionAction* action = GetPageAction(*extension); 54 ExtensionAction* action = GetPageAction(*extension);
55 ASSERT_TRUE(action); 55 ASSERT_TRUE(action);
56 EXPECT_EQ("Modified", action->GetTitle(tab_id)); 56 EXPECT_EQ("Modified", action->GetTitle(tab_id));
57 57
58 { 58 {
59 // Simulate the page action being clicked. 59 // Simulate the page action being clicked.
60 ResultCatcher catcher; 60 ResultCatcher catcher;
61 int tab_id = ExtensionTabUtil::GetTabId( 61 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
62 browser()->tab_strip_model()->GetActiveWebContents()); 62 extension, browser(), true);
63 ExtensionActionAPI::PageActionExecuted(
64 browser()->profile(), *action, tab_id, std::string(), 0);
65 EXPECT_TRUE(catcher.GetNextResult()); 63 EXPECT_TRUE(catcher.GetNextResult());
66 } 64 }
67 65
68 { 66 {
69 // Tell the extension to update the page action state again. 67 // Tell the extension to update the page action state again.
70 ResultCatcher catcher; 68 ResultCatcher catcher;
71 ui_test_utils::NavigateToURL(browser(), 69 ui_test_utils::NavigateToURL(browser(),
72 GURL(extension->GetResourceURL("update2.html"))); 70 GURL(extension->GetResourceURL("update2.html")));
73 ASSERT_TRUE(catcher.GetNextResult()); 71 ASSERT_TRUE(catcher.GetNextResult());
74 } 72 }
(...skipping 21 matching lines...) Expand all
96 ExtensionAction* page_action = GetPageAction(*extension); 94 ExtensionAction* page_action = GetPageAction(*extension);
97 ASSERT_TRUE(page_action) 95 ASSERT_TRUE(page_action)
98 << "Page action test extension should have a page action."; 96 << "Page action test extension should have a page action.";
99 97
100 ASSERT_FALSE(page_action->HasPopup(tab_id)); 98 ASSERT_FALSE(page_action->HasPopup(tab_id));
101 99
102 // Simulate the page action being clicked. The resulting event should 100 // Simulate the page action being clicked. The resulting event should
103 // install a page action popup. 101 // install a page action popup.
104 { 102 {
105 ResultCatcher catcher; 103 ResultCatcher catcher;
106 ExtensionActionAPI::PageActionExecuted( 104 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
107 browser()->profile(), *page_action, tab_id, std::string(), 1); 105 extension, browser(), true);
108 ASSERT_TRUE(catcher.GetNextResult()); 106 ASSERT_TRUE(catcher.GetNextResult());
109 } 107 }
110 108
111 ASSERT_TRUE(page_action->HasPopup(tab_id)) 109 ASSERT_TRUE(page_action->HasPopup(tab_id))
112 << "Clicking on the page action should have caused a popup to be added."; 110 << "Clicking on the page action should have caused a popup to be added.";
113 111
114 ASSERT_STREQ("/a_popup.html", 112 ASSERT_STREQ("/a_popup.html",
115 page_action->GetPopupUrl(tab_id).path().c_str()); 113 page_action->GetPopupUrl(tab_id).path().c_str());
116 114
117 // Now change the popup from a_popup.html to a_second_popup.html . 115 // Now change the popup from a_popup.html to a_second_popup.html .
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 ASSERT_TRUE(RunExtensionTest("trigger_actions/page_action")) << message_; 206 ASSERT_TRUE(RunExtensionTest("trigger_actions/page_action")) << message_;
209 const Extension* extension = GetSingleLoadedExtension(); 207 const Extension* extension = GetSingleLoadedExtension();
210 ASSERT_TRUE(extension) << message_; 208 ASSERT_TRUE(extension) << message_;
211 209
212 // Page action icon is displayed when a tab is created. 210 // Page action icon is displayed when a tab is created.
213 ui_test_utils::NavigateToURL(browser(), 211 ui_test_utils::NavigateToURL(browser(),
214 test_server()->GetURL("files/simple.html")); 212 test_server()->GetURL("files/simple.html"));
215 chrome::NewTab(browser()); 213 chrome::NewTab(browser());
216 browser()->tab_strip_model()->ActivateTabAt(0, true); 214 browser()->tab_strip_model()->ActivateTabAt(0, true);
217 215
216 // Give the extension time to show the page action on the tab.
217 WaitForPageActionVisibilityChangeTo(1);
218
218 ExtensionAction* page_action = GetPageAction(*extension); 219 ExtensionAction* page_action = GetPageAction(*extension);
219 ASSERT_TRUE(page_action); 220 ASSERT_TRUE(page_action);
220 221
222 WebContents* tab =
223 browser()->tab_strip_model()->GetActiveWebContents();
224 ASSERT_TRUE(tab);
225
226 EXPECT_TRUE(page_action->GetIsVisible(ExtensionTabUtil::GetTabId(tab)));
227
221 { 228 {
222 // Simulate the page action being clicked. 229 // Simulate the page action being clicked.
223 ResultCatcher catcher; 230 ResultCatcher catcher;
224 int tab_id = ExtensionTabUtil::GetTabId( 231 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
225 browser()->tab_strip_model()->GetActiveWebContents()); 232 extension, browser(), true);
226 ExtensionActionAPI::PageActionExecuted(
227 browser()->profile(), *page_action, tab_id, std::string(), 0);
228 EXPECT_TRUE(catcher.GetNextResult()); 233 EXPECT_TRUE(catcher.GetNextResult());
229 } 234 }
230 235
231 WebContents* tab =
232 browser()->tab_strip_model()->GetActiveWebContents();
233 EXPECT_TRUE(tab != NULL);
234
235 // Verify that the browser action turned the background color red. 236 // Verify that the browser action turned the background color red.
236 const std::string script = 237 const std::string script =
237 "window.domAutomationController.send(document.body.style." 238 "window.domAutomationController.send(document.body.style."
238 "backgroundColor);"; 239 "backgroundColor);";
239 std::string result; 240 std::string result;
240 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); 241 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result));
241 EXPECT_EQ(result, "red"); 242 EXPECT_EQ(result, "red");
242 } 243 }
243 244
244 } // namespace 245 } // namespace
245 } // namespace extensions 246 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698