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

Side by Side Diff: components/feature_engagement_tracker/internal/model_impl_unittest.cc

Issue 2877243002: Support IPH NotifyEvent calls before Initialize (Closed)
Patch Set: Fixed build.gn Created 3 years, 7 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
« no previous file with comments | « components/feature_engagement_tracker/internal/model_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/feature_engagement_tracker/internal/model_impl.h" 5 #include "components/feature_engagement_tracker/internal/model_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/test/test_simple_task_runner.h"
14 #include "base/run_loop.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/feature_engagement_tracker/internal/editable_configuration. h" 15 #include "components/feature_engagement_tracker/internal/editable_configuration. h"
16 #include "components/feature_engagement_tracker/internal/in_memory_store.h" 16 #include "components/feature_engagement_tracker/internal/in_memory_store.h"
17 #include "components/feature_engagement_tracker/internal/never_storage_validator .h" 17 #include "components/feature_engagement_tracker/internal/never_storage_validator .h"
18 #include "components/feature_engagement_tracker/internal/proto/event.pb.h" 18 #include "components/feature_engagement_tracker/internal/proto/event.pb.h"
19 #include "components/feature_engagement_tracker/internal/test/event_util.h" 19 #include "components/feature_engagement_tracker/internal/test/event_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace feature_engagement_tracker { 22 namespace feature_engagement_tracker {
23 23
24 namespace { 24 namespace {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 test::SetEventCountForDay(&qux, 2, 1); 122 test::SetEventCountForDay(&qux, 2, 1);
123 test::SetEventCountForDay(&qux, 3, 2); 123 test::SetEventCountForDay(&qux, 3, 2);
124 events->push_back(qux); 124 events->push_back(qux);
125 125
126 return base::MakeUnique<TestInMemoryStore>(std::move(events), true); 126 return base::MakeUnique<TestInMemoryStore>(std::move(events), true);
127 } 127 }
128 128
129 class ModelImplTest : public ::testing::Test { 129 class ModelImplTest : public ::testing::Test {
130 public: 130 public:
131 ModelImplTest() 131 ModelImplTest()
132 : got_initialize_callback_(false), initialize_callback_result_(false) {} 132 : task_runner_(new base::TestSimpleTaskRunner),
133 handle_(task_runner_),
134 got_initialize_callback_(false),
135 initialize_callback_result_(false) {}
133 136
134 void SetUp() override { 137 void SetUp() override {
135 std::unique_ptr<TestInMemoryStore> store = CreateStore(); 138 std::unique_ptr<TestInMemoryStore> store = CreateStore();
136 store_ = store.get(); 139 store_ = store.get();
137 140
138 auto storage_validator = base::MakeUnique<TestStorageValidator>(); 141 auto storage_validator = base::MakeUnique<TestStorageValidator>();
139 storage_validator_ = storage_validator.get(); 142 storage_validator_ = storage_validator.get();
140 143
141 model_.reset(new ModelImpl(std::move(store), std::move(storage_validator))); 144 model_.reset(new ModelImpl(std::move(store), std::move(storage_validator)));
142 145
143 // By default store all events for a very long time. 146 // By default store all events for a very long time.
144 storage_validator_->SetMaxKeepAge("foo", 10000u); 147 storage_validator_->SetMaxKeepAge("foo", 10000u);
145 storage_validator_->SetMaxKeepAge("bar", 10000u); 148 storage_validator_->SetMaxKeepAge("bar", 10000u);
146 storage_validator_->SetMaxKeepAge("qux", 10000u); 149 storage_validator_->SetMaxKeepAge("qux", 10000u);
147 } 150 }
148 151
149 virtual std::unique_ptr<TestInMemoryStore> CreateStore() { 152 virtual std::unique_ptr<TestInMemoryStore> CreateStore() {
150 return CreatePrefilledStore(); 153 return CreatePrefilledStore();
151 } 154 }
152 155
153 void OnModelInitializationFinished(bool success) { 156 void OnModelInitializationFinished(bool success) {
154 got_initialize_callback_ = true; 157 got_initialize_callback_ = true;
155 initialize_callback_result_ = success; 158 initialize_callback_result_ = success;
156 } 159 }
157 160
158 protected: 161 protected:
162 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
163 base::ThreadTaskRunnerHandle handle_;
164
159 std::unique_ptr<ModelImpl> model_; 165 std::unique_ptr<ModelImpl> model_;
160 TestInMemoryStore* store_; 166 TestInMemoryStore* store_;
161 TestStorageValidator* storage_validator_; 167 TestStorageValidator* storage_validator_;
162 bool got_initialize_callback_; 168 bool got_initialize_callback_;
163 bool initialize_callback_result_; 169 bool initialize_callback_result_;
164
165 private:
166 base::MessageLoop message_loop_;
167 }; 170 };
168 171
169 class LoadFailingModelImplTest : public ModelImplTest { 172 class LoadFailingModelImplTest : public ModelImplTest {
170 public: 173 public:
171 LoadFailingModelImplTest() : ModelImplTest() {} 174 LoadFailingModelImplTest() : ModelImplTest() {}
172 175
173 std::unique_ptr<TestInMemoryStore> CreateStore() override { 176 std::unique_ptr<TestInMemoryStore> CreateStore() override {
174 return base::MakeUnique<TestInMemoryStore>( 177 return base::MakeUnique<TestInMemoryStore>(
175 base::MakeUnique<std::vector<Event>>(), false); 178 base::MakeUnique<std::vector<Event>>(), false);
176 } 179 }
177 }; 180 };
178 181
179 } // namespace 182 } // namespace
180 183
184 TEST_F(ModelImplTest, InitializeShouldBeReadyImmediatelyAfterCallback) {
185 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
186 base::Unretained(this)),
187 1000u);
188
189 // Only run pending tasks on the queue. Do not run any subsequently queued
190 // tasks that result from running the current pending tasks.
191 task_runner_->RunPendingTasks();
192
193 EXPECT_TRUE(got_initialize_callback_);
194 EXPECT_TRUE(model_->IsReady());
195 }
196
181 TEST_F(ModelImplTest, InitializeShouldLoadEntries) { 197 TEST_F(ModelImplTest, InitializeShouldLoadEntries) {
182 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 198 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
183 base::Unretained(this)), 199 base::Unretained(this)),
184 1000u); 200 1000u);
185 base::RunLoop().RunUntilIdle(); 201 task_runner_->RunUntilIdle();
186 EXPECT_TRUE(model_->IsReady()); 202 EXPECT_TRUE(model_->IsReady());
187 EXPECT_TRUE(got_initialize_callback_); 203 EXPECT_TRUE(got_initialize_callback_);
188 EXPECT_TRUE(initialize_callback_result_); 204 EXPECT_TRUE(initialize_callback_result_);
189 205
190 // Verify that all the data matches what was put into the store in 206 // Verify that all the data matches what was put into the store in
191 // CreateStore(). 207 // CreateStore().
192 const Event* foo_event = model_->GetEvent("foo"); 208 const Event* foo_event = model_->GetEvent("foo");
193 EXPECT_EQ("foo", foo_event->name()); 209 EXPECT_EQ("foo", foo_event->name());
194 EXPECT_EQ(1, foo_event->events_size()); 210 EXPECT_EQ(1, foo_event->events_size());
195 test::VerifyEventCount(foo_event, 1u, 1u); 211 test::VerifyEventCount(foo_event, 1u, 1u);
(...skipping 19 matching lines...) Expand all
215 231
216 // Back to day 2, i.e. 2 events. 232 // Back to day 2, i.e. 2 events.
217 storage_validator_->SetMaxKeepAge("bar", 4u); 233 storage_validator_->SetMaxKeepAge("bar", 4u);
218 234
219 // Back to day epoch, i.e. all events. 235 // Back to day epoch, i.e. all events.
220 storage_validator_->SetMaxKeepAge("qux", 10u); 236 storage_validator_->SetMaxKeepAge("qux", 10u);
221 237
222 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 238 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
223 base::Unretained(this)), 239 base::Unretained(this)),
224 5u); 240 5u);
225 base::RunLoop().RunUntilIdle(); 241 task_runner_->RunUntilIdle();
226 EXPECT_TRUE(model_->IsReady()); 242 EXPECT_TRUE(model_->IsReady());
227 EXPECT_TRUE(got_initialize_callback_); 243 EXPECT_TRUE(got_initialize_callback_);
228 EXPECT_TRUE(initialize_callback_result_); 244 EXPECT_TRUE(initialize_callback_result_);
229 245
230 // Verify that all the data matches what was put into the store in 246 // Verify that all the data matches what was put into the store in
231 // CreateStore(), minus the events that should no longer exist. 247 // CreateStore(), minus the events that should no longer exist.
232 const Event* foo_event = model_->GetEvent("foo"); 248 const Event* foo_event = model_->GetEvent("foo");
233 EXPECT_EQ(nullptr, foo_event); 249 EXPECT_EQ(nullptr, foo_event);
234 EXPECT_EQ("foo", store_->GetLastDeletedEvent()); 250 EXPECT_EQ("foo", store_->GetLastDeletedEvent());
235 251
(...skipping 14 matching lines...) Expand all
250 266
251 // In total, only two operations should have happened, the update of "bar", 267 // In total, only two operations should have happened, the update of "bar",
252 // and the delete of "foo". 268 // and the delete of "foo".
253 EXPECT_EQ(2u, store_->GetStoreOperationCount()); 269 EXPECT_EQ(2u, store_->GetStoreOperationCount());
254 } 270 }
255 271
256 TEST_F(ModelImplTest, RetrievingNewEventsShouldYieldNullptr) { 272 TEST_F(ModelImplTest, RetrievingNewEventsShouldYieldNullptr) {
257 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 273 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
258 base::Unretained(this)), 274 base::Unretained(this)),
259 1000u); 275 1000u);
260 base::RunLoop().RunUntilIdle(); 276 task_runner_->RunUntilIdle();
261 EXPECT_TRUE(model_->IsReady()); 277 EXPECT_TRUE(model_->IsReady());
262 278
263 const Event* no_event = model_->GetEvent("no"); 279 const Event* no_event = model_->GetEvent("no");
264 EXPECT_EQ(nullptr, no_event); 280 EXPECT_EQ(nullptr, no_event);
265 test::VerifyEventsEqual(nullptr, store_->GetLastWrittenEvent()); 281 test::VerifyEventsEqual(nullptr, store_->GetLastWrittenEvent());
266 } 282 }
267 283
268 TEST_F(ModelImplTest, IncrementingNonExistingEvent) { 284 TEST_F(ModelImplTest, IncrementingNonExistingEvent) {
269 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 285 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
270 base::Unretained(this)), 286 base::Unretained(this)),
271 1000u); 287 1000u);
272 base::RunLoop().RunUntilIdle(); 288 task_runner_->RunUntilIdle();
273 EXPECT_TRUE(model_->IsReady()); 289 EXPECT_TRUE(model_->IsReady());
274 290
275 // Incrementing the event should work even if it does not exist. 291 // Incrementing the event should work even if it does not exist.
276 model_->IncrementEvent("nonexisting", 1u); 292 model_->IncrementEvent("nonexisting", 1u);
277 const Event* event1 = model_->GetEvent("nonexisting"); 293 const Event* event1 = model_->GetEvent("nonexisting");
278 ASSERT_NE(nullptr, event1); 294 ASSERT_NE(nullptr, event1);
279 EXPECT_EQ("nonexisting", event1->name()); 295 EXPECT_EQ("nonexisting", event1->name());
280 EXPECT_EQ(1, event1->events_size()); 296 EXPECT_EQ(1, event1->events_size());
281 test::VerifyEventCount(event1, 1u, 1u); 297 test::VerifyEventCount(event1, 1u, 1u);
282 test::VerifyEventsEqual(event1, store_->GetLastWrittenEvent()); 298 test::VerifyEventsEqual(event1, store_->GetLastWrittenEvent());
283 299
284 // Incrementing the event after it has been initialized to 1, it should now 300 // Incrementing the event after it has been initialized to 1, it should now
285 // have a count of 2 for the given day. 301 // have a count of 2 for the given day.
286 model_->IncrementEvent("nonexisting", 1u); 302 model_->IncrementEvent("nonexisting", 1u);
287 const Event* event2 = model_->GetEvent("nonexisting"); 303 const Event* event2 = model_->GetEvent("nonexisting");
288 ASSERT_NE(nullptr, event2); 304 ASSERT_NE(nullptr, event2);
289 Event_Count event2_count = event2->events(0); 305 Event_Count event2_count = event2->events(0);
290 EXPECT_EQ(1, event2->events_size()); 306 EXPECT_EQ(1, event2->events_size());
291 test::VerifyEventCount(event2, 1u, 2u); 307 test::VerifyEventCount(event2, 1u, 2u);
292 test::VerifyEventsEqual(event2, store_->GetLastWrittenEvent()); 308 test::VerifyEventsEqual(event2, store_->GetLastWrittenEvent());
293 } 309 }
294 310
295 TEST_F(ModelImplTest, IncrementingNonExistingEventMultipleDays) { 311 TEST_F(ModelImplTest, IncrementingNonExistingEventMultipleDays) {
296 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 312 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
297 base::Unretained(this)), 313 base::Unretained(this)),
298 1000u); 314 1000u);
299 base::RunLoop().RunUntilIdle(); 315 task_runner_->RunUntilIdle();
300 EXPECT_TRUE(model_->IsReady()); 316 EXPECT_TRUE(model_->IsReady());
301 317
302 model_->IncrementEvent("nonexisting", 1u); 318 model_->IncrementEvent("nonexisting", 1u);
303 model_->IncrementEvent("nonexisting", 2u); 319 model_->IncrementEvent("nonexisting", 2u);
304 model_->IncrementEvent("nonexisting", 2u); 320 model_->IncrementEvent("nonexisting", 2u);
305 model_->IncrementEvent("nonexisting", 3u); 321 model_->IncrementEvent("nonexisting", 3u);
306 const Event* event = model_->GetEvent("nonexisting"); 322 const Event* event = model_->GetEvent("nonexisting");
307 ASSERT_NE(nullptr, event); 323 ASSERT_NE(nullptr, event);
308 EXPECT_EQ(3, event->events_size()); 324 EXPECT_EQ(3, event->events_size());
309 test::VerifyEventCount(event, 1u, 1u); 325 test::VerifyEventCount(event, 1u, 1u);
310 test::VerifyEventCount(event, 2u, 2u); 326 test::VerifyEventCount(event, 2u, 2u);
311 test::VerifyEventCount(event, 3u, 1u); 327 test::VerifyEventCount(event, 3u, 1u);
312 test::VerifyEventsEqual(event, store_->GetLastWrittenEvent()); 328 test::VerifyEventsEqual(event, store_->GetLastWrittenEvent());
313 } 329 }
314 330
315 TEST_F(ModelImplTest, IncrementingNonExistingEventWithoutStoring) { 331 TEST_F(ModelImplTest, IncrementingNonExistingEventWithoutStoring) {
316 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 332 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
317 base::Unretained(this)), 333 base::Unretained(this)),
318 1000u); 334 1000u);
319 base::RunLoop().RunUntilIdle(); 335 task_runner_->RunUntilIdle();
320 EXPECT_TRUE(model_->IsReady()); 336 EXPECT_TRUE(model_->IsReady());
321 337
322 storage_validator_->SetShouldStore(false); 338 storage_validator_->SetShouldStore(false);
323 339
324 // Incrementing the event should not be written or stored in-memory. 340 // Incrementing the event should not be written or stored in-memory.
325 model_->IncrementEvent("nonexisting", 1u); 341 model_->IncrementEvent("nonexisting", 1u);
326 const Event* event1 = model_->GetEvent("nonexisting"); 342 const Event* event1 = model_->GetEvent("nonexisting");
327 EXPECT_EQ(nullptr, event1); 343 EXPECT_EQ(nullptr, event1);
328 test::VerifyEventsEqual(nullptr, store_->GetLastWrittenEvent()); 344 test::VerifyEventsEqual(nullptr, store_->GetLastWrittenEvent());
329 } 345 }
330 346
331 TEST_F(ModelImplTest, IncrementingExistingEventWithoutStoring) { 347 TEST_F(ModelImplTest, IncrementingExistingEventWithoutStoring) {
332 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 348 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
333 base::Unretained(this)), 349 base::Unretained(this)),
334 1000u); 350 1000u);
335 base::RunLoop().RunUntilIdle(); 351 task_runner_->RunUntilIdle();
336 EXPECT_TRUE(model_->IsReady()); 352 EXPECT_TRUE(model_->IsReady());
337 353
338 // Write one event before turning off storage. 354 // Write one event before turning off storage.
339 model_->IncrementEvent("nonexisting", 1u); 355 model_->IncrementEvent("nonexisting", 1u);
340 const Event* first_event = model_->GetEvent("nonexisting"); 356 const Event* first_event = model_->GetEvent("nonexisting");
341 ASSERT_NE(nullptr, first_event); 357 ASSERT_NE(nullptr, first_event);
342 test::VerifyEventsEqual(first_event, store_->GetLastWrittenEvent()); 358 test::VerifyEventsEqual(first_event, store_->GetLastWrittenEvent());
343 359
344 storage_validator_->SetShouldStore(false); 360 storage_validator_->SetShouldStore(false);
345 361
346 // Incrementing the event should no longer be written or stored in-memory. 362 // Incrementing the event should no longer be written or stored in-memory.
347 model_->IncrementEvent("nonexisting", 1u); 363 model_->IncrementEvent("nonexisting", 1u);
348 const Event* second_event = model_->GetEvent("nonexisting"); 364 const Event* second_event = model_->GetEvent("nonexisting");
349 EXPECT_EQ(first_event, second_event); 365 EXPECT_EQ(first_event, second_event);
350 test::VerifyEventsEqual(first_event, store_->GetLastWrittenEvent()); 366 test::VerifyEventsEqual(first_event, store_->GetLastWrittenEvent());
351 } 367 }
352 368
353 TEST_F(ModelImplTest, IncrementingSingleDayExistingEvent) { 369 TEST_F(ModelImplTest, IncrementingSingleDayExistingEvent) {
354 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 370 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
355 base::Unretained(this)), 371 base::Unretained(this)),
356 1000u); 372 1000u);
357 base::RunLoop().RunUntilIdle(); 373 task_runner_->RunUntilIdle();
358 EXPECT_TRUE(model_->IsReady()); 374 EXPECT_TRUE(model_->IsReady());
359 375
360 // |foo| is inserted into the store with a count of 1 at day 1. 376 // |foo| is inserted into the store with a count of 1 at day 1.
361 const Event* foo_event = model_->GetEvent("foo"); 377 const Event* foo_event = model_->GetEvent("foo");
362 EXPECT_EQ("foo", foo_event->name()); 378 EXPECT_EQ("foo", foo_event->name());
363 EXPECT_EQ(1, foo_event->events_size()); 379 EXPECT_EQ(1, foo_event->events_size());
364 test::VerifyEventCount(foo_event, 1u, 1u); 380 test::VerifyEventCount(foo_event, 1u, 1u);
365 381
366 // Incrementing |foo| should change count to 2. 382 // Incrementing |foo| should change count to 2.
367 model_->IncrementEvent("foo", 1u); 383 model_->IncrementEvent("foo", 1u);
368 const Event* foo_event2 = model_->GetEvent("foo"); 384 const Event* foo_event2 = model_->GetEvent("foo");
369 EXPECT_EQ(1, foo_event2->events_size()); 385 EXPECT_EQ(1, foo_event2->events_size());
370 test::VerifyEventCount(foo_event2, 1u, 2u); 386 test::VerifyEventCount(foo_event2, 1u, 2u);
371 test::VerifyEventsEqual(foo_event2, store_->GetLastWrittenEvent()); 387 test::VerifyEventsEqual(foo_event2, store_->GetLastWrittenEvent());
372 } 388 }
373 389
374 TEST_F(ModelImplTest, IncrementingSingleDayExistingEventTwice) { 390 TEST_F(ModelImplTest, IncrementingSingleDayExistingEventTwice) {
375 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 391 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
376 base::Unretained(this)), 392 base::Unretained(this)),
377 1000u); 393 1000u);
378 base::RunLoop().RunUntilIdle(); 394 task_runner_->RunUntilIdle();
379 EXPECT_TRUE(model_->IsReady()); 395 EXPECT_TRUE(model_->IsReady());
380 396
381 // |foo| is inserted into the store with a count of 1 at day 1, so 397 // |foo| is inserted into the store with a count of 1 at day 1, so
382 // incrementing twice should lead to 3. 398 // incrementing twice should lead to 3.
383 model_->IncrementEvent("foo", 1u); 399 model_->IncrementEvent("foo", 1u);
384 model_->IncrementEvent("foo", 1u); 400 model_->IncrementEvent("foo", 1u);
385 const Event* foo_event = model_->GetEvent("foo"); 401 const Event* foo_event = model_->GetEvent("foo");
386 EXPECT_EQ(1, foo_event->events_size()); 402 EXPECT_EQ(1, foo_event->events_size());
387 test::VerifyEventCount(foo_event, 1u, 3u); 403 test::VerifyEventCount(foo_event, 1u, 3u);
388 test::VerifyEventsEqual(foo_event, store_->GetLastWrittenEvent()); 404 test::VerifyEventsEqual(foo_event, store_->GetLastWrittenEvent());
389 } 405 }
390 406
391 TEST_F(ModelImplTest, IncrementingExistingMultiDayEvent) { 407 TEST_F(ModelImplTest, IncrementingExistingMultiDayEvent) {
392 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 408 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
393 base::Unretained(this)), 409 base::Unretained(this)),
394 1000u); 410 1000u);
395 base::RunLoop().RunUntilIdle(); 411 task_runner_->RunUntilIdle();
396 EXPECT_TRUE(model_->IsReady()); 412 EXPECT_TRUE(model_->IsReady());
397 413
398 // |bar| is inserted into the store with a count of 3 at day 2. Incrementing 414 // |bar| is inserted into the store with a count of 3 at day 2. Incrementing
399 // that day should lead to a count of 4. 415 // that day should lead to a count of 4.
400 const Event* bar_event = model_->GetEvent("bar"); 416 const Event* bar_event = model_->GetEvent("bar");
401 test::VerifyEventCount(bar_event, 2u, 3u); 417 test::VerifyEventCount(bar_event, 2u, 3u);
402 model_->IncrementEvent("bar", 2u); 418 model_->IncrementEvent("bar", 2u);
403 const Event* bar_event2 = model_->GetEvent("bar"); 419 const Event* bar_event2 = model_->GetEvent("bar");
404 test::VerifyEventCount(bar_event2, 2u, 4u); 420 test::VerifyEventCount(bar_event2, 2u, 4u);
405 test::VerifyEventsEqual(bar_event2, store_->GetLastWrittenEvent()); 421 test::VerifyEventsEqual(bar_event2, store_->GetLastWrittenEvent());
406 } 422 }
407 423
408 TEST_F(ModelImplTest, IncrementingExistingMultiDayEventNewDay) { 424 TEST_F(ModelImplTest, IncrementingExistingMultiDayEventNewDay) {
409 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 425 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
410 base::Unretained(this)), 426 base::Unretained(this)),
411 1000u); 427 1000u);
412 base::RunLoop().RunUntilIdle(); 428 task_runner_->RunUntilIdle();
413 EXPECT_TRUE(model_->IsReady()); 429 EXPECT_TRUE(model_->IsReady());
414 430
415 // |bar| does not contain entries for day 10, so incrementing should create 431 // |bar| does not contain entries for day 10, so incrementing should create
416 // the day. 432 // the day.
417 model_->IncrementEvent("bar", 10u); 433 model_->IncrementEvent("bar", 10u);
418 const Event* bar_event = model_->GetEvent("bar"); 434 const Event* bar_event = model_->GetEvent("bar");
419 test::VerifyEventCount(bar_event, 10u, 1u); 435 test::VerifyEventCount(bar_event, 10u, 1u);
420 test::VerifyEventsEqual(bar_event, store_->GetLastWrittenEvent()); 436 test::VerifyEventsEqual(bar_event, store_->GetLastWrittenEvent());
421 model_->IncrementEvent("bar", 10u); 437 model_->IncrementEvent("bar", 10u);
422 const Event* bar_event2 = model_->GetEvent("bar"); 438 const Event* bar_event2 = model_->GetEvent("bar");
423 test::VerifyEventCount(bar_event2, 10u, 2u); 439 test::VerifyEventCount(bar_event2, 10u, 2u);
424 test::VerifyEventsEqual(bar_event2, store_->GetLastWrittenEvent()); 440 test::VerifyEventsEqual(bar_event2, store_->GetLastWrittenEvent());
425 } 441 }
426 442
427 TEST_F(LoadFailingModelImplTest, FailedInitializeInformsCaller) { 443 TEST_F(LoadFailingModelImplTest, FailedInitializeInformsCaller) {
428 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished, 444 model_->Initialize(base::Bind(&ModelImplTest::OnModelInitializationFinished,
429 base::Unretained(this)), 445 base::Unretained(this)),
430 1000u); 446 1000u);
431 base::RunLoop().RunUntilIdle(); 447 task_runner_->RunUntilIdle();
432 EXPECT_FALSE(model_->IsReady()); 448 EXPECT_FALSE(model_->IsReady());
433 EXPECT_TRUE(got_initialize_callback_); 449 EXPECT_TRUE(got_initialize_callback_);
434 EXPECT_FALSE(initialize_callback_result_); 450 EXPECT_FALSE(initialize_callback_result_);
435 } 451 }
436 452
437 } // namespace feature_engagement_tracker 453 } // namespace feature_engagement_tracker
OLDNEW
« no previous file with comments | « components/feature_engagement_tracker/internal/model_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698