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_event_details.h" 10 11 namespace syncer { 12 13 void PrintTo(const JsEventDetails& details, ::std::ostream* os) { 14 *os << details.ToString(); 15 } 16 17 namespace { 18 19 // Matcher implementation for HasDetails(). 20 class HasDetailsMatcher 21 : public ::testing::MatcherInterface<const JsEventDetails&> { 22 public: 23 explicit HasDetailsMatcher(const JsEventDetails& expected_details) 24 : expected_details_(expected_details) {} 25 26 virtual ~HasDetailsMatcher() {} 27 28 virtual bool MatchAndExplain( 29 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 35 virtual void DescribeTo(::std::ostream* os) const { 36 *os << "has details " << expected_details_.ToString(); 37 } 38 39 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 51 ::testing::Matcher<const JsEventDetails&> HasDetails( 52 const JsEventDetails& expected_details) { 53 return ::testing::MakeMatcher(new HasDetailsMatcher(expected_details)); 54 } 55 56 ::testing::Matcher<const JsEventDetails&> HasDetailsAsDictionary( 57 const base::DictionaryValue& expected_details) { 58 scoped_ptr<base::DictionaryValue> expected_details_copy( 59 expected_details.DeepCopy()); 60 return HasDetails(JsEventDetails(expected_details_copy.get())); 61 } 62 63 MockJsBackend::MockJsBackend() {} 64 65 MockJsBackend::~MockJsBackend() {} 66 67 WeakHandle<JsBackend> MockJsBackend::AsWeakHandle() { 68 return MakeWeakHandle(AsWeakPtr()); 69 } 70 71 MockJsController::MockJsController() {} 72 73 MockJsController::~MockJsController() {} 74 75 MockJsEventHandler::MockJsEventHandler() {} 76 77 WeakHandle<JsEventHandler> MockJsEventHandler::AsWeakHandle() { 78 return MakeWeakHandle(AsWeakPtr()); 79 } 80 81 MockJsEventHandler::~MockJsEventHandler() {} 82 83 } // namespace syncer 84 85