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

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: Fix test. Created 5 years, 7 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') | content/common/view_messages.h » ('J')
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"
34 #include "url/gurl.h" 39 #include "url/gurl.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 LazyBackgroundPageApiTest() {} 90 LazyBackgroundPageApiTest() {}
86 ~LazyBackgroundPageApiTest() override {} 91 ~LazyBackgroundPageApiTest() override {}
87 92
88 void SetUpOnMainThread() override { 93 void SetUpOnMainThread() override {
89 ExtensionApiTest::SetUpOnMainThread(); 94 ExtensionApiTest::SetUpOnMainThread();
90 // Set shorter delays to prevent test timeouts. 95 // Set shorter delays to prevent test timeouts.
91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); 96 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); 97 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
93 } 98 }
94 99
100 void SetUpCommandLine(base::CommandLine* command_line) override {
101 ExtensionApiTest::SetUpCommandLine(command_line);
102 // Disable background network activity as it can suddenly bring the Lazy
103 // Background Page alive.
104 command_line->AppendSwitch(switches::kDisableBackgroundNetworking);
105 command_line->AppendSwitch(switches::kNoProxyServer);
106 }
107
95 // Loads the extension, which temporarily starts the lazy background page 108 // Loads the extension, which temporarily starts the lazy background page
96 // to dispatch the onInstalled event. We wait until it shuts down again. 109 // to dispatch the onInstalled event. We wait until it shuts down again.
97 const Extension* LoadExtensionAndWait(const std::string& test_name) { 110 const Extension* LoadExtensionAndWait(const std::string& test_name) {
98 LazyBackgroundObserver page_complete; 111 LazyBackgroundObserver page_complete;
99 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). 112 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
100 AppendASCII(test_name); 113 AppendASCII(test_name);
101 const Extension* extension = LoadExtension(extdir); 114 const Extension* extension = LoadExtension(extdir);
102 if (extension) 115 if (extension)
103 page_complete.Wait(); 116 page_complete.Wait();
104 return extension; 117 return extension;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 bool result = false; 304 bool result = false;
292 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 305 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
293 host->render_view_host(), "abortRequest()", &result)); 306 host->render_view_host(), "abortRequest()", &result));
294 EXPECT_TRUE(result); 307 EXPECT_TRUE(result);
295 page_complete.Wait(); 308 page_complete.Wait();
296 309
297 // Lazy Background Page has been shut down. 310 // Lazy Background Page has been shut down.
298 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id())); 311 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
299 } 312 }
300 313
314 // Tests that the lazy background page stays alive while a NaCl module exists in
315 // its DOM.
316 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, NaCl) {
317 #if !defined(DISABLE_NACL)
not at google - send to devlin 2015/05/11 17:53:48 Is it better to ifdef out the entire test? That wa
emaxx 2015/05/18 15:06:29 Done.
318 {
319 base::FilePath extdir;
320 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &extdir));
bartfab (slow) 2015/05/18 09:57:41 Nit: #include "testing/gtest/include/gtest/gtest.h
emaxx 2015/05/18 15:06:29 Done.
321 extdir = extdir.AppendASCII("ppapi/tests/extensions/load_unload/newlib");
322 LazyBackgroundObserver page_complete;
323 ASSERT_TRUE(LoadExtension(base::FilePath(extdir)));
bartfab (slow) 2015/05/18 09:57:41 Why do you cast |extdir| to |base::FilePath| once
emaxx 2015/05/18 15:06:29 Done (it was left from some old version).
324 page_complete.Wait();
325 }
326
327 // The NaCl module is loaded, and the Lazy Background Page stays alive.
328 {
329 ExtensionTestMessageListener nacl_module_loaded("nacl_module_loaded",
330 false);
331 BrowserActionTestUtil(browser()).Press(0);
332 nacl_module_loaded.WaitUntilSatisfied();
333 content::RunAllBlockingPoolTasksUntilIdle();
not at google - send to devlin 2015/05/11 17:53:48 It's a pity, we're basically forcing this test to
bartfab (slow) 2015/05/18 09:57:41 I would be worried not just about early returns bu
emaxx 2015/05/18 15:06:29 Actually the test class LazyBackgroundPageApiTest
emaxx 2015/05/18 15:06:29 Done (see the answer above).
334 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
335 }
336
337 // The NaCl module is detached from DOM, and the Lazy Background Page shuts
338 // down.
339 {
340 LazyBackgroundObserver page_complete;
341 BrowserActionTestUtil(browser()).Press(0);
342 page_complete.WaitUntilClosed();
343 }
344
345 // The Lazy Background Page has been shut down.
346 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
347 #endif
348 }
349
301 // Tests that the lazy background page stays alive until all visible views are 350 // Tests that the lazy background page stays alive until all visible views are
302 // closed. 351 // closed.
303 // http://crbug.com/175778; test fails frequently on OS X 352 // http://crbug.com/175778; test fails frequently on OS X
304 #if defined(OS_MACOSX) 353 #if defined(OS_MACOSX)
305 #define MAYBE_WaitForNTP DISABLED_WaitForNTP 354 #define MAYBE_WaitForNTP DISABLED_WaitForNTP
306 #else 355 #else
307 #define MAYBE_WaitForNTP WaitForNTP 356 #define MAYBE_WaitForNTP WaitForNTP
308 #endif 357 #endif
309 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) { 358 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) {
310 LazyBackgroundObserver lazybg; 359 LazyBackgroundObserver lazybg;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 622
574 // Tests that the lazy background page will be unloaded if the onSuspend event 623 // 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(). 624 // handler calls an API function such as chrome.storage.local.set().
576 // See: http://crbug.com/296834 625 // See: http://crbug.com/296834
577 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { 626 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) {
578 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); 627 EXPECT_TRUE(LoadExtensionAndWait("on_suspend"));
579 } 628 }
580 629
581 // TODO: background page with timer. 630 // TODO: background page with timer.
582 // TODO: background page that interacts with popup. 631 // TODO: background page that interacts with popup.
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/common/view_messages.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698