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

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

Issue 12066003: Remove TabStripModel wrapper use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 7 years, 10 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/browser_event_router.h" 5 #include "chrome/browser/extensions/browser_event_router.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"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sessions/session_tab_helper.h" 14 #include "chrome/browser/sessions/session_tab_helper.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/omnibox/location_bar.h" 17 #include "chrome/browser/ui/omnibox/location_bar.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 22
23 namespace extensions { 23 namespace extensions {
24 namespace { 24 namespace {
25 25
26 class PageActionApiTest : public ExtensionApiTest { 26 class PageActionApiTest : public ExtensionApiTest {
27 protected: 27 protected:
28 ExtensionAction* GetPageAction(const Extension& extension) { 28 ExtensionAction* GetPageAction(const Extension& extension) {
(...skipping 10 matching lines...) Expand all
39 { 39 {
40 // Tell the extension to update the page action state. 40 // Tell the extension to update the page action state.
41 ResultCatcher catcher; 41 ResultCatcher catcher;
42 ui_test_utils::NavigateToURL(browser(), 42 ui_test_utils::NavigateToURL(browser(),
43 GURL(extension->GetResourceURL("update.html"))); 43 GURL(extension->GetResourceURL("update.html")));
44 ASSERT_TRUE(catcher.GetNextResult()); 44 ASSERT_TRUE(catcher.GetNextResult());
45 } 45 }
46 46
47 // Test that we received the changes. 47 // Test that we received the changes.
48 int tab_id = SessionTabHelper::FromWebContents( 48 int tab_id = SessionTabHelper::FromWebContents(
49 chrome::GetActiveWebContents(browser()))->session_id().id(); 49 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
50 ExtensionAction* action = GetPageAction(*extension); 50 ExtensionAction* action = GetPageAction(*extension);
51 ASSERT_TRUE(action); 51 ASSERT_TRUE(action);
52 EXPECT_EQ("Modified", action->GetTitle(tab_id)); 52 EXPECT_EQ("Modified", action->GetTitle(tab_id));
53 53
54 { 54 {
55 // Simulate the page action being clicked. 55 // Simulate the page action being clicked.
56 ResultCatcher catcher; 56 ResultCatcher catcher;
57 int tab_id = 57 int tab_id = ExtensionTabUtil::GetTabId(
58 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); 58 browser()->tab_strip_model()->GetActiveWebContents());
59 ExtensionService* service = extensions::ExtensionSystem::Get( 59 ExtensionService* service = extensions::ExtensionSystem::Get(
60 browser()->profile())->extension_service(); 60 browser()->profile())->extension_service();
61 service->browser_event_router()->PageActionExecuted( 61 service->browser_event_router()->PageActionExecuted(
62 browser()->profile(), *action, tab_id, "", 0); 62 browser()->profile(), *action, tab_id, "", 0);
63 EXPECT_TRUE(catcher.GetNextResult()); 63 EXPECT_TRUE(catcher.GetNextResult());
64 } 64 }
65 65
66 { 66 {
67 // Tell the extension to update the page action state again. 67 // Tell the extension to update the page action state again.
68 ResultCatcher catcher; 68 ResultCatcher catcher;
69 ui_test_utils::NavigateToURL(browser(), 69 ui_test_utils::NavigateToURL(browser(),
70 GURL(extension->GetResourceURL("update2.html"))); 70 GURL(extension->GetResourceURL("update2.html")));
71 ASSERT_TRUE(catcher.GetNextResult()); 71 ASSERT_TRUE(catcher.GetNextResult());
72 } 72 }
73 73
74 // We should not be creating icons asynchronously, so we don't need an 74 // We should not be creating icons asynchronously, so we don't need an
75 // observer. 75 // observer.
76 ExtensionActionIconFactory icon_factory(extension, action, NULL); 76 ExtensionActionIconFactory icon_factory(extension, action, NULL);
77 77
78 // Test that we received the changes. 78 // Test that we received the changes.
79 tab_id = SessionTabHelper::FromWebContents( 79 tab_id = SessionTabHelper::FromWebContents(
80 chrome::GetActiveWebContents(browser()))->session_id().id(); 80 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
81 EXPECT_FALSE(icon_factory.GetIcon(tab_id).IsEmpty()); 81 EXPECT_FALSE(icon_factory.GetIcon(tab_id).IsEmpty());
82 } 82 }
83 83
84 // Test that calling chrome.pageAction.setPopup() can enable a popup. 84 // Test that calling chrome.pageAction.setPopup() can enable a popup.
85 IN_PROC_BROWSER_TEST_F(PageActionApiTest, AddPopup) { 85 IN_PROC_BROWSER_TEST_F(PageActionApiTest, AddPopup) {
86 // Load the extension, which has no default popup. 86 // Load the extension, which has no default popup.
87 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; 87 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_;
88 const Extension* extension = GetSingleLoadedExtension(); 88 const Extension* extension = GetSingleLoadedExtension();
89 ASSERT_TRUE(extension) << message_; 89 ASSERT_TRUE(extension) << message_;
90 90
91 int tab_id = ExtensionTabUtil::GetTabId( 91 int tab_id = ExtensionTabUtil::GetTabId(
92 chrome::GetActiveWebContents(browser())); 92 browser()->tab_strip_model()->GetActiveWebContents());
93 93
94 ExtensionAction* page_action = GetPageAction(*extension); 94 ExtensionAction* page_action = GetPageAction(*extension);
95 ASSERT_TRUE(page_action) 95 ASSERT_TRUE(page_action)
96 << "Page action test extension should have a page action."; 96 << "Page action test extension should have a page action.";
97 97
98 ASSERT_FALSE(page_action->HasPopup(tab_id)); 98 ASSERT_FALSE(page_action->HasPopup(tab_id));
99 99
100 // Simulate the page action being clicked. The resulting event should 100 // Simulate the page action being clicked. The resulting event should
101 // install a page action popup. 101 // install a page action popup.
102 { 102 {
(...skipping 27 matching lines...) Expand all
130 } 130 }
131 131
132 // Test that calling chrome.pageAction.setPopup() can remove a popup. 132 // Test that calling chrome.pageAction.setPopup() can remove a popup.
133 IN_PROC_BROWSER_TEST_F(PageActionApiTest, RemovePopup) { 133 IN_PROC_BROWSER_TEST_F(PageActionApiTest, RemovePopup) {
134 // Load the extension, which has a page action with a default popup. 134 // Load the extension, which has a page action with a default popup.
135 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; 135 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_;
136 const Extension* extension = GetSingleLoadedExtension(); 136 const Extension* extension = GetSingleLoadedExtension();
137 ASSERT_TRUE(extension) << message_; 137 ASSERT_TRUE(extension) << message_;
138 138
139 int tab_id = ExtensionTabUtil::GetTabId( 139 int tab_id = ExtensionTabUtil::GetTabId(
140 chrome::GetActiveWebContents(browser())); 140 browser()->tab_strip_model()->GetActiveWebContents());
141 141
142 ExtensionAction* page_action = GetPageAction(*extension); 142 ExtensionAction* page_action = GetPageAction(*extension);
143 ASSERT_TRUE(page_action) 143 ASSERT_TRUE(page_action)
144 << "Page action test extension should have a page action."; 144 << "Page action test extension should have a page action.";
145 145
146 ASSERT_TRUE(page_action->HasPopup(tab_id)) 146 ASSERT_TRUE(page_action->HasPopup(tab_id))
147 << "Expect a page action popup before the test removes it."; 147 << "Expect a page action popup before the test removes it.";
148 148
149 // Load a page which removes the popup using chrome.pageAction.setPopup(). 149 // Load a page which removes the popup using chrome.pageAction.setPopup().
150 { 150 {
(...skipping 20 matching lines...) Expand all
171 { 171 {
172 ResultCatcher catcher; 172 ResultCatcher catcher;
173 ui_test_utils::NavigateToURL(browser(), 173 ui_test_utils::NavigateToURL(browser(),
174 GURL(extension->GetResourceURL("page.html"))); 174 GURL(extension->GetResourceURL("page.html")));
175 ASSERT_TRUE(catcher.GetNextResult()); 175 ASSERT_TRUE(catcher.GetNextResult());
176 } 176 }
177 177
178 // Simulate the page action being clicked. 178 // Simulate the page action being clicked.
179 { 179 {
180 ResultCatcher catcher; 180 ResultCatcher catcher;
181 int tab_id = 181 int tab_id = ExtensionTabUtil::GetTabId(
182 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); 182 browser()->tab_strip_model()->GetActiveWebContents());
183 ExtensionService* service = extensions::ExtensionSystem::Get( 183 ExtensionService* service = extensions::ExtensionSystem::Get(
184 browser()->profile())->extension_service(); 184 browser()->profile())->extension_service();
185 ExtensionAction* page_action = GetPageAction(*extension); 185 ExtensionAction* page_action = GetPageAction(*extension);
186 service->browser_event_router()->PageActionExecuted( 186 service->browser_event_router()->PageActionExecuted(
187 browser()->profile(), *page_action, tab_id, "", 1); 187 browser()->profile(), *page_action, tab_id, "", 1);
188 EXPECT_TRUE(catcher.GetNextResult()); 188 EXPECT_TRUE(catcher.GetNextResult());
189 } 189 }
190 } 190 }
191 191
192 // Tests popups in page actions. 192 // Tests popups in page actions.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 ASSERT_TRUE(extension) << message_; 226 ASSERT_TRUE(extension) << message_;
227 227
228 ResultCatcher catcher; 228 ResultCatcher catcher;
229 ui_test_utils::NavigateToURL(browser(), 229 ui_test_utils::NavigateToURL(browser(),
230 GURL(extension->GetResourceURL("update.html"))); 230 GURL(extension->GetResourceURL("update.html")));
231 ASSERT_TRUE(catcher.GetNextResult()); 231 ASSERT_TRUE(catcher.GetNextResult());
232 } 232 }
233 233
234 } // namespace 234 } // namespace
235 } // namespace extensions 235 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698