| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SYNC_JS_JS_TEST_UTIL_H_ | |
| 6 #define SYNC_JS_JS_TEST_UTIL_H_ | |
| 7 | |
| 8 #include <ostream> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "sync/internal_api/public/util/weak_handle.h" | |
| 13 #include "sync/js/js_backend.h" | |
| 14 #include "sync/js/js_controller.h" | |
| 15 #include "sync/js/js_event_handler.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class DictionaryValue; | |
| 20 class ListValue; | |
| 21 } | |
| 22 | |
| 23 namespace syncer { | |
| 24 | |
| 25 class JsEventDetails; | |
| 26 | |
| 27 // Defined for googletest. Equivalent to "*os << args.ToString()". | |
| 28 void PrintTo(const JsEventDetails& details, ::std::ostream* os); | |
| 29 | |
| 30 // A gmock matcher for JsEventDetails. Use like: | |
| 31 // | |
| 32 // EXPECT_CALL(mock, HandleJsEvent("foo", HasArgs(expected_details))); | |
| 33 ::testing::Matcher<const JsEventDetails&> HasDetails( | |
| 34 const JsEventDetails& expected_details); | |
| 35 | |
| 36 // Like HasDetails() but takes a DictionaryValue instead. | |
| 37 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary( | |
| 38 const base::DictionaryValue& expected_details); | |
| 39 | |
| 40 // Mocks. | |
| 41 | |
| 42 class MockJsBackend : public JsBackend, | |
| 43 public base::SupportsWeakPtr<MockJsBackend> { | |
| 44 public: | |
| 45 MockJsBackend(); | |
| 46 virtual ~MockJsBackend(); | |
| 47 | |
| 48 WeakHandle<JsBackend> AsWeakHandle(); | |
| 49 | |
| 50 MOCK_METHOD1(SetJsEventHandler, void(const WeakHandle<JsEventHandler>&)); | |
| 51 }; | |
| 52 | |
| 53 class MockJsController : public JsController, | |
| 54 public base::SupportsWeakPtr<MockJsController> { | |
| 55 public: | |
| 56 MockJsController(); | |
| 57 virtual ~MockJsController(); | |
| 58 | |
| 59 MOCK_METHOD1(AddJsEventHandler, void(JsEventHandler*)); | |
| 60 MOCK_METHOD1(RemoveJsEventHandler, void(JsEventHandler*)); | |
| 61 }; | |
| 62 | |
| 63 class MockJsEventHandler | |
| 64 : public JsEventHandler, | |
| 65 public base::SupportsWeakPtr<MockJsEventHandler> { | |
| 66 public: | |
| 67 MockJsEventHandler(); | |
| 68 virtual ~MockJsEventHandler(); | |
| 69 | |
| 70 WeakHandle<JsEventHandler> AsWeakHandle(); | |
| 71 | |
| 72 MOCK_METHOD2(HandleJsEvent, | |
| 73 void(const ::std::string&, const JsEventDetails&)); | |
| 74 }; | |
| 75 | |
| 76 } // namespace syncer | |
| 77 | |
| 78 #endif // SYNC_JS_JS_TEST_UTIL_H_ | |
| OLD | NEW |