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 "components/sync/js/js_test_util.h" 6 7 #include <memory> 8 9 #include "base/macros.h" 10 #include "components/sync/js/js_event_details.h" 11 12 namespace syncer { 13 PrintTo(const JsEventDetails & details,::std::ostream * os)14void PrintTo(const JsEventDetails& details, ::std::ostream* os) { 15 *os << details.ToString(); 16 } 17 18 namespace { 19 20 // Matcher implementation for HasDetails(). 21 class HasDetailsMatcher 22 : public ::testing::MatcherInterface<const JsEventDetails&> { 23 public: HasDetailsMatcher(const JsEventDetails & expected_details)24 explicit HasDetailsMatcher(const JsEventDetails& expected_details) 25 : expected_details_(expected_details) {} 26 ~HasDetailsMatcher()27 virtual ~HasDetailsMatcher() {} 28 MatchAndExplain(const JsEventDetails & details,::testing::MatchResultListener * listener) const29 virtual bool MatchAndExplain(const JsEventDetails& details, 30 ::testing::MatchResultListener* listener) const { 31 // No need to annotate listener since we already define PrintTo(). 32 return details.Get().Equals(&expected_details_.Get()); 33 } 34 DescribeTo(::std::ostream * os) const35 virtual void DescribeTo(::std::ostream* os) const { 36 *os << "has details " << expected_details_.ToString(); 37 } 38 DescribeNegationTo(::std::ostream * os) const39 virtual void DescribeNegationTo(::std::ostream* os) const { 40 *os << "doesn't have details " << expected_details_.ToString(); 41 } 42 43 private: 44 const JsEventDetails expected_details_; 45 46 DISALLOW_COPY_AND_ASSIGN(HasDetailsMatcher); 47 }; 48 49 } // namespace 50 HasDetails(const JsEventDetails & expected_details)51::testing::Matcher<const JsEventDetails&> HasDetails( 52 const JsEventDetails& expected_details) { 53 return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details)); 54 } 55 HasDetailsAsDictionary(const base::DictionaryValue & expected_details)56::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary( 57 const base::DictionaryValue& expected_details) { 58 std::unique_ptr<base::DictionaryValue> expected_details_copy( 59 expected_details.DeepCopy()); 60 return HasDetails(JsEventDetails(expected_details_copy.get())); 61 } 62 MockJsBackend()63MockJsBackend::MockJsBackend() {} 64 ~MockJsBackend()65MockJsBackend::~MockJsBackend() {} 66 AsWeakHandle()67WeakHandle<JsBackend> MockJsBackend::AsWeakHandle() { 68 return MakeWeakHandle(AsWeakPtr()); 69 } 70 MockJsController()71MockJsController::MockJsController() {} 72 ~MockJsController()73MockJsController::~MockJsController() {} 74 MockJsEventHandler()75MockJsEventHandler::MockJsEventHandler() {} 76 AsWeakHandle()77WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() { 78 return MakeWeakHandle(AsWeakPtr()); 79 } 80 ~MockJsEventHandler()81MockJsEventHandler::~MockJsEventHandler() {} 82 83 } // namespace syncer 84