1 // Copyright 2015 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.
7 #include "base/callback.h"
8 #include "base/macros.h"
9 #include "extensions/browser/process_manager_observer.h"
11 namespace extensions
{
16 // Observes the background page load state of an extension. Use this in tests
17 // which rely on a specific open or close state of a background page.
18 class BackgroundPageWatcher
: public ProcessManagerObserver
{
20 BackgroundPageWatcher(ProcessManager
* process_manager
,
21 const Extension
* extension
);
23 ~BackgroundPageWatcher();
25 // Returns when the background page is open. If the background page is
26 // already open, returns immediately.
29 // Returns when the background page is closed. If the background page is
30 // already closed, returns immediately.
34 // Returns when the background page has open state of |wait_for_open|. If the
35 // background page is already in that state, returns immediately.
36 void WaitForOpenState(bool wait_for_open
);
38 bool IsBackgroundPageOpen();
40 // ProcessManagerObserver:
41 void OnExtensionFrameRegistered(
42 const std::string
& extension_id
,
43 content::RenderFrameHost
* render_frame_host
) override
;
44 void OnExtensionFrameUnregistered(
45 const std::string
& extension_id
,
46 content::RenderFrameHost
* render_frame_host
) override
;
48 ProcessManager
* process_manager_
;
49 const std::string extension_id_
;
50 base::Closure quit_run_loop_
;
51 bool is_waiting_for_open_
;
52 bool is_waiting_for_close_
;
54 DISALLOW_COPY_AND_ASSIGN(BackgroundPageWatcher
);
57 } // namespace extensions