OLD | NEW |
---|---|
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" | |
6 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
7 #include "base/scoped_observer.h" | 6 #include "base/scoped_observer.h" |
8 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
14 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 13 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 15 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
17 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/location_bar/location_bar.h" | 18 #include "chrome/browser/ui/location_bar/location_bar.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
23 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
24 #include "components/bookmarks/browser/bookmark_utils.h" | 23 #include "components/bookmarks/browser/bookmark_utils.h" |
25 #include "components/bookmarks/test/bookmark_test_helpers.h" | 24 #include "components/bookmarks/test/bookmark_test_helpers.h" |
26 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
27 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
28 #include "extensions/browser/extension_host.h" | 27 #include "extensions/browser/extension_host.h" |
29 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_registry_observer.h" | 29 #include "extensions/browser/extension_registry_observer.h" |
31 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
32 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
33 #include "extensions/common/switches.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 | 37 |
40 namespace { | 38 namespace { |
41 | 39 |
42 // This unfortunate bit of silliness is necessary when loading an extension in | 40 // This unfortunate bit of silliness is necessary when loading an extension in |
43 // incognito. The goal is to load the extension, enable incognito, then wait | 41 // incognito. The goal is to load the extension, enable incognito, then wait |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 scoped_ptr<LazyBackgroundObserver> incognito_complete_; | 75 scoped_ptr<LazyBackgroundObserver> incognito_complete_; |
78 }; | 76 }; |
79 | 77 |
80 } // namespace | 78 } // namespace |
81 | 79 |
82 class LazyBackgroundPageApiTest : public ExtensionApiTest { | 80 class LazyBackgroundPageApiTest : public ExtensionApiTest { |
83 public: | 81 public: |
84 LazyBackgroundPageApiTest() {} | 82 LazyBackgroundPageApiTest() {} |
85 virtual ~LazyBackgroundPageApiTest() {} | 83 virtual ~LazyBackgroundPageApiTest() {} |
86 | 84 |
87 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 85 virtual void SetUpOnMainThread() OVERRIDE { |
88 ExtensionApiTest::SetUpCommandLine(command_line); | 86 ExtensionApiTest::SetUpOnMainThread(); |
89 // Set shorter delays to prevent test timeouts. | 87 // Set shorter delays to prevent test timeouts. |
90 command_line->AppendSwitchASCII( | 88 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); |
Devlin
2014/09/05 22:06:08
here too
Yoyo Zhou
2014/09/08 16:19:10
Done.
| |
91 extensions::switches::kEventPageIdleTime, "1000"); | 89 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
92 command_line->AppendSwitchASCII( | |
93 extensions::switches::kEventPageSuspendingTime, "1000"); | |
94 } | 90 } |
95 | 91 |
96 // Loads the extension, which temporarily starts the lazy background page | 92 // Loads the extension, which temporarily starts the lazy background page |
97 // to dispatch the onInstalled event. We wait until it shuts down again. | 93 // to dispatch the onInstalled event. We wait until it shuts down again. |
98 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 94 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
99 LazyBackgroundObserver page_complete; | 95 LazyBackgroundObserver page_complete; |
100 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 96 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
101 AppendASCII(test_name); | 97 AppendASCII(test_name); |
102 const Extension* extension = LoadExtension(extdir); | 98 const Extension* extension = LoadExtension(extdir); |
103 if (extension) | 99 if (extension) |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 | 560 |
565 // 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 |
566 // handler calls an API function such as chrome.storage.local.set(). | 562 // handler calls an API function such as chrome.storage.local.set(). |
567 // See: http://crbug.com/296834 | 563 // See: http://crbug.com/296834 |
568 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 564 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
569 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 565 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
570 } | 566 } |
571 | 567 |
572 // TODO: background page with timer. | 568 // TODO: background page with timer. |
573 // TODO: background page that interacts with popup. | 569 // TODO: background page that interacts with popup. |
OLD | NEW |