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

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

Issue 1413403003: [Media Router] Auto-close Media Router dialog after starting or stopping a session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missed renaming. Created 5 years, 2 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 " sinks[i].click();" 48 " sinks[i].click();"
49 " break;" 49 " break;"
50 "}}"; 50 "}}";
51 const char kCloseRouteScript[] = 51 const char kCloseRouteScript[] =
52 "window.document.getElementById('media-router-container').shadowRoot." 52 "window.document.getElementById('media-router-container').shadowRoot."
53 " getElementById('route-details').shadowRoot.getElementById(" 53 " getElementById('route-details').shadowRoot.getElementById("
54 " 'close-route-button').click()"; 54 " 'close-route-button').click()";
55 const char kGetRouteLengthScript[] = 55 const char kGetRouteLengthScript[] =
56 "domAutomationController.send(window.document.getElementById(" 56 "domAutomationController.send(window.document.getElementById("
57 " 'media-router-container').routeList.length)"; 57 " 'media-router-container').routeList.length)";
58 58 const char kClickDialog[] =
59 "window.document.getElementById('media-router-container').click();";
59 std::string GetStartedSessionId(content::WebContents* web_contents) { 60 std::string GetStartedSessionId(content::WebContents* web_contents) {
60 std::string session_id; 61 std::string session_id;
61 CHECK(content::ExecuteScriptAndExtractString( 62 CHECK(content::ExecuteScriptAndExtractString(
62 web_contents, "window.domAutomationController.send(startedSession.id)", 63 web_contents, "window.domAutomationController.send(startedSession.id)",
63 &session_id)); 64 &session_id));
64 return session_id; 65 return session_id;
65 } 66 }
66 67
67 std::string GetDefaultRequestSessionId(content::WebContents* web_contents) { 68 std::string GetDefaultRequestSessionId(content::WebContents* web_contents) {
68 std::string session_id; 69 std::string session_id;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 void MediaRouterIntegrationBrowserTest::ChooseSink( 138 void MediaRouterIntegrationBrowserTest::ChooseSink(
138 content::WebContents* web_contents, 139 content::WebContents* web_contents,
139 const std::string& sink_name) { 140 const std::string& sink_name) {
140 content::WebContents* dialog_contents = GetMRDialog(web_contents); 141 content::WebContents* dialog_contents = GetMRDialog(web_contents);
141 std::string script = base::StringPrintf( 142 std::string script = base::StringPrintf(
142 kChooseSinkScript, sink_name.c_str()); 143 kChooseSinkScript, sink_name.c_str());
143 ASSERT_TRUE(content::ExecuteScript(dialog_contents, script)); 144 ASSERT_TRUE(content::ExecuteScript(dialog_contents, script));
144 } 145 }
145 146
147 void MediaRouterIntegrationBrowserTest::ClickDialog() {
148 content::WebContents* web_contents =
149 browser()->tab_strip_model()->GetActiveWebContents();
150 content::WebContents* dialog_contents = GetMRDialog(web_contents);
151 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kClickDialog));
152 }
146 content::WebContents* MediaRouterIntegrationBrowserTest::GetMRDialog( 153 content::WebContents* MediaRouterIntegrationBrowserTest::GetMRDialog(
147 content::WebContents* web_contents) { 154 content::WebContents* web_contents) {
148 MediaRouterDialogControllerImpl* controller = 155 MediaRouterDialogControllerImpl* controller =
149 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); 156 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
150 content::WebContents* dialog_contents = controller->GetMediaRouterDialog(); 157 content::WebContents* dialog_contents = controller->GetMediaRouterDialog();
151 CHECK(dialog_contents); 158 CHECK(dialog_contents);
152 return dialog_contents; 159 return dialog_contents;
153 } 160 }
154 161
162 bool MediaRouterIntegrationBrowserTest::IsDialogClosed(
163 content::WebContents* web_contents) {
164 MediaRouterDialogControllerImpl* controller =
165 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents);
166 return !controller->GetMediaRouterDialog();
167 }
168
169 void MediaRouterIntegrationBrowserTest::WaitUntilDialogClosed(
170 content::WebContents* web_contents) {
171 ASSERT_TRUE(ConditionalWait(
172 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1),
173 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed,
174 base::Unretained(this), web_contents)));
175 }
176
177 void MediaRouterIntegrationBrowserTest::CheckDialogRemainsOpen(
178 content::WebContents* web_contents) {
179 ASSERT_FALSE(ConditionalWait(
180 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(1),
181 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed,
182 base::Unretained(this), web_contents)));
183 }
184
155 void MediaRouterIntegrationBrowserTest::SetTestData( 185 void MediaRouterIntegrationBrowserTest::SetTestData(
156 base::FilePath::StringPieceType test_data_file) { 186 base::FilePath::StringPieceType test_data_file) {
157 base::FilePath full_path = GetResourceFile(test_data_file); 187 base::FilePath full_path = GetResourceFile(test_data_file);
158 JSONFileValueDeserializer deserializer(full_path); 188 JSONFileValueDeserializer deserializer(full_path);
159 int error_code = 0; 189 int error_code = 0;
160 std::string error_message; 190 std::string error_message;
161 scoped_ptr<base::Value> value = 191 scoped_ptr<base::Value> value =
162 deserializer.Deserialize(&error_code, &error_message); 192 deserializer.Deserialize(&error_code, &error_message);
163 CHECK(value.get()) << "Deserialize failed: " << error_message; 193 CHECK(value.get()) << "Deserialize failed: " << error_message;
164 std::string test_data_str; 194 std::string test_data_str;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 content::WebContents* new_web_contents = 397 content::WebContents* new_web_contents =
368 browser()->tab_strip_model()->GetActiveWebContents(); 398 browser()->tab_strip_model()->GetActiveWebContents();
369 ASSERT_TRUE(new_web_contents); 399 ASSERT_TRUE(new_web_contents);
370 ExecuteJavaScriptAPI( 400 ExecuteJavaScriptAPI(
371 new_web_contents, 401 new_web_contents,
372 base::StringPrintf("checkReconnectSessionFails('%s');", 402 base::StringPrintf("checkReconnectSessionFails('%s');",
373 session_id.c_str())); 403 session_id.c_str()));
374 } 404 }
375 405
376 } // namespace media_router 406 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698