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

Side by Side Diff: chrome/browser/extensions/api/storage/settings_frontend_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months 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) 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 return scoped_ptr<Value>(megabyte); 47 return scoped_ptr<Value>(megabyte);
48 } 48 }
49 49
50 } 50 }
51 51
52 class ExtensionSettingsFrontendTest : public testing::Test { 52 class ExtensionSettingsFrontendTest : public testing::Test {
53 public: 53 public:
54 ExtensionSettingsFrontendTest() 54 ExtensionSettingsFrontendTest()
55 : storage_factory_(new util::ScopedSettingsStorageFactory()), 55 : storage_factory_(new util::ScopedSettingsStorageFactory()),
56 ui_thread_(BrowserThread::UI, MessageLoop::current()), 56 ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
57 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} 57 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
58 58
59 virtual void SetUp() OVERRIDE { 59 virtual void SetUp() OVERRIDE {
60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
61 profile_.reset(new util::MockProfile(temp_dir_.path())); 61 profile_.reset(new util::MockProfile(temp_dir_.path()));
62 ResetFrontend(); 62 ResetFrontend();
63 } 63 }
64 64
65 virtual void TearDown() OVERRIDE { 65 virtual void TearDown() OVERRIDE {
66 frontend_.reset(); 66 frontend_.reset();
67 profile_.reset(); 67 profile_.reset();
68 // Execute any pending deletion tasks. 68 // Execute any pending deletion tasks.
69 message_loop_.RunUntilIdle(); 69 message_loop_.RunUntilIdle();
70 } 70 }
71 71
72 protected: 72 protected:
73 void ResetFrontend() { 73 void ResetFrontend() {
74 storage_factory_->Reset(new LeveldbSettingsStorageFactory()); 74 storage_factory_->Reset(new LeveldbSettingsStorageFactory());
75 frontend_.reset( 75 frontend_.reset(
76 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); 76 SettingsFrontend::Create(storage_factory_.get(), profile_.get()));
77 } 77 }
78 78
79 base::ScopedTempDir temp_dir_; 79 base::ScopedTempDir temp_dir_;
80 scoped_ptr<util::MockProfile> profile_; 80 scoped_ptr<util::MockProfile> profile_;
81 scoped_ptr<SettingsFrontend> frontend_; 81 scoped_ptr<SettingsFrontend> frontend_;
82 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; 82 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
83 83
84 private: 84 private:
85 MessageLoop message_loop_; 85 base::MessageLoop message_loop_;
86 content::TestBrowserThread ui_thread_; 86 content::TestBrowserThread ui_thread_;
87 content::TestBrowserThread file_thread_; 87 content::TestBrowserThread file_thread_;
88 }; 88 };
89 89
90 // Get a semblance of coverage for both extension and app settings by 90 // Get a semblance of coverage for both extension and app settings by
91 // alternating in each test. 91 // alternating in each test.
92 // TODO(kalman): explicitly test the two interact correctly. 92 // TODO(kalman): explicitly test the two interact correctly.
93 93
94 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { 94 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
95 const std::string id = "ext"; 95 const std::string id = "ext";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ValueStore* storage = util::GetStorage(id, frontend_.get()); 134 ValueStore* storage = util::GetStorage(id, frontend_.get());
135 135
136 { 136 {
137 StringValue bar("bar"); 137 StringValue bar("bar");
138 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); 138 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
139 ASSERT_FALSE(result->HasError()); 139 ASSERT_FALSE(result->HasError());
140 } 140 }
141 141
142 // This would be triggered by extension uninstall via a DataDeleter. 142 // This would be triggered by extension uninstall via a DataDeleter.
143 frontend_->DeleteStorageSoon(id); 143 frontend_->DeleteStorageSoon(id);
144 MessageLoop::current()->RunUntilIdle(); 144 base::MessageLoop::current()->RunUntilIdle();
145 145
146 // The storage area may no longer be valid post-uninstall, so re-request. 146 // The storage area may no longer be valid post-uninstall, so re-request.
147 storage = util::GetStorage(id, frontend_.get()); 147 storage = util::GetStorage(id, frontend_.get());
148 { 148 {
149 ValueStore::ReadResult result = storage->Get(); 149 ValueStore::ReadResult result = storage->Get();
150 ASSERT_FALSE(result->HasError()); 150 ASSERT_FALSE(result->HasError());
151 EXPECT_TRUE(result->settings()->empty()); 151 EXPECT_TRUE(result->settings()->empty());
152 } 152 }
153 } 153 }
154 154
(...skipping 15 matching lines...) Expand all
170 170
171 // Should need to both clear the database and delete the frontend for the 171 // Should need to both clear the database and delete the frontend for the
172 // leveldb database to be deleted from disk. 172 // leveldb database to be deleted from disk.
173 { 173 {
174 ValueStore::WriteResult result = storage->Clear(); 174 ValueStore::WriteResult result = storage->Clear();
175 ASSERT_FALSE(result->HasError()); 175 ASSERT_FALSE(result->HasError());
176 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); 176 EXPECT_TRUE(file_util::PathExists(temp_dir_.path()));
177 } 177 }
178 178
179 frontend_.reset(); 179 frontend_.reset();
180 MessageLoop::current()->RunUntilIdle(); 180 base::MessageLoop::current()->RunUntilIdle();
181 // TODO(kalman): Figure out why this fails, despite appearing to work. 181 // TODO(kalman): Figure out why this fails, despite appearing to work.
182 // Leaving this commented out rather than disabling the whole test so that the 182 // Leaving this commented out rather than disabling the whole test so that the
183 // deletion code paths are at least exercised. 183 // deletion code paths are at least exercised.
184 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); 184 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path()));
185 } 185 }
186 186
187 TEST_F(ExtensionSettingsFrontendTest, 187 TEST_F(ExtensionSettingsFrontendTest,
188 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) { 188 QuotaLimitsEnforcedCorrectlyForSyncAndLocal) {
189 const std::string id = "ext"; 189 const std::string id = "ext";
190 ExtensionServiceInterface* esi = 190 ExtensionServiceInterface* esi =
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); 275 extensions::ExtensionSystem::Get(profile_.get())->extension_service();
276 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)-> 276 static_cast<extensions::settings_test_util::MockExtensionService*>(esi)->
277 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION, 277 AddExtensionWithIdAndPermissions(id, Manifest::TYPE_EXTENSION,
278 permissions); 278 permissions);
279 279
280 frontend_->RunWithStorage( 280 frontend_->RunWithStorage(
281 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); 281 id, settings::SYNC, base::Bind(&UnlimitedSyncStorageTestCallback));
282 frontend_->RunWithStorage( 282 frontend_->RunWithStorage(
283 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); 283 id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback));
284 284
285 MessageLoop::current()->RunUntilIdle(); 285 base::MessageLoop::current()->RunUntilIdle();
286 } 286 }
287 287
288 } // namespace extensions 288 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698