Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/chromeos/policy/extension_cache_unittest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h" 13 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
16 #include "chrome/browser/extensions/updater/chromeos_extension_cache_delegate.h" 14 #include "chrome/browser/extensions/updater/chromeos_extension_cache_delegate.h"
17 #include "chrome/browser/extensions/updater/extension_cache_impl.h" 15 #include "chrome/browser/extensions/updater/extension_cache_impl.h"
18 #include "chrome/browser/extensions/updater/local_extension_cache.h" 16 #include "chrome/browser/extensions/updater/local_extension_cache.h"
19 #include "chromeos/settings/cros_settings_names.h" 17 #include "chromeos/settings/cros_settings_names.h"
20 #include "chromeos/settings/cros_settings_provider.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
23 20
24 namespace extensions { 21 namespace extensions {
25 namespace { 22 namespace {
26 23
27 const char kTestExtensionId1[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 24 const char kTestExtensionId1[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
28 const char kTestExtensionId2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 25 const char kTestExtensionId2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
29 const char kTestExtensionId3[] = "cccccccccccccccccccccccccccccccc"; 26 const char kTestExtensionId3[] = "cccccccccccccccccccccccccccccccc";
30 27
(...skipping 20 matching lines...) Expand all
51 const base::Time& timestamp) { 48 const base::Time& timestamp) {
52 const base::FilePath filename = dir.Append( 49 const base::FilePath filename = dir.Append(
53 LocalExtensionCache::ExtensionFileName(id, version, "" /* hash */)); 50 LocalExtensionCache::ExtensionFileName(id, version, "" /* hash */));
54 CreateFile(filename, size, timestamp); 51 CreateFile(filename, size, timestamp);
55 return filename; 52 return filename;
56 } 53 }
57 54
58 } // namespace 55 } // namespace
59 56
60 class ExtensionCacheTest : public testing::Test { 57 class ExtensionCacheTest : public testing::Test {
61 public: 58 protected:
62 void SetUp() override {
63 // Swap out the DeviceSettingsProvider with our stub settings provider
64 // so we can set values for maximum extension cache size.
65 chromeos::CrosSettings* const cros_settings = chromeos::CrosSettings::Get();
66 device_settings_provider_ =
67 cros_settings->GetProvider(chromeos::kExtensionCacheSize);
68 EXPECT_TRUE(device_settings_provider_);
69 EXPECT_TRUE(
70 cros_settings->RemoveSettingsProvider(device_settings_provider_));
71 cros_settings->AddSettingsProvider(&stub_settings_provider_);
72 }
73
74 void TearDown() override {
75 // Restore the real DeviceSettingsProvider.
76 chromeos::CrosSettings* const cros_settings = chromeos::CrosSettings::Get();
77 EXPECT_TRUE(
78 cros_settings->RemoveSettingsProvider(&stub_settings_provider_));
79 cros_settings->AddSettingsProvider(device_settings_provider_);
80 }
81
82 // Helpers used to mock out cros settings.
83 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
84 chromeos::ScopedTestCrosSettings test_cros_settings_;
85 chromeos::CrosSettingsProvider* device_settings_provider_ = nullptr;
86 chromeos::StubCrosSettingsProvider stub_settings_provider_;
87
88 content::TestBrowserThreadBundle thread_bundle_; 59 content::TestBrowserThreadBundle thread_bundle_;
60 chromeos::ScopedCrosSettingsTestHelper settings_helper_;
89 }; 61 };
90 62
91 TEST_F(ExtensionCacheTest, SizePolicy) { 63 TEST_F(ExtensionCacheTest, SizePolicy) {
92 chromeos::CrosSettings::Get()->SetInteger(chromeos::kExtensionCacheSize, 64 settings_helper_.ReplaceProvider(chromeos::kExtensionCacheSize);
93 kMaxCacheSize); 65 settings_helper_.SetInteger(chromeos::kExtensionCacheSize, kMaxCacheSize);
94 66
95 // Create and initialize local cache. 67 // Create and initialize local cache.
96 const base::Time now = base::Time::Now(); 68 const base::Time now = base::Time::Now();
97 base::ScopedTempDir cache_dir; 69 base::ScopedTempDir cache_dir;
98 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 70 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
99 const base::FilePath cache_path = cache_dir.path(); 71 const base::FilePath cache_path = cache_dir.path();
100 CreateFile(cache_path.Append(LocalExtensionCache::kCacheReadyFlagFileName), 0, 72 CreateFile(cache_path.Append(LocalExtensionCache::kCacheReadyFlagFileName), 0,
101 now); 73 now);
102 74
103 // The extension cache only has enough space for two of the three extensions. 75 // The extension cache only has enough space for two of the three extensions.
(...skipping 17 matching lines...) Expand all
121 run_loop.reset(new base::RunLoop); 93 run_loop.reset(new base::RunLoop);
122 cache_impl.Shutdown(run_loop->QuitClosure()); 94 cache_impl.Shutdown(run_loop->QuitClosure());
123 run_loop->Run(); 95 run_loop->Run();
124 96
125 EXPECT_TRUE(base::PathExists(file1)); 97 EXPECT_TRUE(base::PathExists(file1));
126 EXPECT_TRUE(base::PathExists(file2)); 98 EXPECT_TRUE(base::PathExists(file2));
127 EXPECT_FALSE(base::PathExists(file3)); 99 EXPECT_FALSE(base::PathExists(file3));
128 } 100 }
129 101
130 } // namespace extensions 102 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698