[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / test / media_router / media_router_base_browsertest.cc
blob34a88dbfcf89d109c34484be3ad48f7064081e70
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 #include "chrome/test/media_router/media_router_base_browsertest.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/path_service.h"
10 #include "base/timer/elapsed_timer.h"
11 #include "chrome/browser/extensions/unpacked_installer.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/test/test_utils.h"
16 #include "extensions/browser/process_manager.h"
17 #include "extensions/common/switches.h"
20 namespace {
21 // Command line argument to specify CRX extension location.
22 const char kExtensionCrx[] = "extension-crx";
23 // Command line argument to specify unpacked extension location.
24 const char kExtensionUnpacked[] = "extension-unpacked";
25 } // namespace
27 namespace media_router {
29 MediaRouterBaseBrowserTest::MediaRouterBaseBrowserTest()
30 : extension_load_event_(false, false), extension_host_created_(false) {
31 base::CommandLine::ForCurrentProcess()->AppendSwitch(
32 switches::kEnableMediaRouter);
33 base::CommandLine::ForCurrentProcess()->AppendSwitch(
34 extensions::switches::kEnableExtensionActionRedesign);
35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
36 switches::kEnableBlinkFeatures, "Presentation");
39 MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() {
42 void MediaRouterBaseBrowserTest::SetUp() {
43 ParseCommandLine();
44 ExtensionBrowserTest::SetUp();
47 void MediaRouterBaseBrowserTest::TearDown() {
48 ExtensionBrowserTest::TearDown();
51 void MediaRouterBaseBrowserTest::SetUpOnMainThread() {
52 extensions::ProcessManager* process_manager =
53 extensions::ProcessManager::Get(browser()->profile());
54 DCHECK(process_manager);
55 process_manager->AddObserver(this);
56 InstallAndEnableMRExtension();
57 extension_load_event_.Wait();
58 ExtensionBrowserTest::SetUpOnMainThread();
61 void MediaRouterBaseBrowserTest::TearDownOnMainThread() {
62 UninstallMRExtension();
63 extensions::ProcessManager* process_manager =
64 extensions::ProcessManager::Get(browser()->profile());
65 DCHECK(process_manager);
66 process_manager->RemoveObserver(this);
67 ExtensionBrowserTest::TearDownOnMainThread();
70 void MediaRouterBaseBrowserTest::InstallAndEnableMRExtension() {
71 if (is_unpacked()) {
72 const extensions::Extension* extension = LoadExtension(extension_unpacked_);
73 extension_id_ = extension->id();
74 } else {
75 NOTIMPLEMENTED();
79 void MediaRouterBaseBrowserTest::UninstallMRExtension() {
80 if (!extension_id_.empty()) {
81 UninstallExtension(extension_id_);
85 void MediaRouterBaseBrowserTest::ConditionalWait(
86 base::TimeDelta timeout,
87 base::TimeDelta interval,
88 const base::Callback<bool(void)>& callback) {
89 base::ElapsedTimer timer;
90 while (!callback.Run() && timer.Elapsed() < timeout) {
91 base::RunLoop run_loop;
92 base::MessageLoop::current()->PostDelayedTask(
93 FROM_HERE, run_loop.QuitClosure(), interval);
94 run_loop.Run();
98 void MediaRouterBaseBrowserTest::Wait(base::TimeDelta timeout) {
99 base::RunLoop run_loop;
100 base::MessageLoop::current()->PostDelayedTask(
101 FROM_HERE, run_loop.QuitClosure(), timeout);
102 run_loop.Run();
105 void MediaRouterBaseBrowserTest::OnBackgroundHostCreated(
106 extensions::ExtensionHost* host) {
107 extension_host_created_ = true;
108 DVLOG(0) << "Host created";
109 extension_load_event_.Signal();
112 void MediaRouterBaseBrowserTest::ParseCommandLine() {
113 DVLOG(0) << "ParseCommandLine";
114 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
116 extension_crx_ = command_line->GetSwitchValuePath(kExtensionCrx);
117 extension_unpacked_ = command_line->GetSwitchValuePath(kExtensionUnpacked);
119 // Check if there is mr_extension folder under PRODUCT_DIR folder.
120 if (extension_crx_.empty() && extension_unpacked_.empty()) {
121 base::FilePath base_dir;
122 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &base_dir));
123 base::FilePath extension_path =
124 base_dir.Append(FILE_PATH_LITERAL("mr_extension/"));
125 if (PathExists(extension_path)) {
126 extension_unpacked_ = extension_path;
130 // Exactly one of these two arguments should be provided.
131 ASSERT_NE(extension_crx_.empty(), extension_unpacked_.empty());
134 } // namespace media_router