| 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 <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" |
| 11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im
pl.h" | 22 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im
pl.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed, | 277 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogClosed, |
| 277 base::Unretained(this), web_contents))); | 278 base::Unretained(this), web_contents))); |
| 278 } | 279 } |
| 279 | 280 |
| 280 void MediaRouterIntegrationBrowserTest::SetTestData( | 281 void MediaRouterIntegrationBrowserTest::SetTestData( |
| 281 base::FilePath::StringPieceType test_data_file) { | 282 base::FilePath::StringPieceType test_data_file) { |
| 282 base::FilePath full_path = GetResourceFile(test_data_file); | 283 base::FilePath full_path = GetResourceFile(test_data_file); |
| 283 JSONFileValueDeserializer deserializer(full_path); | 284 JSONFileValueDeserializer deserializer(full_path); |
| 284 int error_code = 0; | 285 int error_code = 0; |
| 285 std::string error_message; | 286 std::string error_message; |
| 286 std::unique_ptr<base::Value> value = | 287 std::unique_ptr<base::Value> value; |
| 287 deserializer.Deserialize(&error_code, &error_message); | 288 { |
| 289 // crbug.com/724573 |
| 290 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 291 value = deserializer.Deserialize(&error_code, &error_message); |
| 292 } |
| 288 CHECK(value.get()) << "Deserialize failed: " << error_message; | 293 CHECK(value.get()) << "Deserialize failed: " << error_message; |
| 289 std::string test_data_str; | 294 std::string test_data_str; |
| 290 ASSERT_TRUE(base::JSONWriter::Write(*value, &test_data_str)); | 295 ASSERT_TRUE(base::JSONWriter::Write(*value, &test_data_str)); |
| 291 ExecuteScriptInBackgroundPageNoWait( | 296 ExecuteScriptInBackgroundPageNoWait( |
| 292 extension_id_, | 297 extension_id_, |
| 293 base::StringPrintf("localStorage['testdata'] = '%s'", | 298 base::StringPrintf("localStorage['testdata'] = '%s'", |
| 294 test_data_str.c_str())); | 299 test_data_str.c_str())); |
| 295 } | 300 } |
| 296 | 301 |
| 297 WebContents* MediaRouterIntegrationBrowserTest::OpenMRDialog( | 302 WebContents* MediaRouterIntegrationBrowserTest::OpenMRDialog( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 311 } | 316 } |
| 312 | 317 |
| 313 base::FilePath MediaRouterIntegrationBrowserTest::GetResourceFile( | 318 base::FilePath MediaRouterIntegrationBrowserTest::GetResourceFile( |
| 314 base::FilePath::StringPieceType relative_path) const { | 319 base::FilePath::StringPieceType relative_path) const { |
| 315 base::FilePath base_dir; | 320 base::FilePath base_dir; |
| 316 // ASSERT_TRUE can only be used in void returning functions. | 321 // ASSERT_TRUE can only be used in void returning functions. |
| 317 // Use CHECK instead in non-void returning functions. | 322 // Use CHECK instead in non-void returning functions. |
| 318 CHECK(PathService::Get(base::DIR_MODULE, &base_dir)); | 323 CHECK(PathService::Get(base::DIR_MODULE, &base_dir)); |
| 319 base::FilePath full_path = | 324 base::FilePath full_path = |
| 320 base_dir.Append(kResourcePath).Append(relative_path); | 325 base_dir.Append(kResourcePath).Append(relative_path); |
| 321 CHECK(PathExists(full_path)); | 326 { |
| 327 // crbug.com/724573 |
| 328 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 329 CHECK(PathExists(full_path)); |
| 330 } |
| 322 return full_path; | 331 return full_path; |
| 323 } | 332 } |
| 324 | 333 |
| 325 int MediaRouterIntegrationBrowserTest::ExecuteScriptAndExtractInt( | 334 int MediaRouterIntegrationBrowserTest::ExecuteScriptAndExtractInt( |
| 326 const content::ToRenderFrameHost& adapter, const std::string& script) { | 335 const content::ToRenderFrameHost& adapter, const std::string& script) { |
| 327 int result; | 336 int result; |
| 328 CHECK(content::ExecuteScriptAndExtractInt(adapter, script, &result)); | 337 CHECK(content::ExecuteScriptAndExtractInt(adapter, script, &result)); |
| 329 return result; | 338 return result; |
| 330 } | 339 } |
| 331 | 340 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 MANUAL_Basic) { | 668 MANUAL_Basic) { |
| 660 RunBasicTest(); | 669 RunBasicTest(); |
| 661 } | 670 } |
| 662 | 671 |
| 663 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest, | 672 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest, |
| 664 MANUAL_ReconnectSession) { | 673 MANUAL_ReconnectSession) { |
| 665 RunReconnectSessionTest(); | 674 RunReconnectSessionTest(); |
| 666 } | 675 } |
| 667 | 676 |
| 668 } // namespace media_router | 677 } // namespace media_router |
| OLD | NEW |