| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 #ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MOCK_RPC_H_ | |
| 6 #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MOCK_RPC_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/string_util.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "webkit/glue/devtools/devtools_rpc.h" | |
| 13 #include "webkit/glue/glue_util.h" | |
| 14 | |
| 15 // Universal mock delegate for DevToolsRpc. Typical usage of the mock is: | |
| 16 // mock->Method1(); // Set expectation. | |
| 17 // mock->Replay(); | |
| 18 // // Do Something here; | |
| 19 // mock->Verify(); // Verify. | |
| 20 class DevToolsMockRpc : public DevToolsRpc::Delegate { | |
| 21 public: | |
| 22 DevToolsMockRpc() {} | |
| 23 ~DevToolsMockRpc() {} | |
| 24 | |
| 25 virtual void SendRpcMessage(const std::string& class_name, | |
| 26 const std::string& method_name, | |
| 27 const std::string& msg) { | |
| 28 last_class_name_ = class_name; | |
| 29 last_method_name_ = method_name; | |
| 30 last_msg_ = msg; | |
| 31 | |
| 32 if (!log_.length()) { | |
| 33 log_ = StringPrintf("%s %s %s", class_name.c_str(), | |
| 34 method_name.c_str(), msg.c_str());; | |
| 35 } else { | |
| 36 log_ = StringPrintf("%s\n%s %s %s", log_.c_str(), class_name.c_str(), | |
| 37 method_name.c_str(), msg.c_str()); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 void Replay() { | |
| 42 ref_last_class_name_ = last_class_name_; | |
| 43 last_class_name_ = ""; | |
| 44 ref_last_method_name_ = last_method_name_; | |
| 45 last_method_name_ = ""; | |
| 46 ref_last_msg_ = last_msg_; | |
| 47 last_msg_ = ""; | |
| 48 | |
| 49 ref_log_ = log_; | |
| 50 log_ = ""; | |
| 51 } | |
| 52 | |
| 53 void Verify() { | |
| 54 ASSERT_EQ(ref_last_class_name_, last_class_name_); | |
| 55 ASSERT_EQ(ref_last_method_name_, last_method_name_); | |
| 56 ASSERT_EQ(ref_last_msg_, last_msg_); | |
| 57 ASSERT_EQ(ref_log_, log_); | |
| 58 } | |
| 59 | |
| 60 void Reset() { | |
| 61 last_class_name_ = ""; | |
| 62 last_method_name_ = ""; | |
| 63 last_msg_ = ""; | |
| 64 | |
| 65 ref_last_class_name_ = ""; | |
| 66 ref_last_method_name_ = ""; | |
| 67 ref_last_msg_ = ""; | |
| 68 | |
| 69 ref_log_ = ""; | |
| 70 log_ = ""; | |
| 71 } | |
| 72 | |
| 73 const std::string& last_class_name() { return last_class_name_; } | |
| 74 const std::string& last_method_name() { return last_method_name_; } | |
| 75 const std::string& last_msg() { return last_msg_; } | |
| 76 | |
| 77 private: | |
| 78 std::string last_class_name_; | |
| 79 std::string last_method_name_; | |
| 80 std::string last_msg_; | |
| 81 | |
| 82 std::string ref_last_class_name_; | |
| 83 std::string ref_last_method_name_; | |
| 84 std::string ref_last_msg_; | |
| 85 | |
| 86 std::string log_; | |
| 87 std::string ref_log_; | |
| 88 DISALLOW_COPY_AND_ASSIGN(DevToolsMockRpc); | |
| 89 }; | |
| 90 | |
| 91 #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_MOCK_RPC_H_ | |
| OLD | NEW |