Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1689)

Unified Diff: chrome/browser/extensions/lazy_background_page_apitest.cc

Issue 9562017: Keep lazy background page alive while there are pending network requests or (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixins Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/lazy_background_page_apitest.cc
diff --git a/chrome/browser/extensions/lazy_background_page_apitest.cc b/chrome/browser/extensions/lazy_background_page_apitest.cc
index 593a42236ae3fabf34e3879eb04f774fb19f9dd4..1b3b6dd27151fe56494fb875e630f897458b2827 100644
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc
@@ -6,6 +6,7 @@
#include "base/file_path.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -18,6 +19,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
+#include "net/base/mock_host_resolver.h"
namespace {
// Helper class to wait for a lazy background page to load and close again.
@@ -146,6 +148,67 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) {
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
}
+// Tests that the lazy background page stays alive until all visible views are
+// closed.
+IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForView) {
+ LazyBackgroundObserver page_complete;
+ ResultCatcher catcher;
+ FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
+ AppendASCII("wait_for_view");
+ const Extension* extension = LoadExtension(extdir);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+
+ // The extension should've opened a new tab to an extension page.
+ EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(),
+ browser()->GetSelectedWebContents()->GetURL().spec());
+
+ // Lazy Background Page still exists, because the extension created a new tab
+ // to an extension page.
+ ExtensionProcessManager* pm =
+ browser()->profile()->GetExtensionProcessManager();
+ EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
+
+ // Close the new tab.
+ browser()->CloseTabContents(browser()->GetSelectedWebContents());
+ page_complete.Wait();
+
+ // Lazy Background Page has been shut down.
+ EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
+}
+
+// Tests that the lazy background page stays alive until all network requests
+// are complete.
+IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) {
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(StartTestServer());
+
+ LazyBackgroundObserver page_complete;
+ ResultCatcher catcher;
+ FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
+ AppendASCII("wait_for_request");
+ const Extension* extension = LoadExtension(extdir);
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+
+ // Lazy Background Page still exists, because the extension started a request.
+ ExtensionProcessManager* pm =
+ browser()->profile()->GetExtensionProcessManager();
+ ExtensionHost* host =
+ pm->GetBackgroundHostForExtension(last_loaded_extension_id_);
+ ASSERT_TRUE(host);
+
+ // Abort the request.
+ bool result = false;
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ host->render_view_host(), std::wstring(), L"abortRequest()", &result));
+ EXPECT_TRUE(result);
+ page_complete.Wait();
+
+ // Lazy Background Page has been shut down.
+ 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.

Powered by Google App Engine
This is Rietveld 408576698