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

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

Issue 2634213002: [Media Router] Add integration browser tests (Closed)
Patch Set: Address Mark's comments Created 3 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/media_router/media_router_base_browsertest.h" 5 #include "chrome/test/media_router/media_router_base_browsertest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/timer/elapsed_timer.h" 13 #include "base/timer/elapsed_timer.h"
14 #include "chrome/browser/extensions/unpacked_installer.h" 14 #include "chrome/browser/extensions/unpacked_installer.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
19 #include "extensions/browser/process_manager.h" 19 #include "extensions/browser/process_manager.h"
20 #include "extensions/common/switches.h" 20 #include "extensions/common/switches.h"
21 21
22 22
23 namespace { 23 namespace {
24 // Command line argument to specify CRX extension location.
25 const char kExtensionCrx[] = "extension-crx";
26 // Command line argument to specify unpacked extension location. 24 // Command line argument to specify unpacked extension location.
27 const char kExtensionUnpacked[] = "extension-unpacked"; 25 const char kExtensionUnpacked[] = "extension-unpacked";
28 } // namespace 26 } // namespace
29 27
30 28
31 namespace media_router { 29 namespace media_router {
32 30
33 MediaRouterBaseBrowserTest::MediaRouterBaseBrowserTest() 31 MediaRouterBaseBrowserTest::MediaRouterBaseBrowserTest()
34 : extension_load_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 32 : extension_load_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
35 base::WaitableEvent::InitialState::NOT_SIGNALED), 33 base::WaitableEvent::InitialState::NOT_SIGNALED),
36 extension_host_created_(false) { 34 extension_host_created_(false) {
37 } 35 }
38 36
39 MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() { 37 MediaRouterBaseBrowserTest::~MediaRouterBaseBrowserTest() {
40 } 38 }
41 39
42 void MediaRouterBaseBrowserTest::SetUp() { 40 void MediaRouterBaseBrowserTest::SetUp() {
43 ParseCommandLine(); 41 ParseCommandLine();
44 ExtensionBrowserTest::SetUp(); 42 ExtensionBrowserTest::SetUp();
45 } 43 }
46 44
47 void MediaRouterBaseBrowserTest::TearDown() { 45 void MediaRouterBaseBrowserTest::TearDown() {
48 ExtensionBrowserTest::TearDown(); 46 ExtensionBrowserTest::TearDown();
49 } 47 }
50 48
51 void MediaRouterBaseBrowserTest::SetUpOnMainThread() { 49 void MediaRouterBaseBrowserTest::SetUpOnMainThread() {
52 ExtensionBrowserTest::SetUpOnMainThread(); 50 ExtensionBrowserTest::SetUpOnMainThread();
53 extensions::ProcessManager* process_manager = 51 extensions::ProcessManager* process_manager = extensions::ProcessManager::Get(
54 extensions::ProcessManager::Get(browser()->profile()); 52 browser()->profile()->GetOriginalProfile());
55 DCHECK(process_manager); 53 DCHECK(process_manager);
56 process_manager->AddObserver(this); 54 process_manager->AddObserver(this);
57 InstallAndEnableMRExtension(); 55 InstallAndEnableMRExtension();
58 extension_load_event_.Wait(); 56 extension_load_event_.Wait();
59 } 57 }
60 58
61 void MediaRouterBaseBrowserTest::TearDownOnMainThread() { 59 void MediaRouterBaseBrowserTest::TearDownOnMainThread() {
62 UninstallMRExtension(); 60 UninstallMRExtension();
63 extensions::ProcessManager* process_manager = 61 extensions::ProcessManager* process_manager =
64 extensions::ProcessManager::Get(browser()->profile()); 62 extensions::ProcessManager::Get(browser()->profile());
65 DCHECK(process_manager); 63 DCHECK(process_manager);
66 process_manager->RemoveObserver(this); 64 process_manager->RemoveObserver(this);
67 ExtensionBrowserTest::TearDownOnMainThread(); 65 ExtensionBrowserTest::TearDownOnMainThread();
68 } 66 }
69 67
70 void MediaRouterBaseBrowserTest::InstallAndEnableMRExtension() { 68 void MediaRouterBaseBrowserTest::InstallAndEnableMRExtension() {
71 if (is_unpacked()) { 69 const extensions::Extension* extension = LoadExtension(extension_unpacked_);
72 const extensions::Extension* extension = LoadExtension(extension_unpacked_); 70 extension_id_ = extension->id();
73 extension_id_ = extension->id();
74 } else {
75 NOTIMPLEMENTED();
76 }
77 } 71 }
78 72
79 void MediaRouterBaseBrowserTest::UninstallMRExtension() { 73 void MediaRouterBaseBrowserTest::UninstallMRExtension() {
80 if (!extension_id_.empty()) { 74 if (!extension_id_.empty()) {
81 UninstallExtension(extension_id_); 75 UninstallExtension(extension_id_);
82 } 76 }
83 } 77 }
84 78
85 bool MediaRouterBaseBrowserTest::ConditionalWait( 79 bool MediaRouterBaseBrowserTest::ConditionalWait(
86 base::TimeDelta timeout, 80 base::TimeDelta timeout,
(...skipping 23 matching lines...) Expand all
110 void MediaRouterBaseBrowserTest::OnBackgroundHostCreated( 104 void MediaRouterBaseBrowserTest::OnBackgroundHostCreated(
111 extensions::ExtensionHost* host) { 105 extensions::ExtensionHost* host) {
112 extension_host_created_ = true; 106 extension_host_created_ = true;
113 DVLOG(0) << "Host created"; 107 DVLOG(0) << "Host created";
114 extension_load_event_.Signal(); 108 extension_load_event_.Signal();
115 } 109 }
116 110
117 void MediaRouterBaseBrowserTest::ParseCommandLine() { 111 void MediaRouterBaseBrowserTest::ParseCommandLine() {
118 DVLOG(0) << "ParseCommandLine"; 112 DVLOG(0) << "ParseCommandLine";
119 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
120
121 extension_crx_ = command_line->GetSwitchValuePath(kExtensionCrx);
122 extension_unpacked_ = command_line->GetSwitchValuePath(kExtensionUnpacked); 114 extension_unpacked_ = command_line->GetSwitchValuePath(kExtensionUnpacked);
123 115
124 // Check if there is mr_extension folder under PRODUCT_DIR folder. 116 // Check if there is mr_extension folder under PRODUCT_DIR folder.
125 if (extension_crx_.empty() && extension_unpacked_.empty()) { 117 if (extension_unpacked_.empty()) {
126 base::FilePath base_dir; 118 base::FilePath base_dir;
127 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &base_dir)); 119 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &base_dir));
128 base::FilePath extension_path = 120 base::FilePath extension_path =
129 base_dir.Append(FILE_PATH_LITERAL("mr_extension/")); 121 base_dir.Append(FILE_PATH_LITERAL("mr_extension/"));
130 if (PathExists(extension_path)) { 122 if (PathExists(extension_path)) {
131 extension_unpacked_ = extension_path; 123 extension_unpacked_ = extension_path;
132 } 124 }
133 } 125 }
134 126
135 // Exactly one of these two arguments should be provided. 127 // An unpacked component extension must be provided.
136 ASSERT_NE(extension_crx_.empty(), extension_unpacked_.empty()); 128 ASSERT_FALSE(extension_unpacked_.empty());
129 }
130
131 Browser* MediaRouterBaseBrowserTest::browser() {
132 return ExtensionBrowserTest::browser();
mark a. foltz 2017/02/09 23:29:58 If this method returns a Browser*, there's no need
takumif 2017/02/14 19:11:48 The superclass' browser() is not virtual, and if I
mark a. foltz 2017/02/15 00:41:27 It's a little weird to override a non-virtual meth
takumif 2017/02/18 20:44:05 Done.
137 } 133 }
138 134
139 } // namespace media_router 135 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698