Revert of Merge duplicate code in invalidation helper. (patchset #2 id:40001 of https...
[chromium-blink-merge.git] / sync / js / js_test_util.h
blobb5ae4e8d78ae58c217cf94ffe89c3332c0370b30
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.
5 #ifndef SYNC_JS_JS_TEST_UTIL_H_
6 #define SYNC_JS_JS_TEST_UTIL_H_
8 #include <ostream>
9 #include <string>
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"
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
23 namespace syncer {
25 class JsEventDetails;
27 // Defined for googletest. Equivalent to "*os << args.ToString()".
28 void PrintTo(const JsEventDetails& details, ::std::ostream* os);
30 // A gmock matcher for JsEventDetails. Use like:
32 // EXPECT_CALL(mock, HandleJsEvent("foo", HasArgs(expected_details)));
33 ::testing::Matcher<const JsEventDetails&> HasDetails(
34 const JsEventDetails& expected_details);
36 // Like HasDetails() but takes a DictionaryValue instead.
37 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary(
38 const base::DictionaryValue& expected_details);
40 // Mocks.
42 class MockJsBackend : public JsBackend,
43 public base::SupportsWeakPtr<MockJsBackend> {
44 public:
45 MockJsBackend();
46 virtual ~MockJsBackend();
48 WeakHandle<JsBackend> AsWeakHandle();
50 MOCK_METHOD1(SetJsEventHandler, void(const WeakHandle<JsEventHandler>&));
53 class MockJsController : public JsController,
54 public base::SupportsWeakPtr<MockJsController> {
55 public:
56 MockJsController();
57 virtual ~MockJsController();
59 MOCK_METHOD1(AddJsEventHandler, void(JsEventHandler*));
60 MOCK_METHOD1(RemoveJsEventHandler, void(JsEventHandler*));
63 class MockJsEventHandler
64 : public JsEventHandler,
65 public base::SupportsWeakPtr<MockJsEventHandler> {
66 public:
67 MockJsEventHandler();
68 virtual ~MockJsEventHandler();
70 WeakHandle<JsEventHandler> AsWeakHandle();
72 MOCK_METHOD2(HandleJsEvent,
73 void(const ::std::string&, const JsEventDetails&));
76 } // namespace syncer
78 #endif // SYNC_JS_JS_TEST_UTIL_H_