Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / sync / js / js_test_util.cc
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.
4
5 #include "sync/js/js_test_util.h"
6
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "sync/js/js_arg_list.h"
10 #include "sync/js/js_event_details.h"
11
12 namespace syncer {
13
14 void PrintTo(const JsArgList& args, ::std::ostream* os) {
15   *os << args.ToString();
16 }
17
18 void PrintTo(const JsEventDetails& details, ::std::ostream* os) {
19   *os << details.ToString();
20 }
21
22 namespace {
23
24 // Matcher implementation for HasArgs().
25 class HasArgsMatcher
26     : public ::testing::MatcherInterface<const JsArgList&> {
27  public:
28   explicit HasArgsMatcher(const JsArgList& expected_args)
29       : expected_args_(expected_args) {}
30
31   virtual ~HasArgsMatcher() {}
32
33   virtual bool MatchAndExplain(
34       const JsArgList& args,
35       ::testing::MatchResultListener* listener) const {
36     // No need to annotate listener since we already define PrintTo().
37     return args.Get().Equals(&expected_args_.Get());
38   }
39
40   virtual void DescribeTo(::std::ostream* os) const {
41     *os << "has args " << expected_args_.ToString();
42   }
43
44   virtual void DescribeNegationTo(::std::ostream* os) const {
45     *os << "doesn't have args " << expected_args_.ToString();
46   }
47
48  private:
49   const JsArgList expected_args_;
50
51   DISALLOW_COPY_AND_ASSIGN(HasArgsMatcher);
52 };
53
54 // Matcher implementation for HasDetails().
55 class HasDetailsMatcher
56     : public ::testing::MatcherInterface<const JsEventDetails&> {
57  public:
58   explicit HasDetailsMatcher(const JsEventDetails& expected_details)
59       : expected_details_(expected_details) {}
60
61   virtual ~HasDetailsMatcher() {}
62
63   virtual bool MatchAndExplain(
64       const JsEventDetails& details,
65       ::testing::MatchResultListener* listener) const {
66     // No need to annotate listener since we already define PrintTo().
67     return details.Get().Equals(&expected_details_.Get());
68   }
69
70   virtual void DescribeTo(::std::ostream* os) const {
71     *os << "has details " << expected_details_.ToString();
72   }
73
74   virtual void DescribeNegationTo(::std::ostream* os) const {
75     *os << "doesn't have details " << expected_details_.ToString();
76   }
77
78  private:
79   const JsEventDetails expected_details_;
80
81   DISALLOW_COPY_AND_ASSIGN(HasDetailsMatcher);
82 };
83
84 }  // namespace
85
86 ::testing::Matcher<const JsArgList&> HasArgs(const JsArgList& expected_args) {
87   return ::testing::MakeMatcher(new HasArgsMatcher(expected_args));
88 }
89
90 ::testing::Matcher<const JsEventDetails&> HasDetails(
91     const JsEventDetails& expected_details) {
92   return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details));
93 }
94
95 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary(
96     const base::DictionaryValue& expected_details) {
97   scoped_ptr<base::DictionaryValue> expected_details_copy(
98       expected_details.DeepCopy());
99   return HasDetails(JsEventDetails(expected_details_copy.get()));
100 }
101
102 MockJsBackend::MockJsBackend() {}
103
104 MockJsBackend::~MockJsBackend() {}
105
106 WeakHandle<JsBackend> MockJsBackend::AsWeakHandle() {
107   return MakeWeakHandle(AsWeakPtr());
108 }
109
110 MockJsController::MockJsController() {}
111
112 MockJsController::~MockJsController() {}
113
114 MockJsEventHandler::MockJsEventHandler() {}
115
116 WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() {
117   return MakeWeakHandle(AsWeakPtr());
118 }
119
120 MockJsEventHandler::~MockJsEventHandler() {}
121
122 MockJsReplyHandler::MockJsReplyHandler() {}
123
124 MockJsReplyHandler::~MockJsReplyHandler() {}
125
126 WeakHandle<JsReplyHandler> MockJsReplyHandler::AsWeakHandle() {
127   return MakeWeakHandle(AsWeakPtr());
128 }
129
130 }  // namespace syncer
131