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

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

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_browser_event_router.h" 6 #include "chrome/browser/extensions/extension_browser_event_router.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_tab_util.h" 8 #include "chrome/browser/extensions/extension_tab_util.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 10 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/omnibox/location_bar.h" 13 #include "chrome/browser/ui/omnibox/location_bar.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_action.h" 16 #include "chrome/common/extensions/extension_action.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/public/browser/web_contents.h"
19 19
20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { 20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) {
21 ASSERT_TRUE(test_server()->Start()); 21 ASSERT_TRUE(test_server()->Start());
22 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; 22 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_;
23 const Extension* extension = GetSingleLoadedExtension(); 23 const Extension* extension = GetSingleLoadedExtension();
24 ASSERT_TRUE(extension) << message_; 24 ASSERT_TRUE(extension) << message_;
25 { 25 {
26 // Tell the extension to update the page action state. 26 // Tell the extension to update the page action state.
27 ResultCatcher catcher; 27 ResultCatcher catcher;
28 ui_test_utils::NavigateToURL(browser(), 28 ui_test_utils::NavigateToURL(browser(),
29 GURL(extension->GetResourceURL("update.html"))); 29 GURL(extension->GetResourceURL("update.html")));
30 ASSERT_TRUE(catcher.GetNextResult()); 30 ASSERT_TRUE(catcher.GetNextResult());
31 } 31 }
32 32
33 // Test that we received the changes. 33 // Test that we received the changes.
34 int tab_id = browser()->GetSelectedTabContentsWrapper()-> 34 int tab_id = browser()->GetSelectedTabContentsWrapper()->
35 restore_tab_helper()->session_id().id(); 35 restore_tab_helper()->session_id().id();
36 ExtensionAction* action = extension->page_action(); 36 ExtensionAction* action = extension->page_action();
37 ASSERT_TRUE(action); 37 ASSERT_TRUE(action);
38 EXPECT_EQ("Modified", action->GetTitle(tab_id)); 38 EXPECT_EQ("Modified", action->GetTitle(tab_id));
39 39
40 { 40 {
41 // Simulate the page action being clicked. 41 // Simulate the page action being clicked.
42 ResultCatcher catcher; 42 ResultCatcher catcher;
43 int tab_id = 43 int tab_id =
44 ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); 44 ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents());
45 ExtensionService* service = browser()->profile()->GetExtensionService(); 45 ExtensionService* service = browser()->profile()->GetExtensionService();
46 service->browser_event_router()->PageActionExecuted( 46 service->browser_event_router()->PageActionExecuted(
47 browser()->profile(), extension->id(), "", tab_id, "", 0); 47 browser()->profile(), extension->id(), "", tab_id, "", 0);
48 EXPECT_TRUE(catcher.GetNextResult()); 48 EXPECT_TRUE(catcher.GetNextResult());
49 } 49 }
50 50
51 { 51 {
52 // Tell the extension to update the page action state again. 52 // Tell the extension to update the page action state again.
53 ResultCatcher catcher; 53 ResultCatcher catcher;
54 ui_test_utils::NavigateToURL(browser(), 54 ui_test_utils::NavigateToURL(browser(),
55 GURL(extension->GetResourceURL("update2.html"))); 55 GURL(extension->GetResourceURL("update2.html")));
56 ASSERT_TRUE(catcher.GetNextResult()); 56 ASSERT_TRUE(catcher.GetNextResult());
57 } 57 }
58 58
59 // Test that we received the changes. 59 // Test that we received the changes.
60 tab_id = browser()->GetSelectedTabContentsWrapper()->restore_tab_helper()-> 60 tab_id = browser()->GetSelectedTabContentsWrapper()->restore_tab_helper()->
61 session_id().id(); 61 session_id().id();
62 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); 62 EXPECT_FALSE(action->GetIcon(tab_id).isNull());
63 } 63 }
64 64
65 // Test that calling chrome.pageAction.setPopup() can enable a popup. 65 // Test that calling chrome.pageAction.setPopup() can enable a popup.
66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) { 66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) {
67 // Load the extension, which has no default popup. 67 // Load the extension, which has no default popup.
68 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; 68 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_;
69 const Extension* extension = GetSingleLoadedExtension(); 69 const Extension* extension = GetSingleLoadedExtension();
70 ASSERT_TRUE(extension) << message_; 70 ASSERT_TRUE(extension) << message_;
71 71
72 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); 72 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents());
73 73
74 ExtensionAction* page_action = extension->page_action(); 74 ExtensionAction* page_action = extension->page_action();
75 ASSERT_TRUE(page_action) 75 ASSERT_TRUE(page_action)
76 << "Page action test extension should have a page action."; 76 << "Page action test extension should have a page action.";
77 77
78 ASSERT_FALSE(page_action->HasPopup(tab_id)); 78 ASSERT_FALSE(page_action->HasPopup(tab_id));
79 79
80 // Simulate the page action being clicked. The resulting event should 80 // Simulate the page action being clicked. The resulting event should
81 // install a page action popup. 81 // install a page action popup.
82 { 82 {
(...skipping 25 matching lines...) Expand all
108 page_action->GetPopupUrl(tab_id).path().c_str()); 108 page_action->GetPopupUrl(tab_id).path().c_str());
109 } 109 }
110 110
111 // Test that calling chrome.pageAction.setPopup() can remove a popup. 111 // Test that calling chrome.pageAction.setPopup() can remove a popup.
112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) { 112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) {
113 // Load the extension, which has a page action with a default popup. 113 // Load the extension, which has a page action with a default popup.
114 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; 114 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_;
115 const Extension* extension = GetSingleLoadedExtension(); 115 const Extension* extension = GetSingleLoadedExtension();
116 ASSERT_TRUE(extension) << message_; 116 ASSERT_TRUE(extension) << message_;
117 117
118 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); 118 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents());
119 119
120 ExtensionAction* page_action = extension->page_action(); 120 ExtensionAction* page_action = extension->page_action();
121 ASSERT_TRUE(page_action) 121 ASSERT_TRUE(page_action)
122 << "Page action test extension should have a page action."; 122 << "Page action test extension should have a page action.";
123 123
124 ASSERT_TRUE(page_action->HasPopup(tab_id)) 124 ASSERT_TRUE(page_action->HasPopup(tab_id))
125 << "Expect a page action popup before the test removes it."; 125 << "Expect a page action popup before the test removes it.";
126 126
127 // Load a page which removes the popup using chrome.pageAction.setPopup(). 127 // Load a page which removes the popup using chrome.pageAction.setPopup().
128 { 128 {
(...skipping 20 matching lines...) Expand all
149 ResultCatcher catcher; 149 ResultCatcher catcher;
150 ui_test_utils::NavigateToURL(browser(), 150 ui_test_utils::NavigateToURL(browser(),
151 GURL(extension->GetResourceURL("page.html"))); 151 GURL(extension->GetResourceURL("page.html")));
152 ASSERT_TRUE(catcher.GetNextResult()); 152 ASSERT_TRUE(catcher.GetNextResult());
153 } 153 }
154 154
155 // Simulate the page action being clicked. 155 // Simulate the page action being clicked.
156 { 156 {
157 ResultCatcher catcher; 157 ResultCatcher catcher;
158 int tab_id = 158 int tab_id =
159 ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); 159 ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents());
160 ExtensionService* service = browser()->profile()->GetExtensionService(); 160 ExtensionService* service = browser()->profile()->GetExtensionService();
161 service->browser_event_router()->PageActionExecuted( 161 service->browser_event_router()->PageActionExecuted(
162 browser()->profile(), extension->id(), "action", tab_id, "", 1); 162 browser()->profile(), extension->id(), "action", tab_id, "", 1);
163 EXPECT_TRUE(catcher.GetNextResult()); 163 EXPECT_TRUE(catcher.GetNextResult());
164 } 164 }
165 } 165 }
166 166
167 // Tests popups in page actions. 167 // Tests popups in page actions.
168 // Flaky on the trybots. See http://crbug.com/96725. 168 // Flaky on the trybots. See http://crbug.com/96725.
169 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_ShowPageActionPopup) { 169 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_ShowPageActionPopup) {
(...skipping 17 matching lines...) Expand all
187 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TestCrash57333) { 187 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TestCrash57333) {
188 // Load extension A. 188 // Load extension A.
189 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action") 189 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action")
190 .AppendASCII("crash_57333") 190 .AppendASCII("crash_57333")
191 .AppendASCII("Extension1"))); 191 .AppendASCII("Extension1")));
192 // Load extension B. 192 // Load extension B.
193 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action") 193 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("page_action")
194 .AppendASCII("crash_57333") 194 .AppendASCII("crash_57333")
195 .AppendASCII("Extension2"))); 195 .AppendASCII("Extension2")));
196 } 196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698