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"
36 using bookmarks::BookmarkModel
;
37 using extensions::Extension
;
38 using extensions::ResultCatcher
;
42 // This unfortunate bit of silliness is necessary when loading an extension in
43 // incognito. The goal is to load the extension, enable incognito, then wait
44 // for both background pages to load and close. The problem is that enabling
45 // incognito involves reloading the extension - and the background pages may
46 // have already loaded once before then. So we wait until the extension is
47 // unloaded before listening to the background page notifications.
48 class LoadedIncognitoObserver
: public extensions::ExtensionRegistryObserver
{
50 explicit LoadedIncognitoObserver(Profile
* profile
)
51 : profile_(profile
), extension_registry_observer_(this) {
52 extension_registry_observer_
.Add(
53 extensions::ExtensionRegistry::Get(profile_
));
57 ASSERT_TRUE(original_complete_
.get());
58 original_complete_
->Wait();
59 incognito_complete_
->Wait();
63 void OnExtensionUnloaded(
64 content::BrowserContext
* browser_context
,
65 const Extension
* extension
,
66 extensions::UnloadedExtensionInfo::Reason reason
) override
{
67 original_complete_
.reset(new LazyBackgroundObserver(profile_
));
68 incognito_complete_
.reset(
69 new LazyBackgroundObserver(profile_
->GetOffTheRecordProfile()));
73 ScopedObserver
<extensions::ExtensionRegistry
,
74 extensions::ExtensionRegistryObserver
>
75 extension_registry_observer_
;
76 scoped_ptr
<LazyBackgroundObserver
> original_complete_
;
77 scoped_ptr
<LazyBackgroundObserver
> incognito_complete_
;
82 class LazyBackgroundPageApiTest
: public ExtensionApiTest
{
84 LazyBackgroundPageApiTest() {}
85 ~LazyBackgroundPageApiTest() override
{}
87 void SetUpOnMainThread() override
{
88 ExtensionApiTest::SetUpOnMainThread();
89 // Set shorter delays to prevent test timeouts.
90 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
91 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
94 // Loads the extension, which temporarily starts the lazy background page
95 // to dispatch the onInstalled event. We wait until it shuts down again.
96 const Extension
* LoadExtensionAndWait(const std::string
& test_name
) {
97 LazyBackgroundObserver page_complete
;
98 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
99 AppendASCII(test_name
);
100 const Extension
* extension
= LoadExtension(extdir
);
102 page_complete
.Wait();
106 // Returns true if the lazy background page for the extension with
107 // |extension_id| is still running.
108 bool IsBackgroundPageAlive(const std::string
& extension_id
) {
109 extensions::ProcessManager
* pm
=
110 extensions::ProcessManager::Get(browser()->profile());
111 return pm
->GetBackgroundHostForExtension(extension_id
);
115 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageApiTest
);
118 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, BrowserActionCreateTab
) {
119 ASSERT_TRUE(LoadExtensionAndWait("browser_action_create_tab"));
121 // Lazy Background Page doesn't exist yet.
122 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
123 int num_tabs_before
= browser()->tab_strip_model()->count();
125 // Observe background page being created and closed after
126 // the browser action is clicked.
127 LazyBackgroundObserver page_complete
;
128 BrowserActionTestUtil(browser()).Press(0);
129 page_complete
.Wait();
131 // Background page created a new tab before it closed.
132 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
133 EXPECT_EQ(num_tabs_before
+ 1, browser()->tab_strip_model()->count());
134 EXPECT_EQ(std::string(chrome::kChromeUIExtensionsURL
),
135 browser()->tab_strip_model()->GetActiveWebContents()->
139 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
,
140 BrowserActionCreateTabAfterCallback
) {
141 ASSERT_TRUE(LoadExtensionAndWait("browser_action_with_callback"));
143 // Lazy Background Page doesn't exist yet.
144 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
145 int num_tabs_before
= browser()->tab_strip_model()->count();
147 // Observe background page being created and closed after
148 // the browser action is clicked.
149 LazyBackgroundObserver page_complete
;
150 BrowserActionTestUtil(browser()).Press(0);
151 page_complete
.Wait();
153 // Background page is closed after creating a new tab.
154 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
155 EXPECT_EQ(num_tabs_before
+ 1, browser()->tab_strip_model()->count());
158 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, BroadcastEvent
) {
159 ASSERT_TRUE(StartEmbeddedTestServer());
161 const Extension
* extension
= LoadExtensionAndWait("broadcast_event");
162 ASSERT_TRUE(extension
);
164 // Lazy Background Page doesn't exist yet.
165 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
166 int num_page_actions
= browser()->window()->GetLocationBar()->
167 GetLocationBarForTesting()->PageActionVisibleCount();
169 // Open a tab to a URL that will trigger the page action to show.
170 LazyBackgroundObserver page_complete
;
171 ui_test_utils::NavigateToURL(
172 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
173 page_complete
.Wait();
175 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
177 // Page action is shown.
178 WaitForPageActionVisibilityChangeTo(num_page_actions
+ 1);
179 EXPECT_EQ(num_page_actions
+ 1,
180 browser()->window()->GetLocationBar()->
181 GetLocationBarForTesting()->PageActionVisibleCount());
184 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, Filters
) {
185 ASSERT_TRUE(StartEmbeddedTestServer());
187 const Extension
* extension
= LoadExtensionAndWait("filters");
188 ASSERT_TRUE(extension
);
190 // Lazy Background Page doesn't exist yet.
191 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
193 // Open a tab to a URL that will fire a webNavigation event.
194 LazyBackgroundObserver page_complete
;
195 ui_test_utils::NavigateToURL(
196 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
197 page_complete
.Wait();
200 // Tests that the lazy background page receives the onInstalled event and shuts
202 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, OnInstalled
) {
203 ResultCatcher catcher
;
204 ASSERT_TRUE(LoadExtensionAndWait("on_installed"));
205 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
207 // Lazy Background Page has been shut down.
208 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
211 // Tests that a JavaScript alert keeps the lazy background page alive.
212 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, WaitForDialog
) {
213 LazyBackgroundObserver background_observer
;
214 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
215 AppendASCII("wait_for_dialog");
216 const Extension
* extension
= LoadExtension(extdir
);
217 ASSERT_TRUE(extension
);
219 // The test extension opens a dialog on installation.
220 app_modal::AppModalDialog
* dialog
= ui_test_utils::WaitForAppModalDialog();
223 // With the dialog open the background page is still alive.
224 EXPECT_TRUE(IsBackgroundPageAlive(extension
->id()));
226 // Close the dialog. The keep alive count is decremented.
227 extensions::ProcessManager
* pm
=
228 extensions::ProcessManager::Get(browser()->profile());
229 int previous_keep_alive_count
= pm
->GetLazyKeepaliveCount(extension
);
230 dialog
->CloseModalDialog();
231 EXPECT_EQ(previous_keep_alive_count
- 1,
232 pm
->GetLazyKeepaliveCount(extension
));
234 // The background page closes now that the dialog is gone.
235 background_observer
.WaitUntilClosed();
236 EXPECT_FALSE(IsBackgroundPageAlive(extension
->id()));
239 // Tests that the lazy background page stays alive until all visible views are
241 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, WaitForView
) {
242 LazyBackgroundObserver page_complete
;
243 ResultCatcher catcher
;
244 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
245 AppendASCII("wait_for_view");
246 const Extension
* extension
= LoadExtension(extdir
);
247 ASSERT_TRUE(extension
);
248 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
250 // The extension should've opened a new tab to an extension page.
251 EXPECT_EQ(extension
->GetResourceURL("extension_page.html").spec(),
252 browser()->tab_strip_model()->GetActiveWebContents()->
255 // Lazy Background Page still exists, because the extension created a new tab
256 // to an extension page.
257 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
259 // Close the new tab.
260 browser()->tab_strip_model()->CloseWebContentsAt(
261 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE
);
262 page_complete
.Wait();
264 // Lazy Background Page has been shut down.
265 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
268 // Tests that the lazy background page stays alive until all network requests
270 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, WaitForRequest
) {
271 host_resolver()->AddRule("*", "127.0.0.1");
272 ASSERT_TRUE(StartEmbeddedTestServer());
274 LazyBackgroundObserver page_complete
;
275 ResultCatcher catcher
;
276 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
277 AppendASCII("wait_for_request");
278 const Extension
* extension
= LoadExtension(extdir
);
279 ASSERT_TRUE(extension
);
280 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
282 // Lazy Background Page still exists, because the extension started a request.
283 extensions::ProcessManager
* pm
=
284 extensions::ProcessManager::Get(browser()->profile());
285 extensions::ExtensionHost
* host
=
286 pm
->GetBackgroundHostForExtension(last_loaded_extension_id());
289 // Abort the request.
291 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
292 host
->render_view_host(), "abortRequest()", &result
));
294 page_complete
.Wait();
296 // Lazy Background Page has been shut down.
297 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
300 // Tests that the lazy background page stays alive until all visible views are
302 // http://crbug.com/175778; test fails frequently on OS X
303 #if defined(OS_MACOSX)
304 #define MAYBE_WaitForNTP DISABLED_WaitForNTP
306 #define MAYBE_WaitForNTP WaitForNTP
308 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, MAYBE_WaitForNTP
) {
309 LazyBackgroundObserver lazybg
;
310 ResultCatcher catcher
;
311 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
312 AppendASCII("wait_for_ntp");
313 const Extension
* extension
= LoadExtension(extdir
);
314 ASSERT_TRUE(extension
);
315 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
317 // The extension should've opened a new tab to an extension page.
318 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
319 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
321 // Lazy Background Page still exists, because the extension created a new tab
322 // to an extension page.
323 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
325 // Navigate away from the NTP, which should close the event page.
326 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
329 // Lazy Background Page has been shut down.
330 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
333 // Tests that an incognito split mode extension gets 2 lazy background pages,
334 // and they each load and unload at the proper times.
335 // See crbug.com/248437
336 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, DISABLED_IncognitoSplitMode
) {
337 // Open incognito window.
338 Browser
* incognito_browser
= ui_test_utils::OpenURLOffTheRecord(
339 browser()->profile(), GURL("about:blank"));
341 // Load the extension with incognito enabled.
343 LoadedIncognitoObserver
loaded(browser()->profile());
344 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
345 AppendASCII("incognito_split");
346 ASSERT_TRUE(LoadExtensionIncognito(extdir
));
350 // Lazy Background Page doesn't exist yet.
351 extensions::ProcessManager
* pm
=
352 extensions::ProcessManager::Get(browser()->profile());
353 extensions::ProcessManager
* pmi
=
354 extensions::ProcessManager::Get(incognito_browser
->profile());
355 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
356 EXPECT_FALSE(pmi
->GetBackgroundHostForExtension(last_loaded_extension_id()));
358 // Trigger a browserAction event in the original profile and ensure only
359 // the original event page received it (since the event is scoped to the
362 ExtensionTestMessageListener
listener("waiting", false);
363 ExtensionTestMessageListener
listener_incognito("waiting_incognito", false);
365 LazyBackgroundObserver
page_complete(browser()->profile());
366 BrowserActionTestUtil(browser()).Press(0);
367 page_complete
.Wait();
369 // Only the original event page received the message.
370 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
372 pmi
->GetBackgroundHostForExtension(last_loaded_extension_id()));
373 EXPECT_TRUE(listener
.was_satisfied());
374 EXPECT_FALSE(listener_incognito
.was_satisfied());
377 // Trigger a bookmark created event and ensure both pages receive it.
379 ExtensionTestMessageListener
listener("waiting", false);
380 ExtensionTestMessageListener
listener_incognito("waiting_incognito", false);
382 LazyBackgroundObserver
page_complete(browser()->profile()),
383 page2_complete(incognito_browser
->profile());
384 BookmarkModel
* bookmark_model
=
385 BookmarkModelFactory::GetForProfile(browser()->profile());
386 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model
);
387 const BookmarkNode
* parent
= bookmark_model
->bookmark_bar_node();
388 bookmark_model
->AddURL(
389 parent
, 0, base::ASCIIToUTF16("Title"), GURL("about:blank"));
390 page_complete
.Wait();
391 page2_complete
.Wait();
393 // Both pages received the message.
394 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
396 pmi
->GetBackgroundHostForExtension(last_loaded_extension_id()));
397 EXPECT_TRUE(listener
.was_satisfied());
398 EXPECT_TRUE(listener_incognito
.was_satisfied());
402 // Tests that messages from the content script activate the lazy background
403 // page, and keep it alive until all channels are closed.
404 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, Messaging
) {
405 ASSERT_TRUE(StartEmbeddedTestServer());
406 ASSERT_TRUE(LoadExtensionAndWait("messaging"));
408 // Lazy Background Page doesn't exist yet.
409 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
410 EXPECT_EQ(1, browser()->tab_strip_model()->count());
412 // Navigate to a page that opens a message channel to the background page.
413 ResultCatcher catcher
;
414 LazyBackgroundObserver lazybg
;
415 ui_test_utils::NavigateToURL(
416 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
417 lazybg
.WaitUntilLoaded();
419 // Background page got the content script's message and is still loaded
420 // until we close the channel.
421 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
422 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
424 // Navigate away, closing the message channel and therefore the background
426 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
427 lazybg
.WaitUntilClosed();
429 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
432 // Tests that a KeepaliveImpulse increments the keep alive count, but eventually
433 // times out and background page will still close.
434 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, ImpulseAddsCount
) {
435 ASSERT_TRUE(StartEmbeddedTestServer());
436 const Extension
* extension
= LoadExtensionAndWait("messaging");
437 ASSERT_TRUE(extension
);
439 // Lazy Background Page doesn't exist yet.
440 extensions::ProcessManager
* pm
=
441 extensions::ProcessManager::Get(browser()->profile());
442 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
443 EXPECT_EQ(1, browser()->tab_strip_model()->count());
445 // Navigate to a page that opens a message channel to the background page.
446 ResultCatcher catcher
;
447 LazyBackgroundObserver lazybg
;
448 ui_test_utils::NavigateToURL(
449 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
450 lazybg
.WaitUntilLoaded();
452 // Add an impulse and the keep alive count increases.
453 int previous_keep_alive_count
= pm
->GetLazyKeepaliveCount(extension
);
454 pm
->KeepaliveImpulse(extension
);
455 EXPECT_EQ(previous_keep_alive_count
+ 1,
456 pm
->GetLazyKeepaliveCount(extension
));
458 // Navigate away, closing the message channel and therefore the background
459 // page after the impulse times out.
460 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
461 lazybg
.WaitUntilClosed();
463 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));
466 // Tests that the lazy background page receives the unload event when we
467 // close it, and that it can execute simple API calls that don't require an
468 // asynchronous response.
469 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, OnUnload
) {
470 ASSERT_TRUE(LoadExtensionAndWait("on_unload"));
472 // Lazy Background Page has been shut down.
473 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
475 // The browser action has a new title.
476 BrowserActionTestUtil
browser_action(browser());
477 ASSERT_EQ(1, browser_action
.NumberOfBrowserActions());
478 EXPECT_EQ("Success", browser_action
.GetTooltip(0));
481 // Tests that both a regular page and an event page will receive events when
482 // the event page is not loaded.
483 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, EventDispatchToTab
) {
484 ResultCatcher catcher
;
485 catcher
.RestrictToBrowserContext(browser()->profile());
487 const extensions::Extension
* extension
=
488 LoadExtensionAndWait("event_dispatch_to_tab");
490 ExtensionTestMessageListener
page_ready("ready", true);
491 GURL page_url
= extension
->GetResourceURL("page.html");
492 ui_test_utils::NavigateToURL(browser(), page_url
);
493 EXPECT_TRUE(page_ready
.WaitUntilSatisfied());
495 // After the event is sent below, wait for the event page to have received
496 // the event before proceeding with the test. This allows the regular page
497 // to test that the event page received the event, which makes the pass/fail
499 ExtensionTestMessageListener
event_page_ready("ready", true);
501 // Send an event by making a bookmark.
502 BookmarkModel
* bookmark_model
=
503 BookmarkModelFactory::GetForProfile(browser()->profile());
504 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model
);
505 bookmarks::AddIfNotBookmarked(bookmark_model
,
506 GURL("http://www.google.com"),
507 base::UTF8ToUTF16("Google"));
509 EXPECT_TRUE(event_page_ready
.WaitUntilSatisfied());
511 page_ready
.Reply("go");
513 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
516 // Tests that the lazy background page updates the chrome://extensions page
517 // when it is destroyed.
518 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, UpdateExtensionsPage
) {
519 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL
));
521 ResultCatcher catcher
;
522 base::FilePath extdir
= test_data_dir_
.AppendASCII("lazy_background_page").
523 AppendASCII("wait_for_view");
524 const Extension
* extension
= LoadExtension(extdir
);
525 ASSERT_TRUE(extension
);
526 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
528 // The extension should've opened a new tab to an extension page.
529 EXPECT_EQ(extension
->GetResourceURL("extension_page.html").spec(),
530 browser()->tab_strip_model()->GetActiveWebContents()->
533 // Lazy Background Page still exists, because the extension created a new tab
534 // to an extension page.
535 EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
537 // Close the new tab.
538 LazyBackgroundObserver page_complete
;
539 browser()->tab_strip_model()->CloseWebContentsAt(
540 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE
);
541 page_complete
.WaitUntilClosed();
543 // Lazy Background Page has been shut down.
544 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
546 // Verify that extensions page shows that the lazy background page is
548 content::RenderFrameHost
* frame
= content::FrameMatchingPredicate(
549 browser()->tab_strip_model()->GetActiveWebContents(),
550 base::Bind(&content::FrameHasSourceUrl
,
551 GURL(chrome::kChromeUIExtensionsFrameURL
)));
553 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
555 "var ele = document.querySelectorAll('div.active-views');"
556 "window.domAutomationController.send("
557 " ele[0].innerHTML.search('(Inactive)') > 0);",
559 EXPECT_TRUE(is_inactive
);
562 // Tests that the lazy background page will be unloaded if the onSuspend event
563 // handler calls an API function such as chrome.storage.local.set().
564 // See: http://crbug.com/296834
565 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest
, OnSuspendUseStorageApi
) {
566 EXPECT_TRUE(LoadExtensionAndWait("on_suspend"));
569 // TODO: background page with timer.
570 // TODO: background page that interacts with popup.