Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/test/media_router/media_router_base_browsertest.cc

Issue 595663002: Put chromoting isolate targets under chromoting_swarm_tests=1 GYP variable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/test/media_router/media_router_base_browsertest.h"
6
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/browser/profiles/profile.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/common/content_switches.h"
16 #include "content/public/test/test_utils.h"
17 #include "extensions/browser/process_manager.h"
18
19 namespace {
20 // Command line argument to specify CRX extension location.
21 const char kExtensionCrx[] = "extension-crx";
22 // Command line argument to specify unpacked extension location.
23 const char kExtensionUnpacked[] = "extension-unpacked";
24 } // namespace
25
26 namespace media_router {
27
28 MediaRouterBaseBrowserTest::MediaRouterBaseBrowserTest()
29 : extension_host_created_(false) {
30 base::CommandLine::ForCurrentProcess()->AppendSwitch(
31 switches::kEnableMediaRouter);
32 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
33 switches::kEnableBlinkFeatures, "Presentation");
34 }
35
36 MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() {
37 }
38
39 void MediaRouterBaseBrowserTest::SetUp() {
40 ParseCommandLine();
41 ExtensionBrowserTest::SetUp();
42 }
43
44 void MediaRouterBaseBrowserTest::TearDown() {
45 ExtensionBrowserTest::TearDown();
46 }
47
48 void MediaRouterBaseBrowserTest::SetUpOnMainThread() {
49 extensions::ProcessManager* process_manager =
50 extensions::ProcessManager::Get(browser()->profile());
51 DCHECK(process_manager);
52 process_manager->AddObserver(this);
53 InstallAndEnableMRExtension();
54
55 // Wait until extension host has been created or timeout.
56 Wait(base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
57 base::Bind(&MediaRouterBaseBrowserTest::is_extension_host_created,
58 base::Unretained(this)));
59 }
60
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 }
68
69 void MediaRouterBaseBrowserTest::InstallAndEnableMRExtension() {
70 if (is_unpacked()) {
71 const extensions::Extension* extension = LoadExtension(extension_unpacked_);
72 extension_id_ = extension->id();
73 } else {
74 NOTIMPLEMENTED();
75 }
76 }
77
78 void MediaRouterBaseBrowserTest::UninstallMRExtension() {
79 if (!extension_id_.empty()) {
80 UninstallExtension(extension_id_);
81 }
82 }
83
84 void MediaRouterBaseBrowserTest::Wait(
85 base::TimeDelta timeout, base::TimeDelta interval,
86 const base::Callback<bool(void)>& callback) {
87 base::ElapsedTimer timer;
88 while (!callback.Run() && timer.Elapsed() < timeout) {
89 base::RunLoop run_loop;
90 base::MessageLoop::current()->PostDelayedTask(
91 FROM_HERE, run_loop.QuitClosure(), interval);
92 run_loop.Run();
93 }
94 }
95
96 void MediaRouterBaseBrowserTest::Wait(base::TimeDelta timeout) {
97 base::RunLoop run_loop;
98 base::MessageLoop::current()->PostDelayedTask(
99 FROM_HERE, run_loop.QuitClosure(), timeout);
100 run_loop.Run();
101 }
102
103 void MediaRouterBaseBrowserTest::OnBackgroundHostCreated(
104 extensions::ExtensionHost* host) {
105 extension_host_created_ = true;
106 DVLOG(0) << "Host created";
107 }
108
109 void MediaRouterBaseBrowserTest::ParseCommandLine() {
110 DVLOG(0) << "ParseCommandLine";
111 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
112
113 extension_crx_ = command_line->GetSwitchValuePath(kExtensionCrx);
114 extension_unpacked_ = command_line->GetSwitchValuePath(kExtensionUnpacked);
115
116 // Check if there is mr_extension folder under PRODUCT_DIR folder.
117 if (extension_crx_.empty() && extension_unpacked_.empty()) {
118 base::FilePath base_dir;
119 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &base_dir));
120 base::FilePath extension_path =
121 base_dir.Append(FILE_PATH_LITERAL("mr_extension/"));
122 if (PathExists(extension_path)) {
123 extension_unpacked_ = extension_path;
124 }
125 }
126
127 // Exactly one of these two arguments should be provided.
128 ASSERT_NE(extension_crx_.empty(), extension_unpacked_.empty());
129 }
130
131 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/test/media_router/media_router_base_browsertest.h ('k') | chrome/test/media_router/media_router_e2e_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698