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

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

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

Powered by Google App Engine
This is Rietveld 408576698