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/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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 void Wait() { | 57 void Wait() { |
58 ASSERT_TRUE(original_complete_.get()); | 58 ASSERT_TRUE(original_complete_.get()); |
59 original_complete_->Wait(); | 59 original_complete_->Wait(); |
60 incognito_complete_->Wait(); | 60 incognito_complete_->Wait(); |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 virtual void OnExtensionUnloaded( | 64 virtual void OnExtensionUnloaded( |
65 content::BrowserContext* browser_context, | 65 content::BrowserContext* browser_context, |
66 const Extension* extension, | 66 const Extension* extension, |
67 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE { | 67 extensions::UnloadedExtensionInfo::Reason reason) override { |
68 original_complete_.reset(new LazyBackgroundObserver(profile_)); | 68 original_complete_.reset(new LazyBackgroundObserver(profile_)); |
69 incognito_complete_.reset( | 69 incognito_complete_.reset( |
70 new LazyBackgroundObserver(profile_->GetOffTheRecordProfile())); | 70 new LazyBackgroundObserver(profile_->GetOffTheRecordProfile())); |
71 } | 71 } |
72 | 72 |
73 Profile* profile_; | 73 Profile* profile_; |
74 ScopedObserver<extensions::ExtensionRegistry, | 74 ScopedObserver<extensions::ExtensionRegistry, |
75 extensions::ExtensionRegistryObserver> | 75 extensions::ExtensionRegistryObserver> |
76 extension_registry_observer_; | 76 extension_registry_observer_; |
77 scoped_ptr<LazyBackgroundObserver> original_complete_; | 77 scoped_ptr<LazyBackgroundObserver> original_complete_; |
78 scoped_ptr<LazyBackgroundObserver> incognito_complete_; | 78 scoped_ptr<LazyBackgroundObserver> incognito_complete_; |
79 }; | 79 }; |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 class LazyBackgroundPageApiTest : public ExtensionApiTest { | 83 class LazyBackgroundPageApiTest : public ExtensionApiTest { |
84 public: | 84 public: |
85 LazyBackgroundPageApiTest() {} | 85 LazyBackgroundPageApiTest() {} |
86 virtual ~LazyBackgroundPageApiTest() {} | 86 virtual ~LazyBackgroundPageApiTest() {} |
87 | 87 |
88 virtual void SetUpOnMainThread() OVERRIDE { | 88 virtual void SetUpOnMainThread() override { |
89 ExtensionApiTest::SetUpOnMainThread(); | 89 ExtensionApiTest::SetUpOnMainThread(); |
90 // Set shorter delays to prevent test timeouts. | 90 // Set shorter delays to prevent test timeouts. |
91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); | 91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); |
92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); | 92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
93 } | 93 } |
94 | 94 |
95 // Loads the extension, which temporarily starts the lazy background page | 95 // Loads the extension, which temporarily starts the lazy background page |
96 // 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. |
97 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 97 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
98 LazyBackgroundObserver page_complete; | 98 LazyBackgroundObserver page_complete; |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 563 |
564 // 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 |
565 // handler calls an API function such as chrome.storage.local.set(). | 565 // handler calls an API function such as chrome.storage.local.set(). |
566 // See: http://crbug.com/296834 | 566 // See: http://crbug.com/296834 |
567 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 567 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
568 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 568 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
569 } | 569 } |
570 | 570 |
571 // TODO: background page with timer. | 571 // TODO: background page with timer. |
572 // TODO: background page that interacts with popup. | 572 // TODO: background page that interacts with popup. |
OLD | NEW |