Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: components/sync/core_impl/protocol_event_buffer_unittest.cc

Issue 2413313004: [Sync] Move the last things out of core/. (Closed)
Patch Set: Address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/core_impl/protocol_event_buffer.h"
6
7 #include <stdint.h>
8
9 #include "base/time/time.h"
10 #include "components/sync/engine/events/poll_get_updates_request_event.h"
11 #include "components/sync/engine/events/protocol_event.h"
12 #include "components/sync/protocol/sync.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace syncer {
16
17 class ProtocolEventBufferTest : public ::testing::Test {
18 public:
19 ProtocolEventBufferTest();
20 ~ProtocolEventBufferTest() override;
21
22 static std::unique_ptr<ProtocolEvent> MakeTestEvent(int64_t id);
23 static bool HasId(const ProtocolEvent& event, int64_t id);
24
25 protected:
26 ProtocolEventBuffer buffer_;
27 };
28
29 ProtocolEventBufferTest::ProtocolEventBufferTest() {}
30
31 ProtocolEventBufferTest::~ProtocolEventBufferTest() {}
32
33 std::unique_ptr<ProtocolEvent> ProtocolEventBufferTest::MakeTestEvent(
34 int64_t id) {
35 sync_pb::ClientToServerMessage message;
36 return std::unique_ptr<ProtocolEvent>(new PollGetUpdatesRequestEvent(
37 base::Time::FromInternalValue(id), message));
38 }
39
40 bool ProtocolEventBufferTest::HasId(const ProtocolEvent& event, int64_t id) {
41 return event.GetTimestamp() == base::Time::FromInternalValue(id);
42 }
43
44 TEST_F(ProtocolEventBufferTest, AddThenReturnEvents) {
45 std::unique_ptr<ProtocolEvent> e1(MakeTestEvent(1));
46 std::unique_ptr<ProtocolEvent> e2(MakeTestEvent(2));
47
48 buffer_.RecordProtocolEvent(*e1);
49 buffer_.RecordProtocolEvent(*e2);
50
51 std::vector<std::unique_ptr<ProtocolEvent>> buffered_events(
52 buffer_.GetBufferedProtocolEvents());
53
54 ASSERT_EQ(2U, buffered_events.size());
55 EXPECT_TRUE(HasId(*(buffered_events[0]), 1));
56 EXPECT_TRUE(HasId(*(buffered_events[1]), 2));
57 }
58
59 TEST_F(ProtocolEventBufferTest, AddThenOverflowThenReturnEvents) {
60 for (size_t i = 0; i < ProtocolEventBuffer::kBufferSize + 1; ++i) {
61 std::unique_ptr<ProtocolEvent> e(MakeTestEvent(static_cast<int64_t>(i)));
62 buffer_.RecordProtocolEvent(*e);
63 }
64
65 std::vector<std::unique_ptr<ProtocolEvent>> buffered_events(
66 buffer_.GetBufferedProtocolEvents());
67 ASSERT_EQ(ProtocolEventBuffer::kBufferSize, buffered_events.size());
68
69 for (size_t i = 1; i < ProtocolEventBuffer::kBufferSize + 1; ++i) {
70 EXPECT_TRUE(HasId(*(buffered_events[i - 1]), static_cast<int64_t>(i)));
71 }
72 }
73
74 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core_impl/protocol_event_buffer.cc ('k') | components/sync/core_impl/sync_encryption_handler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698