cros: Split GaiaAuthHost from login screen.
[chromium-blink-merge.git] / sync / js / js_test_util.cc
blob6d9679f2602d03366d771f6c8c5e3de6d9df7599
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 #include "sync/js/js_test_util.h"
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"
12 namespace syncer {
14 void PrintTo(const JsArgList& args, ::std::ostream* os) {
15 *os << args.ToString();
18 void PrintTo(const JsEventDetails& details, ::std::ostream* os) {
19 *os << details.ToString();
22 namespace {
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) {}
31 virtual ~HasArgsMatcher() {}
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());
40 virtual void DescribeTo(::std::ostream* os) const {
41 *os << "has args " << expected_args_.ToString();
44 virtual void DescribeNegationTo(::std::ostream* os) const {
45 *os << "doesn't have args " << expected_args_.ToString();
48 private:
49 const JsArgList expected_args_;
51 DISALLOW_COPY_AND_ASSIGN(HasArgsMatcher);
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) {}
61 virtual ~HasDetailsMatcher() {}
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());
70 virtual void DescribeTo(::std::ostream* os) const {
71 *os << "has details " << expected_details_.ToString();
74 virtual void DescribeNegationTo(::std::ostream* os) const {
75 *os << "doesn't have details " << expected_details_.ToString();
78 private:
79 const JsEventDetails expected_details_;
81 DISALLOW_COPY_AND_ASSIGN(HasDetailsMatcher);
84 } // namespace
86 ::testing::Matcher<const JsArgList&> HasArgs(const JsArgList& expected_args) {
87 return ::testing::MakeMatcher(new HasArgsMatcher(expected_args));
90 ::testing::Matcher<const JsArgList&> HasArgsAsList(
91 const ListValue& expected_args) {
92 scoped_ptr<ListValue> expected_args_copy(expected_args.DeepCopy());
93 return HasArgs(JsArgList(expected_args_copy.get()));
96 ::testing::Matcher<const JsEventDetails&> HasDetails(
97 const JsEventDetails& expected_details) {
98 return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details));
101 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary(
102 const DictionaryValue& expected_details) {
103 scoped_ptr<DictionaryValue> expected_details_copy(
104 expected_details.DeepCopy());
105 return HasDetails(JsEventDetails(expected_details_copy.get()));
108 MockJsBackend::MockJsBackend() {}
110 MockJsBackend::~MockJsBackend() {}
112 WeakHandle<JsBackend> MockJsBackend::AsWeakHandle() {
113 return MakeWeakHandle(AsWeakPtr());
116 MockJsController::MockJsController() {}
118 MockJsController::~MockJsController() {}
120 MockJsEventHandler::MockJsEventHandler() {}
122 WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() {
123 return MakeWeakHandle(AsWeakPtr());
126 MockJsEventHandler::~MockJsEventHandler() {}
128 MockJsReplyHandler::MockJsReplyHandler() {}
130 MockJsReplyHandler::~MockJsReplyHandler() {}
132 WeakHandle<JsReplyHandler> MockJsReplyHandler::AsWeakHandle() {
133 return MakeWeakHandle(AsWeakPtr());
136 } // namespace syncer