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

Unified Diff: sync/internal_api/sync_context_proxy_impl_unittest.cc

Issue 351523003: sync: Mass rename of non-blocking sync classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const ref some smart pointers Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/internal_api/sync_context_proxy_impl.cc ('k') | sync/internal_api/sync_core.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/sync_context_proxy_impl_unittest.cc
diff --git a/sync/internal_api/sync_context_proxy_impl_unittest.cc b/sync/internal_api/sync_context_proxy_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..62edfece46957a612d70a0ce92ea09e5430c12ed
--- /dev/null
+++ b/sync/internal_api/sync_context_proxy_impl_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 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 "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/run_loop.h"
+#include "base/sequenced_task_runner.h"
+#include "sync/engine/model_type_sync_proxy_impl.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "sync/internal_api/sync_context.h"
+#include "sync/internal_api/sync_context_proxy_impl.h"
+#include "sync/sessions/model_type_registry.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncer {
+
+class SyncContextProxyImplTest : public ::testing::Test {
+ public:
+ SyncContextProxyImplTest()
+ : sync_task_runner_(base::MessageLoopProxy::current()),
+ type_task_runner_(base::MessageLoopProxy::current()),
+ context_(new SyncContext(&registry_)),
+ context_proxy_(sync_task_runner_, context_->AsWeakPtr()) {}
+
+ // The sync thread could be shut down at any time without warning. This
+ // function simulates such an event.
+ void DisableSync() { context_.reset(); }
+
+ scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_.Clone(); }
+
+ private:
+ base::MessageLoop loop_;
+ scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> type_task_runner_;
+ ModelTypeRegistry registry_;
+ scoped_ptr<SyncContext> context_;
+ SyncContextProxyImpl context_proxy_;
+};
+
+// Try to connect a type to a SyncContext that has already shut down.
+TEST_F(SyncContextProxyImplTest, FailToConnect1) {
+ ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES);
+ DisableSync();
+ themes_sync_proxy.Enable(GetProxy());
+
+ base::RunLoop run_loop_;
+ run_loop_.RunUntilIdle();
+ EXPECT_FALSE(themes_sync_proxy.IsConnected());
+}
+
+// Try to connect a type to a SyncContext as it shuts down.
+TEST_F(SyncContextProxyImplTest, FailToConnect2) {
+ ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES);
+ themes_sync_proxy.Enable(GetProxy());
+ DisableSync();
+
+ base::RunLoop run_loop_;
+ run_loop_.RunUntilIdle();
+ EXPECT_FALSE(themes_sync_proxy.IsConnected());
+}
+
+// Tests the case where the type's sync proxy shuts down first.
+TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) {
+ scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy(
+ new ModelTypeSyncProxyImpl(syncer::THEMES));
+ themes_sync_proxy->Enable(GetProxy());
+
+ base::RunLoop run_loop_;
+ run_loop_.RunUntilIdle();
+
+ EXPECT_TRUE(themes_sync_proxy->IsConnected());
+ themes_sync_proxy.reset();
+}
+
+// Tests the case where the sync thread shuts down first.
+TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) {
+ scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy(
+ new ModelTypeSyncProxyImpl(syncer::THEMES));
+ themes_sync_proxy->Enable(GetProxy());
+
+ base::RunLoop run_loop_;
+ run_loop_.RunUntilIdle();
+
+ EXPECT_TRUE(themes_sync_proxy->IsConnected());
+ DisableSync();
+}
+
+} // namespace syncer
« no previous file with comments | « sync/internal_api/sync_context_proxy_impl.cc ('k') | sync/internal_api/sync_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698