summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/js_test_util.h
blob: 2571e8be4910a2350264f4805ae8d7dd0fc46860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_
#define CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_
#pragma once

#include <ostream>
#include <string>

#include "chrome/browser/sync/js_backend.h"
#include "chrome/browser/sync/js_frontend.h"
#include "chrome/browser/sync/js_event_handler.h"
#include "chrome/browser/sync/js_event_router.h"
#include "testing/gmock/include/gmock/gmock.h"

class DictionaryValue;
class ListValue;

namespace browser_sync {

class JsArgList;
class JsEventDetails;

// Defined for googletest.  Equivalent to "*os << args.ToString()".
void PrintTo(const JsArgList& args, ::std::ostream* os);
void PrintTo(const JsEventDetails& details, ::std::ostream* os);

// A gmock matcher for JsArgList.  Use like:
//
//   EXPECT_CALL(mock, HandleJsMessageReply("foo", HasArgs(expected_args)));
::testing::Matcher<const JsArgList&> HasArgs(const JsArgList& expected_args);

// Like HasArgs() but takes a ListValue instead.
::testing::Matcher<const JsArgList&> HasArgsAsList(
    const ListValue& expected_args);

// A gmock matcher for JsEventDetails.  Use like:
//
//   EXPECT_CALL(mock, HandleJsEvent("foo", HasArgs(expected_details)));
::testing::Matcher<const JsEventDetails&> HasDetails(
    const JsEventDetails& expected_details);

// Like HasDetails() but takes a DictionaryValue instead.
::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary(
    const DictionaryValue& expected_details);

// Mocks.

class MockJsBackend : public JsBackend {
 public:
  MockJsBackend();
  ~MockJsBackend();

  MOCK_METHOD1(SetParentJsEventRouter, void(JsEventRouter*));
  MOCK_METHOD0(RemoveParentJsEventRouter, void());
  MOCK_CONST_METHOD0(GetParentJsEventRouter, const JsEventRouter*());
  MOCK_METHOD3(ProcessMessage, void(const ::std::string&, const JsArgList&,
                                    const JsEventHandler*));
};

class MockJsFrontend : public JsFrontend {
 public:
  MockJsFrontend();
  ~MockJsFrontend();

  MOCK_METHOD1(AddHandler, void(JsEventHandler*));
  MOCK_METHOD1(RemoveHandler, void(JsEventHandler*));
  MOCK_METHOD3(ProcessMessage,
               void(const ::std::string&, const JsArgList&,
                    const JsEventHandler*));
};

class MockJsEventHandler : public JsEventHandler {
 public:
  MockJsEventHandler();
  ~MockJsEventHandler();

  MOCK_METHOD2(HandleJsEvent,
               void(const ::std::string&, const JsEventDetails&));
  MOCK_METHOD2(HandleJsMessageReply,
               void(const ::std::string&, const JsArgList&));
};

class MockJsEventRouter : public JsEventRouter {
 public:
  MockJsEventRouter();
  ~MockJsEventRouter();

  MOCK_METHOD2(RouteJsEvent,
               void(const ::std::string&, const JsEventDetails&));
  MOCK_METHOD3(RouteJsMessageReply,
               void(const ::std::string&, const JsArgList&,
                    const JsEventHandler*));
};

}  // namespace browser_sync

#endif  // CHROME_BROWSER_SYNC_JS_TEST_UTIL_H_