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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h" 9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_event_router.h" 11 #include "chrome/browser/extensions/extension_event_router.h"
12 #include "chrome/browser/extensions/extension_host.h" 12 #include "chrome/browser/extensions/extension_host.h"
13 #include "chrome/browser/extensions/extension_test_message_listener.h" 13 #include "chrome/browser/extensions/extension_test_message_listener.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/lazy_background_page_test_util.h" 15 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/omnibox/location_bar.h" 21 #include "chrome/browser/ui/omnibox/location_bar.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
24 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
28 #include "net/base/mock_host_resolver.h" 29 #include "net/base/mock_host_resolver.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Observe background page being created and closed after 105 // Observe background page being created and closed after
105 // the browser action is clicked. 106 // the browser action is clicked.
106 LazyBackgroundObserver page_complete; 107 LazyBackgroundObserver page_complete;
107 BrowserActionTestUtil(browser()).Press(0); 108 BrowserActionTestUtil(browser()).Press(0);
108 page_complete.Wait(); 109 page_complete.Wait();
109 110
110 // Background page created a new tab before it closed. 111 // Background page created a new tab before it closed.
111 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 112 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
112 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); 113 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count());
113 EXPECT_EQ("chrome://chrome/extensions/", 114 EXPECT_EQ("chrome://chrome/extensions/",
114 browser()->GetActiveWebContents()->GetURL().spec()); 115 chrome::GetActiveWebContents(browser())->GetURL().spec());
115 } 116 }
116 117
117 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, 118 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
118 BrowserActionCreateTabAfterCallback) { 119 BrowserActionCreateTabAfterCallback) {
119 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback")); 120 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback"));
120 121
121 // Lazy Background Page doesn't exist yet. 122 // Lazy Background Page doesn't exist yet.
122 ExtensionProcessManager* pm = 123 ExtensionProcessManager* pm =
123 browser()->profile()->GetExtensionProcessManager(); 124 browser()->profile()->GetExtensionProcessManager();
124 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 125 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 LazyBackgroundObserver page_complete; 186 LazyBackgroundObserver page_complete;
186 ResultCatcher catcher; 187 ResultCatcher catcher;
187 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). 188 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
188 AppendASCII("wait_for_view"); 189 AppendASCII("wait_for_view");
189 const Extension* extension = LoadExtension(extdir); 190 const Extension* extension = LoadExtension(extdir);
190 ASSERT_TRUE(extension); 191 ASSERT_TRUE(extension);
191 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 192 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
192 193
193 // The extension should've opened a new tab to an extension page. 194 // The extension should've opened a new tab to an extension page.
194 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(), 195 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(),
195 browser()->GetActiveWebContents()->GetURL().spec()); 196 chrome::GetActiveWebContents(browser())->GetURL().spec());
196 197
197 // Lazy Background Page still exists, because the extension created a new tab 198 // Lazy Background Page still exists, because the extension created a new tab
198 // to an extension page. 199 // to an extension page.
199 ExtensionProcessManager* pm = 200 ExtensionProcessManager* pm =
200 browser()->profile()->GetExtensionProcessManager(); 201 browser()->profile()->GetExtensionProcessManager();
201 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 202 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
202 203
203 // Close the new tab. 204 // Close the new tab.
204 browser()->CloseTabContents(browser()->GetActiveWebContents()); 205 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser()));
205 page_complete.Wait(); 206 page_complete.Wait();
206 207
207 // Lazy Background Page has been shut down. 208 // Lazy Background Page has been shut down.
208 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 209 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
209 } 210 }
210 211
211 // Tests that the lazy background page stays alive until all network requests 212 // Tests that the lazy background page stays alive until all network requests
212 // are complete. 213 // are complete.
213 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) { 214 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) {
214 host_resolver()->AddRule("*", "127.0.0.1"); 215 host_resolver()->AddRule("*", "127.0.0.1");
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 353 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
353 354
354 // The browser action has a new title. 355 // The browser action has a new title.
355 BrowserActionTestUtil browser_action(browser()); 356 BrowserActionTestUtil browser_action(browser());
356 ASSERT_EQ(1, browser_action.NumberOfBrowserActions()); 357 ASSERT_EQ(1, browser_action.NumberOfBrowserActions());
357 EXPECT_EQ("Success", browser_action.GetTooltip(0)); 358 EXPECT_EQ("Success", browser_action.GetTooltip(0));
358 } 359 }
359 360
360 // TODO: background page with timer. 361 // TODO: background page with timer.
361 // TODO: background page that interacts with popup. 362 // TODO: background page that interacts with popup.
OLDNEW
« no previous file with comments | « chrome/browser/extensions/isolated_app_browsertest.cc ('k') | chrome/browser/extensions/options_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698