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 "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" |
6 | 6 |
7 // Here we test the TestRulesRegistry which is the simplest possible | 7 // Here we test the TestRulesRegistry which is the simplest possible |
8 // implementation of RulesRegistryWithCache as a proxy for | 8 // implementation of RulesRegistryWithCache as a proxy for |
9 // RulesRegistryWithCache. | 9 // RulesRegistryWithCache. |
10 | 10 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 extension_prefs->UpdateExtensionPref( | 228 extension_prefs->UpdateExtensionPref( |
229 extension_id, | 229 extension_id, |
230 RulesRegistryWithCache::RuleStorageOnUI::kRulesStoredKey, | 230 RulesRegistryWithCache::RuleStorageOnUI::kRulesStoredKey, |
231 new base::FundamentalValue(true)); | 231 new base::FundamentalValue(true)); |
232 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(extension_id)); | 232 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(extension_id)); |
233 | 233 |
234 // 2. Test writing behavior. | 234 // 2. Test writing behavior. |
235 int write_count = store->write_count(); | 235 int write_count = store->write_count(); |
236 | 236 |
237 scoped_ptr<base::ListValue> value(new ListValue); | 237 scoped_ptr<base::ListValue> value(new base::ListValue); |
238 value->AppendBoolean(true); | 238 value->AppendBoolean(true); |
239 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); | 239 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); |
240 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(extension_id)); | 240 EXPECT_TRUE(ui_part->GetDeclarativeRulesStored(extension_id)); |
241 message_loop_.RunUntilIdle(); | 241 message_loop_.RunUntilIdle(); |
242 EXPECT_EQ(write_count + 1, store->write_count()); | 242 EXPECT_EQ(write_count + 1, store->write_count()); |
243 write_count = store->write_count(); | 243 write_count = store->write_count(); |
244 | 244 |
245 value.reset(new ListValue); | 245 value.reset(new base::ListValue); |
246 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); | 246 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); |
247 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(extension_id)); | 247 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(extension_id)); |
248 message_loop_.RunUntilIdle(); | 248 message_loop_.RunUntilIdle(); |
249 // No rules currently, but previously there were, so we expect a write. | 249 // No rules currently, but previously there were, so we expect a write. |
250 EXPECT_EQ(write_count + 1, store->write_count()); | 250 EXPECT_EQ(write_count + 1, store->write_count()); |
251 write_count = store->write_count(); | 251 write_count = store->write_count(); |
252 | 252 |
253 value.reset(new ListValue); | 253 value.reset(new base::ListValue); |
254 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); | 254 ui_part->WriteToStorage(extension_id, value.PassAs<base::Value>()); |
255 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(extension_id)); | 255 EXPECT_FALSE(ui_part->GetDeclarativeRulesStored(extension_id)); |
256 message_loop_.RunUntilIdle(); | 256 message_loop_.RunUntilIdle(); |
257 EXPECT_EQ(write_count, store->write_count()); | 257 EXPECT_EQ(write_count, store->write_count()); |
258 | 258 |
259 // 3. Test reading behavior. | 259 // 3. Test reading behavior. |
260 int read_count = store->read_count(); | 260 int read_count = store->read_count(); |
261 | 261 |
262 ui_part->SetDeclarativeRulesStored(extension_id, false); | 262 ui_part->SetDeclarativeRulesStored(extension_id, false); |
263 ui_part->ReadFromStorage(extension_id); | 263 ui_part->ReadFromStorage(extension_id); |
264 message_loop_.RunUntilIdle(); | 264 message_loop_.RunUntilIdle(); |
265 EXPECT_EQ(read_count, store->read_count()); | 265 EXPECT_EQ(read_count, store->read_count()); |
266 read_count = store->read_count(); | 266 read_count = store->read_count(); |
267 | 267 |
268 ui_part->SetDeclarativeRulesStored(extension_id, true); | 268 ui_part->SetDeclarativeRulesStored(extension_id, true); |
269 ui_part->ReadFromStorage(extension_id); | 269 ui_part->ReadFromStorage(extension_id); |
270 message_loop_.RunUntilIdle(); | 270 message_loop_.RunUntilIdle(); |
271 EXPECT_EQ(read_count + 1, store->read_count()); | 271 EXPECT_EQ(read_count + 1, store->read_count()); |
272 } | 272 } |
273 | 273 |
274 } // namespace extensions | 274 } // namespace extensions |
OLD | NEW |