| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/web_ui_browsertest.h" | 5 #include "chrome/test/base/web_ui_browsertest.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 454 |
| 455 GURL WebUIBrowserTest::WebUITestDataPathToURL( | 455 GURL WebUIBrowserTest::WebUITestDataPathToURL( |
| 456 const base::FilePath::StringType& path) { | 456 const base::FilePath::StringType& path) { |
| 457 base::FilePath dir_test_data; | 457 base::FilePath dir_test_data; |
| 458 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); | 458 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); |
| 459 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); | 459 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); |
| 460 EXPECT_TRUE(base::PathExists(test_path)); | 460 EXPECT_TRUE(base::PathExists(test_path)); |
| 461 return net::FilePathToFileURL(test_path); | 461 return net::FilePathToFileURL(test_path); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void WebUIBrowserTest::BuildJavascriptLibraries(string16* content) { | 464 void WebUIBrowserTest::BuildJavascriptLibraries(base::string16* content) { |
| 465 ASSERT_TRUE(content != NULL); | 465 ASSERT_TRUE(content != NULL); |
| 466 std::string utf8_content; | 466 std::string utf8_content; |
| 467 std::vector<base::FilePath>::iterator user_libraries_iterator; | 467 std::vector<base::FilePath>::iterator user_libraries_iterator; |
| 468 for (user_libraries_iterator = user_libraries_.begin(); | 468 for (user_libraries_iterator = user_libraries_.begin(); |
| 469 user_libraries_iterator != user_libraries_.end(); | 469 user_libraries_iterator != user_libraries_.end(); |
| 470 ++user_libraries_iterator) { | 470 ++user_libraries_iterator) { |
| 471 std::string library_content; | 471 std::string library_content; |
| 472 if (user_libraries_iterator->IsAbsolute()) { | 472 if (user_libraries_iterator->IsAbsolute()) { |
| 473 ASSERT_TRUE(base::ReadFileToString(*user_libraries_iterator, | 473 ASSERT_TRUE(base::ReadFileToString(*user_libraries_iterator, |
| 474 &library_content)) | 474 &library_content)) |
| 475 << user_libraries_iterator->value(); | 475 << user_libraries_iterator->value(); |
| 476 } else { | 476 } else { |
| 477 bool ok = base::ReadFileToString( | 477 bool ok = base::ReadFileToString( |
| 478 gen_test_data_directory_.Append(*user_libraries_iterator), | 478 gen_test_data_directory_.Append(*user_libraries_iterator), |
| 479 &library_content); | 479 &library_content); |
| 480 if (!ok) { | 480 if (!ok) { |
| 481 ok = base::ReadFileToString( | 481 ok = base::ReadFileToString( |
| 482 test_data_directory_.Append(*user_libraries_iterator), | 482 test_data_directory_.Append(*user_libraries_iterator), |
| 483 &library_content); | 483 &library_content); |
| 484 } | 484 } |
| 485 ASSERT_TRUE(ok) << user_libraries_iterator->value(); | 485 ASSERT_TRUE(ok) << user_libraries_iterator->value(); |
| 486 } | 486 } |
| 487 utf8_content.append(library_content); | 487 utf8_content.append(library_content); |
| 488 utf8_content.append(";\n"); | 488 utf8_content.append(";\n"); |
| 489 } | 489 } |
| 490 content->append(UTF8ToUTF16(utf8_content)); | 490 content->append(UTF8ToUTF16(utf8_content)); |
| 491 } | 491 } |
| 492 | 492 |
| 493 string16 WebUIBrowserTest::BuildRunTestJSCall( | 493 base::string16 WebUIBrowserTest::BuildRunTestJSCall( |
| 494 bool is_async, | 494 bool is_async, |
| 495 const std::string& function_name, | 495 const std::string& function_name, |
| 496 const WebUIBrowserTest::ConstValueVector& test_func_args) { | 496 const WebUIBrowserTest::ConstValueVector& test_func_args) { |
| 497 ConstValueVector arguments; | 497 ConstValueVector arguments; |
| 498 base::FundamentalValue* is_async_arg = new base::FundamentalValue(is_async); | 498 base::FundamentalValue* is_async_arg = new base::FundamentalValue(is_async); |
| 499 arguments.push_back(is_async_arg); | 499 arguments.push_back(is_async_arg); |
| 500 base::StringValue* function_name_arg = new base::StringValue(function_name); | 500 base::StringValue* function_name_arg = new base::StringValue(function_name); |
| 501 arguments.push_back(function_name_arg); | 501 arguments.push_back(function_name_arg); |
| 502 base::ListValue* baked_argument_list = new base::ListValue(); | 502 base::ListValue* baked_argument_list = new base::ListValue(); |
| 503 ConstValueVector::const_iterator arguments_iterator; | 503 ConstValueVector::const_iterator arguments_iterator; |
| 504 for (arguments_iterator = test_func_args.begin(); | 504 for (arguments_iterator = test_func_args.begin(); |
| 505 arguments_iterator != test_func_args.end(); | 505 arguments_iterator != test_func_args.end(); |
| 506 ++arguments_iterator) { | 506 ++arguments_iterator) { |
| 507 baked_argument_list->Append((*arguments_iterator)->DeepCopy()); | 507 baked_argument_list->Append((*arguments_iterator)->DeepCopy()); |
| 508 } | 508 } |
| 509 arguments.push_back(baked_argument_list); | 509 arguments.push_back(baked_argument_list); |
| 510 return content::WebUI::GetJavascriptCall(std::string("runTest"), | 510 return content::WebUI::GetJavascriptCall(std::string("runTest"), |
| 511 arguments.get()); | 511 arguments.get()); |
| 512 } | 512 } |
| 513 | 513 |
| 514 bool WebUIBrowserTest::RunJavascriptUsingHandler( | 514 bool WebUIBrowserTest::RunJavascriptUsingHandler( |
| 515 const std::string& function_name, | 515 const std::string& function_name, |
| 516 const ConstValueVector& function_arguments, | 516 const ConstValueVector& function_arguments, |
| 517 bool is_test, | 517 bool is_test, |
| 518 bool is_async, | 518 bool is_async, |
| 519 RenderViewHost* preload_host) { | 519 RenderViewHost* preload_host) { |
| 520 | 520 |
| 521 string16 content; | 521 base::string16 content; |
| 522 if (!libraries_preloaded_) | 522 if (!libraries_preloaded_) |
| 523 BuildJavascriptLibraries(&content); | 523 BuildJavascriptLibraries(&content); |
| 524 | 524 |
| 525 if (!function_name.empty()) { | 525 if (!function_name.empty()) { |
| 526 string16 called_function; | 526 base::string16 called_function; |
| 527 if (is_test) { | 527 if (is_test) { |
| 528 called_function = | 528 called_function = |
| 529 BuildRunTestJSCall(is_async, function_name, function_arguments); | 529 BuildRunTestJSCall(is_async, function_name, function_arguments); |
| 530 } else { | 530 } else { |
| 531 called_function = | 531 called_function = |
| 532 content::WebUI::GetJavascriptCall(function_name, | 532 content::WebUI::GetJavascriptCall(function_name, |
| 533 function_arguments.get()); | 533 function_arguments.get()); |
| 534 } | 534 } |
| 535 content.append(called_function); | 535 content.append(called_function); |
| 536 } | 536 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // testDone directly and expect pass result. | 789 // testDone directly and expect pass result. |
| 790 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 790 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 791 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 791 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 792 } | 792 } |
| 793 | 793 |
| 794 // Test that calling testDone during RunJavascriptTest still completes when | 794 // Test that calling testDone during RunJavascriptTest still completes when |
| 795 // waiting for async result. | 795 // waiting for async result. |
| 796 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 796 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 797 ASSERT_TRUE(RunJavascriptTest("testDone")); | 797 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 798 } | 798 } |
| OLD | NEW |