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

Unified Diff: sync/sessions/model_type_registry_unittest.cc

Issue 93433006: sync: Introduce ModelTypeRegistry and helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak in tests Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/sessions/model_type_registry.cc ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/sessions/model_type_registry_unittest.cc
diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ab36e57ebbbb0f5f3f79f91e040c21ecb01fd324
--- /dev/null
+++ b/sync/sessions/model_type_registry_unittest.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/message_loop/message_loop.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "sync/sessions/model_type_registry.h"
+#include "sync/test/engine/fake_model_worker.h"
+#include "sync/test/engine/test_directory_setter_upper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncer {
+
+class ModelTypeRegistryTest : public ::testing::Test {
+ public:
+ ModelTypeRegistryTest();
+ virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
+
+ ModelTypeRegistry* registry();
+
+ private:
+ syncable::Directory* directory();
+
+ base::MessageLoop message_loop_;
+
+ TestDirectorySetterUpper dir_maker_;
+ std::vector<scoped_refptr<ModelSafeWorker> > workers_;
+ scoped_ptr<ModelTypeRegistry> registry_;
+};
+
+ModelTypeRegistryTest::ModelTypeRegistryTest() {}
+
+void ModelTypeRegistryTest::SetUp() {
+ dir_maker_.SetUp();
+ scoped_refptr<ModelSafeWorker> passive_worker(
+ new FakeModelWorker(GROUP_PASSIVE));
+ scoped_refptr<ModelSafeWorker> ui_worker(
+ new FakeModelWorker(GROUP_UI));
+ scoped_refptr<ModelSafeWorker> db_worker(
+ new FakeModelWorker(GROUP_DB));
+ workers_.push_back(passive_worker);
+ workers_.push_back(ui_worker);
+ workers_.push_back(db_worker);
+
+ registry_.reset(new ModelTypeRegistry(workers_, directory()));
+}
+
+void ModelTypeRegistryTest::TearDown() {
+ registry_.reset();
+ workers_.clear();
+ dir_maker_.TearDown();
+}
+
+ModelTypeRegistry* ModelTypeRegistryTest::registry() {
+ return registry_.get();
+}
+
+syncable::Directory* ModelTypeRegistryTest::directory() {
+ return dir_maker_.directory();
+}
+
+// Create some directory update handlers and commit contributors.
+//
+// We don't get to inspect any of the state we're modifying. This test is
+// useful only for detecting crashes or memory leaks.
+TEST_F(ModelTypeRegistryTest, SetEnabledDirectoryTypes_Once) {
+ ModelSafeRoutingInfo routing_info;
+ routing_info.insert(std::make_pair(NIGORI, GROUP_PASSIVE));
+ routing_info.insert(std::make_pair(BOOKMARKS, GROUP_UI));
+ routing_info.insert(std::make_pair(AUTOFILL, GROUP_DB));
+
+ registry()->SetEnabledDirectoryTypes(routing_info);
+}
+
+// Try two different routing info settings.
+//
+// We don't get to inspect any of the state we're modifying. This test is
+// useful only for detecting crashes or memory leaks.
+TEST_F(ModelTypeRegistryTest, SetEnabledDirectoryTypes_Repeatedly) {
+ ModelSafeRoutingInfo routing_info1;
+ routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE));
+ routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_PASSIVE));
+ routing_info1.insert(std::make_pair(AUTOFILL, GROUP_PASSIVE));
+
+ registry()->SetEnabledDirectoryTypes(routing_info1);
+
+ ModelSafeRoutingInfo routing_info2;
+ routing_info2.insert(std::make_pair(NIGORI, GROUP_PASSIVE));
+ routing_info2.insert(std::make_pair(BOOKMARKS, GROUP_UI));
+ routing_info2.insert(std::make_pair(AUTOFILL, GROUP_DB));
+
+ registry()->SetEnabledDirectoryTypes(routing_info2);
+}
+
+// Test removing all types from the list.
+//
+// We don't get to inspect any of the state we're modifying. This test is
+// useful only for detecting crashes or memory leaks.
+TEST_F(ModelTypeRegistryTest, SetEnabledDirectoryTypes_Clear) {
+ ModelSafeRoutingInfo routing_info1;
+ routing_info1.insert(std::make_pair(NIGORI, GROUP_PASSIVE));
+ routing_info1.insert(std::make_pair(BOOKMARKS, GROUP_UI));
+ routing_info1.insert(std::make_pair(AUTOFILL, GROUP_DB));
+
+ registry()->SetEnabledDirectoryTypes(routing_info1);
+
+ ModelSafeRoutingInfo routing_info2;
+ registry()->SetEnabledDirectoryTypes(routing_info2);
+}
+
+} // namespace syncer
« no previous file with comments | « sync/sessions/model_type_registry.cc ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698