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

Side by Side Diff: chrome/browser/sync/glue/android_invalidator_bridge_proxy_unittest.cc

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h"
6
7 #include <string>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread.h"
11 #include "chrome/browser/sync/glue/android_invalidator_bridge.h"
12 #include "chrome/test/base/profile_mock.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/base/model_type_test_util.h"
16 #include "sync/notifier/fake_invalidation_handler.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace syncer {
21 class InvalidationStateTracker;
22 } // namespace syncer
23
24 namespace browser_sync {
25
26 namespace {
27
28 // All tests just verify that each call is passed through to the delegate, with
29 // the exception of RegisterHandler, UnregisterHandler, and
30 // UpdateRegisteredIds, which also verifies the call is forwarded to the
31 // bridge.
32 class AndroidInvalidatorBridgeProxyTest : public testing::Test {
33 public:
34 AndroidInvalidatorBridgeProxyTest()
35 : ui_thread_(content::BrowserThread::UI, &ui_loop_),
36 bridge_(&mock_profile_, ui_loop_.message_loop_proxy()),
37 invalidator_(new AndroidInvalidatorBridgeProxy(&bridge_)) {
38 // Pump |ui_loop_| to fully initialize |bridge_|.
39 ui_loop_.RunUntilIdle();
40 }
41
42 virtual ~AndroidInvalidatorBridgeProxyTest() {
43 DestroyInvalidator();
44 }
45
46 AndroidInvalidatorBridge* GetBridge() {
47 return &bridge_;
48 }
49
50 AndroidInvalidatorBridgeProxy* GetInvalidator() {
51 return invalidator_.get();
52 }
53
54 protected:
55 void DestroyInvalidator() {
56 invalidator_.reset();
57 bridge_.StopForShutdown();
58 ui_loop_.RunUntilIdle();
59 }
60
61 MessageLoop ui_loop_;
62 content::TestBrowserThread ui_thread_;
63 ::testing::NiceMock<ProfileMock> mock_profile_;
64 AndroidInvalidatorBridge bridge_;
65 scoped_ptr<AndroidInvalidatorBridgeProxy> invalidator_;
66 };
67
68 TEST_F(AndroidInvalidatorBridgeProxyTest, HandlerMethods) {
69 syncer::ObjectIdSet ids;
70 ids.insert(invalidation::ObjectId(1, "id1"));
71
72 syncer::FakeInvalidationHandler handler;
73
74 GetInvalidator()->RegisterHandler(&handler);
75 EXPECT_TRUE(GetBridge()->IsHandlerRegisteredForTest(&handler));
76
77 GetInvalidator()->UpdateRegisteredIds(&handler, ids);
78 EXPECT_EQ(ids, GetBridge()->GetRegisteredIdsForTest(&handler));
79
80 GetInvalidator()->UnregisterHandler(&handler);
81 EXPECT_FALSE(GetBridge()->IsHandlerRegisteredForTest(&handler));
82 }
83
84 TEST_F(AndroidInvalidatorBridgeProxyTest, GetInvalidatorState) {
85 // The AndroidInvalidatorBridge never enters an error state.
86 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED,
87 GetInvalidator()->GetInvalidatorState());
88 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED,
89 GetBridge()->GetInvalidatorState());
90 }
91
92 } // namespace
93 } // namespace browser_sync
94
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698