• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_
6 #define CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_
7 #pragma once
8 
9 #include <ostream>
10 #include <string>
11 
12 #include "chrome/browser/sync/js_backend.h"
13 #include "chrome/browser/sync/js_frontend.h"
14 #include "chrome/browser/sync/js_event_handler.h"
15 #include "chrome/browser/sync/js_event_router.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 
18 class ListValue;
19 
20 namespace browser_sync {
21 
22 class JsArgList;
23 
24 // Defined for googletest.  Equivalent to "*os << args.ToString()".
25 void PrintTo(const JsArgList& args, ::std::ostream* os);
26 
27 // A matcher for gmock.  Use like:
28 //
29 //   EXPECT_CALL(mock, ProcessMessage("foo", HasArgs(args))).Times(1);
30 ::testing::Matcher<const JsArgList&> HasArgs(const JsArgList& expected_args);
31 
32 // Like HasArgs() but takes a ListValue instead.
33 ::testing::Matcher<const JsArgList&> HasArgsAsList(
34     const ListValue& expected_args);
35 
36 // Mocks.
37 
38 class MockJsBackend : public JsBackend {
39  public:
40   MockJsBackend();
41   ~MockJsBackend();
42 
43   MOCK_METHOD1(SetParentJsEventRouter, void(JsEventRouter*));
44   MOCK_METHOD0(RemoveParentJsEventRouter, void());
45   MOCK_CONST_METHOD0(GetParentJsEventRouter, const JsEventRouter*());
46   MOCK_METHOD3(ProcessMessage, void(const ::std::string&, const JsArgList&,
47                                     const JsEventHandler*));
48 };
49 
50 class MockJsFrontend : public JsFrontend {
51  public:
52   MockJsFrontend();
53   ~MockJsFrontend();
54 
55   MOCK_METHOD1(AddHandler, void(JsEventHandler*));
56   MOCK_METHOD1(RemoveHandler, void(JsEventHandler*));
57   MOCK_METHOD3(ProcessMessage,
58                void(const ::std::string&, const JsArgList&,
59                     const JsEventHandler*));
60 };
61 
62 class MockJsEventHandler : public JsEventHandler {
63  public:
64   MockJsEventHandler();
65   ~MockJsEventHandler();
66 
67   MOCK_METHOD2(HandleJsEvent, void(const ::std::string&, const JsArgList&));
68 };
69 
70 class MockJsEventRouter : public JsEventRouter {
71  public:
72   MockJsEventRouter();
73   ~MockJsEventRouter();
74 
75   MOCK_METHOD3(RouteJsEvent,
76                void(const ::std::string&, const JsArgList&,
77                     const JsEventHandler*));
78 };
79 
80 }  // namespace browser_sync
81 
82 #endif  // CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_
83