| 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/extensions/browser_action_test_util.h" | 10 #include "chrome/browser/extensions/browser_action_test_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/bookmarks/browser/bookmark_utils.h" | 24 #include "components/bookmarks/browser/bookmark_utils.h" |
| 25 #include "components/bookmarks/test/bookmark_test_helpers.h" | 25 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
| 29 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 30 #include "extensions/browser/extension_registry_observer.h" | 30 #include "extensions/browser/extension_registry_observer.h" |
| 31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
| 32 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 33 #include "extensions/common/switches.h" | 33 #include "extensions/common/switches.h" |
| 34 #include "extensions/test/result_catcher.h" |
| 34 #include "net/dns/mock_host_resolver.h" | 35 #include "net/dns/mock_host_resolver.h" |
| 35 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 37 | 38 |
| 38 using extensions::Extension; | 39 using extensions::Extension; |
| 40 using extensions::ResultCatcher; |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 // This unfortunate bit of silliness is necessary when loading an extension in | 44 // 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 | 45 // incognito. The goal is to load the extension, enable incognito, then wait |
| 44 // for both background pages to load and close. The problem is that enabling | 46 // for both background pages to load and close. The problem is that enabling |
| 45 // incognito involves reloading the extension - and the background pages may | 47 // incognito involves reloading the extension - and the background pages may |
| 46 // have already loaded once before then. So we wait until the extension is | 48 // have already loaded once before then. So we wait until the extension is |
| 47 // unloaded before listening to the background page notifications. | 49 // unloaded before listening to the background page notifications. |
| 48 class LoadedIncognitoObserver : public extensions::ExtensionRegistryObserver { | 50 class LoadedIncognitoObserver : public extensions::ExtensionRegistryObserver { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // The browser action has a new title. | 480 // The browser action has a new title. |
| 479 BrowserActionTestUtil browser_action(browser()); | 481 BrowserActionTestUtil browser_action(browser()); |
| 480 ASSERT_EQ(1, browser_action.NumberOfBrowserActions()); | 482 ASSERT_EQ(1, browser_action.NumberOfBrowserActions()); |
| 481 EXPECT_EQ("Success", browser_action.GetTooltip(0)); | 483 EXPECT_EQ("Success", browser_action.GetTooltip(0)); |
| 482 } | 484 } |
| 483 | 485 |
| 484 // Tests that both a regular page and an event page will receive events when | 486 // Tests that both a regular page and an event page will receive events when |
| 485 // the event page is not loaded. | 487 // the event page is not loaded. |
| 486 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventDispatchToTab) { | 488 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventDispatchToTab) { |
| 487 ResultCatcher catcher; | 489 ResultCatcher catcher; |
| 488 catcher.RestrictToProfile(browser()->profile()); | 490 catcher.RestrictToBrowserContext(browser()->profile()); |
| 489 | 491 |
| 490 const extensions::Extension* extension = | 492 const extensions::Extension* extension = |
| 491 LoadExtensionAndWait("event_dispatch_to_tab"); | 493 LoadExtensionAndWait("event_dispatch_to_tab"); |
| 492 | 494 |
| 493 ExtensionTestMessageListener page_ready("ready", true); | 495 ExtensionTestMessageListener page_ready("ready", true); |
| 494 GURL page_url = extension->GetResourceURL("page.html"); | 496 GURL page_url = extension->GetResourceURL("page.html"); |
| 495 ui_test_utils::NavigateToURL(browser(), page_url); | 497 ui_test_utils::NavigateToURL(browser(), page_url); |
| 496 EXPECT_TRUE(page_ready.WaitUntilSatisfied()); | 498 EXPECT_TRUE(page_ready.WaitUntilSatisfied()); |
| 497 | 499 |
| 498 // After the event is sent below, wait for the event page to have received | 500 // After the event is sent below, wait for the event page to have received |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 566 |
| 565 // Tests that the lazy background page will be unloaded if the onSuspend event | 567 // 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(). | 568 // handler calls an API function such as chrome.storage.local.set(). |
| 567 // See: http://crbug.com/296834 | 569 // See: http://crbug.com/296834 |
| 568 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { | 570 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { |
| 569 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); | 571 EXPECT_TRUE(LoadExtensionAndWait("on_suspend")); |
| 570 } | 572 } |
| 571 | 573 |
| 572 // TODO: background page with timer. | 574 // TODO: background page with timer. |
| 573 // TODO: background page that interacts with popup. | 575 // TODO: background page that interacts with popup. |
| OLD | NEW |