OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/values.h" |
| 6 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
| 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 |
| 9 // C++ support class for javascript-generated asynchronous tests. |
| 10 class WebUIBrowserAsyncGenTest : public WebUIBrowserTest { |
| 11 public: |
| 12 WebUIBrowserAsyncGenTest(); |
| 13 virtual ~WebUIBrowserAsyncGenTest(); |
| 14 |
| 15 protected: |
| 16 class AsyncWebUIMessageHandler : public WebUIMessageHandler { |
| 17 public: |
| 18 AsyncWebUIMessageHandler(); |
| 19 ~AsyncWebUIMessageHandler(); |
| 20 |
| 21 MOCK_METHOD1(HandleTornDown, void(const base::ListValue*)); |
| 22 |
| 23 private: |
| 24 void HandleCallJS(const base::ListValue* list_value) { |
| 25 std::string call_js; |
| 26 ASSERT_TRUE(list_value->GetString(0, &call_js)); |
| 27 DLOG(INFO) << __FUNCTION__ << '(' << call_js << ')'; |
| 28 web_ui_->CallJavascriptFunction(call_js); |
| 29 } |
| 30 |
| 31 virtual void RegisterMessages() OVERRIDE { |
| 32 web_ui_->RegisterMessageCallback("callJS", NewCallback( |
| 33 this, &AsyncWebUIMessageHandler::HandleCallJS)); |
| 34 web_ui_->RegisterMessageCallback("tornDown", NewCallback( |
| 35 this, &AsyncWebUIMessageHandler::HandleTornDown)); |
| 36 } |
| 37 }; |
| 38 |
| 39 // Handler for this test fixture. |
| 40 ::testing::StrictMock<AsyncWebUIMessageHandler> message_handler_; |
| 41 |
| 42 private: |
| 43 // Provide this object's handler. |
| 44 virtual WebUIMessageHandler* GetMockMessageHandler() OVERRIDE { |
| 45 return &message_handler_; |
| 46 } |
| 47 |
| 48 virtual void SetUpOnMainThread() OVERRIDE { |
| 49 WebUIBrowserTest::SetUpOnMainThread(); |
| 50 EXPECT_CALL(message_handler_, HandleTornDown(::testing::_)); |
| 51 } |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(WebUIBrowserAsyncGenTest); |
| 54 }; |
OLD | NEW |