| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/js/js_test_util.h" | 5 #include "sync/js/js_test_util.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "sync/js/js_arg_list.h" | |
| 10 #include "sync/js/js_event_details.h" | 9 #include "sync/js/js_event_details.h" |
| 11 | 10 |
| 12 namespace syncer { | 11 namespace syncer { |
| 13 | 12 |
| 14 void PrintTo(const JsArgList& args, ::std::ostream* os) { | |
| 15 *os << args.ToString(); | |
| 16 } | |
| 17 | |
| 18 void PrintTo(const JsEventDetails& details, ::std::ostream* os) { | 13 void PrintTo(const JsEventDetails& details, ::std::ostream* os) { |
| 19 *os << details.ToString(); | 14 *os << details.ToString(); |
| 20 } | 15 } |
| 21 | 16 |
| 22 namespace { | 17 namespace { |
| 23 | 18 |
| 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(). | 19 // Matcher implementation for HasDetails(). |
| 55 class HasDetailsMatcher | 20 class HasDetailsMatcher |
| 56 : public ::testing::MatcherInterface<const JsEventDetails&> { | 21 : public ::testing::MatcherInterface<const JsEventDetails&> { |
| 57 public: | 22 public: |
| 58 explicit HasDetailsMatcher(const JsEventDetails& expected_details) | 23 explicit HasDetailsMatcher(const JsEventDetails& expected_details) |
| 59 : expected_details_(expected_details) {} | 24 : expected_details_(expected_details) {} |
| 60 | 25 |
| 61 virtual ~HasDetailsMatcher() {} | 26 virtual ~HasDetailsMatcher() {} |
| 62 | 27 |
| 63 virtual bool MatchAndExplain( | 28 virtual bool MatchAndExplain( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 } | 41 } |
| 77 | 42 |
| 78 private: | 43 private: |
| 79 const JsEventDetails expected_details_; | 44 const JsEventDetails expected_details_; |
| 80 | 45 |
| 81 DISALLOW_COPY_AND_ASSIGN(HasDetailsMatcher); | 46 DISALLOW_COPY_AND_ASSIGN(HasDetailsMatcher); |
| 82 }; | 47 }; |
| 83 | 48 |
| 84 } // namespace | 49 } // namespace |
| 85 | 50 |
| 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( | 51 ::testing::Matcher<const JsEventDetails&> HasDetails( |
| 91 const JsEventDetails& expected_details) { | 52 const JsEventDetails& expected_details) { |
| 92 return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details)); | 53 return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details)); |
| 93 } | 54 } |
| 94 | 55 |
| 95 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary( | 56 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary( |
| 96 const base::DictionaryValue& expected_details) { | 57 const base::DictionaryValue& expected_details) { |
| 97 scoped_ptr<base::DictionaryValue> expected_details_copy( | 58 scoped_ptr<base::DictionaryValue> expected_details_copy( |
| 98 expected_details.DeepCopy()); | 59 expected_details.DeepCopy()); |
| 99 return HasDetails(JsEventDetails(expected_details_copy.get())); | 60 return HasDetails(JsEventDetails(expected_details_copy.get())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 MockJsController::~MockJsController() {} | 73 MockJsController::~MockJsController() {} |
| 113 | 74 |
| 114 MockJsEventHandler::MockJsEventHandler() {} | 75 MockJsEventHandler::MockJsEventHandler() {} |
| 115 | 76 |
| 116 WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() { | 77 WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() { |
| 117 return MakeWeakHandle(AsWeakPtr()); | 78 return MakeWeakHandle(AsWeakPtr()); |
| 118 } | 79 } |
| 119 | 80 |
| 120 MockJsEventHandler::~MockJsEventHandler() {} | 81 MockJsEventHandler::~MockJsEventHandler() {} |
| 121 | 82 |
| 122 MockJsReplyHandler::MockJsReplyHandler() {} | |
| 123 | |
| 124 MockJsReplyHandler::~MockJsReplyHandler() {} | |
| 125 | |
| 126 WeakHandle<JsReplyHandler> MockJsReplyHandler::AsWeakHandle() { | |
| 127 return MakeWeakHandle(AsWeakPtr()); | |
| 128 } | |
| 129 | |
| 130 } // namespace syncer | 83 } // namespace syncer |
| 131 | 84 |
| OLD | NEW |