File: external_cache_impl_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (502 lines) | stat: -rw-r--r-- 19,270 bytes parent folder | download | duplicates (6)
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
// Copyright 2013 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/ash/extensions/external_cache_impl.h"

#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "chrome/browser/ash/extensions/external_cache_delegate.h"
#include "chrome/browser/ash/settings/scoped_cros_settings_test_helper.h"
#include "chrome/browser/extensions/external_provider_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/verifier_formats.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace chromeos {

namespace {

using ::testing::Optional;

const char kTestExtensionId1[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const char kTestExtensionId2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
const char kTestExtensionId3[] = "cccccccccccccccccccccccccccccccc";
const char kTestExtensionId4[] = "dddddddddddddddddddddddddddddddd";
const char kNonWebstoreUpdateUrl[] = "https://localhost/service/update2/crx";
const char kExternalCrxPath[] = "/local/path/to/extension.crx";
const char kExternalCrxVersion[] = "1.2.3.4";

}  // namespace

class ExternalCacheImplTest : public testing::Test,
                              public ExternalCacheDelegate {
 public:
  ExternalCacheImplTest()
      : task_environment_(content::BrowserTaskEnvironment::REAL_IO_THREAD),
        test_shared_loader_factory_(
            base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
                &test_url_loader_factory_)) {}

  ExternalCacheImplTest(const ExternalCacheImplTest&) = delete;
  ExternalCacheImplTest& operator=(const ExternalCacheImplTest&) = delete;

  ~ExternalCacheImplTest() override = default;

  scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory() {
    return test_shared_loader_factory_;
  }

  const std::optional<base::Value::Dict>& provided_prefs() { return prefs_; }
  const std::set<extensions::ExtensionId>& deleted_extension_files() const {
    return deleted_extension_files_;
  }

  // ExternalCacheDelegate:
  void OnExtensionListsUpdated(const base::Value::Dict& prefs) override {
    prefs_ = prefs.Clone();
  }

  bool IsRollbackAllowed() const override { return is_rollback_allowed_; }

  bool CanRollbackNow() const override { return can_rollback_now_; }

  void OnCachedExtensionFileDeleted(
      const extensions::ExtensionId& id) override {
    deleted_extension_files_.insert(id);
  }

  base::FilePath CreateCacheDir(bool initialized) {
    EXPECT_TRUE(cache_dir_.CreateUniqueTempDir());
    if (initialized)
      CreateFlagFile(cache_dir_.GetPath());
    return cache_dir_.GetPath();
  }

  base::FilePath CreateTempDir() {
    EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
    return temp_dir_.GetPath();
  }

  void CreateFlagFile(const base::FilePath& dir) {
    CreateFile(
        dir.Append(extensions::LocalExtensionCache::kCacheReadyFlagFileName));
  }

  void CreateExtensionFile(const base::FilePath& dir,
                           const std::string& id,
                           const std::string& version) {
    CreateFile(GetExtensionFile(dir, id, version));
  }

  void CreateFile(const base::FilePath& file) {
    EXPECT_TRUE(base::WriteFile(file, std::string_view()));
  }

  base::FilePath GetExtensionFile(const base::FilePath& dir,
                                  const std::string& id,
                                  const std::string& version) {
    return dir.Append(id + "-" + version + ".crx");
  }

  base::Value CreateEntryWithUpdateUrl(bool from_webstore) {
    base::Value::Dict entry;
    entry.Set(extensions::ExternalProviderImpl::kExternalUpdateUrl,
              from_webstore ? extension_urls::GetWebstoreUpdateUrl().spec()
                            : kNonWebstoreUpdateUrl);
    return base::Value(std::move(entry));
  }

  base::Value CreateEntryWithExternalCrx() {
    base::Value::Dict entry;
    entry.Set(extensions::ExternalProviderImpl::kExternalCrx, kExternalCrxPath);
    entry.Set(extensions::ExternalProviderImpl::kExternalVersion,
              kExternalCrxVersion);
    return base::Value(std::move(entry));
  }

  void AllowImmediateRollback() {
    is_rollback_allowed_ = true;
    can_rollback_now_ = true;
  }

  void AllowRollbackOnNextInit() {
    is_rollback_allowed_ = true;
    can_rollback_now_ = false;
  }

 private:
  content::BrowserTaskEnvironment task_environment_;

  network::TestURLLoaderFactory test_url_loader_factory_;
  scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;

  bool is_rollback_allowed_ = false;
  bool can_rollback_now_ = false;
  base::ScopedTempDir cache_dir_;
  base::ScopedTempDir temp_dir_;
  std::optional<base::Value::Dict> prefs_;
  std::set<extensions::ExtensionId> deleted_extension_files_;

