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

Side by Side Diff: chrome/test/media_router/media_router_integration_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_integration_browsertest.h" 5 #include "chrome/test/media_router/media_router_integration_browsertest.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" 21 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
26 #include "content/public/test/test_navigation_observer.h" 26 #include "content/public/test/test_navigation_observer.h"
27 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
28 #include "net/base/filename_util.h" 28 #include "net/base/filename_util.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 using content::WebContents;
31 32
32 namespace media_router { 33 namespace media_router {
33 34
34 namespace { 35 namespace {
35 // Command line argument to specify receiver, 36 // Command line argument to specify receiver,
36 const char kReceiver[] = "receiver"; 37 const char kReceiver[] = "receiver";
37 // The path relative to <chromium src>/out/<build config> for media router 38 // The path relative to <chromium src>/out/<build config> for media router
38 // browser test resources. 39 // browser test resources.
39 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( 40 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL(
40 "media_router/browser_test_resources/"); 41 "media_router/browser_test_resources/");
41 const char kTestSinkName[] = "test-sink-1"; 42 const char kTestSinkName[] = "test-sink-1";
42 // The javascript snippets. 43 // The javascript snippets.
43 const char kCheckSessionScript[] = "checkSession();"; 44 const char kCheckSessionScript[] = "checkSession();";
44 const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');"; 45 const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');";
45 const char kStartSessionScript[] = "startSession();"; 46 const char kStartSessionScript[] = "startSession();";
46 const char kTerminateSessionScript[] = 47 const char kTerminateSessionScript[] =
47 "terminateSessionAndWaitForStateChange();"; 48 "terminateSessionAndWaitForStateChange();";
49 const char kCloseSessionScript[] = "closeSessionAndWaitForStateChange();";
50 const char kReconnectSessionScript[] = "reconnectSession('%s');";
51 const char kCheckSendMessageFailedScript[] = "checkSendMessageFailed('%s');";
48 const char kWaitDeviceScript[] = "waitUntilDeviceAvailable();"; 52 const char kWaitDeviceScript[] = "waitUntilDeviceAvailable();";
49 const char kSendMessageAndExpectResponseScript[] = 53 const char kSendMessageAndExpectResponseScript[] =
50 "sendMessageAndExpectResponse('%s');"; 54 "sendMessageAndExpectResponse('%s');";
51 const char kSendMessageAndExpectConnectionCloseOnErrorScript[] = 55 const char kSendMessageAndExpectConnectionCloseOnErrorScript[] =
52 "sendMessageAndExpectConnectionCloseOnError()"; 56 "sendMessageAndExpectConnectionCloseOnError()";
53 const char kChooseSinkScript[] = 57 const char kChooseSinkScript[] =
54 "var sinks = document.getElementById('media-router-container')." 58 "var sinks = document.getElementById('media-router-container')."
55 " shadowRoot.getElementById('sink-list').getElementsByTagName('span');" 59 " shadowRoot.getElementById('sink-list').getElementsByTagName('span');"
56 "for (var i=0; i<sinks.length; i++) {" 60 "for (var i=0; i<sinks.length; i++) {"
57 " if(sinks[i].textContent.trim() == '%s') {" 61 " if(sinks[i].textContent.trim() == '%s') {"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 "/** Wait until media router container is not undefined and " 99 "/** Wait until media router container is not undefined and "
96 "* deviceMissingUrl is not undefined, " 100 "* deviceMissingUrl is not undefined, "
97 "* once deviceMissingUrl is not undefined, which means " 101 "* once deviceMissingUrl is not undefined, which means "
98 "* the dialog is fully loaded." 102 "* the dialog is fully loaded."
99 "*/" 103 "*/"
100 "if (container != undefined && container.deviceMissingUrl != undefined) {" 104 "if (container != undefined && container.deviceMissingUrl != undefined) {"
101 " domAutomationController.send(true);" 105 " domAutomationController.send(true);"
102 "}" 106 "}"
103 "domAutomationController.send(false);"; 107 "domAutomationController.send(false);";
104 108
105 std::string GetStartedConnectionId(content::WebContents* web_contents) { 109 std::string GetStartedConnectionId(WebContents* web_contents) {
106 std::string session_id; 110 std::string session_id;
107 CHECK(content::ExecuteScriptAndExtractString( 111 CHECK(content::ExecuteScriptAndExtractString(
108 web_contents, "window.domAutomationController.send(startedConnection.id)", 112 web_contents, "window.domAutomationController.send(startedConnection.id)",
109 &session_id)); 113 &session_id));
110 return session_id; 114 return session_id;
111 } 115 }
112 116
113 std::string GetDefaultRequestSessionId(content::WebContents* web_contents) { 117 std::string GetDefaultRequestSessionId(WebContents* web_contents) {
114 std::string session_id; 118 std::string session_id;
115 CHECK(content::ExecuteScriptAndExtractString( 119 CHECK(content::ExecuteScriptAndExtractString(
116 web_contents, 120 web_contents,
117 "window.domAutomationController.send(defaultRequestSessionId)", 121 "window.domAutomationController.send(defaultRequestSessionId)",
118 &session_id)); 122 &session_id));
119 return session_id; 123 return session_id;
120 } 124 }
121 125
122 } // namespace 126 } // namespace
123 127
124 MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() { 128 MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() {
125 } 129 }
126 130
127 MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() { 131 MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() {
128 } 132 }
129 133
130 void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() { 134 void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() {
131 MediaRouterBaseBrowserTest::TearDownOnMainThread(); 135 MediaRouterBaseBrowserTest::TearDownOnMainThread();
132 test_navigation_observer_.reset(); 136 test_navigation_observer_.reset();
133 } 137 }
134 138
135 void MediaRouterIntegrationBrowserTest::ExecuteJavaScriptAPI( 139 void MediaRouterIntegrationBrowserTest::ExecuteJavaScriptAPI(
136 content::WebContents* web_contents, 140 WebContents* web_contents,
137 const std::string& script) { 141 const std::string& script) {
138 std::string result(ExecuteScriptAndExtractString(web_contents, script)); 142 std::string result(ExecuteScriptAndExtractString(web_contents, script));
139 143
140 // Read the test result, the test result set by javascript is a 144 // Read the test result, the test result set by javascript is a
141 // JSON string with the following format: 145 // JSON string with the following format:
142 // {"passed": "<true/false>", "errorMessage": "<error_message>"} 146 // {"passed": "<true/false>", "errorMessage": "<error_message>"}
143 std::unique_ptr<base::Value> value = 147 std::unique_ptr<base::Value> value =
144 base::JSONReader::Read(result, base::JSON_ALLOW_TRAILING_COMMAS); 148 base::JSONReader::Read(result, base::JSON_ALLOW_TRAILING_COMMAS);
145 149
146 // Convert to dictionary. 150 // Convert to dictionary.
147 base::DictionaryValue* dict_value = nullptr; 151 base::DictionaryValue* dict_value = nullptr;
148 ASSERT_TRUE(value->GetAsDictionary(&dict_value)); 152 ASSERT_TRUE(value->GetAsDictionary(&dict_value));
149 153
150 // Extract the fields. 154 // Extract the fields.
151 bool passed = false; 155 bool passed = false;
152 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed)); 156 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed));
153 std::string error_message; 157 std::string error_message;
154 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message)); 158 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message));
155 159
156 ASSERT_TRUE(passed) << error_message; 160 ASSERT_TRUE(passed) << error_message;
157 } 161 }
158 162
163 WebContents* MediaRouterIntegrationBrowserTest::StartSessionWithTestPage(
164 bool wait_for_sink) {
165 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
166 WebContents* web_contents = GetActiveWebContents();
167 CHECK(web_contents);
168 if (wait_for_sink)
169 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
mark a. foltz 2017/02/09 23:29:59 I feel link this should be kWaitSinkScript to be c
takumif 2017/02/14 19:11:48 Done.
170 StartSession(web_contents);
171 return web_contents;
172 }
173
174 WebContents*
175 MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink(
176 bool should_succeed) {
177 WebContents* web_contents = StartSessionWithTestPage(true);
178 WaitUntilSinkDiscoveredOnUI();
179 ChooseSink(web_contents, kTestSinkName);
180 if (should_succeed)
181 CheckSessionValidity(web_contents);
182 return web_contents;
183 }
184
159 void MediaRouterIntegrationBrowserTest::OpenTestPage( 185 void MediaRouterIntegrationBrowserTest::OpenTestPage(
160 base::FilePath::StringPieceType file_name) { 186 base::FilePath::StringPieceType file_name) {
161 base::FilePath full_path = GetResourceFile(file_name); 187 base::FilePath full_path = GetResourceFile(file_name);
162 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path)); 188 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path));
163 } 189 }
164 190
165 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( 191 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab(
166 base::FilePath::StringPieceType file_name) { 192 base::FilePath::StringPieceType file_name) {
167 base::FilePath full_path = GetResourceFile(file_name); 193 base::FilePath full_path = GetResourceFile(file_name);
168 ui_test_utils::NavigateToURLWithDisposition( 194 ui_test_utils::NavigateToURLWithDisposition(
169 browser(), net::FilePathToFileURL(full_path), 195 browser(), net::FilePathToFileURL(full_path),
170 WindowOpenDisposition::NEW_FOREGROUND_TAB, 196 WindowOpenDisposition::NEW_FOREGROUND_TAB,
171 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 197 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
172 } 198 }
173 199
174 void MediaRouterIntegrationBrowserTest::StartSession( 200 void MediaRouterIntegrationBrowserTest::StartSession(
175 content::WebContents* web_contents) { 201 WebContents* web_contents) {
176 test_navigation_observer_.reset( 202 test_navigation_observer_.reset(
177 new content::TestNavigationObserver(web_contents, 1)); 203 new content::TestNavigationObserver(web_contents, 1));
178 test_navigation_observer_->StartWatchingNewWebContents(); 204 test_navigation_observer_->StartWatchingNewWebContents();
179 ExecuteJavaScriptAPI(web_contents, kStartSessionScript); 205 ExecuteJavaScriptAPI(web_contents, kStartSessionScript);
180 test_navigation_observer_->Wait(); 206 test_navigation_observer_->Wait();
181 test_navigation_observer_->StopWatchingNewWebContents(); 207 test_navigation_observer_->StopWatchingNewWebContents();
182 } 208 }
183 209
184 void MediaRouterIntegrationBrowserTest::ChooseSink( 210 void MediaRouterIntegrationBrowserTest::ChooseSink(
185 content::WebContents* web_contents, 211 WebContents* web_contents,
186 const std::string& sink_name) { 212 const std::string& sink_name) {
187 content::WebContents* dialog_contents = GetMRDialog(web_contents); 213 WebContents* dialog_contents = GetMRDialog(web_contents);
188 std::string script = base::StringPrintf( 214 std::string script = base::StringPrintf(
189 kChooseSinkScript, sink_name.c_str()); 215 kChooseSinkScript, sink_name.c_str());
190 // Execute javascript to choose sink, but don't wait until it finishes. 216 // Execute javascript to choose sink, but don't wait until it finishes.
191 dialog_contents->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( 217 dialog_contents->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
192 base::UTF8ToUTF16(script)); 218 base::UTF8ToUTF16(script));
193 } 219 }
194 220
195 void MediaRouterIntegrationBrowserTest::CheckStartFailed( 221 void MediaRouterIntegrationBrowserTest::CheckStartFailed(
196 content::WebContents* web_contents, 222 WebContents* web_contents,
197 const std::string& error_name, 223 const std::string& error_name,
198 const std::string& error_message_substring) { 224 const std::string& error_message_substring) {
199 std::string script(base::StringPrintf(kCheckStartFailedScript, 225 std::string script(base::StringPrintf(kCheckStartFailedScript,
200 error_name.c_str(), 226 error_name.c_str(),
201 error_message_substring.c_str())); 227 error_message_substring.c_str()));
202 ExecuteJavaScriptAPI(web_contents, script); 228 ExecuteJavaScriptAPI(web_contents, script);
203 } 229 }
204 230
205 void MediaRouterIntegrationBrowserTest::ClickDialog() { 231 void MediaRouterIntegrationBrowserTest::ClickDialog() {
206 content::WebContents* web_contents = 232 WebContents* web_contents = GetActiveWebContents();
207 browser()->tab_strip_model()->GetActiveWebContents(); 233 WebContents* dialog_contents = GetMRDialog(web_contents);
208 content::WebContents* dialog_contents = GetMRDialog(web_contents);
209 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kClickDialog)); 234 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kClickDialog));
210 } 235 }
211 content::WebContents* MediaRouterIntegrationBrowserTest::GetMRDialog( 236 WebContents* MediaRouterIntegrationBrowserTest::GetMRDialog(
212 content::WebContents* web_contents) { 237 WebContents* web_contents) {
213 MediaRouterDialogControllerImpl* controller = 238 MediaRouterDialogControllerImpl* controller =
214 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); 239 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
215 content::WebContents* dialog_contents = controller->GetMediaRouterDialog(); 240 WebContents* dialog_contents = controller->GetMediaRouterDialog();
216 CHECK(dialog_contents); 241 CHECK(dialog_contents);
217 WaitUntilDialogFullyLoaded(dialog_contents); 242 WaitUntilDialogFullyLoaded(dialog_contents);
218 return dialog_contents; 243 return dialog_contents;
219 } 244 }
220 245
221 bool MediaRouterIntegrationBrowserTest::IsDialogClosed( 246 bool MediaRouterIntegrationBrowserTest::IsDialogClosed(
222 content::WebContents* web_contents) { 247 WebContents* web_contents) {
223 MediaRouterDialogControllerImpl* controller = 248 MediaRouterDialogControllerImpl* controller =
224 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); 249 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
225 return !controller->GetMediaRouterDialog(); 250 return !controller->GetMediaRouterDialog();
226 } 251 }
227 252
228 void MediaRouterIntegrationBrowserTest::WaitUntilDialogClosed( 253 void MediaRouterIntegrationBrowserTest::WaitUntilDialogClosed(
229 content::WebContents* web_contents) { 254 WebContents* web_contents) {
230 ASSERT_TRUE(ConditionalWait( 255 ASSERT_TRUE(ConditionalWait(
231 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1), 256 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1),
232 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed, 257 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed,
233 base::Unretained(this), web_contents))); 258 base::Unretained(this), web_contents)));
234 } 259 }
235 260
236 void MediaRouterIntegrationBrowserTest::CheckDialogRemainsOpen( 261 void MediaRouterIntegrationBrowserTest::CheckDialogRemainsOpen(
237 content::WebContents* web_contents) { 262 WebContents* web_contents) {
238 ASSERT_FALSE(ConditionalWait( 263 ASSERT_FALSE(ConditionalWait(
239 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1), 264 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1),
240 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed, 265 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed,
241 base::Unretained(this), web_contents))); 266 base::Unretained(this), web_contents)));
242 } 267 }
243 268
244 void MediaRouterIntegrationBrowserTest::SetTestData( 269 void MediaRouterIntegrationBrowserTest::SetTestData(
245 base::FilePath::StringPieceType test_data_file) { 270 base::FilePath::StringPieceType test_data_file) {
246 base::FilePath full_path = GetResourceFile(test_data_file); 271 base::FilePath full_path = GetResourceFile(test_data_file);
247 JSONFileValueDeserializer deserializer(full_path); 272 JSONFileValueDeserializer deserializer(full_path);
248 int error_code = 0; 273 int error_code = 0;
249 std::string error_message; 274 std::string error_message;
250 std::unique_ptr<base::Value> value = 275 std::unique_ptr<base::Value> value =
251 deserializer.Deserialize(&error_code, &error_message); 276 deserializer.Deserialize(&error_code, &error_message);
252 CHECK(value.get()) << "Deserialize failed: " << error_message; 277 CHECK(value.get()) << "Deserialize failed: " << error_message;
253 std::string test_data_str; 278 std::string test_data_str;
254 ASSERT_TRUE(base::JSONWriter::Write(*value, &test_data_str)); 279 ASSERT_TRUE(base::JSONWriter::Write(*value, &test_data_str));
255 ExecuteScriptInBackgroundPageNoWait( 280 ExecuteScriptInBackgroundPageNoWait(
256 extension_id_, 281 extension_id_,
257 base::StringPrintf("localStorage['testdata'] = '%s'", 282 base::StringPrintf("localStorage['testdata'] = '%s'",
258 test_data_str.c_str())); 283 test_data_str.c_str()));
259 } 284 }
260 285
261 content::WebContents* MediaRouterIntegrationBrowserTest::OpenMRDialog( 286 WebContents* MediaRouterIntegrationBrowserTest::OpenMRDialog(
262 content::WebContents* web_contents) { 287 WebContents* web_contents) {
263 MediaRouterDialogControllerImpl* controller = 288 MediaRouterDialogControllerImpl* controller =
264 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); 289 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
265 test_navigation_observer_.reset( 290 test_navigation_observer_.reset(
266 new content::TestNavigationObserver(web_contents, 1)); 291 new content::TestNavigationObserver(web_contents, 1));
267 test_navigation_observer_->StartWatchingNewWebContents(); 292 test_navigation_observer_->StartWatchingNewWebContents();
268 CHECK(controller->ShowMediaRouterDialog()); 293 CHECK(controller->ShowMediaRouterDialog());
269 test_navigation_observer_->Wait(); 294 test_navigation_observer_->Wait();
270 test_navigation_observer_->StopWatchingNewWebContents(); 295 test_navigation_observer_->StopWatchingNewWebContents();
271 content::WebContents* dialog_contents = controller->GetMediaRouterDialog(); 296 WebContents* dialog_contents = controller->GetMediaRouterDialog();
272 CHECK(dialog_contents); 297 CHECK(dialog_contents);
273 WaitUntilDialogFullyLoaded(dialog_contents); 298 WaitUntilDialogFullyLoaded(dialog_contents);
274 return dialog_contents; 299 return dialog_contents;
275 } 300 }
276 301
277 base::FilePath MediaRouterIntegrationBrowserTest::GetResourceFile( 302 base::FilePath MediaRouterIntegrationBrowserTest::GetResourceFile(
278 base::FilePath::StringPieceType relative_path) const { 303 base::FilePath::StringPieceType relative_path) const {
279 base::FilePath base_dir; 304 base::FilePath base_dir;
280 // ASSERT_TRUE can only be used in void returning functions. 305 // ASSERT_TRUE can only be used in void returning functions.
281 // Use CHECK instead in non-void returning functions. 306 // Use CHECK instead in non-void returning functions.
(...skipping 29 matching lines...) Expand all
311 const content::ToRenderFrameHost& adapter, const std::string& script) { 336 const content::ToRenderFrameHost& adapter, const std::string& script) {
312 ASSERT_TRUE(content::ExecuteScript(adapter, script)); 337 ASSERT_TRUE(content::ExecuteScript(adapter, script));
313 } 338 }
314 339
315 bool MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI() { 340 bool MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI() {
316 return !GetRouteId(receiver()).empty(); 341 return !GetRouteId(receiver()).empty();
317 } 342 }
318 343
319 std::string MediaRouterIntegrationBrowserTest::GetRouteId( 344 std::string MediaRouterIntegrationBrowserTest::GetRouteId(
320 const std::string& sink_name) { 345 const std::string& sink_name) {
321 content::WebContents* web_contents = 346 WebContents* web_contents = GetActiveWebContents();
322 browser()->tab_strip_model()->GetActiveWebContents(); 347 WebContents* dialog_contents = GetMRDialog(web_contents);
323 content::WebContents* dialog_contents = GetMRDialog(web_contents);
324 std::string script = base::StringPrintf(kGetSinkIdScript, sink_name.c_str()); 348 std::string script = base::StringPrintf(kGetSinkIdScript, sink_name.c_str());
325 std::string sink_id = ExecuteScriptAndExtractString(dialog_contents, script); 349 std::string sink_id = ExecuteScriptAndExtractString(dialog_contents, script);
326 DVLOG(0) << "sink id: " << sink_id; 350 DVLOG(0) << "sink id: " << sink_id;
327 script = base::StringPrintf(kGetRouteIdScript, sink_id.c_str()); 351 script = base::StringPrintf(kGetRouteIdScript, sink_id.c_str());
328 std::string route_id = ExecuteScriptAndExtractString(dialog_contents, script); 352 std::string route_id = ExecuteScriptAndExtractString(dialog_contents, script);
329 DVLOG(0) << "route id: " << route_id; 353 DVLOG(0) << "route id: " << route_id;
330 return route_id; 354 return route_id;
331 } 355 }
332 356
333 void MediaRouterIntegrationBrowserTest::WaitUntilRouteCreated() { 357 void MediaRouterIntegrationBrowserTest::WaitUntilRouteCreated() {
334 ASSERT_TRUE(ConditionalWait( 358 ASSERT_TRUE(ConditionalWait(
335 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), 359 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1),
336 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI, 360 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI,
337 base::Unretained(this)))); 361 base::Unretained(this))));
338 } 362 }
339 363
340 bool MediaRouterIntegrationBrowserTest::IsUIShowingIssue() { 364 bool MediaRouterIntegrationBrowserTest::IsUIShowingIssue() {
341 content::WebContents* web_contents = 365 WebContents* web_contents = GetActiveWebContents();
342 browser()->tab_strip_model()->GetActiveWebContents(); 366 WebContents* dialog_contents = GetMRDialog(web_contents);
343 content::WebContents* dialog_contents = GetMRDialog(web_contents);
344 std::string script = base::StringPrintf( 367 std::string script = base::StringPrintf(
345 "domAutomationController.send(window.document.getElementById(" 368 "domAutomationController.send(window.document.getElementById("
346 "'media-router-container').issue != undefined)"); 369 "'media-router-container').issue != undefined)");
347 bool has_issue = false; 370 bool has_issue = false;
348 CHECK(content::ExecuteScriptAndExtractBool(dialog_contents, script, 371 CHECK(content::ExecuteScriptAndExtractBool(dialog_contents, script,
349 &has_issue)); 372 &has_issue));
350 return has_issue; 373 return has_issue;
351 } 374 }
352 375
353 void MediaRouterIntegrationBrowserTest::WaitUntilIssue() { 376 void MediaRouterIntegrationBrowserTest::WaitUntilIssue() {
354 ASSERT_TRUE(ConditionalWait( 377 ASSERT_TRUE(ConditionalWait(
355 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), 378 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
356 base::Bind(&MediaRouterIntegrationBrowserTest::IsUIShowingIssue, 379 base::Bind(&MediaRouterIntegrationBrowserTest::IsUIShowingIssue,
357 base::Unretained(this)))); 380 base::Unretained(this))));
358 } 381 }
359 382
360 std::string MediaRouterIntegrationBrowserTest::GetIssueTitle() { 383 std::string MediaRouterIntegrationBrowserTest::GetIssueTitle() {
361 content::WebContents* web_contents = 384 WebContents* web_contents = GetActiveWebContents();
362 browser()->tab_strip_model()->GetActiveWebContents(); 385 WebContents* dialog_contents = GetMRDialog(web_contents);
363 content::WebContents* dialog_contents = GetMRDialog(web_contents);
364 std::string script = base::StringPrintf( 386 std::string script = base::StringPrintf(
365 "domAutomationController.send(window.document.getElementById(" 387 "domAutomationController.send(window.document.getElementById("
366 "'media-router-container').issue.title)"); 388 "'media-router-container').issue.title)");
367 return ExecuteScriptAndExtractString(dialog_contents, script); 389 return ExecuteScriptAndExtractString(dialog_contents, script);
368 } 390 }
369 391
370 bool MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI() { 392 bool MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI() {
371 // After execute js script to close route on UI, the dialog will dispear 393 // After execute js script to close route on UI, the dialog will dispear
372 // after 3s. But sometimes it takes more than 3s to close the route, so 394 // after 3s. But sometimes it takes more than 3s to close the route, so
373 // we need to re-open the dialog if it is closed. 395 // we need to re-open the dialog if it is closed.
374 content::WebContents* web_contents = 396 WebContents* web_contents = GetActiveWebContents();
375 browser()->tab_strip_model()->GetActiveWebContents();
376 MediaRouterDialogControllerImpl* controller = 397 MediaRouterDialogControllerImpl* controller =
377 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); 398 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
378 content::WebContents* dialog_contents = controller->GetMediaRouterDialog(); 399 WebContents* dialog_contents = controller->GetMediaRouterDialog();
379 if (!dialog_contents) { 400 if (!dialog_contents) {
380 VLOG(0) << "Media router dialog was closed, reopen it again."; 401 VLOG(0) << "Media router dialog was closed, reopen it again.";
381 OpenMRDialog(web_contents); 402 OpenMRDialog(web_contents);
382 } 403 }
383 return GetRouteId(receiver()).empty(); 404 return GetRouteId(receiver()).empty();
384 } 405 }
385 406
386 void MediaRouterIntegrationBrowserTest::CloseRouteOnUI() { 407 void MediaRouterIntegrationBrowserTest::CloseRouteOnUI() {
387 content::WebContents* web_contents = 408 WebContents* web_contents = GetActiveWebContents();
388 browser()->tab_strip_model()->GetActiveWebContents(); 409 WebContents* dialog_contents = GetMRDialog(web_contents);
389 content::WebContents* dialog_contents = GetMRDialog(web_contents);
390 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kCloseRouteScript)); 410 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kCloseRouteScript));
391 ASSERT_TRUE(ConditionalWait( 411 ASSERT_TRUE(ConditionalWait(
392 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), 412 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1),
393 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI, 413 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI,
394 base::Unretained(this)))); 414 base::Unretained(this))));
395 } 415 }
396 416
397 bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI() { 417 bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI() {
398 content::WebContents* web_contents = 418 WebContents* web_contents = GetActiveWebContents();
399 browser()->tab_strip_model()->GetActiveWebContents(); 419 WebContents* dialog_contents = GetMRDialog(web_contents);
400 content::WebContents* dialog_contents = GetMRDialog(web_contents);
401 std::string script = base::StringPrintf(kFindSinkScript, receiver().c_str()); 420 std::string script = base::StringPrintf(kFindSinkScript, receiver().c_str());
402 return ExecuteScriptAndExtractBool(dialog_contents, script); 421 return ExecuteScriptAndExtractBool(dialog_contents, script);
403 } 422 }
404 423
405 void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI() { 424 void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI() {
mark a. foltz 2017/02/09 23:29:59 How is this different from running kWaitDeviceScri
takumif 2017/02/14 19:11:48 This waits for a sink to appear in the dialog UI,
406 DVLOG(0) << "Receiver name: " << receiver_; 425 DVLOG(0) << "Receiver name: " << receiver_;
407 // Wait for sink to show up in UI. 426 // Wait for sink to show up in UI.
408 ASSERT_TRUE(ConditionalWait( 427 ASSERT_TRUE(ConditionalWait(
409 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), 428 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
410 base::Bind(&MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI, 429 base::Bind(&MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI,
411 base::Unretained(this)))); 430 base::Unretained(this))));
412 } 431 }
413 432
414 bool MediaRouterIntegrationBrowserTest::IsDialogLoaded( 433 bool MediaRouterIntegrationBrowserTest::IsDialogLoaded(
415 content::WebContents* dialog_contents) { 434 WebContents* dialog_contents) {
416 return ExecuteScriptAndExtractBool(dialog_contents, kCheckDialogLoadedScript); 435 return ExecuteScriptAndExtractBool(dialog_contents, kCheckDialogLoadedScript);
417 } 436 }
418 437
419 void MediaRouterIntegrationBrowserTest::WaitUntilDialogFullyLoaded( 438 void MediaRouterIntegrationBrowserTest::WaitUntilDialogFullyLoaded(
420 content::WebContents* dialog_contents) { 439 WebContents* dialog_contents) {
421 ASSERT_TRUE(ConditionalWait( 440 ASSERT_TRUE(ConditionalWait(
422 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), 441 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1),
423 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogLoaded, 442 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogLoaded,
424 base::Unretained(this), dialog_contents))); 443 base::Unretained(this), dialog_contents)));
425 } 444 }
426 445
427 void MediaRouterIntegrationBrowserTest::ParseCommandLine() { 446 void MediaRouterIntegrationBrowserTest::ParseCommandLine() {
428 MediaRouterBaseBrowserTest::ParseCommandLine(); 447 MediaRouterBaseBrowserTest::ParseCommandLine();
429 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 448 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
430 449
431 receiver_ = command_line->GetSwitchValueASCII(kReceiver); 450 receiver_ = command_line->GetSwitchValueASCII(kReceiver);
432 if (receiver_.empty()) 451 if (receiver_.empty())
433 receiver_ = kTestSinkName; 452 receiver_ = kTestSinkName;
434 } 453 }
435 454
436 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { 455 void MediaRouterIntegrationBrowserTest::CheckSessionValidity(
437 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); 456 WebContents* web_contents) {
438 content::WebContents* web_contents =
439 browser()->tab_strip_model()->GetActiveWebContents();
440 ASSERT_TRUE(web_contents);
441 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
442 StartSession(web_contents);
443 WaitUntilSinkDiscoveredOnUI();
444 ChooseSink(web_contents, kTestSinkName);
445 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); 457 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript);
446 std::string session_id(GetStartedConnectionId(web_contents)); 458 std::string session_id(GetStartedConnectionId(web_contents));
447 EXPECT_FALSE(session_id.empty()); 459 EXPECT_FALSE(session_id.empty());
448
449 std::string default_request_session_id( 460 std::string default_request_session_id(
450 GetDefaultRequestSessionId(web_contents)); 461 GetDefaultRequestSessionId(web_contents));
451 EXPECT_EQ(session_id, default_request_session_id); 462 EXPECT_EQ(session_id, default_request_session_id);
463 }
452 464
465 void MediaRouterIntegrationBrowserTest::HideMediaRouterDialog(
466 WebContents* web_contents,
467 bool wait_for_sink) {
468 MediaRouterDialogControllerImpl* controller =
469 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
470 EXPECT_TRUE(controller->IsShowingMediaRouterDialog());
471 if (wait_for_sink)
472 WaitUntilSinkDiscoveredOnUI();
473 controller->HideMediaRouterDialog();
474 }
475
476 WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() {
477 return browser()->tab_strip_model()->GetActiveWebContents();
478 }
479
480 void MediaRouterIntegrationBrowserTest::RunBasicTest() {
481 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
453 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); 482 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript);
454 } 483 }
455 484
456 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 485 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() {
457 MANUAL_SendAndOnMessage) { 486 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
458 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
459 content::WebContents* web_contents =
460 browser()->tab_strip_model()->GetActiveWebContents();
461 ASSERT_TRUE(web_contents);
462 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
463 StartSession(web_contents);
464 WaitUntilSinkDiscoveredOnUI();
465 ChooseSink(web_contents, kTestSinkName);
466 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript);
467 std::string session_id(GetStartedConnectionId(web_contents));
468 EXPECT_FALSE(session_id.empty());
469
470 ExecuteJavaScriptAPI(
471 web_contents,
472 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo"));
473 }
474
475 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_OnClose) {
476 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json"));
477 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
478 content::WebContents* web_contents =
479 browser()->tab_strip_model()->GetActiveWebContents();
480 ASSERT_TRUE(web_contents);
481 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
482 StartSession(web_contents);
483 WaitUntilSinkDiscoveredOnUI();
484 ChooseSink(web_contents, kTestSinkName);
485 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript);
486 std::string session_id(GetStartedConnectionId(web_contents));
487 EXPECT_FALSE(session_id.empty());
488
489 ExecuteJavaScriptAPI(
490 web_contents,
491 base::StringPrintf("%s",
492 kSendMessageAndExpectConnectionCloseOnErrorScript));
493 }
494
495 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
496 MANUAL_Fail_NoProvider) {
497 SetTestData(FILE_PATH_LITERAL("no_provider.json"));
498 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
499 content::WebContents* web_contents =
500 browser()->tab_strip_model()->GetActiveWebContents();
501 ASSERT_TRUE(web_contents);
502 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
503 StartSession(web_contents);
504 WaitUntilSinkDiscoveredOnUI();
505 ChooseSink(web_contents, kTestSinkName);
506 CheckStartFailed(web_contents, "UnknownError",
507 "No provider supports createRoute with source");
508 }
509
510 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
511 MANUAL_Fail_CreateRoute) {
512 SetTestData(FILE_PATH_LITERAL("fail_create_route.json"));
513 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
514 content::WebContents* web_contents =
515 browser()->tab_strip_model()->GetActiveWebContents();
516 ASSERT_TRUE(web_contents);
517 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
518 StartSession(web_contents);
519 WaitUntilSinkDiscoveredOnUI();
520 ChooseSink(web_contents, kTestSinkName);
521 CheckStartFailed(web_contents, "UnknownError", "Unknown sink");
522 }
523
524 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
525 MANUAL_ReconnectSession) {
526 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
527 content::WebContents* web_contents =
528 browser()->tab_strip_model()->GetActiveWebContents();
529 ASSERT_TRUE(web_contents);
530 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
531 StartSession(web_contents);
532 WaitUntilSinkDiscoveredOnUI();
533 ChooseSink(web_contents, kTestSinkName);
534 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript);
535 std::string session_id(GetStartedConnectionId(web_contents)); 487 std::string session_id(GetStartedConnectionId(web_contents));
536 488
537 // Wait a few seconds for MediaRouter to receive updates containing the 489 // Wait a few seconds for MediaRouter to receive updates containing the
538 // created route. 490 // created route.
539 Wait(base::TimeDelta::FromSeconds(3)); 491 Wait(base::TimeDelta::FromSeconds(3));
540 492
541 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html")); 493 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"));
542 content::WebContents* new_web_contents = 494 WebContents* new_web_contents = GetActiveWebContents();
543 browser()->tab_strip_model()->GetActiveWebContents();
544 ASSERT_TRUE(new_web_contents); 495 ASSERT_TRUE(new_web_contents);
545 ASSERT_NE(web_contents, new_web_contents); 496 ASSERT_NE(web_contents, new_web_contents);
546 ExecuteJavaScriptAPI( 497 ExecuteJavaScriptAPI(
547 new_web_contents, 498 new_web_contents,
548 base::StringPrintf("reconnectSession('%s');", session_id.c_str())); 499 base::StringPrintf(kReconnectSessionScript, session_id.c_str()));
549 std::string reconnected_session_id; 500 std::string reconnected_session_id;
550 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 501 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
551 new_web_contents, 502 new_web_contents,
552 "window.domAutomationController.send(reconnectedSession.id)", 503 "window.domAutomationController.send(reconnectedSession.id)",
553 &reconnected_session_id)); 504 &reconnected_session_id));
554 ASSERT_EQ(session_id, reconnected_session_id); 505 ASSERT_EQ(session_id, reconnected_session_id);
555 } 506 }
556 507
508 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) {
509 RunBasicTest();
510 }
511
512 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
513 MANUAL_SendAndOnMessage) {
514 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
515 ExecuteJavaScriptAPI(
516 web_contents,
517 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo"));
518 }
519
520 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
521 MANUAL_CloseAndReconnect) {
522 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
523 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
524
525 // Wait a few seconds for MediaRouter to receive status updates.
526 Wait(base::TimeDelta::FromSeconds(3));
527 std::string session_id(GetStartedConnectionId(web_contents));
528 ExecuteJavaScriptAPI(web_contents, base::StringPrintf(kReconnectSessionScript,
529 session_id.c_str()));
530 }
531
532 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) {
533 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json"));
534 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
535 ExecuteJavaScriptAPI(web_contents,
536 kSendMessageAndExpectConnectionCloseOnErrorScript);
537 }
538
539 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
540 MANUAL_Fail_SendMessage) {
541 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
542 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
543
544 // Wait a few seconds for MediaRouter to receive status updates.
545 Wait(base::TimeDelta::FromSeconds(3));
546 ExecuteJavaScriptAPI(
547 web_contents,
548 base::StringPrintf(kCheckSendMessageFailedScript, "closed"));
549 }
550
551 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
552 MANUAL_Fail_NoProvider) {
553 SetTestData(FILE_PATH_LITERAL("no_provider.json"));
554 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(false);
555 CheckStartFailed(web_contents, "UnknownError",
556 "No provider supports createRoute with source");
557 }
558
559 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
560 MANUAL_Fail_CreateRoute) {
561 SetTestData(FILE_PATH_LITERAL("fail_create_route.json"));
562 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(false);
563 CheckStartFailed(web_contents, "UnknownError", "Unknown sink");
564 }
565
566 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
567 MANUAL_ReconnectSession) {
568 RunReconnectSessionTest();
569 }
570
557 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 571 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
558 MANUAL_Fail_ReconnectSession) { 572 MANUAL_Fail_ReconnectSession) {
559 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); 573 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(true);
560 content::WebContents* web_contents =
561 browser()->tab_strip_model()->GetActiveWebContents();
562 ASSERT_TRUE(web_contents);
563 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
564 content::TestNavigationObserver test_navigation_observer(web_contents, 1);
565 StartSession(web_contents);
566 WaitUntilSinkDiscoveredOnUI();
567 ChooseSink(web_contents, kTestSinkName);
568 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript);
569 std::string session_id(GetStartedConnectionId(web_contents)); 574 std::string session_id(GetStartedConnectionId(web_contents));
570 575
571 // Wait a few seconds for MediaRouter to receive updates containing the 576 // Wait a few seconds for MediaRouter to receive updates containing the
572 // created route. 577 // created route.
573 Wait(base::TimeDelta::FromSeconds(3)); 578 Wait(base::TimeDelta::FromSeconds(3));
574 579
575 SetTestData(FILE_PATH_LITERAL("fail_reconnect_session.json")); 580 SetTestData(FILE_PATH_LITERAL("fail_reconnect_session.json"));
576 OpenTestPage(FILE_PATH_LITERAL("fail_reconnect_session.html")); 581 OpenTestPageInNewTab(FILE_PATH_LITERAL("fail_reconnect_session.html"));
577 content::WebContents* new_web_contents = 582 WebContents* new_web_contents = GetActiveWebContents();
578 browser()->tab_strip_model()->GetActiveWebContents();
579 ASSERT_TRUE(new_web_contents); 583 ASSERT_TRUE(new_web_contents);
580 ExecuteJavaScriptAPI( 584 ExecuteJavaScriptAPI(
581 new_web_contents, 585 new_web_contents,
582 base::StringPrintf("checkReconnectSessionFails('%s');", 586 base::StringPrintf("checkReconnectSessionFails('%s');",
583 session_id.c_str())); 587 session_id.c_str()));
584 } 588 }
585 589
586 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 590 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
587 MANUAL_Fail_StartCancelled) { 591 MANUAL_Fail_StartCancelled) {
588 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); 592 WebContents* web_contents = StartSessionWithTestPage(true);
589 content::WebContents* web_contents = 593 HideMediaRouterDialog(web_contents, false);
590 browser()->tab_strip_model()->GetActiveWebContents();
591 ASSERT_TRUE(web_contents);
592 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript);
593 content::TestNavigationObserver test_navigation_observer(web_contents, 1);
594 StartSession(web_contents);
595
596 MediaRouterDialogControllerImpl* controller =
597 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
598 EXPECT_TRUE(controller->IsShowingMediaRouterDialog());
599 controller->HideMediaRouterDialog();
600 CheckStartFailed(web_contents, "NotAllowedError", "Dialog closed."); 594 CheckStartFailed(web_contents, "NotAllowedError", "Dialog closed.");
601 } 595 }
602 596
603 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 597 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
604 MANUAL_Fail_StartCancelledNoSinks) { 598 MANUAL_Fail_StartCancelledNoSinks) {
605 SetTestData(FILE_PATH_LITERAL("no_sinks.json")); 599 SetTestData(FILE_PATH_LITERAL("no_sinks.json"));
606 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); 600 WebContents* web_contents = StartSessionWithTestPage(false);
607 content::WebContents* web_contents = 601 HideMediaRouterDialog(web_contents, false);
608 browser()->tab_strip_model()->GetActiveWebContents();
609 ASSERT_TRUE(web_contents);
610 content::TestNavigationObserver test_navigation_observer(web_contents, 1);
611 StartSession(web_contents);
612
613 MediaRouterDialogControllerImpl* controller =
614 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
615 EXPECT_TRUE(controller->IsShowingMediaRouterDialog());
616 controller->HideMediaRouterDialog();
617 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); 602 CheckStartFailed(web_contents, "NotFoundError", "No screens found.");
618 } 603 }
619 604
620 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 605 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
621 MANUAL_Fail_StartCancelledNoSupportedSinks) { 606 MANUAL_Fail_StartCancelledNoSupportedSinks) {
622 SetTestData(FILE_PATH_LITERAL("no_supported_sinks.json")); 607 SetTestData(FILE_PATH_LITERAL("no_supported_sinks.json"));
623 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); 608 WebContents* web_contents = StartSessionWithTestPage(false);
624 content::WebContents* web_contents = 609 HideMediaRouterDialog(web_contents, true);
625 browser()->tab_strip_model()->GetActiveWebContents();
626 ASSERT_TRUE(web_contents);
627 content::TestNavigationObserver test_navigation_observer(web_contents, 1);
628 StartSession(web_contents);
629
630 MediaRouterDialogControllerImpl* controller =
631 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
632 EXPECT_TRUE(controller->IsShowingMediaRouterDialog());
633 WaitUntilSinkDiscoveredOnUI();
634 controller->HideMediaRouterDialog();
635 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); 610 CheckStartFailed(web_contents, "NotFoundError", "No screens found.");
636 } 611 }
637 612
613 void MediaRouterIntegrationIncognitoBrowserTest::InstallAndEnableMRExtension() {
614 const extensions::Extension* extension =
615 LoadExtensionIncognito(extension_unpacked_);
616 extension_id_ = extension->id();
617 }
618
619 void MediaRouterIntegrationIncognitoBrowserTest::UninstallMRExtension() {
620 if (!extension_id_.empty()) {
621 UninstallExtension(extension_id_);
622 }
623 }
624
625 Browser* MediaRouterIntegrationIncognitoBrowserTest::browser() {
626 if (!browser_)
627 browser_ = CreateIncognitoBrowser();
628 return browser_;
629 }
630
631 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest,
632 MANUAL_Basic) {
633 RunBasicTest();
634 }
635
636 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest,
637 MANUAL_ReconnectSession) {
638 RunReconnectSessionTest();
639 }
640
638 } // namespace media_router 641 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698