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

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

Issue 1117023002: Keep event page alive when there's some Pepper plugin on it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove DCHECK. Created 5 years, 6 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
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/path_service.h"
6 #include "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
7 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h" 11 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/lazy_background_page_test_util.h" 13 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
12 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/location_bar/location_bar.h" 17 #include "chrome/browser/ui/location_bar/location_bar.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/app_modal/app_modal_dialog.h" 23 #include "components/app_modal/app_modal_dialog.h"
20 #include "components/bookmarks/browser/bookmark_model.h" 24 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/browser/bookmark_utils.h" 25 #include "components/bookmarks/browser/bookmark_utils.h"
22 #include "components/bookmarks/test/bookmark_test_helpers.h" 26 #include "components/bookmarks/test/bookmark_test_helpers.h"
23 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
29 #include "content/public/test/test_utils.h"
25 #include "extensions/browser/extension_host.h" 30 #include "extensions/browser/extension_host.h"
26 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_registry_observer.h" 32 #include "extensions/browser/extension_registry_observer.h"
28 #include "extensions/browser/process_manager.h" 33 #include "extensions/browser/process_manager.h"
29 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
30 #include "extensions/test/extension_test_message_listener.h" 35 #include "extensions/test/extension_test_message_listener.h"
31 #include "extensions/test/result_catcher.h" 36 #include "extensions/test/result_catcher.h"
32 #include "net/dns/mock_host_resolver.h" 37 #include "net/dns/mock_host_resolver.h"
33 #include "net/test/embedded_test_server/embedded_test_server.h" 38 #include "net/test/embedded_test_server/embedded_test_server.h"
39 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/gurl.h" 40 #include "url/gurl.h"
35 41
36 using bookmarks::BookmarkModel; 42 using bookmarks::BookmarkModel;
37 using bookmarks::BookmarkNode; 43 using bookmarks::BookmarkNode;
38 using extensions::Extension; 44 using extensions::Extension;
39 using extensions::ResultCatcher; 45 using extensions::ResultCatcher;
40 46
41 namespace { 47 namespace {
42 48
43 // This unfortunate bit of silliness is necessary when loading an extension in 49 // This unfortunate bit of silliness is necessary when loading an extension in
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 scoped_ptr<LazyBackgroundObserver> incognito_complete_; 84 scoped_ptr<LazyBackgroundObserver> incognito_complete_;
79 }; 85 };
80 86
81 } // namespace 87 } // namespace
82 88
83 class LazyBackgroundPageApiTest : public ExtensionApiTest { 89 class LazyBackgroundPageApiTest : public ExtensionApiTest {
84 public: 90 public:
85 LazyBackgroundPageApiTest() {} 91 LazyBackgroundPageApiTest() {}
86 ~LazyBackgroundPageApiTest() override {} 92 ~LazyBackgroundPageApiTest() override {}
87 93
88 void SetUpOnMainThread() override { 94 void SetUpInProcessBrowserTestFixture() override {
89 ExtensionApiTest::SetUpOnMainThread(); 95 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
90 // Set shorter delays to prevent test timeouts. 96 // Set shorter delays to prevent test timeouts.
91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); 97 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); 98 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
93 } 99 }
94 100
101 void SetUpCommandLine(base::CommandLine* command_line) override {
102 ExtensionApiTest::SetUpCommandLine(command_line);
103 // Disable background network activity as it can suddenly bring the Lazy
104 // Background Page alive.
105 command_line->AppendSwitch(switches::kDisableBackgroundNetworking);
106 command_line->AppendSwitch(switches::kNoProxyServer);
107 }
108
95 // Loads the extension, which temporarily starts the lazy background page 109 // Loads the extension, which temporarily starts the lazy background page
96 // to dispatch the onInstalled event. We wait until it shuts down again. 110 // to dispatch the onInstalled event. We wait until it shuts down again.
97 const Extension* LoadExtensionAndWait(const std::string& test_name) { 111 const Extension* LoadExtensionAndWait(const std::string& test_name) {
98 LazyBackgroundObserver page_complete; 112 LazyBackgroundObserver page_complete;
99 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). 113 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
100 AppendASCII(test_name); 114 AppendASCII(test_name);
101 const Extension* extension = LoadExtension(extdir); 115 const Extension* extension = LoadExtension(extdir);
102 if (extension) 116 if (extension)
103 page_complete.Wait(); 117 page_complete.Wait();
104 return extension; 118 return extension;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 bool result = false; 305 bool result = false;
292 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 306 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
293 host->render_view_host(), "abortRequest()", &result)); 307 host->render_view_host(), "abortRequest()", &result));
294 EXPECT_TRUE(result); 308 EXPECT_TRUE(result);
295 page_complete.Wait(); 309 page_complete.Wait();
296 310
297 // Lazy Background Page has been shut down. 311 // Lazy Background Page has been shut down.
298 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); 312 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
299 } 313 }
300 314
315 // Tests that the lazy background page stays alive while a NaCl module exists in
316 // its DOM.
317 #if !defined(DISABLE_NACL)
318 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, NaCl) {
319 {
320 base::FilePath extdir;
321 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &extdir));
322 extdir = extdir.AppendASCII("ppapi/tests/extensions/load_unload/newlib");
323 LazyBackgroundObserver page_complete;
324 ASSERT_TRUE(LoadExtension(extdir));
325 page_complete.Wait();
326 }
327
328 // The NaCl module is loaded, and the Lazy Background Page stays alive.
329 {
330 ExtensionTestMessageListener nacl_module_loaded("nacl_module_loaded",
331 false);
332 BrowserActionTestUtil(browser()).Press(0);
333 nacl_module_loaded.WaitUntilSatisfied();
334 content::RunAllBlockingPoolTasksUntilIdle();
335 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
336 }
337
338 // The NaCl module is detached from DOM, and the Lazy Background Page shuts
339 // down.
340 {
341 LazyBackgroundObserver page_complete;
342 BrowserActionTestUtil(browser()).Press(0);
343 page_complete.WaitUntilClosed();
344 }
345
346 // The Lazy Background Page has been shut down.
347 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
348 }
349 #endif
350
301 // Tests that the lazy background page stays alive until all visible views are 351 // Tests that the lazy background page stays alive until all visible views are
302 // closed. 352 // closed.
303 // http://crbug.com/175778; test fails frequently on OS X 353 // http://crbug.com/175778; test fails frequently on OS X
304 #if defined(OS_MACOSX) 354 #if defined(OS_MACOSX)
305 #define MAYBE_WaitForNTP DISABLED_WaitForNTP 355 #define MAYBE_WaitForNTP DISABLED_WaitForNTP
306 #else 356 #else
307 #define MAYBE_WaitForNTP WaitForNTP 357 #define MAYBE_WaitForNTP WaitForNTP
308 #endif 358 #endif
309 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) { 359 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) {
310 LazyBackgroundObserver lazybg; 360 LazyBackgroundObserver lazybg;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 623
574 // Tests that the lazy background page will be unloaded if the onSuspend event 624 // Tests that the lazy background page will be unloaded if the onSuspend event
575 // handler calls an API function such as chrome.storage.local.set(). 625 // handler calls an API function such as chrome.storage.local.set().
576 // See: http://crbug.com/296834 626 // See: http://crbug.com/296834
577 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { 627 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) {
578 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); 628 EXPECT_TRUE(LoadExtensionAndWait("on_suspend"));
579 } 629 }
580 630
581 // TODO: background page with timer. 631 // TODO: background page with timer.
582 // TODO: background page that interacts with popup. 632 // TODO: background page that interacts with popup.
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698