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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 12 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
12 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" | 13 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" |
13 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" | 14 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" |
| 15 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
15 #include "extensions/browser/api/storage/leveldb_settings_storage_factory.h" | 17 #include "extensions/browser/api/storage/leveldb_settings_storage_factory.h" |
16 #include "extensions/browser/api/storage/settings_storage_factory.h" | 18 #include "extensions/browser/api/storage/settings_storage_factory.h" |
17 #include "extensions/browser/api/storage/settings_test_util.h" | 19 #include "extensions/browser/api/storage/settings_test_util.h" |
18 #include "extensions/browser/api/storage/storage_frontend.h" | 20 #include "extensions/browser/api/storage/storage_frontend.h" |
19 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/mock_extension_system.h" |
20 #include "extensions/browser/value_store/testing_value_store.h" | 23 #include "extensions/browser/value_store/testing_value_store.h" |
21 #include "extensions/common/manifest.h" | 24 #include "extensions/common/manifest.h" |
22 #include "sync/api/sync_change_processor.h" | 25 #include "sync/api/sync_change_processor.h" |
23 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 26 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
24 #include "sync/api/sync_error_factory.h" | 27 #include "sync/api/sync_error_factory.h" |
25 #include "sync/api/sync_error_factory_mock.h" | 28 #include "sync/api/sync_error_factory_mock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
27 | 30 |
28 using base::DictionaryValue; | 31 using base::DictionaryValue; |
29 using base::ListValue; | 32 using base::ListValue; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ExtensionSettingsSyncTest() | 201 ExtensionSettingsSyncTest() |
199 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | 202 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), |
200 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), | 203 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), |
201 storage_factory_(new util::ScopedSettingsStorageFactory()), | 204 storage_factory_(new util::ScopedSettingsStorageFactory()), |
202 sync_processor_(new MockSyncChangeProcessor), | 205 sync_processor_(new MockSyncChangeProcessor), |
203 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( | 206 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
204 sync_processor_.get())) {} | 207 sync_processor_.get())) {} |
205 | 208 |
206 virtual void SetUp() OVERRIDE { | 209 virtual void SetUp() OVERRIDE { |
207 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
208 profile_.reset(new util::MockProfile(temp_dir_.path())); | 211 profile_.reset(new TestingProfile(temp_dir_.path())); |
209 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); | 212 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); |
210 frontend_.reset( | 213 frontend_.reset( |
211 StorageFrontend::CreateForTesting(storage_factory_, profile_.get())); | 214 StorageFrontend::CreateForTesting(storage_factory_, profile_.get())); |
| 215 |
| 216 ExtensionsBrowserClient::Get() |
| 217 ->GetExtensionSystemFactory() |
| 218 ->SetTestingFactoryAndUse( |
| 219 profile_.get(), &util::MockExtensionSystemWithEventRouter::Build); |
212 } | 220 } |
213 | 221 |
214 virtual void TearDown() OVERRIDE { | 222 virtual void TearDown() OVERRIDE { |
215 frontend_.reset(); | 223 frontend_.reset(); |
216 profile_.reset(); | 224 profile_.reset(); |
217 // Execute any pending deletion tasks. | 225 // Execute any pending deletion tasks. |
218 message_loop_.RunUntilIdle(); | 226 message_loop_.RunUntilIdle(); |
219 } | 227 } |
220 | 228 |
221 protected: | 229 protected: |
(...skipping 28 matching lines...) Expand all Loading... |
250 } | 258 } |
251 return as_map; | 259 return as_map; |
252 } | 260 } |
253 | 261 |
254 // Need these so that the DCHECKs for running on FILE or UI threads pass. | 262 // Need these so that the DCHECKs for running on FILE or UI threads pass. |
255 base::MessageLoop message_loop_; | 263 base::MessageLoop message_loop_; |
256 content::TestBrowserThread ui_thread_; | 264 content::TestBrowserThread ui_thread_; |
257 content::TestBrowserThread file_thread_; | 265 content::TestBrowserThread file_thread_; |
258 | 266 |
259 base::ScopedTempDir temp_dir_; | 267 base::ScopedTempDir temp_dir_; |
260 scoped_ptr<util::MockProfile> profile_; | 268 scoped_ptr<TestingProfile> profile_; |
261 scoped_ptr<StorageFrontend> frontend_; | 269 scoped_ptr<StorageFrontend> frontend_; |
262 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; | 270 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; |
263 scoped_ptr<MockSyncChangeProcessor> sync_processor_; | 271 scoped_ptr<MockSyncChangeProcessor> sync_processor_; |
264 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; | 272 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; |
265 }; | 273 }; |
266 | 274 |
267 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS | 275 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS |
268 // sync by roughly alternative which one to test. | 276 // sync by roughly alternative which one to test. |
269 | 277 |
270 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { | 278 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 | 1424 |
1417 ASSERT_EQ(1u, sync_processor_->changes().size()); | 1425 ASSERT_EQ(1u, sync_processor_->changes().size()); |
1418 SettingSyncData sync_data = sync_processor_->changes()[0]; | 1426 SettingSyncData sync_data = sync_processor_->changes()[0]; |
1419 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type()); | 1427 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type()); |
1420 EXPECT_EQ("ext", sync_data.extension_id()); | 1428 EXPECT_EQ("ext", sync_data.extension_id()); |
1421 EXPECT_EQ("key.with.spot", sync_data.key()); | 1429 EXPECT_EQ("key.with.spot", sync_data.key()); |
1422 EXPECT_TRUE(sync_data.value().Equals(string_value.get())); | 1430 EXPECT_TRUE(sync_data.value().Equals(string_value.get())); |
1423 } | 1431 } |
1424 } | 1432 } |
1425 | 1433 |
| 1434 // In other (frontend) tests, we assume that the result of GetStorage |
| 1435 // is a pointer to the a Storage owned by a Frontend object, but for |
| 1436 // the unlimitedStorage case, this might not be true. So, write the |
| 1437 // tests in a "callback" style. We should really rewrite all tests to |
| 1438 // be asynchronous in this way. |
| 1439 |
| 1440 namespace { |
| 1441 |
| 1442 static void UnlimitedSyncStorageTestCallback(ValueStore* sync_storage) { |
| 1443 // Sync storage should still run out after ~100K; the unlimitedStorage |
| 1444 // permission can't apply to sync. |
| 1445 scoped_ptr<base::Value> kilobyte = util::CreateKilobyte(); |
| 1446 for (int i = 0; i < 100; ++i) { |
| 1447 sync_storage->Set( |
| 1448 ValueStore::DEFAULTS, base::StringPrintf("%d", i), *kilobyte); |
| 1449 } |
| 1450 |
| 1451 EXPECT_TRUE(sync_storage->Set(ValueStore::DEFAULTS, "WillError", *kilobyte) |
| 1452 ->HasError()); |
| 1453 } |
| 1454 |
| 1455 static void UnlimitedLocalStorageTestCallback(ValueStore* local_storage) { |
| 1456 // Local storage should never run out. |
| 1457 scoped_ptr<base::Value> megabyte = util::CreateMegabyte(); |
| 1458 for (int i = 0; i < 7; ++i) { |
| 1459 local_storage->Set( |
| 1460 ValueStore::DEFAULTS, base::StringPrintf("%d", i), *megabyte); |
| 1461 } |
| 1462 |
| 1463 EXPECT_FALSE(local_storage->Set(ValueStore::DEFAULTS, "WontError", *megabyte) |
| 1464 ->HasError()); |
| 1465 } |
| 1466 |
| 1467 } // namespace |
| 1468 |
| 1469 #if defined(OS_WIN) |
| 1470 // See: http://crbug.com/227296 |
| 1471 #define MAYBE_UnlimitedStorageForLocalButNotSync \ |
| 1472 DISABLED_UnlimitedStorageForLocalButNotSync |
| 1473 #else |
| 1474 #define MAYBE_UnlimitedStorageForLocalButNotSync \ |
| 1475 UnlimitedStorageForLocalButNotSync |
| 1476 #endif |
| 1477 TEST_F(ExtensionSettingsSyncTest, MAYBE_UnlimitedStorageForLocalButNotSync) { |
| 1478 const std::string id = "ext"; |
| 1479 std::set<std::string> permissions; |
| 1480 permissions.insert("unlimitedStorage"); |
| 1481 scoped_refptr<const Extension> extension = |
| 1482 util::AddExtensionWithIdAndPermissions( |
| 1483 profile_.get(), id, Manifest::TYPE_EXTENSION, permissions); |
| 1484 |
| 1485 frontend_->RunWithStorage(extension, |
| 1486 settings_namespace::SYNC, |
| 1487 base::Bind(&UnlimitedSyncStorageTestCallback)); |
| 1488 frontend_->RunWithStorage(extension, |
| 1489 settings_namespace::LOCAL, |
| 1490 base::Bind(&UnlimitedLocalStorageTestCallback)); |
| 1491 |
| 1492 base::MessageLoop::current()->RunUntilIdle(); |
| 1493 } |
| 1494 |
1426 } // namespace extensions | 1495 } // namespace extensions |
OLD | NEW |