OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 content::TestBrowserThread ui_thread_; | 87 content::TestBrowserThread ui_thread_; |
88 content::TestBrowserThread file_thread_; | 88 content::TestBrowserThread file_thread_; |
89 }; | 89 }; |
90 | 90 |
91 // Get a semblance of coverage for both extension and app settings by | 91 // Get a semblance of coverage for both extension and app settings by |
92 // alternating in each test. | 92 // alternating in each test. |
93 // TODO(kalman): explicitly test the two interact correctly. | 93 // TODO(kalman): explicitly test the two interact correctly. |
94 | 94 |
95 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { | 95 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { |
96 const std::string id = "ext"; | 96 const std::string id = "ext"; |
97 profile_->GetMockExtensionService()->AddExtensionWithId( | 97 ExtensionServiceInterface* esi = static_cast<ExtensionServiceInterface*>( |
Yoyo Zhou
2012/11/21 00:27:13
I don't think you need this static_cast (here and
Miranda Callahan
2012/11/26 22:14:24
Done.
| |
98 id, Extension::TYPE_EXTENSION); | 98 extensions::ExtensionSystem::Get(profile_.get())->extension_service()); |
99 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | |
100 AddExtensionWithId(id, Extension::TYPE_EXTENSION); | |
99 | 101 |
100 ValueStore* storage = util::GetStorage(id, frontend_.get()); | 102 ValueStore* storage = util::GetStorage(id, frontend_.get()); |
101 | 103 |
102 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to | 104 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to |
103 // be too rigorous. | 105 // be too rigorous. |
104 { | 106 { |
105 StringValue bar("bar"); | 107 StringValue bar("bar"); |
106 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 108 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
107 ASSERT_FALSE(result->HasError()); | 109 ASSERT_FALSE(result->HasError()); |
108 } | 110 } |
109 | 111 |
110 { | 112 { |
111 ValueStore::ReadResult result = storage->Get(); | 113 ValueStore::ReadResult result = storage->Get(); |
112 ASSERT_FALSE(result->HasError()); | 114 ASSERT_FALSE(result->HasError()); |
113 EXPECT_FALSE(result->settings()->empty()); | 115 EXPECT_FALSE(result->settings()->empty()); |
114 } | 116 } |
115 | 117 |
116 ResetFrontend(); | 118 ResetFrontend(); |
117 storage = util::GetStorage(id, frontend_.get()); | 119 storage = util::GetStorage(id, frontend_.get()); |
118 | 120 |
119 { | 121 { |
120 ValueStore::ReadResult result = storage->Get(); | 122 ValueStore::ReadResult result = storage->Get(); |
121 ASSERT_FALSE(result->HasError()); | 123 ASSERT_FALSE(result->HasError()); |
122 EXPECT_FALSE(result->settings()->empty()); | 124 EXPECT_FALSE(result->settings()->empty()); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { | 128 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { |
127 const std::string id = "ext"; | 129 const std::string id = "ext"; |
128 profile_->GetMockExtensionService()->AddExtensionWithId( | 130 ExtensionServiceInterface* esi = static_cast<ExtensionServiceInterface*>( |
129 id, Extension::TYPE_LEGACY_PACKAGED_APP); | 131 extensions::ExtensionSystem::Get(profile_.get())->extension_service()); |
132 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | |
133 AddExtensionWithId(id, Extension::TYPE_LEGACY_PACKAGED_APP); | |
130 | 134 |
131 ValueStore* storage = util::GetStorage(id, frontend_.get()); | 135 ValueStore* storage = util::GetStorage(id, frontend_.get()); |
132 | 136 |
133 { | 137 { |
134 StringValue bar("bar"); | 138 StringValue bar("bar"); |
135 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 139 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
136 ASSERT_FALSE(result->HasError()); | 140 ASSERT_FALSE(result->HasError()); |
137 } | 141 } |
138 | 142 |
139 // This would be triggered by extension uninstall via a DataDeleter. | 143 // This would be triggered by extension uninstall via a DataDeleter. |
140 frontend_->DeleteStorageSoon(id); | 144 frontend_->DeleteStorageSoon(id); |
141 MessageLoop::current()->RunUntilIdle(); | 145 MessageLoop::current()->RunUntilIdle(); |
142 | 146 |
143 // The storage area may no longer be valid post-uninstall, so re-request. | 147 // The storage area may no longer be valid post-uninstall, so re-request. |
144 storage = util::GetStorage(id, frontend_.get()); | 148 storage = util::GetStorage(id, frontend_.get()); |
145 { | 149 { |
146 ValueStore::ReadResult result = storage->Get(); | 150 ValueStore::ReadResult result = storage->Get(); |
147 ASSERT_FALSE(result->HasError()); | 151 ASSERT_FALSE(result->HasError()); |
148 EXPECT_TRUE(result->settings()->empty()); | 152 EXPECT_TRUE(result->settings()->empty()); |
149 } | 153 } |
150 } | 154 } |
151 | 155 |
152 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { | 156 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { |
153 const std::string id = "ext"; | 157 const std::string id = "ext"; |
154 profile_->GetMockExtensionService()->AddExtensionWithId( | 158 ExtensionServiceInterface* esi = static_cast<ExtensionServiceInterface*>( |
155 id, Extension::TYPE_EXTENSION); | 159 extensions::ExtensionSystem::Get(profile_.get())->extension_service()); |
160 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | |
161 AddExtensionWithId(id, Extension::TYPE_EXTENSION); | |
156 | 162 |
157 ValueStore* storage = util::GetStorage(id, frontend_.get()); | 163 ValueStore* storage = util::GetStorage(id, frontend_.get()); |
158 | 164 |
159 { | 165 { |
160 StringValue bar("bar"); | 166 StringValue bar("bar"); |
161 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); | 167 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); |
162 ASSERT_FALSE(result->HasError()); | 168 ASSERT_FALSE(result->HasError()); |
163 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); | 169 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); |
164 } | 170 } |
165 | 171 |
(...skipping 14 matching lines...) Expand all Loading... | |
180 } | 186 } |
181 | 187 |
182 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
183 // Failing on vista dbg. http://crbug.com/111100, http://crbug.com/108724 | 189 // Failing on vista dbg. http://crbug.com/111100, http://crbug.com/108724 |
184 #define QuotaLimitsEnforcedCorrectlyForSyncAndLocal \ | 190 #define QuotaLimitsEnforcedCorrectlyForSyncAndLocal \ |
185 DISABLED_QuotaLimitsEnforcedCorrectlyForSyncAndLocal | 191 DISABLED_QuotaLimitsEnforcedCorrectlyForSyncAndLocal |
186 #endif | 192 #endif |
187 TEST_F(ExtensionSettingsFrontendTest, | 193 TEST_F(ExtensionSettingsFrontendTest, |
188 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { | 194 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { |
189 const std::string id = "ext"; | 195 const std::string id = "ext"; |
190 profile_->GetMockExtensionService()->AddExtensionWithId( | 196 ExtensionServiceInterface* esi = static_cast<ExtensionServiceInterface*>( |
191 id, Extension::TYPE_EXTENSION); | 197 extensions::ExtensionSystem::Get(profile_.get())->extension_service()); |
198 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | |
199 AddExtensionWithId(id, Extension::TYPE_EXTENSION); | |
192 | 200 |
193 ValueStore* sync_storage = | 201 ValueStore* sync_storage = |
194 util::GetStorage(id, settings::SYNC, frontend_.get()); | 202 util::GetStorage(id, settings::SYNC, frontend_.get()); |
195 ValueStore* local_storage = | 203 ValueStore* local_storage = |
196 util::GetStorage(id, settings::LOCAL, frontend_.get()); | 204 util::GetStorage(id, settings::LOCAL, frontend_.get()); |
197 | 205 |
198 // Sync storage should run out after ~100K. | 206 // Sync storage should run out after ~100K. |
199 scoped_ptr<Value> kilobyte = CreateKilobyte(); | 207 scoped_ptr<Value> kilobyte = CreateKilobyte(); |
200 for (int i = 0; i < 100; ++i) { | 208 for (int i = 0; i < 100; ++i) { |
201 sync_storage->Set( | 209 sync_storage->Set( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 265 |
258 #if defined(OS_WIN) | 266 #if defined(OS_WIN) |
259 // Failing on vista dbg. http://crbug.com/111100, http://crbug.com/108724 | 267 // Failing on vista dbg. http://crbug.com/111100, http://crbug.com/108724 |
260 #define UnlimitedStorageForLocalButNotSync DISABLED_UnlimitedStorageForLocalButN otSync | 268 #define UnlimitedStorageForLocalButNotSync DISABLED_UnlimitedStorageForLocalButN otSync |
261 #endif | 269 #endif |
262 TEST_F(ExtensionSettingsFrontendTest, | 270 TEST_F(ExtensionSettingsFrontendTest, |
263 UnlimitedStorageForLocalButNotSync) { | 271 UnlimitedStorageForLocalButNotSync) { |
264 const std::string id = "ext"; | 272 const std::string id = "ext"; |
265 std::set<std::string> permissions; | 273 std::set<std::string> permissions; |
266 permissions.insert("unlimitedStorage"); | 274 permissions.insert("unlimitedStorage"); |
267 profile_->GetMockExtensionService()->AddExtensionWithIdAndPermissions( | 275 ExtensionServiceInterface* esi = static_cast<ExtensionServiceInterface*>( |
268 id, Extension::TYPE_EXTENSION, permissions); | 276 extensions::ExtensionSystem::Get(profile_.get())->extension_service()); |
277 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> | |
278 AddExtensionWithIdAndPermissions(id, Extension::TYPE_EXTENSION, | |
279 permissions); | |
269 | 280 |
270 frontend_->RunWithStorage( | 281 frontend_->RunWithStorage( |
271 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); | 282 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); |
272 frontend_->RunWithStorage( | 283 frontend_->RunWithStorage( |
273 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); | 284 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); |
274 | 285 |
275 MessageLoop::current()->RunUntilIdle(); | 286 MessageLoop::current()->RunUntilIdle(); |
276 } | 287 } |
277 | 288 |
278 } // namespace extensions | 289 } // namespace extensions |
OLD | NEW |