File: sync_cycle_snapshot_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (78 lines) | stat: -rw-r--r-- 3,151 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync/engine/cycle/sync_cycle_snapshot.h"

#include "base/i18n/rtl.h"
#include "base/test/icu_test_util.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace syncer {
namespace {

class SyncCycleSnapshotTest : public testing::Test {};

TEST_F(SyncCycleSnapshotTest, SyncCycleSnapshotToValue) {
  // Formatting of "poll_interval" value depends on the current locale.
  // Expectations below use English (US) formatting.
  base::test::ScopedRestoreICUDefaultLocale restore_locale;
  base::i18n::SetICUDefaultLocale("en_US");

  ModelNeutralState model_neutral;
  model_neutral.num_successful_commits = 5;
  model_neutral.num_successful_bookmark_commits = 10;
  model_neutral.num_updates_downloaded_total = 100;
  model_neutral.num_tombstone_updates_downloaded_total = 200;

  ProgressMarkerMap download_progress_markers;
  download_progress_markers[BOOKMARKS] = "\xef\xb7\xa4";
  download_progress_markers[APPS] = "apps";
  base::Value::Dict expected_download_progress_markers_value =
      ProgressMarkerMapToValueDict(download_progress_markers);

  const std::string kBirthday = "test_birthday";
  const std::string kBagOfChips = "bagofchips\1";
  const bool kIsSilenced = true;
  const int kNumServerConflicts = 1057;
  SyncCycleSnapshot snapshot(
      kBirthday, kBagOfChips, model_neutral, download_progress_markers,
      kIsSilenced, kNumServerConflicts, false, base::Time::Now(),
      base::Time::Now(), sync_pb::SyncEnums::UNKNOWN_ORIGIN,
      /*poll_interval=*/base::Minutes(30),
      /*has_remaining_local_changes=*/false);
  base::Value::Dict dict(snapshot.ToValue());
  EXPECT_EQ(14u, dict.size());

  EXPECT_THAT(
      dict,
      base::test::DictionaryHasValues(
          base::Value::Dict()
              .Set("birthday", kBirthday)
              // Base64-encoded version of `kBagOfChips`.
              .Set("bagOfChips", "YmFnb2ZjaGlwcwE=")
              .Set("numSuccessfulCommits", model_neutral.num_successful_commits)
              .Set("numSuccessfulBookmarkCommits",
                   model_neutral.num_successful_bookmark_commits)
              .Set("numUpdatesDownloadedTotal",
                   model_neutral.num_updates_downloaded_total)
              .Set("numTombstoneUpdatesDownloadedTotal",
                   model_neutral.num_tombstone_updates_downloaded_total)
              .Set("downloadProgressMarkers",
                   expected_download_progress_markers_value.Clone())
              .Set("isSilenced", kIsSilenced)
              .Set("numServerConflicts", kNumServerConflicts)
              .Set("notificationsEnabled", false)
              .Set("hasRemainingLocalChanges", false)
              .Set("poll_interval", "0h 30m")));

  // poll_finish_time includes the local time zone, so simply verify its
  // existence.
  EXPECT_TRUE(dict.FindString("poll_finish_time"));
}

}  // namespace
}  // namespace syncer