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

Unified Diff: chrome/browser/extensions/api/storage/settings_sync_unittest.cc

Issue 472343003: Use ApiUnitTest for storage API tests (storage_api_unittest and storage_frontend_unittest). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/storage/settings_sync_unittest.cc
diff --git a/chrome/browser/extensions/api/storage/settings_sync_unittest.cc b/chrome/browser/extensions/api/storage/settings_sync_unittest.cc
index fd8964164adf340aeeb98ac4f53aaed0e466203d..baa0defd647fd7a75030f371f9ec6459f52db7f0 100644
--- a/chrome/browser/extensions/api/storage/settings_sync_unittest.cc
+++ b/chrome/browser/extensions/api/storage/settings_sync_unittest.cc
@@ -8,15 +8,18 @@
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/api/storage/settings_sync_util.h"
#include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
#include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
+#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
#include "extensions/browser/api/storage/leveldb_settings_storage_factory.h"
#include "extensions/browser/api/storage/settings_storage_factory.h"
#include "extensions/browser/api/storage/settings_test_util.h"
#include "extensions/browser/api/storage/storage_frontend.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/mock_extension_system.h"
#include "extensions/browser/value_store/testing_value_store.h"
#include "extensions/common/manifest.h"
#include "sync/api/sync_change_processor.h"
@@ -205,10 +208,15 @@ class ExtensionSettingsSyncTest : public testing::Test {
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- profile_.reset(new util::MockProfile(temp_dir_.path()));
+ profile_.reset(new TestingProfile(temp_dir_.path()));
storage_factory_->Reset(new LeveldbSettingsStorageFactory());
frontend_.reset(
StorageFrontend::CreateForTesting(storage_factory_, profile_.get()));
+
+ ExtensionsBrowserClient::Get()
+ ->GetExtensionSystemFactory()
+ ->SetTestingFactoryAndUse(
+ profile_.get(), &util::MockExtensionSystemWithEventRouter::Build);
}
virtual void TearDown() OVERRIDE {
@@ -257,7 +265,7 @@ class ExtensionSettingsSyncTest : public testing::Test {
content::TestBrowserThread file_thread_;
base::ScopedTempDir temp_dir_;
- scoped_ptr<util::MockProfile> profile_;
+ scoped_ptr<TestingProfile> profile_;
scoped_ptr<StorageFrontend> frontend_;
scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
scoped_ptr<MockSyncChangeProcessor> sync_processor_;
@@ -1423,4 +1431,65 @@ TEST_F(ExtensionSettingsSyncTest, Dots) {
}
}
+// In other (frontend) tests, we assume that the result of GetStorage
+// is a pointer to the a Storage owned by a Frontend object, but for
+// the unlimitedStorage case, this might not be true. So, write the
+// tests in a "callback" style. We should really rewrite all tests to
+// be asynchronous in this way.
+
+namespace {
+
+static void UnlimitedSyncStorageTestCallback(ValueStore* sync_storage) {
+ // Sync storage should still run out after ~100K; the unlimitedStorage
+ // permission can't apply to sync.
+ scoped_ptr<base::Value> kilobyte = util::CreateKilobyte();
+ for (int i = 0; i < 100; ++i) {
+ sync_storage->Set(
+ ValueStore::DEFAULTS, base::StringPrintf("%d", i), *kilobyte);
+ }
+
+ EXPECT_TRUE(sync_storage->Set(ValueStore::DEFAULTS, "WillError", *kilobyte)
+ ->HasError());
+}
+
+static void UnlimitedLocalStorageTestCallback(ValueStore* local_storage) {
+ // Local storage should never run out.
+ scoped_ptr<base::Value> megabyte = util::CreateMegabyte();
+ for (int i = 0; i < 7; ++i) {
+ local_storage->Set(
+ ValueStore::DEFAULTS, base::StringPrintf("%d", i), *megabyte);
+ }
+
+ EXPECT_FALSE(local_storage->Set(ValueStore::DEFAULTS, "WontError", *megabyte)
+ ->HasError());
+}
+
+} // namespace
+
+#if defined(OS_WIN)
+// See: http://crbug.com/227296
+#define MAYBE_UnlimitedStorageForLocalButNotSync \
+ DISABLED_UnlimitedStorageForLocalButNotSync
+#else
+#define MAYBE_UnlimitedStorageForLocalButNotSync \
+ UnlimitedStorageForLocalButNotSync
+#endif
+TEST_F(ExtensionSettingsSyncTest, MAYBE_UnlimitedStorageForLocalButNotSync) {
+ const std::string id = "ext";
+ std::set<std::string> permissions;
+ permissions.insert("unlimitedStorage");
+ scoped_refptr<const Extension> extension =
+ util::AddExtensionWithIdAndPermissions(
+ profile_.get(), id, Manifest::TYPE_EXTENSION, permissions);
+
+ frontend_->RunWithStorage(extension,
+ settings_namespace::SYNC,
+ base::Bind(&UnlimitedSyncStorageTestCallback));
+ frontend_->RunWithStorage(extension,
+ settings_namespace::LOCAL,
+ base::Bind(&UnlimitedLocalStorageTestCallback));
+
+ base::MessageLoop::current()->RunUntilIdle();
+}
+
} // namespace extensions
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698