| 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/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 11 #include "chrome/browser/extensions/browser_action_test_util.h" | 11 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_host.h" | 13 #include "chrome/browser/extensions/extension_host.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 16 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 16 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 17 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/omnibox/location_bar.h" | 22 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 page_complete.Wait(); | 94 page_complete.Wait(); |
| 94 return extension; | 95 return extension; |
| 95 } | 96 } |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { | 99 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { |
| 99 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab")); | 100 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab")); |
| 100 | 101 |
| 101 // Lazy Background Page doesn't exist yet. | 102 // Lazy Background Page doesn't exist yet. |
| 102 ExtensionProcessManager* pm = | 103 ExtensionProcessManager* pm = |
| 103 browser()->profile()->GetExtensionProcessManager(); | 104 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 104 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 105 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 105 int num_tabs_before = browser()->tab_count(); | 106 int num_tabs_before = browser()->tab_count(); |
| 106 | 107 |
| 107 // Observe background page being created and closed after | 108 // Observe background page being created and closed after |
| 108 // the browser action is clicked. | 109 // the browser action is clicked. |
| 109 LazyBackgroundObserver page_complete; | 110 LazyBackgroundObserver page_complete; |
| 110 BrowserActionTestUtil(browser()).Press(0); | 111 BrowserActionTestUtil(browser()).Press(0); |
| 111 page_complete.Wait(); | 112 page_complete.Wait(); |
| 112 | 113 |
| 113 // Background page created a new tab before it closed. | 114 // Background page created a new tab before it closed. |
| 114 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 115 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 115 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); | 116 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); |
| 116 EXPECT_EQ(std::string(chrome::kChromeUIExtensionsURL), | 117 EXPECT_EQ(std::string(chrome::kChromeUIExtensionsURL), |
| 117 chrome::GetActiveWebContents(browser())->GetURL().spec()); | 118 chrome::GetActiveWebContents(browser())->GetURL().spec()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, | 121 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, |
| 121 BrowserActionCreateTabAfterCallback) { | 122 BrowserActionCreateTabAfterCallback) { |
| 122 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback")); | 123 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback")); |
| 123 | 124 |
| 124 // Lazy Background Page doesn't exist yet. | 125 // Lazy Background Page doesn't exist yet. |
| 125 ExtensionProcessManager* pm = | 126 ExtensionProcessManager* pm = |
| 126 browser()->profile()->GetExtensionProcessManager(); | 127 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 127 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 128 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 128 int num_tabs_before = browser()->tab_count(); | 129 int num_tabs_before = browser()->tab_count(); |
| 129 | 130 |
| 130 // Observe background page being created and closed after | 131 // Observe background page being created and closed after |
| 131 // the browser action is clicked. | 132 // the browser action is clicked. |
| 132 LazyBackgroundObserver page_complete; | 133 LazyBackgroundObserver page_complete; |
| 133 BrowserActionTestUtil(browser()).Press(0); | 134 BrowserActionTestUtil(browser()).Press(0); |
| 134 page_complete.Wait(); | 135 page_complete.Wait(); |
| 135 | 136 |
| 136 // Background page is closed after creating a new tab. | 137 // Background page is closed after creating a new tab. |
| 137 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 138 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 138 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); | 139 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { | 142 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { |
| 142 ASSERT_TRUE(StartTestServer()); | 143 ASSERT_TRUE(StartTestServer()); |
| 143 | 144 |
| 144 const Extension* extension = LoadExtensionAndWait("broadcast_event"); | 145 const Extension* extension = LoadExtensionAndWait("broadcast_event"); |
| 145 ASSERT_TRUE(extension); | 146 ASSERT_TRUE(extension); |
| 146 | 147 |
| 147 // Lazy Background Page doesn't exist yet. | 148 // Lazy Background Page doesn't exist yet. |
| 148 ExtensionProcessManager* pm = | 149 ExtensionProcessManager* pm = |
| 149 browser()->profile()->GetExtensionProcessManager(); | 150 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 150 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 151 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 151 int num_page_actions = browser()->window()->GetLocationBar()-> | 152 int num_page_actions = browser()->window()->GetLocationBar()-> |
| 152 GetLocationBarForTesting()->PageActionVisibleCount(); | 153 GetLocationBarForTesting()->PageActionVisibleCount(); |
| 153 | 154 |
| 154 // Open a tab to a URL that will trigger the page action to show. | 155 // Open a tab to a URL that will trigger the page action to show. |
| 155 LazyBackgroundObserver page_complete; | 156 LazyBackgroundObserver page_complete; |
| 156 content::WindowedNotificationObserver page_action_changed( | 157 content::WindowedNotificationObserver page_action_changed( |
| 157 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 158 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 158 content::NotificationService::AllSources()); | 159 content::NotificationService::AllSources()); |
| 159 ui_test_utils::NavigateToURL( | 160 ui_test_utils::NavigateToURL( |
| 160 browser(), test_server()->GetURL("files/extensions/test_file.html")); | 161 browser(), test_server()->GetURL("files/extensions/test_file.html")); |
| 161 page_complete.Wait(); | 162 page_complete.Wait(); |
| 162 | 163 |
| 163 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 164 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 164 | 165 |
| 165 // Page action is shown. | 166 // Page action is shown. |
| 166 page_action_changed.Wait(); | 167 page_action_changed.Wait(); |
| 167 EXPECT_EQ(num_page_actions + 1, | 168 EXPECT_EQ(num_page_actions + 1, |
| 168 browser()->window()->GetLocationBar()-> | 169 browser()->window()->GetLocationBar()-> |
| 169 GetLocationBarForTesting()->PageActionVisibleCount()); | 170 GetLocationBarForTesting()->PageActionVisibleCount()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { | 173 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { |
| 173 const Extension* extension = LoadExtensionAndWait("filters"); | 174 const Extension* extension = LoadExtensionAndWait("filters"); |
| 174 ASSERT_TRUE(extension); | 175 ASSERT_TRUE(extension); |
| 175 | 176 |
| 176 // Lazy Background Page doesn't exist yet. | 177 // Lazy Background Page doesn't exist yet. |
| 177 ExtensionProcessManager* pm = | 178 ExtensionProcessManager* pm = |
| 178 browser()->profile()->GetExtensionProcessManager(); | 179 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 179 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 180 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 180 | 181 |
| 181 // Open a tab to a URL that will fire a webNavigation event. | 182 // Open a tab to a URL that will fire a webNavigation event. |
| 182 LazyBackgroundObserver page_complete; | 183 LazyBackgroundObserver page_complete; |
| 183 ui_test_utils::NavigateToURL( | 184 ui_test_utils::NavigateToURL( |
| 184 browser(), test_server()->GetURL("files/extensions/test_file.html")); | 185 browser(), test_server()->GetURL("files/extensions/test_file.html")); |
| 185 page_complete.Wait(); | 186 page_complete.Wait(); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // Tests that the lazy background page receives the onInstalled event and shuts | 189 // Tests that the lazy background page receives the onInstalled event and shuts |
| 189 // down. | 190 // down. |
| 190 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) { | 191 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) { |
| 191 ResultCatcher catcher; | 192 ResultCatcher catcher; |
| 192 ASSERT_TRUE(LoadExtensionAndWait("on_installed")); | 193 ASSERT_TRUE(LoadExtensionAndWait("on_installed")); |
| 193 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 194 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 194 | 195 |
| 195 // Lazy Background Page has been shut down. | 196 // Lazy Background Page has been shut down. |
| 196 ExtensionProcessManager* pm = | 197 ExtensionProcessManager* pm = |
| 197 browser()->profile()->GetExtensionProcessManager(); | 198 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 198 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 199 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 199 } | 200 } |
| 200 | 201 |
| 201 // Tests that the lazy background page stays alive until all visible views are | 202 // Tests that the lazy background page stays alive until all visible views are |
| 202 // closed. | 203 // closed. |
| 203 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForView) { | 204 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForView) { |
| 204 LazyBackgroundObserver page_complete; | 205 LazyBackgroundObserver page_complete; |
| 205 ResultCatcher catcher; | 206 ResultCatcher catcher; |
| 206 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 207 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
| 207 AppendASCII("wait_for_view"); | 208 AppendASCII("wait_for_view"); |
| 208 const Extension* extension = LoadExtension(extdir); | 209 const Extension* extension = LoadExtension(extdir); |
| 209 ASSERT_TRUE(extension); | 210 ASSERT_TRUE(extension); |
| 210 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 211 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 211 | 212 |
| 212 // The extension should've opened a new tab to an extension page. | 213 // The extension should've opened a new tab to an extension page. |
| 213 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(), | 214 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(), |
| 214 chrome::GetActiveWebContents(browser())->GetURL().spec()); | 215 chrome::GetActiveWebContents(browser())->GetURL().spec()); |
| 215 | 216 |
| 216 // Lazy Background Page still exists, because the extension created a new tab | 217 // Lazy Background Page still exists, because the extension created a new tab |
| 217 // to an extension page. | 218 // to an extension page. |
| 218 ExtensionProcessManager* pm = | 219 ExtensionProcessManager* pm = |
| 219 browser()->profile()->GetExtensionProcessManager(); | 220 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 220 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 221 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 221 | 222 |
| 222 // Close the new tab. | 223 // Close the new tab. |
| 223 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser())); | 224 chrome::CloseWebContents(browser(), chrome::GetActiveWebContents(browser())); |
| 224 page_complete.Wait(); | 225 page_complete.Wait(); |
| 225 | 226 |
| 226 // Lazy Background Page has been shut down. | 227 // Lazy Background Page has been shut down. |
| 227 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 228 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 228 } | 229 } |
| 229 | 230 |
| 230 // Tests that the lazy background page stays alive until all network requests | 231 // Tests that the lazy background page stays alive until all network requests |
| 231 // are complete. | 232 // are complete. |
| 232 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) { | 233 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) { |
| 233 host_resolver()->AddRule("*", "127.0.0.1"); | 234 host_resolver()->AddRule("*", "127.0.0.1"); |
| 234 ASSERT_TRUE(StartTestServer()); | 235 ASSERT_TRUE(StartTestServer()); |
| 235 | 236 |
| 236 LazyBackgroundObserver page_complete; | 237 LazyBackgroundObserver page_complete; |
| 237 ResultCatcher catcher; | 238 ResultCatcher catcher; |
| 238 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 239 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
| 239 AppendASCII("wait_for_request"); | 240 AppendASCII("wait_for_request"); |
| 240 const Extension* extension = LoadExtension(extdir); | 241 const Extension* extension = LoadExtension(extdir); |
| 241 ASSERT_TRUE(extension); | 242 ASSERT_TRUE(extension); |
| 242 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 243 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 243 | 244 |
| 244 // Lazy Background Page still exists, because the extension started a request. | 245 // Lazy Background Page still exists, because the extension started a request. |
| 245 ExtensionProcessManager* pm = | 246 ExtensionProcessManager* pm = |
| 246 browser()->profile()->GetExtensionProcessManager(); | 247 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 247 extensions::ExtensionHost* host = | 248 extensions::ExtensionHost* host = |
| 248 pm->GetBackgroundHostForExtension(last_loaded_extension_id_); | 249 pm->GetBackgroundHostForExtension(last_loaded_extension_id_); |
| 249 ASSERT_TRUE(host); | 250 ASSERT_TRUE(host); |
| 250 | 251 |
| 251 // Abort the request. | 252 // Abort the request. |
| 252 bool result = false; | 253 bool result = false; |
| 253 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 254 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 254 host->render_view_host(), std::wstring(), L"abortRequest()", &result)); | 255 host->render_view_host(), std::wstring(), L"abortRequest()", &result)); |
| 255 EXPECT_TRUE(result); | 256 EXPECT_TRUE(result); |
| 256 page_complete.Wait(); | 257 page_complete.Wait(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 270 { | 271 { |
| 271 LoadedIncognitoObserver loaded(browser()->profile()); | 272 LoadedIncognitoObserver loaded(browser()->profile()); |
| 272 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 273 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
| 273 AppendASCII("incognito_split"); | 274 AppendASCII("incognito_split"); |
| 274 ASSERT_TRUE(LoadExtensionIncognito(extdir)); | 275 ASSERT_TRUE(LoadExtensionIncognito(extdir)); |
| 275 loaded.Wait(); | 276 loaded.Wait(); |
| 276 } | 277 } |
| 277 | 278 |
| 278 // Lazy Background Page doesn't exist yet. | 279 // Lazy Background Page doesn't exist yet. |
| 279 ExtensionProcessManager* pm = | 280 ExtensionProcessManager* pm = |
| 280 browser()->profile()->GetExtensionProcessManager(); | 281 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 281 ExtensionProcessManager* pmi = | 282 ExtensionProcessManager* pmi = |
| 282 incognito_browser->profile()->GetExtensionProcessManager(); | 283 extensions::ExtensionSystem::Get(incognito_browser->profile())-> |
| 284 process_manager(); |
| 283 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 285 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 284 EXPECT_FALSE(pmi->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 286 EXPECT_FALSE(pmi->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 285 | 287 |
| 286 // Trigger a browserAction event in the original profile and ensure only | 288 // Trigger a browserAction event in the original profile and ensure only |
| 287 // the original event page received it (since the event is scoped to the | 289 // the original event page received it (since the event is scoped to the |
| 288 // profile). | 290 // profile). |
| 289 { | 291 { |
| 290 ExtensionTestMessageListener listener("waiting", false); | 292 ExtensionTestMessageListener listener("waiting", false); |
| 291 ExtensionTestMessageListener listener_incognito("waiting_incognito", false); | 293 ExtensionTestMessageListener listener_incognito("waiting_incognito", false); |
| 292 | 294 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 328 } |
| 327 | 329 |
| 328 // Tests that messages from the content script activate the lazy background | 330 // Tests that messages from the content script activate the lazy background |
| 329 // page, and keep it alive until all channels are closed. | 331 // page, and keep it alive until all channels are closed. |
| 330 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Messaging) { | 332 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Messaging) { |
| 331 ASSERT_TRUE(StartTestServer()); | 333 ASSERT_TRUE(StartTestServer()); |
| 332 ASSERT_TRUE(LoadExtensionAndWait("messaging")); | 334 ASSERT_TRUE(LoadExtensionAndWait("messaging")); |
| 333 | 335 |
| 334 // Lazy Background Page doesn't exist yet. | 336 // Lazy Background Page doesn't exist yet. |
| 335 ExtensionProcessManager* pm = | 337 ExtensionProcessManager* pm = |
| 336 browser()->profile()->GetExtensionProcessManager(); | 338 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 337 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 339 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 338 EXPECT_EQ(1, browser()->tab_count()); | 340 EXPECT_EQ(1, browser()->tab_count()); |
| 339 | 341 |
| 340 // Navigate to a page that opens a message channel to the background page. | 342 // Navigate to a page that opens a message channel to the background page. |
| 341 ResultCatcher catcher; | 343 ResultCatcher catcher; |
| 342 LazyBackgroundObserver lazybg; | 344 LazyBackgroundObserver lazybg; |
| 343 ui_test_utils::NavigateToURL( | 345 ui_test_utils::NavigateToURL( |
| 344 browser(), test_server()->GetURL("files/extensions/test_file.html")); | 346 browser(), test_server()->GetURL("files/extensions/test_file.html")); |
| 345 lazybg.WaitUntilLoaded(); | 347 lazybg.WaitUntilLoaded(); |
| 346 | 348 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 358 } | 360 } |
| 359 | 361 |
| 360 // Tests that the lazy background page receives the unload event when we | 362 // Tests that the lazy background page receives the unload event when we |
| 361 // close it, and that it can execute simple API calls that don't require an | 363 // close it, and that it can execute simple API calls that don't require an |
| 362 // asynchronous response. | 364 // asynchronous response. |
| 363 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) { | 365 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) { |
| 364 ASSERT_TRUE(LoadExtensionAndWait("on_unload")); | 366 ASSERT_TRUE(LoadExtensionAndWait("on_unload")); |
| 365 | 367 |
| 366 // Lazy Background Page has been shut down. | 368 // Lazy Background Page has been shut down. |
| 367 ExtensionProcessManager* pm = | 369 ExtensionProcessManager* pm = |
| 368 browser()->profile()->GetExtensionProcessManager(); | 370 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 369 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 371 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 370 | 372 |
| 371 // The browser action has a new title. | 373 // The browser action has a new title. |
| 372 BrowserActionTestUtil browser_action(browser()); | 374 BrowserActionTestUtil browser_action(browser()); |
| 373 ASSERT_EQ(1, browser_action.NumberOfBrowserActions()); | 375 ASSERT_EQ(1, browser_action.NumberOfBrowserActions()); |
| 374 EXPECT_EQ("Success", browser_action.GetTooltip(0)); | 376 EXPECT_EQ("Success", browser_action.GetTooltip(0)); |
| 375 } | 377 } |
| 376 | 378 |
| 377 // Tests that both a regular page and an event page will receive events when | 379 // Tests that both a regular page and an event page will receive events when |
| 378 // the event page is not loaded. | 380 // the event page is not loaded. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 405 | 407 |
| 406 EXPECT_TRUE(event_page_ready.WaitUntilSatisfied()); | 408 EXPECT_TRUE(event_page_ready.WaitUntilSatisfied()); |
| 407 | 409 |
| 408 page_ready.Reply("go"); | 410 page_ready.Reply("go"); |
| 409 | 411 |
| 410 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 412 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 411 } | 413 } |
| 412 | 414 |
| 413 // TODO: background page with timer. | 415 // TODO: background page with timer. |
| 414 // TODO: background page that interacts with popup. | 416 // TODO: background page that interacts with popup. |
| OLD | NEW |