OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 "base/macros.h" | |
6 #include "base/time/time.h" | |
7 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" | |
8 #include "chrome/browser/sync/test/integration/status_change_checker.h" | |
9 #include "chrome/browser/sync/test/integration/sync_test.h" | |
10 #include "chrome/browser/sync/user_event_service_factory.h" | |
11 #include "components/sync/protocol/user_event_specifics.pb.h" | |
12 #include "components/sync/user_events/user_event_service.h" | |
13 | |
14 using fake_server::FakeServer; | |
15 using sync_pb::UserEventSpecifics; | |
16 using sync_pb::SyncEntity; | |
17 | |
18 namespace { | |
19 | |
20 class UserEventEqualityChecker : public SingleClientStatusChangeChecker { | |
21 public: | |
22 UserEventEqualityChecker(browser_sync::ProfileSyncService* service, | |
23 FakeServer* fake_server, | |
24 std::vector<UserEventSpecifics> expected_specifics) | |
25 : SingleClientStatusChangeChecker(service), fake_server_(fake_server) { | |
26 for (const UserEventSpecifics& specifics : expected_specifics) { | |
27 expected_specifics_[specifics.event_time_usec()] = specifics; | |
28 } | |
29 } | |
30 | |
31 bool IsExitConditionSatisfied() override { | |
32 std::vector<SyncEntity> entities = | |
33 fake_server_->GetSyncEntitiesByModelType(syncer::USER_EVENTS); | |
34 | |
35 // |entities.size()| is only going to grow, if |entities.size()| ever | |
36 // becomes bigger then all hope is lost of passing, stop now. | |
37 EXPECT_GE(expected_specifics_.size(), entities.size()); | |
38 | |
39 if (expected_specifics_.size() > entities.size()) { | |
40 return false; | |
41 } | |
42 | |
43 for (const SyncEntity& entity : entities) { | |
44 UserEventSpecifics server_specifics = entity.specifics().user_event(); | |
45 auto iter = expected_specifics_.find(server_specifics.event_time_usec()); | |
46 // We don't expect to encounter id matching events with different values, | |
47 // this isn't going to recover to fail the test case now. | |
Patrick Noland
2017/06/26 19:20:23
[nit] Is this supposed to be "so fail the test cas
skym
2017/06/26 19:59:40
Done.
| |
48 DCHECK(expected_specifics_.end() != iter); | |
Patrick Noland
2017/06/26 19:20:23
Why DCHECK and not CHECK or assert?
skym
2017/06/26 19:59:40
Cannot ASSERT because GTEST and and this method ha
| |
49 // TODO(skym): This may need to change if we start updating navigation_id | |
50 // based on what sessions data is committed, and end up committing the | |
51 // same event multiple times. | |
52 EXPECT_EQ(iter->second.navigation_id(), server_specifics.navigation_id()); | |
53 EXPECT_EQ(iter->second.event_case(), server_specifics.event_case()); | |
54 } | |
55 | |
56 return true; | |
57 } | |
58 | |
59 std::string GetDebugMessage() const override { | |
60 return "Waiting server side USER_EVENTS to match expected."; | |
61 } | |
62 | |
63 private: | |
64 FakeServer* fake_server_; | |
65 std::map<int64_t, UserEventSpecifics> expected_specifics_; | |
66 }; | |
67 | |
68 class SingleClientUserEventsSyncTest : public SyncTest { | |
69 public: | |
70 SingleClientUserEventsSyncTest() : SyncTest(TWO_CLIENT) { DisableVerifier(); } | |
Patrick Noland
2017/06/26 19:20:23
Why TWO_CLIENT?
skym
2017/06/26 19:59:40
Whoops, thanks for catching this. I initially wrot
| |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(SingleClientUserEventsSyncTest); | |
74 }; | |
75 | |
76 IN_PROC_BROWSER_TEST_F(SingleClientUserEventsSyncTest, Sanity) { | |
77 ASSERT_TRUE(SetupSync()); | |
78 EXPECT_EQ( | |
79 0u, | |
80 GetFakeServer()->GetSyncEntitiesByModelType(syncer::USER_EVENTS).size()); | |
81 syncer::UserEventService* event_service = | |
82 browser_sync::UserEventServiceFactory::GetForProfile(GetProfile(0)); | |
83 UserEventSpecifics specifics1; | |
84 specifics1.set_event_time_usec(base::Time::Now().ToInternalValue()); | |
85 specifics1.mutable_test_event(); | |
86 event_service->RecordUserEvent(specifics1); | |
87 UserEventEqualityChecker(GetSyncService(0), GetFakeServer(), {specifics1}) | |
88 .Wait(); | |
89 } | |
90 | |
91 } // namespace | |
OLD | NEW |