  ash::ScopedCrosSettingsTestHelper cros_settings_test_helper_;
};

TEST_F(ExternalCacheImplTest, Basic) {
  base::FilePath cache_dir(CreateCacheDir(false));
  ExternalCacheImpl external_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  base::Value::Dict prefs;
  prefs.Set(kTestExtensionId1, CreateEntryWithUpdateUrl(true));
  CreateExtensionFile(cache_dir, kTestExtensionId1, "1");
  prefs.Set(kTestExtensionId2, CreateEntryWithUpdateUrl(true));
  prefs.Set(kTestExtensionId3, CreateEntryWithUpdateUrl(false));
  CreateExtensionFile(cache_dir, kTestExtensionId3, "3");
  prefs.Set(kTestExtensionId4, CreateEntryWithUpdateUrl(false));

  external_cache.UpdateExtensionsList(std::move(prefs));
  content::RunAllTasksUntilIdle();

  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 2ul);

  // File in cache from Webstore.
  const base::Value::Dict* entry1 =
      provided_prefs()->FindDictByDottedPath(kTestExtensionId1);
  ASSERT_TRUE(entry1);
  EXPECT_EQ(entry1->Find(extensions::ExternalProviderImpl::kExternalUpdateUrl),
            nullptr);
  EXPECT_NE(entry1->Find(extensions::ExternalProviderImpl::kExternalCrx),
            nullptr);
  EXPECT_NE(entry1->Find(extensions::ExternalProviderImpl::kExternalVersion),
            nullptr);
  EXPECT_THAT(
      entry1->FindBool(extensions::ExternalProviderImpl::kIsFromWebstore),
      Optional(true));

  // File in cache not from Webstore.
  const base::Value::Dict* entry3 =
      provided_prefs()->FindDictByDottedPath(kTestExtensionId3);
  ASSERT_TRUE(entry3);
  EXPECT_EQ(entry3->Find(extensions::ExternalProviderImpl::kExternalUpdateUrl),
            nullptr);
  EXPECT_NE(entry3->Find(extensions::ExternalProviderImpl::kExternalCrx),
            nullptr);
  EXPECT_NE(entry3->Find(extensions::ExternalProviderImpl::kExternalVersion),
            nullptr);
  EXPECT_EQ(entry3->Find(extensions::ExternalProviderImpl::kIsFromWebstore),
            nullptr);

  // Update from Webstore.
  base::FilePath temp_dir(CreateTempDir());
  base::FilePath temp_file2 = temp_dir.Append("b.crx");
  CreateFile(temp_file2);
  extensions::CRXFileInfo crx_info_v2(temp_file2,
                                      extensions::GetTestVerifierFormat());
  crx_info_v2.extension_id = kTestExtensionId2;
  crx_info_v2.expected_version = base::Version("2");
  external_cache.OnExtensionDownloadFinished(
      crx_info_v2, true, GURL(),
      extensions::ExtensionDownloaderDelegate::PingResult(), std::set<int>(),
      extensions::ExtensionDownloaderDelegate::InstallCallback());

  content::RunAllTasksUntilIdle();
  EXPECT_EQ(provided_prefs()->size(), 3ul);

  const base::Value::Dict* entry2 =
      provided_prefs()->FindDictByDottedPath(kTestExtensionId2);
  ASSERT_TRUE(entry2);
  EXPECT_EQ(entry2->Find(extensions::ExternalProviderImpl::kExternalUpdateUrl),
            nullptr);
  EXPECT_NE(entry2->Find(extensions::ExternalProviderImpl::kExternalCrx),
            nullptr);
  EXPECT_NE(entry2->Find(extensions::ExternalProviderImpl::kExternalVersion),
            nullptr);
  EXPECT_THAT(
      entry2->FindBool(extensions::ExternalProviderImpl::kIsFromWebstore),
      Optional(true));
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId2, "2")));

  // Update not from Webstore.
  base::FilePath temp_file4 = temp_dir.Append("d.crx");
  CreateFile(temp_file4);
  {
    extensions::CRXFileInfo crx_info_v4(temp_file4,
                                        extensions::GetTestVerifierFormat());
    crx_info_v4.extension_id = kTestExtensionId4;
    crx_info_v4.expected_version = base::Version("4");
    external_cache.OnExtensionDownloadFinished(
        crx_info_v4, true, GURL(),
        extensions::ExtensionDownloaderDelegate::PingResult(), std::set<int>(),
        extensions::ExtensionDownloaderDelegate::InstallCallback());
  }

  content::RunAllTasksUntilIdle();
  EXPECT_EQ(provided_prefs()->size(), 4ul);

  const base::Value::Dict* entry4 =
      provided_prefs()->FindDictByDottedPath(kTestExtensionId4);
  ASSERT_TRUE(entry4);
  EXPECT_EQ(entry4->Find(extensions::ExternalProviderImpl::kExternalUpdateUrl),
            nullptr);
  EXPECT_NE(entry4->Find(extensions::ExternalProviderImpl::kExternalCrx),
            nullptr);
  EXPECT_NE(entry4->Find(extensions::ExternalProviderImpl::kExternalVersion),
            nullptr);
  EXPECT_EQ(entry4->Find(extensions::ExternalProviderImpl::kIsFromWebstore),
            nullptr);
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId4, "4")));

  // Damaged file should be removed from disk.
  EXPECT_TRUE(deleted_extension_files().empty());
  external_cache.OnDamagedFileDetected(
      GetExtensionFile(cache_dir, kTestExtensionId2, "2"));
  content::RunAllTasksUntilIdle();
  EXPECT_EQ(3ul, provided_prefs()->size());
  EXPECT_FALSE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId2, "2")));
  EXPECT_THAT(deleted_extension_files(),
              testing::ElementsAre(kTestExtensionId2));

  // Shutdown with callback OnExtensionListsUpdated that clears prefs.
  external_cache.Shutdown(
      base::BindOnce(&ExternalCacheImplTest::OnExtensionListsUpdated,
                     base::Unretained(this), base::Value::Dict()));
  content::RunAllTasksUntilIdle();
  EXPECT_TRUE(provided_prefs()->empty());

  // After Shutdown directory shouldn't be touched.
  external_cache.OnDamagedFileDetected(
      GetExtensionFile(cache_dir, kTestExtensionId4, "4"));
  content::RunAllTasksUntilIdle();
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId4, "4")));
}

