Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / extensions / lazy_background_page_apitest.cc
blobbad80e40d6df3c00b6c33c06fa43b6fb927f7a15
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/scoped_observer.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/location_bar/location_bar.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/app_modal/app_modal_dialog.h"
20 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/browser/bookmark_utils.h"
22 #include "components/bookmarks/test/bookmark_test_helpers.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/browser_test_utils.h"
25 #include "extensions/browser/extension_host.h"
26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_registry_observer.h"
28 #include "extensions/browser/process_manager.h"
29 #include "extensions/common/extension.h"
30 #include "extensions/test/extension_test_message_listener.h"
31 #include "extensions/test/result_catcher.h"
32 #include "net/dns/mock_host_resolver.h"
33 #include "net/test/embedded_test_server/embedded_test_server.h"
34 #include "url/gurl.h"
36 using bookmarks::BookmarkModel;
37 using bookmarks::BookmarkNode;
38 using extensions::Extension;
39 using extensions::ResultCatcher;
41 namespace {
43 // This unfortunate bit of silliness is necessary when loading an extension in
44 // incognito. The goal is to load the extension, enable incognito, then wait
45 // for both background pages to load and close. The problem is that enabling
46 // incognito involves reloading the extension - and the background pages may
47 // have already loaded once before then. So we wait until the extension is
48 // unloaded before listening to the background page notifications.
49 class LoadedIncognitoObserver : public extensions::ExtensionRegistryObserver {
50 public:
51 explicit LoadedIncognitoObserver(Profile* profile)
52 : profile_(profile), extension_registry_observer_(this) {
53 extension_registry_observer_.Add(
54 extensions::ExtensionRegistry::Get(profile_));
57 void Wait() {
58 ASSERT_TRUE(original_complete_.get());
59 original_complete_->Wait();
60 incognito_complete_->Wait();
63 private:
64 void OnExtensionUnloaded(
65 content::BrowserContext* browser_context,
66 const Extension* extension,
67 extensions::UnloadedExtensionInfo::Reason reason) override {
68 original_complete_.reset(new LazyBackgroundObserver(profile_));
69 incognito_complete_.reset(
70 new LazyBackgroundObserver(profile_->GetOffTheRecordProfile()));
73 Profile* profile_;
74 ScopedObserver<extensions::ExtensionRegistry,
75 extensions::ExtensionRegistryObserver>
76 extension_registry_observer_;
77 scoped_ptr<LazyBackgroundObserver> original_complete_;
78 scoped_ptr<LazyBackgroundObserver> incognito_complete_;
81 } // namespace
83 class LazyBackgroundPageApiTest : public ExtensionApiTest {
84 public:
85 LazyBackgroundPageApiTest() {}
86 ~LazyBackgroundPageApiTest() override {}
88 void SetUpOnMainThread() override {
89 ExtensionApiTest::SetUpOnMainThread();
90 // Set shorter delays to prevent test timeouts.
91 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
92 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
95 // Loads the extension, which temporarily starts the lazy background page
96 // to dispatch the onInstalled event. We wait until it shuts down again.
97 const Extension* LoadExtensionAndWait(const std::string& test_name) {
98 LazyBackgroundObserver page_complete;
99 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
100 AppendASCII(test_name);
101 const Extension* extension = LoadExtension(extdir);
102 if (extension)
103 page_complete.Wait();
104 return extension;
107 // Returns true if the lazy background page for the extension with
108 // |extension_id| is still running.
109 bool IsBackgroundPageAlive(const std::string& extension_id) {
110 extensions::ProcessManager* pm =
111 extensions::ProcessManager::Get(browser()->profile());
112 return pm->GetBackgroundHostForExtension(extension_id);
115 private:
116 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageApiTest);
119 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) {
120 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab"));
122 // Lazy Background Page doesn't exist yet.
123 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
124 int num_tabs_before = browser()->tab_strip_model()->count();
126 // Observe background page being created and closed after
127 // the browser action is clicked.
128 LazyBackgroundObserver page_complete;
129 BrowserActionTestUtil(browser()).Press(0);
130 page_complete.Wait();
132 // Background page created a new tab before it closed.
133 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
134 EXPECT_EQ(num_tabs_before + 1, browser()->tab_strip_model()->count());
135 EXPECT_EQ(std::string(chrome::kChromeUIExtensionsURL),
136 browser()->tab_strip_model()->GetActiveWebContents()->
137 GetURL().spec());
140 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
141 BrowserActionCreateTabAfterCallback) {
142 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback"));
144 // Lazy Background Page doesn't exist yet.
145 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
146 int num_tabs_before = browser()->tab_strip_model()->count();
148 // Observe background page being created and closed after
149 // the browser action is clicked.
150 LazyBackgroundObserver page_complete;
151 BrowserActionTestUtil(browser()).Press(0);
152 page_complete.Wait();
154 // Background page is closed after creating a new tab.
155 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
156 EXPECT_EQ(num_tabs_before + 1, browser()->tab_strip_model()->count());
159 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
160 ASSERT_TRUE(StartEmbeddedTestServer());
162 const Extension* extension = LoadExtensionAndWait("broadcast_event");
163 ASSERT_TRUE(extension);
165 // Lazy Background Page doesn't exist yet.
166 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
167 int num_page_actions = browser()->window()->GetLocationBar()->
168 GetLocationBarForTesting()->PageActionVisibleCount();
170 // Open a tab to a URL that will trigger the page action to show.
171 LazyBackgroundObserver page_complete;
172 ui_test_utils::NavigateToURL(
173 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
174 page_complete.Wait();
176 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
178 // Page action is shown.
179 WaitForPageActionVisibilityChangeTo(num_page_actions + 1);
180 EXPECT_EQ(num_page_actions + 1,
181 browser()->window()->GetLocationBar()->
182 GetLocationBarForTesting()->PageActionVisibleCount());
185 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) {
186 ASSERT_TRUE(StartEmbeddedTestServer());
188 const Extension* extension = LoadExtensionAndWait("filters");
189 ASSERT_TRUE(extension);
191 // Lazy Background Page doesn't exist yet.
192 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
194 // Open a tab to a URL that will fire a webNavigation event.
195 LazyBackgroundObserver page_complete;
196 ui_test_utils::NavigateToURL(
197 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
198 page_complete.Wait();
201 // Tests that the lazy background page receives the onInstalled event and shuts
202 // down.
203 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) {
204 ResultCatcher catcher;
205 ASSERT_TRUE(LoadExtensionAndWait("on_installed"));
206 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
208 // Lazy Background Page has been shut down.
209 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
212 // Tests that a JavaScript alert keeps the lazy background page alive.
213 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForDialog) {
214 LazyBackgroundObserver background_observer;
215 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
216 AppendASCII("wait_for_dialog");
217 const Extension* extension = LoadExtension(extdir);
218 ASSERT_TRUE(extension);
220 // The test extension opens a dialog on installation.
221 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
222 ASSERT_TRUE(dialog);
224 // With the dialog open the background page is still alive.
225 EXPECT_TRUE(IsBackgroundPageAlive(extension->id()));
227 // Close the dialog. The keep alive count is decremented.
228 extensions::ProcessManager* pm =
229 extensions::ProcessManager::Get(browser()->profile());
230 int previous_keep_alive_count = pm->GetLazyKeepaliveCount(extension);
231 dialog->CloseModalDialog();
232 EXPECT_EQ(previous_keep_alive_count - 1,
233 pm->GetLazyKeepaliveCount(extension));
235 // The background page closes now that the dialog is gone.
236 background_observer.WaitUntilClosed();
237 EXPECT_FALSE(IsBackgroundPageAlive(extension->id()));
240 // Tests that the lazy background page stays alive until all visible views are
241 // closed.
242 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForView) {
243 LazyBackgroundObserver page_complete;
244 ResultCatcher catcher;
245 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
246 AppendASCII("wait_for_view");
247 const Extension* extension = LoadExtension(extdir);
248 ASSERT_TRUE(extension);
249 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
251 // The extension should've opened a new tab to an extension page.
252 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(),
253 browser()->tab_strip_model()->GetActiveWebContents()->
254 GetURL().spec());
256 // Lazy Background Page still exists, because the extension created a new tab
257 // to an extension page.
258 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
260 // Close the new tab.
261 browser()->tab_strip_model()->CloseWebContentsAt(
262 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE);
263 page_complete.Wait();
265 // Lazy Background Page has been shut down.
266 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
269 // Tests that the lazy background page stays alive until all network requests
270 // are complete.
271 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) {
272 host_resolver()->AddRule("*", "127.0.0.1");
273 ASSERT_TRUE(StartEmbeddedTestServer());
275 LazyBackgroundObserver page_complete;
276 ResultCatcher catcher;
277 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
278 AppendASCII("wait_for_request");
279 const Extension* extension = LoadExtension(extdir);
280 ASSERT_TRUE(extension);
281 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
283 // Lazy Background Page still exists, because the extension started a request.
284 extensions::ProcessManager* pm =
285 extensions::ProcessManager::Get(browser()->profile());
286 extensions::ExtensionHost* host =
287 pm->GetBackgroundHostForExtension(last_loaded_extension_id());
288 ASSERT_TRUE(host);
290 // Abort the request.
291 bool result = false;
292 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
293 host->render_view_host(), "abortRequest()", &result));
294 EXPECT_TRUE(result);
295 page_complete.Wait();
297 // Lazy Background Page has been shut down.
298 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
301 // Tests that the lazy background page stays alive until all visible views are
302 // closed.
303 // http://crbug.com/175778; test fails frequently on OS X
304 #if defined(OS_MACOSX)
305 #define MAYBE_WaitForNTP DISABLED_WaitForNTP
306 #else
307 #define MAYBE_WaitForNTP WaitForNTP
308 #endif
309 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) {
310 LazyBackgroundObserver lazybg;
311 ResultCatcher catcher;
312 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
313 AppendASCII("wait_for_ntp");
314 const Extension* extension = LoadExtension(extdir);
315 ASSERT_TRUE(extension);
316 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
318 // The extension should've opened a new tab to an extension page.
319 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
320 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
322 // Lazy Background Page still exists, because the extension created a new tab
323 // to an extension page.
324 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
326 // Navigate away from the NTP, which should close the event page.
327 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
328 lazybg.Wait();
330 // Lazy Background Page has been shut down.
331 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
334 // Tests that an incognito split mode extension gets 2 lazy background pages,
335 // and they each load and unload at the proper times.
336 // See crbug.com/248437
337 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, DISABLED_IncognitoSplitMode) {
338 // Open incognito window.
339 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord(
340 browser()->profile(), GURL("about:blank"));
342 // Load the extension with incognito enabled.
344 LoadedIncognitoObserver loaded(browser()->profile());
345 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
346 AppendASCII("incognito_split");
347 ASSERT_TRUE(LoadExtensionIncognito(extdir));
348 loaded.Wait();
351 // Lazy Background Page doesn't exist yet.
352 extensions::ProcessManager* pm =
353 extensions::ProcessManager::Get(browser()->profile());
354 extensions::ProcessManager* pmi =
355 extensions::ProcessManager::Get(incognito_browser->profile());
356 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
357 EXPECT_FALSE(pmi->GetBackgroundHostForExtension(last_loaded_extension_id()));
359 // Trigger a browserAction event in the original profile and ensure only
360 // the original event page received it (since the event is scoped to the
361 // profile).
363 ExtensionTestMessageListener listener("waiting", false);
364 ExtensionTestMessageListener listener_incognito("waiting_incognito", false);
366 LazyBackgroundObserver page_complete(browser()->profile());
367 BrowserActionTestUtil(browser()).Press(0);
368 page_complete.Wait();
370 // Only the original event page received the message.
371 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
372 EXPECT_FALSE(
373 pmi->GetBackgroundHostForExtension(last_loaded_extension_id()));
374 EXPECT_TRUE(listener.was_satisfied());
375 EXPECT_FALSE(listener_incognito.was_satisfied());
378 // Trigger a bookmark created event and ensure both pages receive it.
380 ExtensionTestMessageListener listener("waiting", false);
381 ExtensionTestMessageListener listener_incognito("waiting_incognito", false);
383 LazyBackgroundObserver page_complete(browser()->profile()),
384 page2_complete(incognito_browser->profile());
385 BookmarkModel* bookmark_model =
386 BookmarkModelFactory::GetForProfile(browser()->profile());
387 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
388 const BookmarkNode* parent = bookmark_model->bookmark_bar_node();
389 bookmark_model->AddURL(
390 parent, 0, base::ASCIIToUTF16("Title"), GURL("about:blank"));
391 page_complete.Wait();
392 page2_complete.Wait();
394 // Both pages received the message.
395 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
396 EXPECT_FALSE(
397 pmi->GetBackgroundHostForExtension(last_loaded_extension_id()));
398 EXPECT_TRUE(listener.was_satisfied());
399 EXPECT_TRUE(listener_incognito.was_satisfied());
403 // Tests that messages from the content script activate the lazy background
404 // page, and keep it alive until all channels are closed.
405 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Messaging) {
406 ASSERT_TRUE(StartEmbeddedTestServer());
407 ASSERT_TRUE(LoadExtensionAndWait("messaging"));
409 // Lazy Background Page doesn't exist yet.
410 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
411 EXPECT_EQ(1, browser()->tab_strip_model()->count());
413 // Navigate to a page that opens a message channel to the background page.
414 ResultCatcher catcher;
415 LazyBackgroundObserver lazybg;
416 ui_test_utils::NavigateToURL(
417 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
418 lazybg.WaitUntilLoaded();
420 // Background page got the content script's message and is still loaded
421 // until we close the channel.
422 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
423 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
425 // Navigate away, closing the message channel and therefore the background
426 // page.
427 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
428 lazybg.WaitUntilClosed();
430 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
433 // Tests that a KeepaliveImpulse increments the keep alive count, but eventually
434 // times out and background page will still close.
435 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, ImpulseAddsCount) {
436 ASSERT_TRUE(StartEmbeddedTestServer());
437 const Extension* extension = LoadExtensionAndWait("messaging");
438 ASSERT_TRUE(extension);
440 // Lazy Background Page doesn't exist yet.
441 extensions::ProcessManager* pm =
442 extensions::ProcessManager::Get(browser()->profile());
443 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
444 EXPECT_EQ(1, browser()->tab_strip_model()->count());
446 // Navigate to a page that opens a message channel to the background page.
447 ResultCatcher catcher;
448 LazyBackgroundObserver lazybg;
449 ui_test_utils::NavigateToURL(
450 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
451 lazybg.WaitUntilLoaded();
453 // Add an impulse and the keep alive count increases.
454 int previous_keep_alive_count = pm->GetLazyKeepaliveCount(extension);
455 pm->KeepaliveImpulse(extension);
456 EXPECT_EQ(previous_keep_alive_count + 1,
457 pm->GetLazyKeepaliveCount(extension));
459 // Navigate away, closing the message channel and therefore the background
460 // page after the impulse times out.
461 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
462 lazybg.WaitUntilClosed();
464 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id()));
467 // Tests that the lazy background page receives the unload event when we
468 // close it, and that it can execute simple API calls that don't require an
469 // asynchronous response.
470 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) {
471 ASSERT_TRUE(LoadExtensionAndWait("on_unload"));
473 // Lazy Background Page has been shut down.
474 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
476 // The browser action has a new title.
477 BrowserActionTestUtil browser_action(browser());
478 ASSERT_EQ(1, browser_action.NumberOfBrowserActions());
479 EXPECT_EQ("Success", browser_action.GetTooltip(0));
482 // Tests that both a regular page and an event page will receive events when
483 // the event page is not loaded.
484 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventDispatchToTab) {
485 ResultCatcher catcher;
486 catcher.RestrictToBrowserContext(browser()->profile());
488 const extensions::Extension* extension =
489 LoadExtensionAndWait("event_dispatch_to_tab");
491 ExtensionTestMessageListener page_ready("ready", true);
492 GURL page_url = extension->GetResourceURL("page.html");
493 ui_test_utils::NavigateToURL(browser(), page_url);
494 EXPECT_TRUE(page_ready.WaitUntilSatisfied());
496 // After the event is sent below, wait for the event page to have received
497 // the event before proceeding with the test. This allows the regular page
498 // to test that the event page received the event, which makes the pass/fail
499 // logic simpler.
500 ExtensionTestMessageListener event_page_ready("ready", true);
502 // Send an event by making a bookmark.
503 BookmarkModel* bookmark_model =
504 BookmarkModelFactory::GetForProfile(browser()->profile());
505 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
506 bookmarks::AddIfNotBookmarked(bookmark_model,
507 GURL("http://www.google.com"),
508 base::UTF8ToUTF16("Google"));
510 EXPECT_TRUE(event_page_ready.WaitUntilSatisfied());
512 page_ready.Reply("go");
514 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
517 // Tests that the lazy background page updates the chrome://extensions page
518 // when it is destroyed.
519 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage) {
520 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL));
522 ResultCatcher catcher;
523 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page").
524 AppendASCII("wait_for_view");
525 const Extension* extension = LoadExtension(extdir);
526 ASSERT_TRUE(extension);
527 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
529 // The extension should've opened a new tab to an extension page.
530 EXPECT_EQ(extension->GetResourceURL("extension_page.html").spec(),
531 browser()->tab_strip_model()->GetActiveWebContents()->
532 GetURL().spec());
534 // Lazy Background Page still exists, because the extension created a new tab
535 // to an extension page.
536 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
538 // Close the new tab.
539 LazyBackgroundObserver page_complete;
540 browser()->tab_strip_model()->CloseWebContentsAt(
541 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE);
542 page_complete.WaitUntilClosed();
544 // Lazy Background Page has been shut down.
545 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
547 // Verify that extensions page shows that the lazy background page is
548 // inactive.
549 content::RenderFrameHost* frame = content::FrameMatchingPredicate(
550 browser()->tab_strip_model()->GetActiveWebContents(),
551 base::Bind(&content::FrameHasSourceUrl,
552 GURL(chrome::kChromeUIExtensionsFrameURL)));
554 // We do the first ExecuteScript to serve as a "Run All Pending" hack.
555 EXPECT_TRUE(content::ExecuteScript(frame, "1 == 1;"));
557 bool is_inactive;
558 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
559 frame,
560 "var ele = document.querySelectorAll('div.active-views');"
561 "window.domAutomationController.send("
562 " ele[0].innerHTML.search('(Inactive)') > 0);",
563 &is_inactive));
564 EXPECT_TRUE(is_inactive);
567 // Tests that the lazy background page will be unloaded if the onSuspend event
568 // handler calls an API function such as chrome.storage.local.set().
569 // See: http://crbug.com/296834
570 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) {
571 EXPECT_TRUE(LoadExtensionAndWait("on_suspend"));
574 // TODO: background page with timer.
575 // TODO: background page that interacts with popup.