summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/public/base/invalidation_test_util.cc
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 05:31:12 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-05 05:31:12 +0000
commit0e7f2b7f4023f10cc1d4d4a9eabca701faedec01 (patch)
tree5eed13dfa3d07adf11853b833434fa785ee34776 /sync/internal_api/public/base/invalidation_test_util.cc
parent5fbd63798b997475fded3cc90f456425c607edcd (diff)
downloadchromium_src-0e7f2b7f4023f10cc1d4d4a9eabca701faedec01.zip
chromium_src-0e7f2b7f4023f10cc1d4d4a9eabca701faedec01.tar.gz
chromium_src-0e7f2b7f4023f10cc1d4d4a9eabca701faedec01.tar.bz2
Implement features needed for local ack handling in InvalidationStateTracker.
Adds the ability to save payloads in InvalidationStateTracker, and also adds the functionality to generate, track, and acknowledge local ack handles. BUG=124149 Review URL: https://codereview.chromium.org/11415049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/public/base/invalidation_test_util.cc')
-rw-r--r--sync/internal_api/public/base/invalidation_test_util.cc55
1 files changed, 53 insertions, 2 deletions
diff --git a/sync/internal_api/public/base/invalidation_test_util.cc b/sync/internal_api/public/base/invalidation_test_util.cc
index a95b657..3f3910b 100644
--- a/sync/internal_api/public/base/invalidation_test_util.cc
+++ b/sync/internal_api/public/base/invalidation_test_util.cc
@@ -5,6 +5,9 @@
#include "sync/internal_api/public/base/invalidation_test_util.h"
#include "base/basictypes.h"
+#include "base/json/json_writer.h"
+#include "base/json/string_escape.h"
+#include "base/values.h"
#include "sync/internal_api/public/base/invalidation.h"
namespace syncer {
@@ -17,6 +20,39 @@ using ::testing::PrintToString;
namespace {
+class AckHandleEqMatcher
+ : public MatcherInterface<const AckHandle&> {
+ public:
+ explicit AckHandleEqMatcher(const AckHandle& expected);
+
+ virtual bool MatchAndExplain(const AckHandle& actual,
+ MatchResultListener* listener) const;
+ virtual void DescribeTo(::std::ostream* os) const;
+ virtual void DescribeNegationTo(::std::ostream* os) const;
+
+ private:
+ const AckHandle expected_;
+
+ DISALLOW_COPY_AND_ASSIGN(AckHandleEqMatcher);
+};
+
+AckHandleEqMatcher::AckHandleEqMatcher(const AckHandle& expected)
+ : expected_(expected) {
+}
+
+bool AckHandleEqMatcher::MatchAndExplain(const AckHandle& actual,
+ MatchResultListener* listener) const {
+ return expected_.Equals(actual);
+}
+
+void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const {
+ *os << " is equal to " << PrintToString(expected_);
+}
+
+void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const {
+ *os << " isn't equal to " << PrintToString(expected_);
+}
+
class InvalidationEqMatcher
: public MatcherInterface<const Invalidation&> {
public:
@@ -52,8 +88,23 @@ void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const {
} // namespace
-void PrintTo(const Invalidation& invalidation, ::std::ostream* os) {
- *os << "{ payload: " << invalidation.payload << " }";
+void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) {
+ scoped_ptr<base::Value> value(ack_handle.ToValue());
+ std::string printable_ack_handle;
+ base::JSONWriter::Write(value.get(), &printable_ack_handle);
+ *os << "{ ack_handle: " << printable_ack_handle << " }";
+}
+
+Matcher<const AckHandle&> Eq(const AckHandle& expected) {
+ return MakeMatcher(new AckHandleEqMatcher(expected));
+}
+
+void PrintTo(const Invalidation& state, ::std::ostream* os) {
+ std::string printable_payload;
+ base::JsonDoubleQuote(state.payload,
+ true /* put_in_quotes */,
+ &printable_payload);
+ *os << "{ payload: " << printable_payload << " }";
}
Matcher<const Invalidation&> Eq(const Invalidation& expected) {