| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/web_ui_browsertest.h" | 4 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 9 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_navigator.h" | 16 #include "chrome/browser/ui/browser_navigator.h" |
| 15 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 17 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
| 16 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 18 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 class AsyncWebUIMessageHandler : public WebUIMessageHandler { | 459 class AsyncWebUIMessageHandler : public WebUIMessageHandler { |
| 458 public: | 460 public: |
| 459 AsyncWebUIMessageHandler() {} | 461 AsyncWebUIMessageHandler() {} |
| 460 | 462 |
| 461 MOCK_METHOD1(HandleTestContinues, void(const ListValue*)); | 463 MOCK_METHOD1(HandleTestContinues, void(const ListValue*)); |
| 462 MOCK_METHOD1(HandleTestFails, void(const ListValue*)); | 464 MOCK_METHOD1(HandleTestFails, void(const ListValue*)); |
| 463 MOCK_METHOD1(HandleTestPasses, void(const ListValue*)); | 465 MOCK_METHOD1(HandleTestPasses, void(const ListValue*)); |
| 464 | 466 |
| 465 private: | 467 private: |
| 466 virtual void RegisterMessages() OVERRIDE { | 468 virtual void RegisterMessages() OVERRIDE { |
| 467 web_ui_->RegisterMessageCallback("startAsyncTest", NewCallback( | 469 web_ui_->RegisterMessageCallback("startAsyncTest", |
| 468 this, &AsyncWebUIMessageHandler::HandleStartAsyncTest)); | 470 base::Bind(&AsyncWebUIMessageHandler::HandleStartAsyncTest, |
| 469 web_ui_->RegisterMessageCallback("testContinues", NewCallback( | 471 base::Unretained(this))); |
| 470 this, &AsyncWebUIMessageHandler::HandleTestContinues)); | 472 web_ui_->RegisterMessageCallback("testContinues", |
| 471 web_ui_->RegisterMessageCallback("testFails", NewCallback( | 473 base::Bind(&AsyncWebUIMessageHandler::HandleTestContinues, |
| 472 this, &AsyncWebUIMessageHandler::HandleTestFails)); | 474 base::Unretained(this))); |
| 473 web_ui_->RegisterMessageCallback("testPasses", NewCallback( | 475 web_ui_->RegisterMessageCallback("testFails", |
| 474 this, &AsyncWebUIMessageHandler::HandleTestPasses)); | 476 base::Bind(&AsyncWebUIMessageHandler::HandleTestFails, |
| 477 base::Unretained(this))); |
| 478 web_ui_->RegisterMessageCallback("testPasses", |
| 479 base::Bind(&AsyncWebUIMessageHandler::HandleTestPasses, |
| 480 base::Unretained(this))); |
| 475 } | 481 } |
| 476 | 482 |
| 477 // Starts the test in |list_value|[0] with the runAsync wrapper. | 483 // Starts the test in |list_value|[0] with the runAsync wrapper. |
| 478 void HandleStartAsyncTest(const ListValue* list_value) { | 484 void HandleStartAsyncTest(const ListValue* list_value) { |
| 479 Value* test_name; | 485 Value* test_name; |
| 480 ASSERT_TRUE(list_value->Get(0, &test_name)); | 486 ASSERT_TRUE(list_value->Get(0, &test_name)); |
| 481 web_ui_->CallJavascriptFunction("runAsync", *test_name); | 487 web_ui_->CallJavascriptFunction("runAsync", *test_name); |
| 482 } | 488 } |
| 483 | 489 |
| 484 DISALLOW_COPY_AND_ASSIGN(AsyncWebUIMessageHandler); | 490 DISALLOW_COPY_AND_ASSIGN(AsyncWebUIMessageHandler); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // testDone directly and expect pass result. | 593 // testDone directly and expect pass result. |
| 588 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 594 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 589 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 595 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 590 } | 596 } |
| 591 | 597 |
| 592 // Test that calling testDone during RunJavascriptTest still completes when | 598 // Test that calling testDone during RunJavascriptTest still completes when |
| 593 // waiting for async result. | 599 // waiting for async result. |
| 594 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 600 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 595 ASSERT_TRUE(RunJavascriptTest("testDone")); | 601 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 596 } | 602 } |
| OLD | NEW |