| 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 "chrome/browser/extensions/extension_settings_storage_unittest.h" | 5 #include "chrome/browser/extensions/extension_settings_storage_unittest.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/extension_settings.h" | 10 #include "chrome/browser/extensions/extension_settings.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return testing::AssertionSuccess(); | 44 return testing::AssertionSuccess(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ExtensionSettingsStorageTest::ExtensionSettingsStorageTest() | 47 ExtensionSettingsStorageTest::ExtensionSettingsStorageTest() |
| 48 : key1_("foo"), | 48 : key1_("foo"), |
| 49 key2_("bar"), | 49 key2_("bar"), |
| 50 key3_("baz"), | 50 key3_("baz"), |
| 51 empty_dict_(new DictionaryValue), | 51 empty_dict_(new DictionaryValue), |
| 52 dict1_(new DictionaryValue), | 52 dict1_(new DictionaryValue), |
| 53 dict12_(new DictionaryValue), | 53 dict12_(new DictionaryValue), |
| 54 dict123_(new DictionaryValue) { | 54 dict123_(new DictionaryValue), |
| 55 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 56 file_thread_(BrowserThread::FILE, MessageLoop::current()) { |
| 55 val1_.reset(Value::CreateStringValue(key1_ + "Value")); | 57 val1_.reset(Value::CreateStringValue(key1_ + "Value")); |
| 56 val2_.reset(Value::CreateStringValue(key2_ + "Value")); | 58 val2_.reset(Value::CreateStringValue(key2_ + "Value")); |
| 57 val3_.reset(Value::CreateStringValue(key3_ + "Value")); | 59 val3_.reset(Value::CreateStringValue(key3_ + "Value")); |
| 58 | 60 |
| 59 list1_.push_back(key1_); | 61 list1_.push_back(key1_); |
| 60 list2_.push_back(key2_); | 62 list2_.push_back(key2_); |
| 61 list12_.push_back(key1_); | 63 list12_.push_back(key1_); |
| 62 list12_.push_back(key2_); | 64 list12_.push_back(key2_); |
| 63 list13_.push_back(key1_); | 65 list13_.push_back(key1_); |
| 64 list13_.push_back(key3_); | 66 list13_.push_back(key3_); |
| 65 list123_.push_back(key1_); | 67 list123_.push_back(key1_); |
| 66 list123_.push_back(key2_); | 68 list123_.push_back(key2_); |
| 67 list123_.push_back(key3_); | 69 list123_.push_back(key3_); |
| 68 | 70 |
| 69 dict1_->Set(key1_, val1_->DeepCopy()); | 71 dict1_->Set(key1_, val1_->DeepCopy()); |
| 70 dict12_->Set(key1_, val1_->DeepCopy()); | 72 dict12_->Set(key1_, val1_->DeepCopy()); |
| 71 dict12_->Set(key2_, val2_->DeepCopy()); | 73 dict12_->Set(key2_, val2_->DeepCopy()); |
| 72 dict123_->Set(key1_, val1_->DeepCopy()); | 74 dict123_->Set(key1_, val1_->DeepCopy()); |
| 73 dict123_->Set(key2_, val2_->DeepCopy()); | 75 dict123_->Set(key2_, val2_->DeepCopy()); |
| 74 dict123_->Set(key3_, val3_->DeepCopy()); | 76 dict123_->Set(key3_, val3_->DeepCopy()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 ExtensionSettingsStorageTest::~ExtensionSettingsStorageTest() {} | 79 ExtensionSettingsStorageTest::~ExtensionSettingsStorageTest() {} |
| 78 | 80 |
| 79 void ExtensionSettingsStorageTest::SetUp() { | 81 void ExtensionSettingsStorageTest::SetUp() { |
| 80 ui_message_loop_.reset(new MessageLoopForUI()); | 82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 81 ui_thread_.reset( | 83 settings_.reset(new ExtensionSettings(temp_dir_.path())); |
| 82 new BrowserThread(BrowserThread::UI, MessageLoop::current())); | 84 storage_ = (GetParam())(*settings_, "fakeExtension"); |
| 83 file_thread_.reset( | 85 ASSERT_TRUE(storage_ != NULL); |
| 84 new BrowserThread(BrowserThread::FILE, MessageLoop::current())); | 86 } |
| 85 | 87 |
| 86 FilePath temp_dir; | 88 void ExtensionSettingsStorageTest::TearDown() { |
| 87 file_util::CreateNewTempDirectory(FilePath::StringType(), &temp_dir); | 89 // Must do this explicitly here so that it's destroyed before the |
| 88 settings_ = new ExtensionSettings(temp_dir); | 90 // message loops are. |
| 89 storage_ = (GetParam())(settings_.get(), "fakeExtension"); | 91 settings_.reset(); |
| 90 DCHECK(storage_ != NULL); | |
| 91 } | 92 } |
| 92 | 93 |
| 93 TEST_P(ExtensionSettingsStorageTest, GetWhenEmpty) { | 94 TEST_P(ExtensionSettingsStorageTest, GetWhenEmpty) { |
| 94 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get(key1_)); | 95 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get(key1_)); |
| 95 ASSERT_PRED_FORMAT2(SettingsEq, | 96 ASSERT_PRED_FORMAT2(SettingsEq, |
| 96 empty_dict_.get(), storage_->Get(empty_list_)); | 97 empty_dict_.get(), storage_->Get(empty_list_)); |
| 97 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get(list123_)); | 98 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get(list123_)); |
| 98 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get()); | 99 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get()); |
| 99 } | 100 } |
| 100 | 101 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 TEST_P(ExtensionSettingsStorageTest, DotsInKeyNamesWithDicts) { | 234 TEST_P(ExtensionSettingsStorageTest, DotsInKeyNamesWithDicts) { |
| 234 DictionaryValue outer_dict; | 235 DictionaryValue outer_dict; |
| 235 DictionaryValue* inner_dict = new DictionaryValue(); | 236 DictionaryValue* inner_dict = new DictionaryValue(); |
| 236 outer_dict.Set("foo", inner_dict); | 237 outer_dict.Set("foo", inner_dict); |
| 237 inner_dict->Set("bar", Value::CreateStringValue("baz")); | 238 inner_dict->Set("bar", Value::CreateStringValue("baz")); |
| 238 | 239 |
| 239 ASSERT_PRED_FORMAT2(SettingsEq, &outer_dict, storage_->Set(outer_dict)); | 240 ASSERT_PRED_FORMAT2(SettingsEq, &outer_dict, storage_->Set(outer_dict)); |
| 240 ASSERT_PRED_FORMAT2(SettingsEq, &outer_dict, storage_->Get("foo")); | 241 ASSERT_PRED_FORMAT2(SettingsEq, &outer_dict, storage_->Get("foo")); |
| 241 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get("foo.bar")); | 242 ASSERT_PRED_FORMAT2(SettingsEq, empty_dict_.get(), storage_->Get("foo.bar")); |
| 242 } | 243 } |
| OLD | NEW |