File: snapshot_manager_unittest.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; 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 (461 lines) | stat: -rw-r--r-- 19,497 bytes parent folder | download | duplicates (4)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/downgrade/snapshot_manager.h"

#include "base/containers/adapters.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/downgrade/downgrade_utils.h"
#include "chrome/browser/downgrade/snapshot_file_collector.h"
#include "chrome/browser/downgrade/user_data_downgrade.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace downgrade {

namespace {

constexpr base::FilePath::StringViewType kSomeFolder =
    FILE_PATH_LITERAL("Some Folder");
constexpr base::FilePath::StringViewType kSomeFile =
    FILE_PATH_LITERAL("Some File");
constexpr base::FilePath::StringViewType kSomeFolderFile =
    FILE_PATH_LITERAL("A File");
constexpr base::FilePath::StringViewType kSomeSubFolder =
    FILE_PATH_LITERAL("Some Sub Folder");
constexpr base::FilePath::StringViewType kSomeSubFile =
    FILE_PATH_LITERAL("Some Sub File");

constexpr base::FilePath::StringViewType kUserDataFolder =
    FILE_PATH_LITERAL("User Data Folder");
constexpr base::FilePath::StringViewType kProfileDataFolder =
    FILE_PATH_LITERAL("Profile Data Folder");
constexpr base::FilePath::StringViewType kUserDataFile =
    FILE_PATH_LITERAL("User Data File");
constexpr base::FilePath::StringViewType kProfileDataFile =
    FILE_PATH_LITERAL("Profile Data File");
constexpr base::FilePath::StringViewType kProfileDataJournalFile =
    FILE_PATH_LITERAL("Profile Data File-journal");
constexpr base::FilePath::StringViewType kProfileDataExtFile =
    FILE_PATH_LITERAL("Profile Data File.ext");
constexpr base::FilePath::StringViewType kProfileDataExtWalFile =
    FILE_PATH_LITERAL("Profile Data File.ext-wal");
constexpr base::FilePath::StringViewType kProfileDataExtShmFile =
    FILE_PATH_LITERAL("Profile Data File.ext-shm");

constexpr std::array<base::FilePath::StringViewType, 3>
    kProfileDirectoryBaseNames = {FILE_PATH_LITERAL("Default"),
                                  FILE_PATH_LITERAL("Profile 1"),
                                  FILE_PATH_LITERAL("Profile 2")};

// Structure containing a folders and files structure for tests.
// root
// |_ SomeFile
// |_ Some Folder
//    |_ Some File
//    |_ Some Sub Folder
//       |_ Some Sub File
class TestFolderAndFiles {
 public:
  // Creates the files and folders under the provided |root|.
  // Cleanup must be done manually.
  static void CreateFilesAndFolders(const base::FilePath& root) {
    TestFolderAndFiles folders_and_files(root);
    ASSERT_TRUE(base::CreateDirectory(folders_and_files.some_sub_folder_path_));
    base::File(folders_and_files.some_file_path_,
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File(folders_and_files.some_folder_file_path_,
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File(folders_and_files.some_sub_folder_file_path_,
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  }

  static bool AllPathExists(const base::FilePath& root) {
    TestFolderAndFiles folders_and_files(root);
    return base::DirectoryExists(folders_and_files.some_folder_path_) &&
           base::DirectoryExists(folders_and_files.some_sub_folder_path_) &&
           base::PathExists(folders_and_files.some_file_path_) &&
           base::PathExists(folders_and_files.some_folder_file_path_) &&
           base::PathExists(folders_and_files.some_sub_folder_file_path_);
  }

  static bool NoPathExists(const base::FilePath& root) {
    TestFolderAndFiles folders_and_files(root);
    return !base::DirectoryExists(folders_and_files.some_folder_path_) &&
           !base::DirectoryExists(folders_and_files.some_sub_folder_path_) &&
           !base::PathExists(folders_and_files.some_file_path_) &&
           !base::PathExists(folders_and_files.some_folder_file_path_) &&
           !base::PathExists(folders_and_files.some_sub_folder_file_path_);
  }

 private:
  explicit TestFolderAndFiles(const base::FilePath& root) {
    some_folder_path_ = root.Append(kSomeFolder);
    some_folder_file_path_ = some_folder_path_.Append(kSomeFile);
    some_file_path_ = some_folder_path_.Append(kSomeFolderFile);
    some_sub_folder_path_ = some_folder_path_.Append(kSomeSubFolder);
    some_sub_folder_file_path_ = some_sub_folder_path_.Append(kSomeSubFile);
  }
  ~TestFolderAndFiles() = default;

  base::FilePath some_folder_path_;
  base::FilePath some_file_path_;
  base::FilePath some_folder_file_path_;
  base::FilePath some_sub_folder_path_;
  base::FilePath some_sub_folder_file_path_;
};

}  // namespace

class TestSnapshotManager : public SnapshotManager {
 public:
  explicit TestSnapshotManager(base::FilePath path) : SnapshotManager(path) {}
  ~TestSnapshotManager() = default;

 private:
  std::vector<SnapshotItemDetails> GetUserSnapshotItemDetails() const override {
    return std::vector<SnapshotItemDetails>{
        SnapshotItemDetails(base::FilePath(kUserDataFile),
                            SnapshotItemDetails::ItemType::kFile, 0,
                            SnapshotItemId::kMaxValue),
        SnapshotItemDetails(base::FilePath(kUserDataFolder),
                            SnapshotItemDetails::ItemType::kDirectory, 0,
                            SnapshotItemId::kMaxValue)};
  }
  std::vector<SnapshotItemDetails> GetProfileSnapshotItemDetails()
      const override {
    return std::vector<SnapshotItemDetails>{
        SnapshotItemDetails(base::FilePath(kProfileDataFile),
                            SnapshotItemDetails::ItemType::kFile, 0,
                            SnapshotItemId::kMaxValue),
        SnapshotItemDetails(base::FilePath(kProfileDataExtFile),
                            SnapshotItemDetails::ItemType::kFile, 0,
                            SnapshotItemId::kMaxValue),
        SnapshotItemDetails(base::FilePath(kProfileDataFolder),
                            SnapshotItemDetails::ItemType::kDirectory, 0,
                            SnapshotItemId::kMaxValue)};
  }
};

class SnapshotManagerTest : public testing::Test {
 protected:
  void SetUp() override { ASSERT_TRUE(user_data_dir_.CreateUniqueTempDir()); }

  void TearDown() override { EXPECT_TRUE(user_data_dir_.Delete()); }

  base::FilePath user_data_dir() const { return user_data_dir_.GetPath(); }

  void CreateProfileDirectories() {
    for (const auto& path : kProfileDirectoryBaseNames) {
      ASSERT_TRUE(base::CreateDirectory(user_data_dir().Append(path)));
      absolute_profile_directories_.push_back(user_data_dir().Append(path));
    }
  }

  const std::vector<base::FilePath>& absolute_profile_directories() const {
    return absolute_profile_directories_;
  }

  base::FilePath GetSnapshotDirectory(const base::Version& version) const {
    return user_data_dir()
        .Append(kSnapshotsDir)
        .AppendASCII(version.GetString());
  }

 private:
  base::ScopedTempDir user_data_dir_;
  std::vector<base::FilePath> absolute_profile_directories_;
};

TEST_F(SnapshotManagerTest, TakeSnapshot) {
  base::Version version("10.0.0");

  ASSERT_NO_FATAL_FAILURE(CreateProfileDirectories());
  const auto& absolute_profile_paths = absolute_profile_directories();

  // Files and folders at User Data level that should not be snapshotted.
  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(user_data_dir()));

  // Files and folders at User Data level that should be snapshotted.
  base::File user_data_file(user_data_dir().Append(kUserDataFile),
                            base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  ASSERT_NO_FATAL_FAILURE(TestFolderAndFiles::CreateFilesAndFolders(
      user_data_dir().Append(kUserDataFolder)));

  for (const auto& path : absolute_profile_paths) {
    // Files and folders at Profile Data level that should be snapshotted.
    base::File file(path.Append(kProfileDataFile),
                    base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File file_ext(path.Append(kProfileDataExtFile),
                        base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File file_journal(path.Append(kProfileDataJournalFile),
                            base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File file_ext_wal(path.Append(kProfileDataExtWalFile),
                            base::File::FLAG_CREATE | base::File::FLAG_WRITE);
    base::File file_ext_shm(path.Append(kProfileDataExtShmFile),
                            base::File::FLAG_CREATE | base::File::FLAG_WRITE);

    ASSERT_NO_FATAL_FAILURE(TestFolderAndFiles::CreateFilesAndFolders(
        path.Append(kProfileDataFolder)));

    // Files and folders at Profile Data level that should not be snapshotted.
    ASSERT_NO_FATAL_FAILURE(TestFolderAndFiles::CreateFilesAndFolders(path));
  }

  TestSnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.TakeSnapshot(version);

  auto snapshot_dir = GetSnapshotDirectory(version);

  EXPECT_TRUE(base::PathExists(user_data_dir().Append(kUserDataFile)));
  EXPECT_TRUE(base::DirectoryExists(user_data_dir().Append(kUserDataFolder)));
  EXPECT_TRUE(base::PathExists(snapshot_dir.Append(kUserDataFile)));
  EXPECT_TRUE(base::DirectoryExists(snapshot_dir.Append(kUserDataFolder)));
  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(user_data_dir()));
  EXPECT_TRUE(TestFolderAndFiles::NoPathExists(snapshot_dir));

  for (const auto& path : absolute_profile_paths) {
    EXPECT_TRUE(base::PathExists(path.Append(kProfileDataFile)));
    EXPECT_TRUE(base::PathExists(path.Append(kProfileDataExtFile)));
    EXPECT_TRUE(base::PathExists(path.Append(kProfileDataJournalFile)));
    EXPECT_TRUE(base::PathExists(path.Append(kProfileDataExtWalFile)));
    EXPECT_TRUE(base::PathExists(path.Append(kProfileDataExtShmFile)));
    EXPECT_TRUE(base::DirectoryExists(path.Append(kProfileDataFolder)));
    EXPECT_TRUE(TestFolderAndFiles::AllPathExists(path));
  }

  for (const auto& path : kProfileDirectoryBaseNames) {
    EXPECT_TRUE(
        base::PathExists(snapshot_dir.Append(path).Append(kProfileDataFile)));
    EXPECT_TRUE(base::PathExists(
        snapshot_dir.Append(path).Append(kProfileDataJournalFile)));
    EXPECT_TRUE(base::PathExists(
        snapshot_dir.Append(path).Append(kProfileDataExtFile)));
    EXPECT_TRUE(base::PathExists(
        snapshot_dir.Append(path).Append(kProfileDataExtWalFile)));
    EXPECT_TRUE(base::PathExists(
        snapshot_dir.Append(path).Append(kProfileDataExtShmFile)));
    EXPECT_TRUE(base::DirectoryExists(
        snapshot_dir.Append(path).Append(kProfileDataFolder)));
    EXPECT_TRUE(TestFolderAndFiles::NoPathExists(snapshot_dir.Append(path)));
    EXPECT_TRUE(TestFolderAndFiles::AllPathExists(
        snapshot_dir.Append(path).Append(kProfileDataFolder)));
  }
}

TEST_F(SnapshotManagerTest, RestoreSnapshotOlderVersionAvailable) {
  base::Version older_version("9.0.0");
  base::Version existing_version("10.0.0");

  auto older_snapshot_dir = GetSnapshotDirectory(older_version);
  auto existing_snapshot_dir = GetSnapshotDirectory(existing_version);

  ASSERT_TRUE(base::CreateDirectory(older_snapshot_dir));
  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(existing_snapshot_dir));

  base::File(older_snapshot_dir.Append(kDowngradeLastVersionFile),
             base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  base::File(existing_snapshot_dir.Append(kDowngradeLastVersionFile),
             base::File::FLAG_CREATE | base::File::FLAG_WRITE);

  for (const auto& profile : kProfileDirectoryBaseNames) {
    const base::FilePath profile_folder = existing_snapshot_dir.Append(profile);
    ASSERT_NO_FATAL_FAILURE(
        TestFolderAndFiles::CreateFilesAndFolders(profile_folder));
  }

  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.RestoreSnapshot(base::Version("11.0.0"));

  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(user_data_dir()));
  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(existing_snapshot_dir));

  for (const auto& profile : kProfileDirectoryBaseNames) {
    EXPECT_TRUE(
        TestFolderAndFiles::AllPathExists(user_data_dir().Append(profile)));
    EXPECT_TRUE(TestFolderAndFiles::AllPathExists(
        existing_snapshot_dir.Append(profile)));
  }
}

TEST_F(SnapshotManagerTest, RestoreSnapshotTargetVersionAvailable) {
  base::Version older_version("9.0.0");
  base::Version version("10.0.0");

  auto existing_snapshot_dir = GetSnapshotDirectory(version);
  auto older_snapshot_dir = GetSnapshotDirectory(older_version);

  ASSERT_TRUE(base::CreateDirectory(older_snapshot_dir));
  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(existing_snapshot_dir));

  base::File(older_snapshot_dir.Append(kDowngradeLastVersionFile),
             base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  base::File(existing_snapshot_dir.Append(kDowngradeLastVersionFile),
             base::File::FLAG_CREATE | base::File::FLAG_WRITE);

  for (const auto& profile : kProfileDirectoryBaseNames) {
    const base::FilePath profile_folder = existing_snapshot_dir.Append(profile);
    ASSERT_NO_FATAL_FAILURE(
        TestFolderAndFiles::CreateFilesAndFolders(profile_folder));
  }

  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.RestoreSnapshot(version);

  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(user_data_dir()));
  EXPECT_TRUE(TestFolderAndFiles::NoPathExists(existing_snapshot_dir));
  EXPECT_TRUE(
      base::PathExists(user_data_dir().Append(kDowngradeLastVersionFile)));

  for (const auto& profile : kProfileDirectoryBaseNames) {
    EXPECT_TRUE(
        TestFolderAndFiles::AllPathExists(user_data_dir().Append(profile)));
    EXPECT_TRUE(TestFolderAndFiles::NoPathExists(
        existing_snapshot_dir.Append(profile)));
  }
}

TEST_F(SnapshotManagerTest, RestoreSnapshotIgnoresIncompleteSnapshots) {
  base::Version older_version("9.0.0");
  base::Version existing_version("10.0.0");
  base::Version newer_version("11.0.0");

  auto older_snapshot_dir = GetSnapshotDirectory(older_version);
  auto existing_snapshot_dir = GetSnapshotDirectory(existing_version);
  auto newer_snapshot_dir = GetSnapshotDirectory(newer_version);

  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(older_snapshot_dir));
  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(existing_snapshot_dir));
  ASSERT_NO_FATAL_FAILURE(
      TestFolderAndFiles::CreateFilesAndFolders(newer_snapshot_dir));

