| 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" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "chrome/browser/extensions/settings/settings_frontend.h" | 12 #include "chrome/browser/extensions/settings/settings_frontend.h" |
| 13 #include "chrome/browser/extensions/settings/settings_storage.h" | 13 #include "chrome/browser/extensions/settings/settings_storage.h" |
| 14 #include "chrome/browser/extensions/settings/settings_test_util.h" | 14 #include "chrome/browser/extensions/settings/settings_test_util.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/test/test_browser_thread.h" | 16 #include "content/test/test_browser_thread.h" |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 using namespace settings_test_util; | 22 using namespace settings_test_util; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // SettingsStorageFactory which acts as a wrapper for other factories. | |
| 27 class ScopedSettingsStorageFactory : public SettingsStorageFactory { | |
| 28 public: | |
| 29 explicit ScopedSettingsStorageFactory(SettingsStorageFactory* delegate) | |
| 30 : delegate_(delegate) { | |
| 31 DCHECK(delegate); | |
| 32 } | |
| 33 | |
| 34 virtual ~ScopedSettingsStorageFactory() {} | |
| 35 | |
| 36 void Reset(SettingsStorageFactory* delegate) { | |
| 37 DCHECK(delegate); | |
| 38 delegate_.reset(delegate); | |
| 39 } | |
| 40 | |
| 41 virtual SettingsStorage* Create( | |
| 42 const FilePath& base_path, const std::string& extension_id) OVERRIDE { | |
| 43 return delegate_->Create(base_path, extension_id); | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 scoped_ptr<SettingsStorageFactory> delegate_; | |
| 48 }; | |
| 49 | |
| 50 // A SettingsStorageFactory which always returns NULL. | 26 // A SettingsStorageFactory which always returns NULL. |
| 51 class NullSettingsStorageFactory : public SettingsStorageFactory { | 27 class NullSettingsStorageFactory : public SettingsStorageFactory { |
| 52 public: | 28 public: |
| 53 virtual ~NullSettingsStorageFactory() {} | 29 virtual ~NullSettingsStorageFactory() {} |
| 54 | 30 |
| 55 // SettingsStorageFactory implementation. | 31 // SettingsStorageFactory implementation. |
| 56 virtual SettingsStorage* Create( | 32 virtual SettingsStorage* Create( |
| 57 const FilePath& base_path, const std::string& extension_id) OVERRIDE { | 33 const FilePath& base_path, const std::string& extension_id) OVERRIDE { |
| 58 return NULL; | 34 return NULL; |
| 59 } | 35 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 } | 50 } |
| 75 | 51 |
| 76 virtual void TearDown() OVERRIDE { | 52 virtual void TearDown() OVERRIDE { |
| 77 frontend_.reset(); | 53 frontend_.reset(); |
| 78 profile_.reset(); | 54 profile_.reset(); |
| 79 } | 55 } |
| 80 | 56 |
| 81 protected: | 57 protected: |
| 82 void ResetFrontend() { | 58 void ResetFrontend() { |
| 83 storage_factory_ = | 59 storage_factory_ = |
| 84 new ScopedSettingsStorageFactory( | 60 new ScopedSettingsStorageFactory(new SettingsLeveldbStorage::Factory()); |
| 85 new SettingsLeveldbStorage::Factory()); | |
| 86 frontend_.reset(SettingsFrontend::Create(storage_factory_, profile_.get())); | 61 frontend_.reset(SettingsFrontend::Create(storage_factory_, profile_.get())); |
| 87 } | 62 } |
| 88 | 63 |
| 89 ScopedTempDir temp_dir_; | 64 ScopedTempDir temp_dir_; |
| 90 scoped_ptr<MockProfile> profile_; | 65 scoped_ptr<MockProfile> profile_; |
| 91 scoped_ptr<SettingsFrontend> frontend_; | 66 scoped_ptr<SettingsFrontend> frontend_; |
| 92 | 67 |
| 93 // Owned by |frontend_|. | 68 // Owned by |frontend_|. |
| 94 ScopedSettingsStorageFactory* storage_factory_; | 69 ScopedSettingsStorageFactory* storage_factory_; |
| 95 | 70 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 storage = GetStorage(id, frontend_.get()); | 189 storage = GetStorage(id, frontend_.get()); |
| 215 ASSERT_TRUE(storage != NULL); | 190 ASSERT_TRUE(storage != NULL); |
| 216 | 191 |
| 217 EXPECT_TRUE(storage->Get().HasError()); | 192 EXPECT_TRUE(storage->Get().HasError()); |
| 218 EXPECT_TRUE(storage->Clear().HasError()); | 193 EXPECT_TRUE(storage->Clear().HasError()); |
| 219 EXPECT_TRUE(storage->Set("foo", bar).HasError()); | 194 EXPECT_TRUE(storage->Set("foo", bar).HasError()); |
| 220 EXPECT_TRUE(storage->Remove("foo").HasError()); | 195 EXPECT_TRUE(storage->Remove("foo").HasError()); |
| 221 } | 196 } |
| 222 | 197 |
| 223 } // namespace extensions | 198 } // namespace extensions |
| OLD | NEW |