| 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" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/scoped_observer.h" | 7 #include "base/scoped_observer.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/extensions/browser_action_test_util.h" | 10 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 15 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 14 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 16 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
| 18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/location_bar/location_bar.h" | 19 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "components/bookmarks/browser/bookmark_model.h" | 23 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/bookmarks/browser/bookmark_utils.h" | 24 #include "components/bookmarks/browser/bookmark_utils.h" |
| 26 #include "components/bookmarks/test/bookmark_test_helpers.h" | 25 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 27 #include "content/public/browser/notification_service.h" | |
| 28 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 30 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
| 31 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_registry_observer.h" | 30 #include "extensions/browser/extension_registry_observer.h" |
| 33 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
| 34 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 35 #include "extensions/common/switches.h" | 33 #include "extensions/common/switches.h" |
| 36 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const Extension* extension = LoadExtensionAndWait("broadcast_event"); | 163 const Extension* extension = LoadExtensionAndWait("broadcast_event"); |
| 166 ASSERT_TRUE(extension); | 164 ASSERT_TRUE(extension); |
| 167 | 165 |
| 168 // Lazy Background Page doesn't exist yet. | 166 // Lazy Background Page doesn't exist yet. |
| 169 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 167 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 170 int num_page_actions = browser()->window()->GetLocationBar()-> | 168 int num_page_actions = browser()->window()->GetLocationBar()-> |
| 171 GetLocationBarForTesting()->PageActionVisibleCount(); | 169 GetLocationBarForTesting()->PageActionVisibleCount(); |
| 172 | 170 |
| 173 // Open a tab to a URL that will trigger the page action to show. | 171 // Open a tab to a URL that will trigger the page action to show. |
| 174 LazyBackgroundObserver page_complete; | 172 LazyBackgroundObserver page_complete; |
| 175 content::WindowedNotificationObserver page_action_changed( | |
| 176 extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED, | |
| 177 content::NotificationService::AllSources()); | |
| 178 ui_test_utils::NavigateToURL( | 173 ui_test_utils::NavigateToURL( |
| 179 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); | 174 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); |
| 180 page_complete.Wait(); | 175 page_complete.Wait(); |
| 181 | 176 |
| 182 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 177 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
| 183 | 178 |
| 184 // Page action is shown. | 179 // Page action is shown. |
| 185 page_action_changed.Wait(); | 180 WaitForPageActionVisibilityChangeTo(num_page_actions + 1); |
| 186 EXPECT_EQ(num_page_actions + 1, | 181 EXPECT_EQ(num_page_actions + 1, |
| 187 browser()->window()->GetLocationBar()-> | 182 browser()->window()->GetLocationBar()-> |
| 188 GetLocationBarForTesting()->PageActionVisibleCount()); | 183 GetLocationBarForTesting()->PageActionVisibleCount()); |
| 189 } | 184 } |
| 190 | 185 |
| 191 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { | 186 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { |
| 192 ASSERT_TRUE(StartEmbeddedTestServer()); | 187 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 193 | 188 |
| 194 const Extension* extension = LoadExtensionAndWait("filters"); | 189 const Extension* extension = LoadExtensionAndWait("filters"); |
| 195 ASSERT_TRUE(extension); | 190 ASSERT_TRUE(extension); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 564 |
| 570 // Tests that the lazy background page will be unloaded if the onSuspend event | 565 // Tests that the lazy background page will be unloaded if the onSuspend event |
| 571 // handler calls an API function such as chrome.storage.local.set(). | 566 // handler calls an API function such as chrome.storage.local.set(). |
| 572 // See: http://crbug.com/296834 | 567 // See: http://crbug.com/296834 |
| 573 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 568 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
| 574 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 569 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
| 575 } | 570 } |
| 576 | 571 |
| 577 // TODO: background page with timer. | 572 // TODO: background page with timer. |
| 578 // TODO: background page that interacts with popup. | 573 // TODO: background page that interacts with popup. |
| OLD | NEW |