OLD | NEW |
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 alarm_manager_->last_poll_time_ = base::Time::FromJsTime(2 * 60000); | 609 alarm_manager_->last_poll_time_ = base::Time::FromJsTime(2 * 60000); |
610 // In released extensions, we set the granularity to at least 1 | 610 // In released extensions, we set the granularity to at least 1 |
611 // minute, which makes scheduler set it to 1 minute, rather than | 611 // minute, which makes scheduler set it to 1 minute, rather than |
612 // 1 second later (when b is supposed to go off). | 612 // 1 second later (when b is supposed to go off). |
613 alarm_manager_->ScheduleNextPoll(); | 613 alarm_manager_->ScheduleNextPoll(); |
614 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + | 614 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + |
615 base::TimeDelta::FromMinutes(1)).ToJsTime(), | 615 base::TimeDelta::FromMinutes(1)).ToJsTime(), |
616 alarm_manager_->test_next_poll_time_.ToJsTime()); | 616 alarm_manager_->test_next_poll_time_.ToJsTime()); |
617 } | 617 } |
618 | 618 |
| 619 TEST_F(ExtensionAlarmsSchedulingTest, DifferentMinimumGranularities) { |
| 620 test_clock_->SetNow(base::Time::FromJsTime(0)); |
| 621 // Create an alarm to go off in 12 seconds. This uses the default, unpacked |
| 622 // extension - so there is no minimum granularity. |
| 623 CreateAlarm("[\"a\", {\"periodInMinutes\": 0.2}]"); // 12 seconds. |
| 624 |
| 625 // Create a new extension, which is packed, and has a granularity of 1 minute. |
| 626 // CreateAlarm() uses extension_, so keep a ref of the old one around, and |
| 627 // repopulate extension_. |
| 628 scoped_refptr<Extension> extension2(extension_); |
| 629 extension_ = |
| 630 utils::CreateEmptyExtensionWithLocation(extensions::Manifest::INTERNAL); |
| 631 |
| 632 CreateAlarm("[\"b\", {\"periodInMinutes\": 2}]"); |
| 633 |
| 634 alarm_manager_->last_poll_time_ = base::Time::FromJsTime(0); |
| 635 alarm_manager_->ScheduleNextPoll(); |
| 636 |
| 637 // The next poll time should be 12 seconds from now - the time at which the |
| 638 // first alarm should go off. |
| 639 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + |
| 640 base::TimeDelta::FromSeconds(12)).ToJsTime(), |
| 641 alarm_manager_->test_next_poll_time_.ToJsTime()); |
| 642 } |
| 643 |
619 } // namespace extensions | 644 } // namespace extensions |
OLD | NEW |