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

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

Issue 205323002: Chrome Alarm Clear and ClearAll Updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
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 "base/test/simple_test_clock.h" 7 #include "base/test/simple_test_clock.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" 9 #include "chrome/browser/extensions/api/alarms/alarm_manager.h"
10 #include "chrome/browser/extensions/api/alarms/alarms_api.h" 10 #include "chrome/browser/extensions/api/alarms/alarms_api.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 EXPECT_EQ("", test->alarm_delegate_->alarms_seen[0]); 382 EXPECT_EQ("", test->alarm_delegate_->alarms_seen[0]);
383 383
384 // Ensure the 0.001-minute alarm is still there, since it's repeating. 384 // Ensure the 0.001-minute alarm is still there, since it's repeating.
385 test->alarm_manager_->GetAllAlarms(test->extension()->id(), base::Bind( 385 test->alarm_manager_->GetAllAlarms(test->extension()->id(), base::Bind(
386 ExtensionAlarmsTestClearGetAllAlarms2Callback)); 386 ExtensionAlarmsTestClearGetAllAlarms2Callback));
387 } 387 }
388 388
389 TEST_F(ExtensionAlarmsTest, Clear) { 389 TEST_F(ExtensionAlarmsTest, Clear) {
390 // Clear a non-existent one. 390 // Clear a non-existent one.
391 { 391 {
392 std::string error = RunFunctionAndReturnError( 392 scoped_ptr<base::Value> result(
393 new AlarmsClearFunction(), "[\"nobody\"]"); 393 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"nobody\"]"));
394 EXPECT_FALSE(error.empty()); 394 bool copy_bool_result = false;
395 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
396 EXPECT_FALSE(copy_bool_result);
395 } 397 }
396 398
397 // Create 3 alarms. 399 // Create 3 alarms.
398 CreateAlarms(3); 400 CreateAlarms(3);
399 401
400 // Clear all but the 0.001-minute alarm. 402 // Clear all but the 0.001-minute alarm.
401 RunFunction(new AlarmsClearFunction(), "[\"7\"]"); 403 {
402 RunFunction(new AlarmsClearFunction(), "[\"0\"]"); 404 scoped_ptr<base::Value> result(
405 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"7\"]"));
406 bool copy_bool_result = false;
407 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
408 EXPECT_TRUE(copy_bool_result);
409 }
410 {
411 scoped_ptr<base::Value> result(
412 RunFunctionAndReturnValue(new AlarmsClearFunction(), "[\"0\"]"));
413 bool copy_bool_result = false;
414 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
415 EXPECT_TRUE(copy_bool_result);
416 }
403 417
404 alarm_manager_->GetAllAlarms(extension()->id(), base::Bind( 418 alarm_manager_->GetAllAlarms(extension()->id(), base::Bind(
405 ExtensionAlarmsTestClearGetAllAlarms1Callback, this)); 419 ExtensionAlarmsTestClearGetAllAlarms1Callback, this));
406 } 420 }
407 421
408 void ExtensionAlarmsTestClearAllGetAllAlarms2Callback( 422 void ExtensionAlarmsTestClearAllGetAllAlarms2Callback(
409 const AlarmManager::AlarmList* alarms) { 423 const AlarmManager::AlarmList* alarms) {
410 ASSERT_FALSE(alarms); 424 ASSERT_FALSE(alarms);
411 } 425 }
412 426
413 void ExtensionAlarmsTestClearAllGetAllAlarms1Callback( 427 void ExtensionAlarmsTestClearAllGetAllAlarms1Callback(
414 ExtensionAlarmsTest* test, const AlarmManager::AlarmList* alarms) { 428 ExtensionAlarmsTest* test, const AlarmManager::AlarmList* alarms) {
415 ASSERT_TRUE(alarms); 429 ASSERT_TRUE(alarms);
416 EXPECT_EQ(3u, alarms->size()); 430 EXPECT_EQ(3u, alarms->size());
417 431
418 // Clear them. 432 // Clear them.
419 test->RunFunction(new AlarmsClearAllFunction(), "[]"); 433 test->RunFunction(new AlarmsClearAllFunction(), "[]");
420 test->alarm_manager_->GetAllAlarms( 434 test->alarm_manager_->GetAllAlarms(
421 test->extension()->id(), base::Bind( 435 test->extension()->id(), base::Bind(
422 ExtensionAlarmsTestClearAllGetAllAlarms2Callback)); 436 ExtensionAlarmsTestClearAllGetAllAlarms2Callback));
423 } 437 }
424 438
425 TEST_F(ExtensionAlarmsTest, ClearAll) { 439 TEST_F(ExtensionAlarmsTest, ClearAll) {
426 // ClearAll with no alarms set. 440 // ClearAll with no alarms set.
427 { 441 {
428 scoped_ptr<base::Value> result(RunFunctionAndReturnValue( 442 scoped_ptr<base::Value> result(RunFunctionAndReturnValue(
429 new AlarmsClearAllFunction(), "[]")); 443 new AlarmsClearAllFunction(), "[]"));
430 EXPECT_FALSE(result.get()); 444 bool copy_bool_result = false;
445 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_result));
446 EXPECT_TRUE(copy_bool_result);
431 } 447 }
432 448
433 // Create 3 alarms. 449 // Create 3 alarms.
434 CreateAlarms(3); 450 CreateAlarms(3);
435 alarm_manager_->GetAllAlarms(extension()->id(), base::Bind( 451 alarm_manager_->GetAllAlarms(extension()->id(), base::Bind(
436 ExtensionAlarmsTestClearAllGetAllAlarms1Callback, this)); 452 ExtensionAlarmsTestClearAllGetAllAlarms1Callback, this));
437 } 453 }
438 454
439 class ExtensionAlarmsSchedulingTest : public ExtensionAlarmsTest { 455 class ExtensionAlarmsSchedulingTest : public ExtensionAlarmsTest {
440 void GetAlarmCallback(Alarm* alarm) { 456 void GetAlarmCallback(Alarm* alarm) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 657
642 // The next poll should be the first poll that hasn't happened and is in-line 658 // The next poll should be the first poll that hasn't happened and is in-line
643 // with the original scheduling. 659 // with the original scheduling.
644 // Last poll was at 380 seconds; next poll should be at 480 seconds. 660 // Last poll was at 380 seconds; next poll should be at 480 seconds.
645 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + 661 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ +
646 base::TimeDelta::FromSeconds(100)).ToJsTime(), 662 base::TimeDelta::FromSeconds(100)).ToJsTime(),
647 alarm_manager_->next_poll_time_.ToJsTime()); 663 alarm_manager_->next_poll_time_.ToJsTime());
648 } 664 }
649 665
650 } // namespace extensions 666 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698