| OLD | NEW |
| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im
pl.h" | 19 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im
pl.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 23 #include "content/public/test/test_navigation_observer.h" | 24 #include "content/public/test/test_navigation_observer.h" |
| 24 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 25 #include "net/base/filename_util.h" | 26 #include "net/base/filename_util.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "ui/base/l10n/l10n_util.h" |
| 27 | 29 |
| 28 | 30 |
| 29 namespace media_router { | 31 namespace media_router { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 // The path relative to <chromium src>/out/<build config> for media router | 34 // The path relative to <chromium src>/out/<build config> for media router |
| 33 // browser test resources. | 35 // browser test resources. |
| 34 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( | 36 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( |
| 35 "media_router/browser_test_resources/"); | 37 "media_router/browser_test_resources/"); |
| 36 // The javascript snippets. | 38 // The javascript snippets. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return ExecuteScriptAndExtractInt(dialog_contents, script) == 1; | 220 return ExecuteScriptAndExtractInt(dialog_contents, script) == 1; |
| 219 } | 221 } |
| 220 | 222 |
| 221 void MediaRouterIntegrationBrowserTest::WaitUntilRouteCreated() { | 223 void MediaRouterIntegrationBrowserTest::WaitUntilRouteCreated() { |
| 222 ASSERT_TRUE(ConditionalWait( | 224 ASSERT_TRUE(ConditionalWait( |
| 223 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), | 225 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), |
| 224 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI, | 226 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI, |
| 225 base::Unretained(this)))); | 227 base::Unretained(this)))); |
| 226 } | 228 } |
| 227 | 229 |
| 230 void MediaRouterIntegrationBrowserTest::WaitUntilRouteCreationTimeout() { |
| 231 ASSERT_FALSE(ConditionalWait( |
| 232 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| 233 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI, |
| 234 base::Unretained(this)))); |
| 235 } |
| 236 |
| 228 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { | 237 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { |
| 229 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 238 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| 230 content::WebContents* web_contents = | 239 content::WebContents* web_contents = |
| 231 browser()->tab_strip_model()->GetActiveWebContents(); | 240 browser()->tab_strip_model()->GetActiveWebContents(); |
| 232 ASSERT_TRUE(web_contents); | 241 ASSERT_TRUE(web_contents); |
| 233 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | 242 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| 234 StartSession(web_contents); | 243 StartSession(web_contents); |
| 235 ChooseSink(web_contents, "id1", ""); | 244 ChooseSink(web_contents, "id1", ""); |
| 236 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | 245 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| 237 Wait(base::TimeDelta::FromSeconds(5)); | 246 Wait(base::TimeDelta::FromSeconds(5)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 249 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 258 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 250 MANUAL_Fail_No_Provider) { | 259 MANUAL_Fail_No_Provider) { |
| 251 SetTestData(FILE_PATH_LITERAL("no_provider.json")); | 260 SetTestData(FILE_PATH_LITERAL("no_provider.json")); |
| 252 OpenTestPage(FILE_PATH_LITERAL("no_provider.html")); | 261 OpenTestPage(FILE_PATH_LITERAL("no_provider.html")); |
| 253 content::WebContents* web_contents = | 262 content::WebContents* web_contents = |
| 254 browser()->tab_strip_model()->GetActiveWebContents(); | 263 browser()->tab_strip_model()->GetActiveWebContents(); |
| 255 ASSERT_TRUE(web_contents); | 264 ASSERT_TRUE(web_contents); |
| 256 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | 265 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| 257 StartSession(web_contents); | 266 StartSession(web_contents); |
| 258 ChooseSink(web_contents, "id1", ""); | 267 ChooseSink(web_contents, "id1", ""); |
| 268 WaitUntilRouteCreationTimeout(); |
| 259 ExecuteJavaScriptAPI(web_contents, kCheckSessionFailedScript); | 269 ExecuteJavaScriptAPI(web_contents, kCheckSessionFailedScript); |
| 270 |
| 271 content::WebContents* dialog_contents = GetMRDialog(web_contents); |
| 272 std::string script = base::StringPrintf( |
| 273 "domAutomationController.send(window.document.getElementById(" |
| 274 "'media-router-container').issue.title)"); |
| 275 std::string issue_title = ExecuteScriptAndExtractString( |
| 276 dialog_contents, script); |
| 277 ASSERT_EQ(l10n_util::GetStringUTF8( |
| 278 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT), |
| 279 issue_title); |
| 260 } | 280 } |
| 261 | 281 |
| 262 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 282 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 263 MANUAL_Fail_Create_Route) { | 283 MANUAL_Fail_Create_Route) { |
| 264 SetTestData(FILE_PATH_LITERAL("fail_create_route.json")); | 284 SetTestData(FILE_PATH_LITERAL("fail_create_route.json")); |
| 265 OpenTestPage(FILE_PATH_LITERAL("fail_create_route.html")); | 285 OpenTestPage(FILE_PATH_LITERAL("fail_create_route.html")); |
| 266 content::WebContents* web_contents = | 286 content::WebContents* web_contents = |
| 267 browser()->tab_strip_model()->GetActiveWebContents(); | 287 browser()->tab_strip_model()->GetActiveWebContents(); |
| 268 ASSERT_TRUE(web_contents); | 288 ASSERT_TRUE(web_contents); |
| 269 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | 289 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 content::WebContents* new_web_contents = | 338 content::WebContents* new_web_contents = |
| 319 browser()->tab_strip_model()->GetActiveWebContents(); | 339 browser()->tab_strip_model()->GetActiveWebContents(); |
| 320 ASSERT_TRUE(new_web_contents); | 340 ASSERT_TRUE(new_web_contents); |
| 321 ExecuteJavaScriptAPI( | 341 ExecuteJavaScriptAPI( |
| 322 new_web_contents, | 342 new_web_contents, |
| 323 base::StringPrintf("checkReconnectSessionFails('%s');", | 343 base::StringPrintf("checkReconnectSessionFails('%s');", |
| 324 session_id.c_str())); | 344 session_id.c_str())); |
| 325 } | 345 } |
| 326 | 346 |
| 327 } // namespace media_router | 347 } // namespace media_router |
| OLD | NEW |