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 "testing/gmock/include/gmock/gmock.h"
19 class DictionaryValue
;
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
);
42 class MockJsBackend
: public JsBackend
,
43 public base::SupportsWeakPtr
<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
> {
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
> {
68 virtual ~MockJsEventHandler();
70 WeakHandle
<JsEventHandler
> AsWeakHandle();
72 MOCK_METHOD2(HandleJsEvent
,
73 void(const ::std::string
&, const JsEventDetails
&));
78 #endif // SYNC_JS_JS_TEST_UTIL_H_