summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/lazy_background_page_apitest.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 18:55:23 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 18:55:23 +0000
commitb6536df0203bcb40613d40a6ae28a82c6e8a2e95 (patch)
treed12ed781ce6a46063613a5f6123e8707c9cb0690 /chrome/browser/extensions/lazy_background_page_apitest.cc
parent950ee84c28a20172764da99ed03a4f0d4c9cc371 (diff)
downloadchromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.zip
chromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.tar.gz
chromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.tar.bz2
Lazy background pages now load in response to message passing.
I refactored the pending event stuff so that it handles generic tasks. The first enqueued task for an extension will start its lazy background page, and tasks are run once the page finishes loading. Events and messages now share this mechanism so that either one can activate the page. BUG=81752 TEST=no Review URL: https://chromiumcodereview.appspot.com/9704031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127216 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/lazy_background_page_apitest.cc')
-rw-r--r--chrome/browser/extensions/lazy_background_page_apitest.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome/browser/extensions/lazy_background_page_apitest.cc b/chrome/browser/extensions/lazy_background_page_apitest.cc
index 45fef79..5c93462 100644
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc
@@ -47,6 +47,13 @@ class LazyBackgroundObserver {
page_closed_.Wait();
}
+ void WaitUntilLoaded() {
+ page_created_.Wait();
+ }
+ void WaitUntilClosed() {
+ page_closed_.Wait();
+ }
+
private:
ui_test_utils::WindowedNotificationObserver page_created_;
ui_test_utils::WindowedNotificationObserver page_closed_;
@@ -327,6 +334,38 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, IncognitoSplitMode) {
}
}
+// Tests that messages from the content script activate the lazy background
+// page, and keep it alive until all channels are closed.
+IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Messaging) {
+ ASSERT_TRUE(StartTestServer());
+ ASSERT_TRUE(LoadExtensionAndWait("messaging"));
+
+ // Lazy Background Page doesn't exist yet.
+ ExtensionProcessManager* pm =
+ browser()->profile()->GetExtensionProcessManager();
+ EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
+ EXPECT_EQ(1, browser()->tab_count());
+
+ // Navigate to a page that opens a message channel to the background page.
+ ResultCatcher catcher;
+ LazyBackgroundObserver lazybg;
+ ui_test_utils::NavigateToURL(
+ browser(), test_server()->GetURL("files/extensions/test_file.html"));
+ lazybg.WaitUntilLoaded();
+
+ // Background page got the content script's message and is still loaded
+ // until we close the channel.
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+ EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
+
+ // Navigate away, closing the message channel and therefore the background
+ // page.
+ ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
+ lazybg.WaitUntilClosed();
+
+ EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
+}
+
// TODO: background page with timer.
// TODO: background page that interacts with popup.
// TODO: background page with menu.