Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: chrome/browser/extensions/settings/settings_frontend_unittest.cc

Issue 8587025: Extension settings API: force through changes that come from sync (ignoring (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // To save typing SettingsStorage::DEFAULTS everywhere.
27 const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS;
28
26 // A SettingsStorageFactory which always returns NULL. 29 // A SettingsStorageFactory which always returns NULL.
27 class NullSettingsStorageFactory : public SettingsStorageFactory { 30 class NullSettingsStorageFactory : public SettingsStorageFactory {
28 public: 31 public:
29 virtual ~NullSettingsStorageFactory() {} 32 virtual ~NullSettingsStorageFactory() {}
30 33
31 // SettingsStorageFactory implementation. 34 // SettingsStorageFactory implementation.
32 virtual SettingsStorage* Create( 35 virtual SettingsStorage* Create(
33 const FilePath& base_path, const std::string& extension_id) OVERRIDE { 36 const FilePath& base_path, const std::string& extension_id) OVERRIDE {
34 return NULL; 37 return NULL;
35 } 38 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const std::string id = "ext"; 85 const std::string id = "ext";
83 profile_->GetMockExtensionService()->AddExtensionWithId( 86 profile_->GetMockExtensionService()->AddExtensionWithId(
84 id, Extension::TYPE_EXTENSION); 87 id, Extension::TYPE_EXTENSION);
85 88
86 SettingsStorage* storage = GetStorage(id, frontend_.get()); 89 SettingsStorage* storage = GetStorage(id, frontend_.get());
87 90
88 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to 91 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to
89 // be too rigorous. 92 // be too rigorous.
90 { 93 {
91 StringValue bar("bar"); 94 StringValue bar("bar");
92 SettingsStorage::WriteResult result = storage->Set("foo", bar); 95 SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
93 ASSERT_FALSE(result.HasError()); 96 ASSERT_FALSE(result.HasError());
94 } 97 }
95 98
96 { 99 {
97 SettingsStorage::ReadResult result = storage->Get(); 100 SettingsStorage::ReadResult result = storage->Get();
98 ASSERT_FALSE(result.HasError()); 101 ASSERT_FALSE(result.HasError());
99 EXPECT_FALSE(result.settings().empty()); 102 EXPECT_FALSE(result.settings().empty());
100 } 103 }
101 104
102 ResetFrontend(); 105 ResetFrontend();
103 storage = GetStorage(id, frontend_.get()); 106 storage = GetStorage(id, frontend_.get());
104 107
105 { 108 {
106 SettingsStorage::ReadResult result = storage->Get(); 109 SettingsStorage::ReadResult result = storage->Get();
107 ASSERT_FALSE(result.HasError()); 110 ASSERT_FALSE(result.HasError());
108 EXPECT_FALSE(result.settings().empty()); 111 EXPECT_FALSE(result.settings().empty());
109 } 112 }
110 } 113 }
111 114
112 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { 115 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) {
113 const std::string id = "ext"; 116 const std::string id = "ext";
114 profile_->GetMockExtensionService()->AddExtensionWithId( 117 profile_->GetMockExtensionService()->AddExtensionWithId(
115 id, Extension::TYPE_PACKAGED_APP); 118 id, Extension::TYPE_PACKAGED_APP);
116 119
117 SettingsStorage* storage = GetStorage(id, frontend_.get()); 120 SettingsStorage* storage = GetStorage(id, frontend_.get());
118 121
119 { 122 {
120 StringValue bar("bar"); 123 StringValue bar("bar");
121 SettingsStorage::WriteResult result = storage->Set("foo", bar); 124 SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
122 ASSERT_FALSE(result.HasError()); 125 ASSERT_FALSE(result.HasError());
123 } 126 }
124 127
125 // This would be triggered by extension uninstall via an ExtensionDataDeleter. 128 // This would be triggered by extension uninstall via an ExtensionDataDeleter.
126 frontend_->DeleteStorageSoon(id); 129 frontend_->DeleteStorageSoon(id);
127 MessageLoop::current()->RunAllPending(); 130 MessageLoop::current()->RunAllPending();
128 131
129 // The storage area may no longer be valid post-uninstall, so re-request. 132 // The storage area may no longer be valid post-uninstall, so re-request.
130 storage = GetStorage(id, frontend_.get()); 133 storage = GetStorage(id, frontend_.get());
131 { 134 {
132 SettingsStorage::ReadResult result = storage->Get(); 135 SettingsStorage::ReadResult result = storage->Get();
133 ASSERT_FALSE(result.HasError()); 136 ASSERT_FALSE(result.HasError());
134 EXPECT_TRUE(result.settings().empty()); 137 EXPECT_TRUE(result.settings().empty());
135 } 138 }
136 } 139 }
137 140
138 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { 141 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
139 const std::string id = "ext"; 142 const std::string id = "ext";
140 profile_->GetMockExtensionService()->AddExtensionWithId( 143 profile_->GetMockExtensionService()->AddExtensionWithId(
141 id, Extension::TYPE_EXTENSION); 144 id, Extension::TYPE_EXTENSION);
142 145
143 SettingsStorage* storage = GetStorage(id, frontend_.get()); 146 SettingsStorage* storage = GetStorage(id, frontend_.get());
144 147
145 { 148 {
146 StringValue bar("bar"); 149 StringValue bar("bar");
147 SettingsStorage::WriteResult result = storage->Set("foo", bar); 150 SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
148 ASSERT_FALSE(result.HasError()); 151 ASSERT_FALSE(result.HasError());
149 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); 152 EXPECT_TRUE(file_util::PathExists(temp_dir_.path()));
150 } 153 }
151 154
152 // Should need to both clear the database and delete the frontend for the 155 // Should need to both clear the database and delete the frontend for the
153 // leveldb database to be deleted from disk. 156 // leveldb database to be deleted from disk.
154 { 157 {
155 SettingsStorage::WriteResult result = storage->Clear(); 158 SettingsStorage::WriteResult result = storage->Clear();
156 ASSERT_FALSE(result.HasError()); 159 ASSERT_FALSE(result.HasError());
157 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); 160 EXPECT_TRUE(file_util::PathExists(temp_dir_.path()));
(...skipping 14 matching lines...) Expand all
172 profile_->GetMockExtensionService()->AddExtensionWithId( 175 profile_->GetMockExtensionService()->AddExtensionWithId(
173 id, Extension::TYPE_EXTENSION); 176 id, Extension::TYPE_EXTENSION);
174 177
175 storage_factory_->Reset(new NullSettingsStorageFactory()); 178 storage_factory_->Reset(new NullSettingsStorageFactory());
176 179
177 SettingsStorage* storage = GetStorage(id, frontend_.get()); 180 SettingsStorage* storage = GetStorage(id, frontend_.get());
178 ASSERT_TRUE(storage != NULL); 181 ASSERT_TRUE(storage != NULL);
179 182
180 EXPECT_TRUE(storage->Get().HasError()); 183 EXPECT_TRUE(storage->Get().HasError());
181 EXPECT_TRUE(storage->Clear().HasError()); 184 EXPECT_TRUE(storage->Clear().HasError());
182 EXPECT_TRUE(storage->Set("foo", bar).HasError()); 185 EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError());
183 EXPECT_TRUE(storage->Remove("foo").HasError()); 186 EXPECT_TRUE(storage->Remove("foo").HasError());
184 187
185 // For simplicity: just always fail those requests, even if the leveldb 188 // For simplicity: just always fail those requests, even if the leveldb
186 // storage areas start working. 189 // storage areas start working.
187 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); 190 storage_factory_->Reset(new SettingsLeveldbStorage::Factory());
188 191
189 storage = GetStorage(id, frontend_.get()); 192 storage = GetStorage(id, frontend_.get());
190 ASSERT_TRUE(storage != NULL); 193 ASSERT_TRUE(storage != NULL);
191 194
192 EXPECT_TRUE(storage->Get().HasError()); 195 EXPECT_TRUE(storage->Get().HasError());
193 EXPECT_TRUE(storage->Clear().HasError()); 196 EXPECT_TRUE(storage->Clear().HasError());
194 EXPECT_TRUE(storage->Set("foo", bar).HasError()); 197 EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError());
195 EXPECT_TRUE(storage->Remove("foo").HasError()); 198 EXPECT_TRUE(storage->Remove("foo").HasError());
196 } 199 }
197 200
198 } // namespace extensions 201 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_api.cc ('k') | chrome/browser/extensions/settings/settings_leveldb_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698