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

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

Issue 671763002: Extract ProcessManager from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month 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) 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/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/scoped_observer.h" 6 #include "base/scoped_observer.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 8 #include "chrome/browser/bookmarks/bookmark_model_factory.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_service.h"
12 #include "chrome/browser/extensions/lazy_background_page_test_util.h" 11 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/location_bar/location_bar.h" 15 #include "chrome/browser/ui/location_bar/location_bar.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
20 #include "components/app_modal_dialogs/app_modal_dialog.h" 19 #include "components/app_modal_dialogs/app_modal_dialog.h"
21 #include "components/bookmarks/browser/bookmark_model.h" 20 #include "components/bookmarks/browser/bookmark_model.h"
22 #include "components/bookmarks/browser/bookmark_utils.h" 21 #include "components/bookmarks/browser/bookmark_utils.h"
23 #include "components/bookmarks/test/bookmark_test_helpers.h" 22 #include "components/bookmarks/test/bookmark_test_helpers.h"
24 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
25 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
26 #include "extensions/browser/extension_host.h" 25 #include "extensions/browser/extension_host.h"
27 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/extension_registry_observer.h" 27 #include "extensions/browser/extension_registry_observer.h"
29 #include "extensions/browser/extension_system.h"
30 #include "extensions/browser/process_manager.h" 28 #include "extensions/browser/process_manager.h"
31 #include "extensions/common/extension.h" 29 #include "extensions/common/extension.h"
32 #include "extensions/test/extension_test_message_listener.h" 30 #include "extensions/test/extension_test_message_listener.h"
33 #include "extensions/test/result_catcher.h" 31 #include "extensions/test/result_catcher.h"
34 #include "net/dns/mock_host_resolver.h" 32 #include "net/dns/mock_host_resolver.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 33 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "url/gurl.h" 34 #include "url/gurl.h"
37 35
38 using extensions::Extension; 36 using extensions::Extension;
39 using extensions::ResultCatcher; 37 using extensions::ResultCatcher;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 AppendASCII(test_name); 98 AppendASCII(test_name);
101 const Extension* extension = LoadExtension(extdir); 99 const Extension* extension = LoadExtension(extdir);
102 if (extension) 100 if (extension)
103 page_complete.Wait(); 101 page_complete.Wait();
104 return extension; 102 return extension;
105 } 103 }
106 104
107 // Returns true if the lazy background page for the extension with 105 // Returns true if the lazy background page for the extension with
108 // |extension_id| is still running. 106 // |extension_id| is still running.
109 bool IsBackgroundPageAlive(const std::string& extension_id) { 107 bool IsBackgroundPageAlive(const std::string& extension_id) {
110 extensions::ProcessManager* pm = extensions::ExtensionSystem::Get( 108 extensions::ProcessManager* pm =
111 browser()->profile())->process_manager(); 109 extensions::ProcessManager::Get(browser()->profile());
112 return pm->GetBackgroundHostForExtension(extension_id); 110 return pm->GetBackgroundHostForExtension(extension_id);
113 } 111 }
114 112
115 private: 113 private:
116 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageApiTest); 114 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageApiTest);
117 }; 115 };
118 116
119 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { 117 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
120 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab")); 118 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab"));
121 119
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 217
220 // The test extension opens a dialog on installation. 218 // The test extension opens a dialog on installation.
221 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); 219 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
222 ASSERT_TRUE(dialog); 220 ASSERT_TRUE(dialog);
223 221
224 // With the dialog open the background page is still alive. 222 // With the dialog open the background page is still alive.
225 EXPECT_TRUE(IsBackgroundPageAlive(extension->id())); 223 EXPECT_TRUE(IsBackgroundPageAlive(extension->id()));
226 224
227 // Close the dialog. The keep alive count is decremented. 225 // Close the dialog. The keep alive count is decremented.
228 extensions::ProcessManager* pm = 226 extensions::ProcessManager* pm =
229 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 227 extensions::ProcessManager::Get(browser()->profile());
230 int previous_keep_alive_count = pm->GetLazyKeepaliveCount(extension); 228 int previous_keep_alive_count = pm->GetLazyKeepaliveCount(extension);
231 dialog->CloseModalDialog(); 229 dialog->CloseModalDialog();
232 EXPECT_EQ(previous_keep_alive_count - 1, 230 EXPECT_EQ(previous_keep_alive_count - 1,
233 pm->GetLazyKeepaliveCount(extension)); 231 pm->GetLazyKeepaliveCount(extension));
234 232
235 // The background page closes now that the dialog is gone. 233 // The background page closes now that the dialog is gone.
236 background_observer.WaitUntilClosed(); 234 background_observer.WaitUntilClosed();
237 EXPECT_FALSE(IsBackgroundPageAlive(extension->id())); 235 EXPECT_FALSE(IsBackgroundPageAlive(extension->id()));
238 } 236 }
239 237
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 LazyBackgroundObserver page_complete; 273 LazyBackgroundObserver page_complete;
276 ResultCatcher catcher; 274 ResultCatcher catcher;
277 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). 275 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
278 AppendASCII("wait_for_request"); 276 AppendASCII("wait_for_request");
279 const Extension* extension = LoadExtension(extdir); 277 const Extension* extension = LoadExtension(extdir);
280 ASSERT_TRUE(extension); 278 ASSERT_TRUE(extension);
281 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 279 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
282 280
283 // Lazy Background Page still exists, because the extension started a request. 281 // Lazy Background Page still exists, because the extension started a request.
284 extensions::ProcessManager* pm = 282 extensions::ProcessManager* pm =
285 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 283 extensions::ProcessManager::Get(browser()->profile());
286 extensions::ExtensionHost* host = 284 extensions::ExtensionHost* host =
287 pm->GetBackgroundHostForExtension(last_loaded_extension_id()); 285 pm->GetBackgroundHostForExtension(last_loaded_extension_id());
288 ASSERT_TRUE(host); 286 ASSERT_TRUE(host);
289 287
290 // Abort the request. 288 // Abort the request.
291 bool result = false; 289 bool result = false;
292 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 290 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
293 host->render_view_host(), "abortRequest()", &result)); 291 host->render_view_host(), "abortRequest()", &result));
294 EXPECT_TRUE(result); 292 EXPECT_TRUE(result);
295 page_complete.Wait(); 293 page_complete.Wait();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 { 341 {
344 LoadedIncognitoObserver loaded(browser()->profile()); 342 LoadedIncognitoObserver loaded(browser()->profile());
345 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). 343 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
346 AppendASCII("incognito_split"); 344 AppendASCII("incognito_split");
347 ASSERT_TRUE(LoadExtensionIncognito(extdir)); 345 ASSERT_TRUE(LoadExtensionIncognito(extdir));
348 loaded.Wait(); 346 loaded.Wait();
349 } 347 }
350 348
351 // Lazy Background Page doesn't exist yet. 349 // Lazy Background Page doesn't exist yet.
352 extensions::ProcessManager* pm = 350 extensions::ProcessManager* pm =
353 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 351 extensions::ProcessManager::Get(browser()->profile());
354 extensions::ProcessManager* pmi = 352 extensions::ProcessManager* pmi =
355 extensions::ExtensionSystem::Get(incognito_browser->profile())-> 353 extensions::ProcessManager::Get(incognito_browser->profile());
356 process_manager();
357 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); 354 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
358 EXPECT_FALSE(pmi->GetBackgroundHostForExtension(last_loaded_extension_id())); 355 EXPECT_FALSE(pmi->GetBackgroundHostForExtension(last_loaded_extension_id()));
359 356
360 // Trigger a browserAction event in the original profile and ensure only 357 // Trigger a browserAction event in the original profile and ensure only
361 // the original event page received it (since the event is scoped to the 358 // the original event page received it (since the event is scoped to the
362 // profile). 359 // profile).
363 { 360 {
364 ExtensionTestMessageListener listener("waiting", false); 361 ExtensionTestMessageListener listener("waiting", false);
365 ExtensionTestMessageListener listener_incognito("waiting_incognito", false); 362 ExtensionTestMessageListener listener_incognito("waiting_incognito", false);
366 363
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 430
434 // Tests that a KeepaliveImpulse increments the keep alive count, but eventually 431 // Tests that a KeepaliveImpulse increments the keep alive count, but eventually
435 // times out and background page will still close. 432 // times out and background page will still close.
436 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, ImpulseAddsCount) { 433 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, ImpulseAddsCount) {
437 ASSERT_TRUE(StartEmbeddedTestServer()); 434 ASSERT_TRUE(StartEmbeddedTestServer());
438 const Extension* extension = LoadExtensionAndWait("messaging"); 435 const Extension* extension = LoadExtensionAndWait("messaging");
439 ASSERT_TRUE(extension); 436 ASSERT_TRUE(extension);
440 437
441 // Lazy Background Page doesn't exist yet. 438 // Lazy Background Page doesn't exist yet.
442 extensions::ProcessManager* pm = 439 extensions::ProcessManager* pm =
443 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 440 extensions::ProcessManager::Get(browser()->profile());
444 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); 441 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
445 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 442 EXPECT_EQ(1, browser()->tab_strip_model()->count());
446 443
447 // Navigate to a page that opens a message channel to the background page. 444 // Navigate to a page that opens a message channel to the background page.
448 ResultCatcher catcher; 445 ResultCatcher catcher;
449 LazyBackgroundObserver lazybg; 446 LazyBackgroundObserver lazybg;
450 ui_test_utils::NavigateToURL( 447 ui_test_utils::NavigateToURL(
451 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); 448 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
452 lazybg.WaitUntilLoaded(); 449 lazybg.WaitUntilLoaded();
453 450
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 560
564 // Tests that the lazy background page will be unloaded if the onSuspend event 561 // Tests that the lazy background page will be unloaded if the onSuspend event
565 // handler calls an API function such as chrome.storage.local.set(). 562 // handler calls an API function such as chrome.storage.local.set().
566 // See: http://crbug.com/296834 563 // See: http://crbug.com/296834
567 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { 564 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) {
568 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); 565 EXPECT_TRUE(LoadExtensionAndWait("on_suspend"));
569 } 566 }
570 567
571 // TODO: background page with timer. 568 // TODO: background page with timer.
572 // TODO: background page that interacts with popup. 569 // TODO: background page that interacts with popup.
OLDNEW
« no previous file with comments | « chrome/browser/extensions/gpu_browsertest.cc ('k') | chrome/browser/extensions/notifications_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698