Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / sync / internal_api / sync_core_proxy_impl_unittest.cc
blob2e306ee28fdef43cb9c2acb9a361ddb59f9b6d2e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h"
8 #include "base/sequenced_task_runner.h"
9 #include "sync/internal_api/public/base/model_type.h"
10 #include "sync/internal_api/public/non_blocking_type_processor.h"
11 #include "sync/internal_api/sync_core.h"
12 #include "sync/internal_api/sync_core_proxy_impl.h"
13 #include "sync/sessions/model_type_registry.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace syncer {
18 class SyncCoreProxyImplTest : public ::testing::Test {
19 public:
20 SyncCoreProxyImplTest()
21 : sync_task_runner_(base::MessageLoopProxy::current()),
22 type_task_runner_(base::MessageLoopProxy::current()),
23 core_(new SyncCore(&registry_)),
24 core_proxy_(
25 sync_task_runner_,
26 core_->AsWeakPtr()) {}
28 // The sync thread could be shut down at any time without warning. This
29 // function simulates such an event.
30 void DisableSync() {
31 core_.reset();
34 SyncCoreProxy* GetProxy() {
35 return &core_proxy_;
38 private:
39 base::MessageLoop loop_;
40 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
41 scoped_refptr<base::SequencedTaskRunner> type_task_runner_;
42 ModelTypeRegistry registry_;
43 scoped_ptr<SyncCore> core_;
44 SyncCoreProxyImpl core_proxy_;
47 // Try to connect a type to a SyncCore that has already shut down.
48 TEST_F(SyncCoreProxyImplTest, FailToConnect1) {
49 NonBlockingTypeProcessor themes_processor(syncer::THEMES);
50 DisableSync();
51 themes_processor.Enable(GetProxy());
53 base::RunLoop run_loop_;
54 run_loop_.RunUntilIdle();
55 EXPECT_FALSE(themes_processor.IsConnected());
58 // Try to connect a type to a SyncCore as it shuts down.
59 TEST_F(SyncCoreProxyImplTest, FailToConnect2) {
60 NonBlockingTypeProcessor themes_processor(syncer::THEMES);
61 themes_processor.Enable(GetProxy());
62 DisableSync();
64 base::RunLoop run_loop_;
65 run_loop_.RunUntilIdle();
66 EXPECT_FALSE(themes_processor.IsConnected());
69 // Tests the case where the type's processor shuts down first.
70 TEST_F(SyncCoreProxyImplTest, TypeDisconnectsFirst) {
71 scoped_ptr<NonBlockingTypeProcessor> themes_processor
72 (new NonBlockingTypeProcessor(syncer::THEMES));
73 themes_processor->Enable(GetProxy());
75 base::RunLoop run_loop_;
76 run_loop_.RunUntilIdle();
78 EXPECT_TRUE(themes_processor->IsConnected());
79 themes_processor.reset();
82 // Tests the case where the sync thread shuts down first.
83 TEST_F(SyncCoreProxyImplTest, SyncDisconnectsFirst) {
84 scoped_ptr<NonBlockingTypeProcessor> themes_processor
85 (new NonBlockingTypeProcessor(syncer::THEMES));
86 themes_processor->Enable(GetProxy());
88 base::RunLoop run_loop_;
89 run_loop_.RunUntilIdle();
91 EXPECT_TRUE(themes_processor->IsConnected());
92 DisableSync();
95 } // namespace syncer