OLD | NEW |
---|---|
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/settings_provider_test_base.h" |
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
15 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
bartfab (slow)
2015/03/31 14:12:40
Nit: Still used in line 68.
| |
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 19 matching lines...) Expand all Loading... | |
50 size_t size, | 47 size_t size, |
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, |
58 public chromeos::SettingsProviderTestBase { | |
61 public: | 59 public: |
62 void SetUp() override { | 60 void SetUp() override { ReplaceProvider(chromeos::kExtensionCacheSize); } |
bartfab (slow)
2015/03/31 14:12:40
Nit: Per style guide, this must be broken into thr
| |
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 | 61 |
74 void TearDown() override { | 62 void TearDown() override { RestoreProvider(); } |
bartfab (slow)
2015/03/31 14:12:40
Nit: Per style guide, this must be broken into thr
| |
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 | 63 |
88 content::TestBrowserThreadBundle thread_bundle_; | 64 content::TestBrowserThreadBundle thread_bundle_; |
89 }; | 65 }; |
90 | 66 |
91 TEST_F(ExtensionCacheTest, SizePolicy) { | 67 TEST_F(ExtensionCacheTest, SizePolicy) { |
92 chromeos::CrosSettings::Get()->SetInteger(chromeos::kExtensionCacheSize, | 68 stub_settings_provider_.SetInteger(chromeos::kExtensionCacheSize, |
93 kMaxCacheSize); | 69 kMaxCacheSize); |
94 | 70 |
95 // Create and initialize local cache. | 71 // Create and initialize local cache. |
96 const base::Time now = base::Time::Now(); | 72 const base::Time now = base::Time::Now(); |
97 base::ScopedTempDir cache_dir; | 73 base::ScopedTempDir cache_dir; |
98 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); | 74 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); |
99 const base::FilePath cache_path = cache_dir.path(); | 75 const base::FilePath cache_path = cache_dir.path(); |
100 CreateFile(cache_path.Append(LocalExtensionCache::kCacheReadyFlagFileName), 0, | 76 CreateFile(cache_path.Append(LocalExtensionCache::kCacheReadyFlagFileName), 0, |
101 now); | 77 now); |
102 | 78 |
103 // The extension cache only has enough space for two of the three extensions. | 79 // The extension cache only has enough space for two of the three extensions. |
(...skipping 17 matching lines...) Expand all Loading... | |
121 run_loop.reset(new base::RunLoop); | 97 run_loop.reset(new base::RunLoop); |
122 cache_impl.Shutdown(run_loop->QuitClosure()); | 98 cache_impl.Shutdown(run_loop->QuitClosure()); |
123 run_loop->Run(); | 99 run_loop->Run(); |
124 | 100 |
125 EXPECT_TRUE(base::PathExists(file1)); | 101 EXPECT_TRUE(base::PathExists(file1)); |
126 EXPECT_TRUE(base::PathExists(file2)); | 102 EXPECT_TRUE(base::PathExists(file2)); |
127 EXPECT_FALSE(base::PathExists(file3)); | 103 EXPECT_FALSE(base::PathExists(file3)); |
128 } | 104 } |
129 | 105 |
130 } // namespace extensions | 106 } // namespace extensions |
OLD | NEW |