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" |
| 31 #include "extensions/browser/process_manager.h" |
32 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
33 #include "extensions/common/switches.h" | |
34 #include "extensions/test/result_catcher.h" | 33 #include "extensions/test/result_catcher.h" |
35 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
36 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
37 #include "url/gurl.h" | 36 #include "url/gurl.h" |
38 | 37 |
39 using extensions::Extension; | 38 using extensions::Extension; |
40 using extensions::ResultCatcher; | 39 using extensions::ResultCatcher; |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 scoped_ptr<LazyBackgroundObserver> incognito_complete_; | 78 scoped_ptr<LazyBackgroundObserver> incognito_complete_; |
80 }; | 79 }; |
81 | 80 |
82 } // namespace | 81 } // namespace |
83 | 82 |
84 class LazyBackgroundPageApiTest : public ExtensionApiTest { | 83 class LazyBackgroundPageApiTest : public ExtensionApiTest { |
85 public: | 84 public: |
86 LazyBackgroundPageApiTest() {} | 85 LazyBackgroundPageApiTest() {} |
87 virtual ~LazyBackgroundPageApiTest() {} | 86 virtual ~LazyBackgroundPageApiTest() {} |
88 | 87 |
89 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 88 virtual void SetUpOnMainThread() OVERRIDE { |
90 ExtensionApiTest::SetUpCommandLine(command_line); | 89 ExtensionApiTest::SetUpOnMainThread(); |
91 // Set shorter delays to prevent test timeouts. | 90 // Set shorter delays to prevent test timeouts. |
92 command_line->AppendSwitchASCII( | 91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); |
93 extensions::switches::kEventPageIdleTime, "1000"); | 92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
94 command_line->AppendSwitchASCII( | |
95 extensions::switches::kEventPageSuspendingTime, "1000"); | |
96 } | 93 } |
97 | 94 |
98 // Loads the extension, which temporarily starts the lazy background page | 95 // Loads the extension, which temporarily starts the lazy background page |
99 // to dispatch the onInstalled event. We wait until it shuts down again. | 96 // to dispatch the onInstalled event. We wait until it shuts down again. |
100 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 97 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
101 LazyBackgroundObserver page_complete; | 98 LazyBackgroundObserver page_complete; |
102 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 99 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
103 AppendASCII(test_name); | 100 AppendASCII(test_name); |
104 const Extension* extension = LoadExtension(extdir); | 101 const Extension* extension = LoadExtension(extdir); |
105 if (extension) | 102 if (extension) |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 563 |
567 // Tests that the lazy background page will be unloaded if the onSuspend event | 564 // Tests that the lazy background page will be unloaded if the onSuspend event |
568 // handler calls an API function such as chrome.storage.local.set(). | 565 // handler calls an API function such as chrome.storage.local.set(). |
569 // See: http://crbug.com/296834 | 566 // See: http://crbug.com/296834 |
570 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 567 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
571 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 568 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
572 } | 569 } |
573 | 570 |
574 // TODO: background page with timer. | 571 // TODO: background page with timer. |
575 // TODO: background page that interacts with popup. | 572 // TODO: background page that interacts with popup. |
OLD | NEW |