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 so fail the test case now. |
| 48 CHECK(expected_specifics_.end() != iter); |
| 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(SINGLE_CLIENT) { |
| 71 DisableVerifier(); |
| 72 } |
| 73 |
| 74 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(SingleClientUserEventsSyncTest); |
| 76 }; |
| 77 |
| 78 IN_PROC_BROWSER_TEST_F(SingleClientUserEventsSyncTest, Sanity) { |
| 79 ASSERT_TRUE(SetupSync()); |
| 80 EXPECT_EQ( |
| 81 0u, |
| 82 GetFakeServer()->GetSyncEntitiesByModelType(syncer::USER_EVENTS).size()); |
| 83 syncer::UserEventService* event_service = |
| 84 browser_sync::UserEventServiceFactory::GetForProfile(GetProfile(0)); |
| 85 UserEventSpecifics specifics1; |
| 86 specifics1.set_event_time_usec(base::Time::Now().ToInternalValue()); |
| 87 specifics1.mutable_test_event(); |
| 88 event_service->RecordUserEvent(specifics1); |
| 89 UserEventEqualityChecker(GetSyncService(0), GetFakeServer(), {specifics1}) |
| 90 .Wait(); |
| 91 } |
| 92 |
| 93 } // namespace |
OLD | NEW |