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 c23d30739b442c707a2dff2c719be75572436a29..9da56b8936e80ac7d70e3fb67c10311880756066 100644 |
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc |
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc |
@@ -19,26 +19,6 @@ |
#include "content/public/browser/web_contents.h" |
#include "googleurl/src/gurl.h" |
-namespace { |
-// Helper class to wait for a lazy background page to load and close again. |
-class LazyBackgroundObserver { |
-public: |
- LazyBackgroundObserver() |
- : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
- content::NotificationService::AllSources()), |
- page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
- content::NotificationService::AllSources()) { |
- } |
- void Wait() { |
- page_created_.Wait(); |
- page_closed_.Wait(); |
- } |
-private: |
- ui_test_utils::WindowedNotificationObserver page_created_; |
- ui_test_utils::WindowedNotificationObserver page_closed_; |
-}; |
-} // namespace |
- |
class LazyBackgroundPageApiTest : public ExtensionApiTest { |
public: |
void SetUpCommandLine(CommandLine* command_line) { |
@@ -53,10 +33,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { |
ASSERT_TRUE(LoadExtension(extdir)); |
// Lazy Background Page doesn't exist yet. |
- // Note: We actually loaded and destroyed the page to dispatch the onInstalled |
- // event. LoadExtension waits for the load to finish, after which onInstalled |
- // is dispatched. Since the extension isn't listening to it, we immediately |
- // tear it down again. |
ExtensionProcessManager* pm = |
browser()->profile()->GetExtensionProcessManager(); |
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
@@ -64,9 +40,15 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { |
// Observe background page being created and closed after |
// the browser action is clicked. |
- LazyBackgroundObserver page_complete; |
+ ui_test_utils::WindowedNotificationObserver bg_pg_created( |
+ chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
+ content::NotificationService::AllSources()); |
+ ui_test_utils::WindowedNotificationObserver bg_pg_closed( |
+ chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::NotificationService::AllSources()); |
BrowserActionTestUtil(browser()).Press(0); |
- page_complete.Wait(); |
+ bg_pg_created.Wait(); |
+ bg_pg_closed.Wait(); |
// Background page created a new tab before it closed. |
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
@@ -89,22 +71,26 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, |
// Observe background page being created and closed after |
// the browser action is clicked. |
- LazyBackgroundObserver page_complete; |
+ ui_test_utils::WindowedNotificationObserver bg_pg_created( |
+ chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
+ content::NotificationService::AllSources()); |
+ ui_test_utils::WindowedNotificationObserver bg_pg_closed( |
+ chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::NotificationService::AllSources()); |
BrowserActionTestUtil(browser()).Press(0); |
- page_complete.Wait(); |
+ bg_pg_created.Wait(); |
+ bg_pg_closed.Wait(); |
// Background page is closed after creating a new tab. |
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); |
} |
-IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { |
- ASSERT_TRUE(StartTestServer()); |
- |
+IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, |
+ BroadcastEvent) { |
FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
AppendASCII("broadcast_event"); |
- const Extension* extension = LoadExtension(extdir); |
- ASSERT_TRUE(extension); |
+ ASSERT_TRUE(LoadExtension(extdir)); |
// Lazy Background Page doesn't exist yet. |
ExtensionProcessManager* pm = |
@@ -114,38 +100,17 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { |
GetLocationBarForTesting()->PageActionVisibleCount(); |
// Open a tab to a URL that will trigger the page action to show. |
- LazyBackgroundObserver page_complete; |
- ui_test_utils::WindowedNotificationObserver page_action_changed( |
- chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
- content::NotificationService::AllSources()); |
- ui_test_utils::NavigateToURL( |
- browser(), test_server()->GetURL("files/extensions/test_file.html")); |
- page_complete.Wait(); |
+ // stegosaurus.html doesn't actually exist but that doesn't seem to matter. |
+ GURL stego_url = GURL("stegosaurus.html"); |
+ ui_test_utils::NavigateToURL(browser(), stego_url); |
+ // New page action is never shown because background page is never created. |
+ // TODO(tessamac): Implement! Broadcast events (like tab updates) should |
+ // cause lazy background pages to be created. |
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
- |
- // Page action is shown. |
- page_action_changed.Wait(); |
- EXPECT_EQ(num_page_actions + 1, |
+ EXPECT_EQ(num_page_actions, // should be + 1 |
browser()->window()->GetLocationBar()-> |
- GetLocationBarForTesting()->PageActionVisibleCount()); |
-} |
- |
-IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) { |
- LazyBackgroundObserver page_complete; |
- ResultCatcher catcher; |
- FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
- AppendASCII("on_installed"); |
- const Extension* extension = LoadExtension(extdir); |
- ASSERT_TRUE(extension); |
- |
- EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
- page_complete.Wait(); |
- |
- // Lazy Background Page has been shut down. |
- ExtensionProcessManager* pm = |
- browser()->profile()->GetExtensionProcessManager(); |
- EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
+ GetLocationBarForTesting()->PageActionVisibleCount()); |
} |
// TODO: background page with timer. |