TEST_F(ExternalCacheImplTest, PreserveExternalCrx) {
  base::FilePath cache_dir(CreateCacheDir(false));
  ExternalCacheImpl external_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  base::Value::Dict prefs;
  prefs.Set(kTestExtensionId1, CreateEntryWithExternalCrx());
  prefs.Set(kTestExtensionId2, CreateEntryWithUpdateUrl(true));

  external_cache.UpdateExtensionsList(std::move(prefs));
  content::RunAllTasksUntilIdle();

  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);

  // Extensions downloaded from update url will only be visible in the provided
  // prefs once the download of the .crx has finished. Extensions that are
  // provided as external crx path directly should also be visible in the
  // provided prefs directly.
  const base::Value::Dict* entry1 =
      provided_prefs()->FindDictByDottedPath(kTestExtensionId1);
  ASSERT_TRUE(entry1);
  EXPECT_EQ(entry1->Find(extensions::ExternalProviderImpl::kExternalUpdateUrl),
            nullptr);
  EXPECT_NE(entry1->Find(extensions::ExternalProviderImpl::kExternalCrx),
            nullptr);
  EXPECT_NE(entry1->Find(extensions::ExternalProviderImpl::kExternalVersion),
            nullptr);
}

// Checks that if immediate rollback is allowed, extension cache is removed
// immediately and a lower version is allowed to be installed.
TEST_F(ExternalCacheImplTest, ImmediateRollback) {
  base::FilePath cache_dir(CreateCacheDir(false));
  ExternalCacheImpl external_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  CreateExtensionFile(cache_dir, kTestExtensionId1, "2");
  external_cache.UpdateExtensionsList(base::Value::Dict().Set(
      kTestExtensionId1, CreateEntryWithUpdateUrl(false)));
  content::RunAllTasksUntilIdle();

  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);

  // Allow rollback by ExternalCacheDelegate and check that rollback request
  // succeeds.
  AllowImmediateRollback();
  EXPECT_EQ(ExternalCacheImpl::RequestRollbackResult::kAllowed,
            external_cache.RequestRollback(kTestExtensionId1));

  // Check that kTestExtensionId1's entry in the ExtensionCache will be deleted.
  content::RunAllTasksUntilIdle();
  EXPECT_THAT(deleted_extension_files(),
              testing::ElementsAre(kTestExtensionId1));
  EXPECT_TRUE(provided_prefs()->empty());
  EXPECT_FALSE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "2")));

  // Check that lower version installs correctly.
  base::FilePath temp_dir(CreateTempDir());
  base::FilePath temp_file = temp_dir.Append("a.crx");
  CreateFile(temp_file);
  {
    extensions::CRXFileInfo crx_info_v1(temp_file,
                                        extensions::GetTestVerifierFormat());
    crx_info_v1.extension_id = kTestExtensionId1;
    crx_info_v1.expected_version = base::Version("1");
    external_cache.OnExtensionDownloadFinished(
        crx_info_v1, true, GURL(),
        extensions::ExtensionDownloaderDelegate::PingResult(), std::set<int>(),
        extensions::ExtensionDownloaderDelegate::InstallCallback());
  }

  content::RunAllTasksUntilIdle();
  EXPECT_EQ(1ul, provided_prefs()->size());
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "1")));
}

