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

Side by Side Diff: extensions/browser/api/alarms/alarms_api_unittest.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // This file tests the chrome.alarms extension API. 5 // This file tests the chrome.alarms extension API.
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/test/simple_test_clock.h" 9 #include "base/test/simple_test_clock.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Creates up to 3 alarms using the extension API. 90 // Creates up to 3 alarms using the extension API.
91 void CreateAlarms(size_t num_alarms) { 91 void CreateAlarms(size_t num_alarms) {
92 CHECK_LE(num_alarms, 3U); 92 CHECK_LE(num_alarms, 3U);
93 93
94 const char* const kCreateArgs[] = { 94 const char* const kCreateArgs[] = {
95 "[null, {\"periodInMinutes\": 0.001}]", 95 "[null, {\"periodInMinutes\": 0.001}]",
96 "[\"7\", {\"periodInMinutes\": 7}]", 96 "[\"7\", {\"periodInMinutes\": 7}]",
97 "[\"0\", {\"delayInMinutes\": 0}]", 97 "[\"0\", {\"delayInMinutes\": 0}]",
98 }; 98 };
99 for (size_t i = 0; i < num_alarms; ++i) { 99 for (size_t i = 0; i < num_alarms; ++i) {
100 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( 100 std::unique_ptr<base::DictionaryValue> result(
101 new AlarmsCreateFunction(test_clock_), kCreateArgs[i])); 101 RunFunctionAndReturnDictionary(new AlarmsCreateFunction(test_clock_),
102 kCreateArgs[i]));
102 EXPECT_FALSE(result.get()); 103 EXPECT_FALSE(result.get());
103 } 104 }
104 } 105 }
105 106
106 base::SimpleTestClock* test_clock_; 107 base::SimpleTestClock* test_clock_;
107 AlarmManager* alarm_manager_; 108 AlarmManager* alarm_manager_;
108 AlarmDelegate* alarm_delegate_; 109 AlarmDelegate* alarm_delegate_;
109 }; 110 };
110 111
111 void ExtensionAlarmsTestGetAllAlarmsCallback( 112 void ExtensionAlarmsTestGetAllAlarmsCallback(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 320
320 TEST_F(ExtensionAlarmsTest, Get) { 321 TEST_F(ExtensionAlarmsTest, Get) {
321 test_clock_->SetNow(base::Time::FromDoubleT(4)); 322 test_clock_->SetNow(base::Time::FromDoubleT(4));
322 323
323 // Create 2 alarms, and make sure we can query them. 324 // Create 2 alarms, and make sure we can query them.
324 CreateAlarms(2); 325 CreateAlarms(2);
325 326
326 // Get the default one. 327 // Get the default one.
327 { 328 {
328 JsAlarm alarm; 329 JsAlarm alarm;
329 scoped_ptr<base::DictionaryValue> result( 330 std::unique_ptr<base::DictionaryValue> result(
330 RunFunctionAndReturnDictionary(new AlarmsGetFunction(), "[null]")); 331 RunFunctionAndReturnDictionary(new AlarmsGetFunction(), "[null]"));
331 ASSERT_TRUE(result.get()); 332 ASSERT_TRUE(result.get());
332 EXPECT_TRUE(JsAlarm::Populate(*result, &alarm)); 333 EXPECT_TRUE(JsAlarm::Populate(*result, &alarm));
333 EXPECT_EQ("", alarm.name); 334 EXPECT_EQ("", alarm.name);
334 EXPECT_DOUBLE_EQ(4060, alarm.scheduled_time); 335 EXPECT_DOUBLE_EQ(4060, alarm.scheduled_time);
335 EXPECT_THAT(alarm.period_in_minutes, 336 EXPECT_THAT(alarm.period_in_minutes,
336 testing::Pointee(testing::DoubleEq(0.001))); 337 testing::Pointee(testing::DoubleEq(0.001)));
337 } 338 }
338 339
339 // Get "7". 340 // Get "7".
340 { 341 {
341 JsAlarm alarm; 342 JsAlarm alarm;
342 scoped_ptr<base::DictionaryValue> result( 343 std::unique_ptr<base::DictionaryValue> result(
343 RunFunctionAndReturnDictionary(new AlarmsGetFunction(), "[\"7\"]")); 344 RunFunctionAndReturnDictionary(new AlarmsGetFunction(), "[\"7\"]"));
344 ASSERT_TRUE(result.get()); 345 ASSERT_TRUE(result.get());
345 EXPECT_TRUE(JsAlarm::Populate(*result, &alarm)); 346 EXPECT_TRUE(JsAlarm::Populate(*result, &alarm));
346 EXPECT_EQ("7", alarm.name); 347 EXPECT_EQ("7", alarm.name);
347 EXPECT_EQ(424000, alarm.scheduled_time); 348 EXPECT_EQ(424000, alarm.scheduled_time);
348 EXPECT_THAT(alarm.period_in_minutes, testing::Pointee(7)); 349 EXPECT_THAT(alarm.period_in_minutes, testing::Pointee(7));
349 } 350 }
350 351
351 // Get a non-existent one. 352 // Get a non-existent one.
352 { 353 {
353 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( 354 std::unique_ptr<base::DictionaryValue> result(
354 new AlarmsGetFunction(), "[\"nobody\"]")); 355 RunFunctionAndReturnDictionary(new AlarmsGetFunction(),
356 "[\"nobody\"]"));
355 ASSERT_FALSE(result.get()); 357 ASSERT_FALSE(result.get());
356 } 358 }
357 } 359 }
358 360
359 TEST_F(ExtensionAlarmsTest, GetAll) { 361 TEST_F(ExtensionAlarmsTest, GetAll) {
360 // Test getAll with 0 alarms. 362 // Test getAll with 0 alarms.
361 { 363 {
362 scoped_ptr<base::ListValue> result( 364 std::unique_ptr<base::ListValue> result(
363 RunFunctionAndReturnList(new AlarmsGetAllFunction(), "[]")); 365 RunFunctionAndReturnList(new AlarmsGetAllFunction(), "[]"));
364 std::vector<linked_ptr<JsAlarm>> alarms = ToAlarmList(result.get()); 366 std::vector<linked_ptr<JsAlarm>> alarms = ToAlarmList(result.get());
365 EXPECT_EQ(0u, alarms.size()); 367 EXPECT_EQ(0u, alarms.size());
366 } 368 }
367 369
368 // Create 2 alarms, and make sure we can query them. 370 // Create 2 alarms, and make sure we can query them.
369 CreateAlarms(2); 371 CreateAlarms(2);
370 372
371 { 373 {
372 scoped_ptr<base::ListValue> result( 374 std::unique_ptr<base::ListValue> result(
373 RunFunctionAndReturnList(new AlarmsGetAllFunction(), "[null]")); 375 RunFunctionAndReturnList(new AlarmsGetAllFunction(), "[null]"));
374 std::vector<linked_ptr<JsAlarm>> alarms = ToAlarmList(result.get()); 376 std::vector<linked_ptr<JsAlarm>> alarms = ToAlarmList(result.get());
375 EXPECT_EQ(2u, alarms.size()); 377 EXPECT_EQ(2u, alarms.size());
376 378
377 // Test the "7" alarm. 379 // Test the "7" alarm.
378 JsAlarm* alarm = alarms[0].get(); 380 JsAlarm* alarm = alarms[0].get();
379 if (alarm->name != "7") 381 if (alarm->name != "7")
380 alarm = alarms[1].get(); 382 alarm = alarms[1].get();
381 EXPECT_EQ("7", alarm->name); 383 EXPECT_EQ("7", alarm->name);
382 EXPECT_THAT(alarm->period_in_minutes, testing::Pointee(7)); 384 EXPECT_THAT(alarm->period_in_minutes, testing::Pointee(7));
(...skipping 28 matching lines...) Expand all
411 413
412 // Ensure the 0.001-minute alarm is still there, since it's repeating. 414 // Ensure the 0.001-minute alarm is still there, since it's repeating.
413 test->alarm_manager_->GetAllAlarms( 415 test->alarm_manager_->GetAllAlarms(
414 test->extension()->id(), 416 test->extension()->id(),
415 base::Bind(ExtensionAlarmsTestClearGetAllAlarms2Callback)); 417 base::Bind(ExtensionAlarmsTestClearGetAllAlarms2Callback));
416 } 418 }
417 419
418 TEST_F(ExtensionAlarmsTest, Clear) { 420 TEST_F(ExtensionAlarmsTest, Clear) {
419 // Clear a non-existent one. 421 // Clear a non-existent one.
420 { 422 {
421 scoped_ptr<base::Value> result( 423 std::unique_ptr<base::Value> result(
422 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"nobody\"]")); 424 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"nobody\"]"));
423 bool copy_bool_result = false; 425 bool copy_bool_result = false;
424 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result)); 426 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
425 EXPECT_FALSE(copy_bool_result); 427 EXPECT_FALSE(copy_bool_result);
426 } 428 }
427 429
428 // Create 3 alarms. 430 // Create 3 alarms.
429 CreateAlarms(3); 431 CreateAlarms(3);
430 432
431 // Clear all but the 0.001-minute alarm. 433 // Clear all but the 0.001-minute alarm.
432 { 434 {
433 scoped_ptr<base::Value> result( 435 std::unique_ptr<base::Value> result(
434 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"7\"]")); 436 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"7\"]"));
435 bool copy_bool_result = false; 437 bool copy_bool_result = false;
436 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result)); 438 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
437 EXPECT_TRUE(copy_bool_result); 439 EXPECT_TRUE(copy_bool_result);
438 } 440 }
439 { 441 {
440 scoped_ptr<base::Value> result( 442 std::unique_ptr<base::Value> result(
441 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"0\"]")); 443 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"0\"]"));
442 bool copy_bool_result = false; 444 bool copy_bool_result = false;
443 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result)); 445 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
444 EXPECT_TRUE(copy_bool_result); 446 EXPECT_TRUE(copy_bool_result);
445 } 447 }
446 448
447 alarm_manager_->GetAllAlarms( 449 alarm_manager_->GetAllAlarms(
448 extension()->id(), 450 extension()->id(),
449 base::Bind(ExtensionAlarmsTestClearGetAllAlarms1Callback, this)); 451 base::Bind(ExtensionAlarmsTestClearGetAllAlarms1Callback, this));
450 } 452 }
(...skipping 12 matching lines...) Expand all
463 // Clear them. 465 // Clear them.
464 test->RunFunction(new AlarmsClearAllFunction(), "[]"); 466 test->RunFunction(new AlarmsClearAllFunction(), "[]");
465 test->alarm_manager_->GetAllAlarms( 467 test->alarm_manager_->GetAllAlarms(
466 test->extension()->id(), 468 test->extension()->id(),
467 base::Bind(ExtensionAlarmsTestClearAllGetAllAlarms2Callback)); 469 base::Bind(ExtensionAlarmsTestClearAllGetAllAlarms2Callback));
468 } 470 }
469 471
470 TEST_F(ExtensionAlarmsTest, ClearAll) { 472 TEST_F(ExtensionAlarmsTest, ClearAll) {
471 // ClearAll with no alarms set. 473 // ClearAll with no alarms set.
472 { 474 {
473 scoped_ptr<base::Value> result( 475 std::unique_ptr<base::Value> result(
474 RunFunctionAndReturnValue(new AlarmsClearAllFunction(), "[]")); 476 RunFunctionAndReturnValue(new AlarmsClearAllFunction(), "[]"));
475 bool copy_bool_result = false; 477 bool copy_bool_result = false;
476 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result)); 478 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
477 EXPECT_TRUE(copy_bool_result); 479 EXPECT_TRUE(copy_bool_result);
478 } 480 }
479 481
480 // Create 3 alarms. 482 // Create 3 alarms.
481 CreateAlarms(3); 483 CreateAlarms(3);
482 alarm_manager_->GetAllAlarms( 484 alarm_manager_->GetAllAlarms(
483 extension()->id(), 485 extension()->id(),
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 693
692 // The next poll should be the first poll that hasn't happened and is in-line 694 // The next poll should be the first poll that hasn't happened and is in-line
693 // with the original scheduling. 695 // with the original scheduling.
694 // Last poll was at 380 seconds; next poll should be at 480 seconds. 696 // Last poll was at 380 seconds; next poll should be at 480 seconds.
695 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + 697 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ +
696 base::TimeDelta::FromSeconds(100)).ToJsTime(), 698 base::TimeDelta::FromSeconds(100)).ToJsTime(),
697 alarm_manager_->next_poll_time_.ToJsTime()); 699 alarm_manager_->next_poll_time_.ToJsTime());
698 } 700 }
699 701
700 } // namespace extensions 702 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/alarms/alarms_api.cc ('k') | extensions/browser/api/api_resource_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698