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.
5 #ifndef CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_BASE_BROWSERTEST_H_
6 #define CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_BASE_BROWSERTEST_H_
10 #include "base/callback.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "base/timer/timer.h"
13 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "extensions/browser/process_manager_observer.h"
16 namespace media_router
{
21 * Base class for media router browser test.
23 * It provides the basic functions for integration and e2e browser tests,
24 * including install unpacked or packed extension at beginning of the test,
25 * uninstall the extension at the end of the test.
27 * This class accepts two flags to specify the location of MR extension:
28 * 1. "--extension-crx" flag to specify the packed extension location
29 * 2. "--extension-unpacked" flag to specify the unpacked extension location
30 * Only one of them should be passed when run browser tests.
32 class MediaRouterBaseBrowserTest
: public ExtensionBrowserTest
,
33 public extensions::ProcessManagerObserver
{
35 MediaRouterBaseBrowserTest();
36 ~MediaRouterBaseBrowserTest() override
;
38 // InProcessBrowserTest Overrides
39 void SetUp() override
;
40 void TearDown() override
;
43 // InProcessBrowserTest Overrides
44 void SetUpOnMainThread() override
;
45 void TearDownOnMainThread() override
;
47 void InstallAndEnableMRExtension();
48 void UninstallMRExtension();
50 virtual void ParseCommandLine();
52 // extensions::ProcessManagerObserver Overrides
53 void OnBackgroundHostCreated(extensions::ExtensionHost
* host
) override
;
55 // Wait until get the successful callback or timeout.
56 // Returns true if the condition is satisfied before the timeout.
57 // TODO(leilei): Replace this method with WaitableEvent class.
58 bool ConditionalWait(base::TimeDelta timeout
,
59 base::TimeDelta interval
,
60 const base::Callback
<bool(void)>& callback
);
62 // Wait for a specific time.
63 void Wait(base::TimeDelta timeout
);
65 bool is_unpacked() const { return !extension_unpacked_
.empty(); }
67 bool is_extension_host_created() const { return extension_host_created_
; }
69 // These values are initialized via flags.
70 base::FilePath extension_crx_
;
71 base::FilePath extension_unpacked_
;
73 base::WaitableEvent extension_load_event_
;
74 std::string extension_id_
;
75 bool extension_host_created_
;
78 DISALLOW_COPY_AND_ASSIGN(MediaRouterBaseBrowserTest
);
81 } // namespace media_router
83 #endif // CHROME_TEST_MEDIA_ROUTER_MEDIA_ROUTER_BASE_BROWSERTEST_H_