// Checks that if rollback is generally allowed by delegate but cannot be
// performed immediately, cache invalidation is scheduled for the next run.
// Checks that cache is deleted on the next run.
TEST_F(ExternalCacheImplTest, RollbackOnNextInit) {
  base::FilePath cache_dir(CreateCacheDir(false));
  ExternalCacheImpl external_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  CreateExtensionFile(cache_dir, kTestExtensionId1, "2");
  base::Value::Dict prefs;
  prefs.Set(kTestExtensionId1, CreateEntryWithUpdateUrl(false));
  external_cache.UpdateExtensionsList(prefs.Clone());
  content::RunAllTasksUntilIdle();

  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);

  // Allow rollback on the next run by ExternalCacheDelegate and check that
  // rollback request returns SCHEDULED_FOR_NEXT_RUN value.
  AllowRollbackOnNextInit();
  EXPECT_EQ(ExternalCacheImpl::RequestRollbackResult::kScheduledForNextRun,
            external_cache.RequestRollback(kTestExtensionId1));

  // Check that extension cache is still there.
  content::RunAllTasksUntilIdle();
  EXPECT_TRUE(deleted_extension_files().empty());
  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "2")));

  // Shutdown and initialize new cache.
  base::RunLoop run_loop;
  external_cache.Shutdown(run_loop.QuitClosure());
  run_loop.Run();
  ExternalCacheImpl new_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  new_cache.UpdateExtensionsList(prefs.Clone());
  content::RunAllTasksUntilIdle();

  // Check that kTestExtensionId1's entry in the ExtensionCache was deleted
  // after initialization.
  EXPECT_TRUE(provided_prefs()->empty());
  EXPECT_FALSE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "2")));

  // Check that lower version installs correctly.
  base::FilePath temp_dir(CreateTempDir());
  base::FilePath temp_file = temp_dir.Append("a.crx");
  CreateFile(temp_file);
  {
    extensions::CRXFileInfo crx_info_v1(temp_file,
                                        extensions::GetTestVerifierFormat());
    crx_info_v1.extension_id = kTestExtensionId1;
    crx_info_v1.expected_version = base::Version("1");
    new_cache.OnExtensionDownloadFinished(
        crx_info_v1, true, GURL(),
        extensions::ExtensionDownloaderDelegate::PingResult(), std::set<int>(),
        extensions::ExtensionDownloaderDelegate::InstallCallback());
  }

  content::RunAllTasksUntilIdle();
  EXPECT_EQ(1ul, provided_prefs()->size());
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "1")));
}

// Checks that if rollback is disallowed, cache is not invalidated.
TEST_F(ExternalCacheImplTest, RollbackDisallowed) {
  base::FilePath cache_dir(CreateCacheDir(false));
  ExternalCacheImpl external_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  CreateExtensionFile(cache_dir, kTestExtensionId1, "2");
  base::Value::Dict prefs;
  prefs.Set(kTestExtensionId1, CreateEntryWithUpdateUrl(false));
  external_cache.UpdateExtensionsList(prefs.Clone());
  content::RunAllTasksUntilIdle();

  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);

  // Check that rollback is disallowed.
  EXPECT_EQ(ExternalCacheImpl::RequestRollbackResult::kDisallowed,
            external_cache.RequestRollback(kTestExtensionId1));

  // Check that extension cache is still there.
  content::RunAllTasksUntilIdle();
  EXPECT_TRUE(deleted_extension_files().empty());
  ASSERT_TRUE(provided_prefs());
  EXPECT_EQ(provided_prefs()->size(), 1ul);
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "2")));

  // Shutdown and initialize new cache.
  base::RunLoop run_loop;
  external_cache.Shutdown(run_loop.QuitClosure());
  run_loop.Run();
  ExternalCacheImpl new_cache(
      cache_dir, url_loader_factory(),
      base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}), this,
      true, false, false);

  new_cache.UpdateExtensionsList(prefs.Clone());
  content::RunAllTasksUntilIdle();

  // Check that extension cache was not deleted on initialization.
  EXPECT_EQ(provided_prefs()->size(), 1ul);
  EXPECT_TRUE(
      base::PathExists(GetExtensionFile(cache_dir, kTestExtensionId1, "2")));
}

}  // namespace chromeos