  // Only the older directory is a complete snapshot.
  base::File(older_snapshot_dir.Append(kDowngradeLastVersionFile),
             base::File::FLAG_CREATE | base::File::FLAG_WRITE);

  for (const auto& profile : kProfileDirectoryBaseNames) {
    const base::FilePath profile_folder = older_snapshot_dir.Append(profile);
    ASSERT_NO_FATAL_FAILURE(
        TestFolderAndFiles::CreateFilesAndFolders(profile_folder));
  }

  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.RestoreSnapshot(newer_version);

  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(user_data_dir()));
  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(older_snapshot_dir));
  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(existing_snapshot_dir));
  EXPECT_TRUE(TestFolderAndFiles::AllPathExists(newer_snapshot_dir));
  EXPECT_TRUE(
      base::PathExists(user_data_dir().Append(kDowngradeLastVersionFile)));

  for (const auto& profile : kProfileDirectoryBaseNames) {
    EXPECT_TRUE(
        TestFolderAndFiles::AllPathExists(user_data_dir().Append(profile)));
    EXPECT_TRUE(
        TestFolderAndFiles::AllPathExists(older_snapshot_dir.Append(profile)));
  }
}

TEST_F(SnapshotManagerTest, PurgeInvalidAndOldSnapshotsKeepsMaxValidSnapshots) {
  std::vector<base::FilePath> invalid_snapshot_paths{
      user_data_dir().Append(kSnapshotsDir).AppendASCII("Bad format"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("10"),
  };
  for (const auto& path : invalid_snapshot_paths)
    ASSERT_TRUE(base::CreateDirectory(path));

  std::vector<base::FilePath> valid_snapshot_paths{
      user_data_dir().Append(kSnapshotsDir).AppendASCII("20"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("30"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("40"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("50"),
  };

  for (const auto& path : valid_snapshot_paths) {
    ASSERT_TRUE(base::CreateDirectory(path));
    base::File(path.Append(kDowngradeLastVersionFile),
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  }

  int max_number_of_snapshots = 3;
  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.PurgeInvalidAndOldSnapshots(max_number_of_snapshots,
                                               std::nullopt);

  const base::FilePath deletion_directory =
      user_data_dir()
          .Append(kSnapshotsDir)
          .AddExtension(kDowngradeDeleteSuffix);

  // All invalid snapshots have been movec
  for (const auto& path : invalid_snapshot_paths) {
    EXPECT_FALSE(base::PathExists(path));
    EXPECT_TRUE(base::PathExists(deletion_directory.Append(path.BaseName())));
  }

  // Only 3 valid snapshots remains
  for (const base::FilePath& path : base::Reversed(valid_snapshot_paths)) {
    EXPECT_EQ(base::PathExists(path), max_number_of_snapshots != 0);
    EXPECT_EQ(!base::PathExists(deletion_directory.Append(path.BaseName())),
              max_number_of_snapshots != 0);
    --max_number_of_snapshots;
  }
}

TEST_F(SnapshotManagerTest, PurgeInvalidAndOldSnapshotsKeepsValidSnapshots) {
  std::vector<base::FilePath> valid_snapshot_paths{
      user_data_dir().Append(kSnapshotsDir).AppendASCII("20"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("30"),
  };

  for (const auto& path : valid_snapshot_paths) {
    ASSERT_TRUE(base::CreateDirectory(path));
    base::File(path.Append(kDowngradeLastVersionFile),
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  }

  int max_number_of_snapshots = 3;
  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.PurgeInvalidAndOldSnapshots(max_number_of_snapshots,
                                               std::nullopt);

  for (const auto& path : valid_snapshot_paths)
    EXPECT_TRUE(base::PathExists(path));
}

TEST_F(SnapshotManagerTest,
       PurgeInvalidAndOldSnapshotsKeepsValidSnapshotsPerMilestone) {
  std::vector<base::FilePath> valid_snapshot_paths{
      user_data_dir().Append(kSnapshotsDir).AppendASCII("19.0.0"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("20.0.0"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("20.0.1"),
      user_data_dir().Append(kSnapshotsDir).AppendASCII("21.0.1"),
  };

  for (const auto& path : valid_snapshot_paths) {
    ASSERT_TRUE(base::CreateDirectory(path));
    base::File(path.Append(kDowngradeLastVersionFile),
               base::File::FLAG_CREATE | base::File::FLAG_WRITE);
  }

  int max_number_of_snapshots = 1;
  SnapshotManager snapshot_manager(user_data_dir());
  snapshot_manager.PurgeInvalidAndOldSnapshots(max_number_of_snapshots, 20);

  EXPECT_TRUE(base::PathExists(valid_snapshot_paths[0]));
  EXPECT_FALSE(base::PathExists(valid_snapshot_paths[1]));
  EXPECT_TRUE(base::PathExists(valid_snapshot_paths[2]));
  EXPECT_TRUE(base::PathExists(valid_snapshot_paths[3]));
}

}  // namespace downgrade