OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" | 5 #include "components/ntp_snippets/sessions/tab_delegate_sync_adapter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/sync/driver/fake_sync_service.h" | 10 #include "components/sync/driver/fake_sync_service.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 TabDelegateSyncAdapter adapter_; | 78 TabDelegateSyncAdapter adapter_; |
79 int callback_count_ = 0; | 79 int callback_count_ = 0; |
80 | 80 |
81 DISALLOW_COPY_AND_ASSIGN(TabDelegateSyncAdapterTest); | 81 DISALLOW_COPY_AND_ASSIGN(TabDelegateSyncAdapterTest); |
82 }; | 82 }; |
83 | 83 |
84 // CallbackCount should only trigger on transitions between having and not | 84 // CallbackCount should only trigger on transitions between having and not |
85 // having open tabs. | 85 // having open tabs. |
86 TEST_F(TabDelegateSyncAdapterTest, CallbackCount) { | 86 TEST_F(TabDelegateSyncAdapterTest, CallbackCount) { |
87 ASSERT_EQ(0, CallbackCount()); | 87 ASSERT_EQ(0, CallbackCount()); |
88 observer()->OnStateChanged(); | 88 observer()->OnStateChanged(&service_); |
89 EXPECT_EQ(0, CallbackCount()); | 89 EXPECT_EQ(0, CallbackCount()); |
90 | 90 |
91 SetHasOpenTabs(true); | 91 SetHasOpenTabs(true); |
92 observer()->OnStateChanged(); | 92 observer()->OnStateChanged(&service_); |
93 EXPECT_EQ(1, CallbackCount()); | 93 EXPECT_EQ(1, CallbackCount()); |
94 observer()->OnStateChanged(); | 94 observer()->OnStateChanged(&service_); |
95 EXPECT_EQ(1, CallbackCount()); | 95 EXPECT_EQ(1, CallbackCount()); |
96 | 96 |
97 SetHasOpenTabs(false); | 97 SetHasOpenTabs(false); |
98 observer()->OnStateChanged(); | 98 observer()->OnStateChanged(&service_); |
99 EXPECT_EQ(2, CallbackCount()); | 99 EXPECT_EQ(2, CallbackCount()); |
100 observer()->OnStateChanged(); | 100 observer()->OnStateChanged(&service_); |
101 EXPECT_EQ(2, CallbackCount()); | 101 EXPECT_EQ(2, CallbackCount()); |
102 | 102 |
103 // OnSyncCycleCompleted should behave like OnStateChanged. | 103 // OnSyncCycleCompleted should behave like OnStateChanged. |
104 observer()->OnSyncCycleCompleted(); | 104 observer()->OnSyncCycleCompleted(&service_); |
105 EXPECT_EQ(2, CallbackCount()); | 105 EXPECT_EQ(2, CallbackCount()); |
106 SetHasOpenTabs(true); | 106 SetHasOpenTabs(true); |
107 observer()->OnSyncCycleCompleted(); | 107 observer()->OnSyncCycleCompleted(&service_); |
108 EXPECT_EQ(3, CallbackCount()); | 108 EXPECT_EQ(3, CallbackCount()); |
109 observer()->OnSyncCycleCompleted(); | 109 observer()->OnSyncCycleCompleted(&service_); |
110 EXPECT_EQ(3, CallbackCount()); | 110 EXPECT_EQ(3, CallbackCount()); |
111 } | 111 } |
112 | 112 |
113 // No callback should be invoked from OnSyncConfigurationCompleted. | 113 // No callback should be invoked from OnSyncConfigurationCompleted. |
114 TEST_F(TabDelegateSyncAdapterTest, OnSyncConfigurationCompleted) { | 114 TEST_F(TabDelegateSyncAdapterTest, OnSyncConfigurationCompleted) { |
115 ASSERT_EQ(0, CallbackCount()); | 115 ASSERT_EQ(0, CallbackCount()); |
116 | 116 |
117 observer()->OnSyncConfigurationCompleted(); | 117 observer()->OnSyncConfigurationCompleted(&service_); |
118 EXPECT_EQ(0, CallbackCount()); | 118 EXPECT_EQ(0, CallbackCount()); |
119 | 119 |
120 SetHasOpenTabs(true); | 120 SetHasOpenTabs(true); |
121 observer()->OnSyncConfigurationCompleted(); | 121 observer()->OnSyncConfigurationCompleted(&service_); |
122 EXPECT_EQ(0, CallbackCount()); | 122 EXPECT_EQ(0, CallbackCount()); |
123 } | 123 } |
124 | 124 |
125 // OnForeignSessionUpdated should always trigger a callback. | 125 // OnForeignSessionUpdated should always trigger a callback. |
126 TEST_F(TabDelegateSyncAdapterTest, OnForeignSessionUpdated) { | 126 TEST_F(TabDelegateSyncAdapterTest, OnForeignSessionUpdated) { |
127 ASSERT_EQ(0, CallbackCount()); | 127 ASSERT_EQ(0, CallbackCount()); |
128 observer()->OnForeignSessionUpdated(); | 128 observer()->OnForeignSessionUpdated(&service_); |
129 EXPECT_EQ(1, CallbackCount()); | 129 EXPECT_EQ(1, CallbackCount()); |
130 observer()->OnForeignSessionUpdated(); | 130 observer()->OnForeignSessionUpdated(&service_); |
131 EXPECT_EQ(2, CallbackCount()); | 131 EXPECT_EQ(2, CallbackCount()); |
132 | 132 |
133 SetHasOpenTabs(true); | 133 SetHasOpenTabs(true); |
134 observer()->OnForeignSessionUpdated(); | 134 observer()->OnForeignSessionUpdated(&service_); |
135 EXPECT_EQ(3, CallbackCount()); | 135 EXPECT_EQ(3, CallbackCount()); |
136 observer()->OnForeignSessionUpdated(); | 136 observer()->OnForeignSessionUpdated(&service_); |
137 EXPECT_EQ(4, CallbackCount()); | 137 EXPECT_EQ(4, CallbackCount()); |
138 } | 138 } |
139 | 139 |
140 // If OnForeignSessionUpdated is called before OnStateChanged, then calling | 140 // If OnForeignSessionUpdated is called before OnStateChanged, then calling |
141 // OnStateChanged should not trigger a callback. | 141 // OnStateChanged should not trigger a callback. |
142 TEST_F(TabDelegateSyncAdapterTest, OnForeignSessionUpdatedUpdatesState) { | 142 TEST_F(TabDelegateSyncAdapterTest, OnForeignSessionUpdatedUpdatesState) { |
143 SetHasOpenTabs(true); | 143 SetHasOpenTabs(true); |
144 observer()->OnForeignSessionUpdated(); | 144 observer()->OnForeignSessionUpdated(&service_); |
145 EXPECT_EQ(1, CallbackCount()); | 145 EXPECT_EQ(1, CallbackCount()); |
146 | 146 |
147 observer()->OnStateChanged(); | 147 observer()->OnStateChanged(&service_); |
148 EXPECT_EQ(1, CallbackCount()); | 148 EXPECT_EQ(1, CallbackCount()); |
149 } | 149 } |
150 | 150 |
151 } // namespace | 151 } // namespace |
152 } // namespace ntp_snippets | 152 } // namespace ntp_snippets |
OLD | NEW |