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_
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 "sync/js/js_reply_handler.h"
17 #include "testing/gmock/include/gmock/gmock.h"
20 class DictionaryValue
;
29 // Defined for googletest. Equivalent to "*os << args.ToString()".
30 void PrintTo(const JsArgList
& args
, ::std::ostream
* os
);
31 void PrintTo(const JsEventDetails
& details
, ::std::ostream
* os
);
33 // A gmock matcher for JsArgList. Use like:
35 // EXPECT_CALL(mock, HandleJsReply("foo", HasArgs(expected_args)));
36 ::testing::Matcher
<const JsArgList
&> HasArgs(const JsArgList
& expected_args
);
38 // Like HasArgs() but takes a ListValue instead.
39 ::testing::Matcher
<const JsArgList
&> HasArgsAsList(
40 const base::ListValue
& expected_args
);
42 // A gmock matcher for JsEventDetails. Use like:
44 // EXPECT_CALL(mock, HandleJsEvent("foo", HasArgs(expected_details)));
45 ::testing::Matcher
<const JsEventDetails
&> HasDetails(
46 const JsEventDetails
& expected_details
);
48 // Like HasDetails() but takes a DictionaryValue instead.
49 ::testing::Matcher
<const JsEventDetails
&> HasDetailsAsDictionary(
50 const base::DictionaryValue
& expected_details
);
54 class MockJsBackend
: public JsBackend
,
55 public base::SupportsWeakPtr
<MockJsBackend
> {
58 virtual ~MockJsBackend();
60 WeakHandle
<JsBackend
> AsWeakHandle();
62 MOCK_METHOD1(SetJsEventHandler
, void(const WeakHandle
<JsEventHandler
>&));
63 MOCK_METHOD3(ProcessJsMessage
, void(const ::std::string
&, const JsArgList
&,
64 const WeakHandle
<JsReplyHandler
>&));
67 class MockJsController
: public JsController
,
68 public base::SupportsWeakPtr
<MockJsController
> {
71 virtual ~MockJsController();
73 MOCK_METHOD1(AddJsEventHandler
, void(JsEventHandler
*));
74 MOCK_METHOD1(RemoveJsEventHandler
, void(JsEventHandler
*));
75 MOCK_METHOD3(ProcessJsMessage
,
76 void(const ::std::string
&, const JsArgList
&,
77 const WeakHandle
<JsReplyHandler
>&));
80 class MockJsEventHandler
81 : public JsEventHandler
,
82 public base::SupportsWeakPtr
<MockJsEventHandler
> {
85 virtual ~MockJsEventHandler();
87 WeakHandle
<JsEventHandler
> AsWeakHandle();
89 MOCK_METHOD2(HandleJsEvent
,
90 void(const ::std::string
&, const JsEventDetails
&));
93 class MockJsReplyHandler
94 : public JsReplyHandler
,
95 public base::SupportsWeakPtr
<MockJsReplyHandler
> {
98 virtual ~MockJsReplyHandler();
100 WeakHandle
<JsReplyHandler
> AsWeakHandle();
102 MOCK_METHOD2(HandleJsReply
,
103 void(const ::std::string
&, const JsArgList
&));
106 } // namespace syncer
108 #endif // SYNC_JS_JS_TEST_UTIL_H_