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

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

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 11 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 "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 "base/string_number_conversions.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "chrome/browser/extensions/settings/settings_frontend.h" 14 #include "chrome/browser/extensions/settings/settings_frontend.h"
14 #include "chrome/browser/extensions/settings/settings_namespace.h" 15 #include "chrome/browser/extensions/settings/settings_namespace.h"
15 #include "chrome/browser/extensions/settings/settings_storage.h" 16 #include "chrome/browser/extensions/settings/settings_storage.h"
16 #include "chrome/browser/extensions/settings/settings_test_util.h" 17 #include "chrome/browser/extensions/settings/settings_test_util.h"
18 #include "chrome/common/extensions/api/extension_api.h"
17 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
18 #include "content/test/test_browser_thread.h" 20 #include "content/test/test_browser_thread.h"
19 21
20 using content::BrowserThread; 22 using content::BrowserThread;
21 23
22 namespace extensions { 24 namespace extensions {
23 25
24 using namespace settings_namespace; 26 using namespace settings_namespace;
25 using namespace settings_test_util; 27 using namespace settings_test_util;
26 28
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 virtual void TearDown() OVERRIDE { 81 virtual void TearDown() OVERRIDE {
80 frontend_.reset(); 82 frontend_.reset();
81 profile_.reset(); 83 profile_.reset();
82 } 84 }
83 85
84 protected: 86 protected:
85 void ResetFrontend() { 87 void ResetFrontend() {
86 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); 88 storage_factory_->Reset(new SettingsLeveldbStorage::Factory());
87 frontend_.reset( 89 frontend_.reset(
88 SettingsFrontend::Create(storage_factory_.get(), profile_.get())); 90 SettingsFrontend::Create(storage_factory_.get(), profile_.get()));
91 // frontend_ needs a message loop to initialise.
92 MessageLoop::current()->RunAllPending();
89 } 93 }
90 94
91 ScopedTempDir temp_dir_; 95 ScopedTempDir temp_dir_;
92 scoped_ptr<MockProfile> profile_; 96 scoped_ptr<MockProfile> profile_;
93 scoped_ptr<SettingsFrontend> frontend_; 97 scoped_ptr<SettingsFrontend> frontend_;
94 scoped_refptr<ScopedSettingsStorageFactory> storage_factory_; 98 scoped_refptr<ScopedSettingsStorageFactory> storage_factory_;
95 99
96 private: 100 private:
97 MessageLoop message_loop_; 101 MessageLoop message_loop_;
98 content::TestBrowserThread ui_thread_; 102 content::TestBrowserThread ui_thread_;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 id, Extension::TYPE_EXTENSION, permissions); 302 id, Extension::TYPE_EXTENSION, permissions);
299 303
300 frontend_->RunWithStorage( 304 frontend_->RunWithStorage(
301 id, SYNC, base::Bind(&UnlimitedSyncStorageTestCallback)); 305 id, SYNC, base::Bind(&UnlimitedSyncStorageTestCallback));
302 frontend_->RunWithStorage( 306 frontend_->RunWithStorage(
303 id, LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); 307 id, LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback));
304 308
305 MessageLoop::current()->RunAllPending(); 309 MessageLoop::current()->RunAllPending();
306 } 310 }
307 311
312 // Returns an int given as a string in |dict| at |path|, or -1 if there is not
313 // int located there.
314 static int GetInteger(const DictionaryValue& dict, const std::string& path) {
315 int integer = -1;
316 {
317 std::string integer_as_string;
318 dict.GetString(path, &integer_as_string);
319 base::StringToInt(integer_as_string, &integer);
320 }
321 return integer;
322 }
323
324 TEST_F(ExtensionSettingsFrontendTest, QuotaLimitsMatchJson) {
325 const DictionaryValue* storage_api =
326 ExtensionAPI::GetInstance()->GetSchema("storage");
327 CHECK(storage_api);
328
329 EXPECT_EQ(
330 (int) SettingsFrontend::kSyncQuota.quota_bytes,
331 GetInteger(*storage_api,
332 "properties.sync.properties.QUOTA_BYTES.value"));
333 EXPECT_EQ(
334 (int) SettingsFrontend::kSyncQuota.quota_bytes_per_item,
335 GetInteger(*storage_api,
336 "properties.sync.properties.QUOTA_BYTES_PER_ITEM.value"));
337 EXPECT_EQ(
338 (int) SettingsFrontend::kSyncQuota.max_items,
339 GetInteger(*storage_api,
340 "properties.sync.properties.MAX_ITEMS.value"));
341
342 EXPECT_EQ(
343 (int) SettingsFrontend::kLocalQuota.quota_bytes,
344 GetInteger(*storage_api,
345 "properties.local.properties.QUOTA_BYTES.value"));
346 EXPECT_FALSE(storage_api->HasKey(
347 "properties.local.properties.QUOTA_BYTES_PER_ITEM.value"));
348 EXPECT_FALSE(storage_api->HasKey(
349 "properties.local.properties.MAX_ITEMS.value"));
350 }
351
308 } // namespace extensions 352 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698