| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using namespace settings_test_util; | 22 using namespace settings_test_util; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // To save typing SettingsStorage::DEFAULTS everywhere. | 26 // To save typing SettingsStorage::DEFAULTS everywhere. |
| 27 const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS; | 27 const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS; |
| 28 | 28 |
| 29 // A SettingsStorageFactory which always returns NULL. | 29 // A SettingsStorageFactory which always returns NULL. |
| 30 class NullSettingsStorageFactory : public SettingsStorageFactory { | 30 class NullSettingsStorageFactory : public SettingsStorageFactory { |
| 31 public: | 31 public: |
| 32 virtual ~NullSettingsStorageFactory() {} | |
| 33 | |
| 34 // SettingsStorageFactory implementation. | 32 // SettingsStorageFactory implementation. |
| 35 virtual SettingsStorage* Create( | 33 virtual SettingsStorage* Create( |
| 36 const FilePath& base_path, const std::string& extension_id) OVERRIDE { | 34 const FilePath& base_path, const std::string& extension_id) OVERRIDE { |
| 37 return NULL; | 35 return NULL; |
| 38 } | 36 } |
| 37 |
| 38 private: |
| 39 // SettingsStorageFactory is refcounted. |
| 40 virtual ~NullSettingsStorageFactory() {} |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 } | 43 } |
| 42 | 44 |
| 43 class ExtensionSettingsFrontendTest : public testing::Test { | 45 class ExtensionSettingsFrontendTest : public testing::Test { |
| 44 public: | 46 public: |
| 45 ExtensionSettingsFrontendTest() | 47 ExtensionSettingsFrontendTest() |
| 46 : ui_thread_(BrowserThread::UI, MessageLoop::current()), | 48 : storage_factory_(new ScopedSettingsStorageFactory()), |
| 49 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 47 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} | 50 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} |
| 48 | 51 |
| 49 virtual void SetUp() OVERRIDE { | 52 virtual void SetUp() OVERRIDE { |
| 50 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 53 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 51 profile_.reset(new MockProfile(temp_dir_.path())); | 54 profile_.reset(new MockProfile(temp_dir_.path())); |
| 52 ResetFrontend(); | 55 ResetFrontend(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
| 56 frontend_.reset(); | 59 frontend_.reset(); |
| 57 profile_.reset(); | 60 profile_.reset(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 protected: | 63 protected: |
| 61 void ResetFrontend() { | 64 void ResetFrontend() { |
| 62 storage_factory_ = | 65 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); |
| 63 new ScopedSettingsStorageFactory(new SettingsLeveldbStorage::Factory()); | 66 frontend_.reset( |
| 64 frontend_.reset(SettingsFrontend::Create(storage_factory_, profile_.get())); | 67 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); |
| 65 } | 68 } |
| 66 | 69 |
| 67 ScopedTempDir temp_dir_; | 70 ScopedTempDir temp_dir_; |
| 68 scoped_ptr<MockProfile> profile_; | 71 scoped_ptr<MockProfile> profile_; |
| 69 scoped_ptr<SettingsFrontend> frontend_; | 72 scoped_ptr<SettingsFrontend> frontend_; |
| 70 | 73 scoped_refptr<ScopedSettingsStorageFactory> storage_factory_; |
| 71 // Owned by |frontend_|. | |
| 72 ScopedSettingsStorageFactory* storage_factory_; | |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 MessageLoop message_loop_; | 76 MessageLoop message_loop_; |
| 76 content::TestBrowserThread ui_thread_; | 77 content::TestBrowserThread ui_thread_; |
| 77 content::TestBrowserThread file_thread_; | 78 content::TestBrowserThread file_thread_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 // Get a semblance of coverage for both extension and app settings by | 81 // Get a semblance of coverage for both extension and app settings by |
| 81 // alternating in each test. | 82 // alternating in each test. |
| 82 // TODO(kalman): explicitly test the two interact correctly. | 83 // TODO(kalman): explicitly test the two interact correctly. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 storage = GetStorage(id, frontend_.get()); | 193 storage = GetStorage(id, frontend_.get()); |
| 193 ASSERT_TRUE(storage != NULL); | 194 ASSERT_TRUE(storage != NULL); |
| 194 | 195 |
| 195 EXPECT_TRUE(storage->Get().HasError()); | 196 EXPECT_TRUE(storage->Get().HasError()); |
| 196 EXPECT_TRUE(storage->Clear().HasError()); | 197 EXPECT_TRUE(storage->Clear().HasError()); |
| 197 EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError()); | 198 EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError()); |
| 198 EXPECT_TRUE(storage->Remove("foo").HasError()); | 199 EXPECT_TRUE(storage->Remove("foo").HasError()); |
| 199 } | 200 } |
| 200 | 201 |
| 201 } // namespace extensions | 202 } // namespace extensions |
| OLD | NEW |