| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(ExtensionAlarmsTest, CreateDelayBelowMinimum) { | 278 TEST_F(ExtensionAlarmsTest, CreateDelayBelowMinimum) { |
| 279 // Create an alarm with delay below the minimum accepted value. | 279 // Create an alarm with delay below the minimum accepted value. |
| 280 CreateAlarm("[\"negative\", {\"delayInMinutes\": -0.2}]"); | 280 CreateAlarm("[\"negative\", {\"delayInMinutes\": -0.2}]"); |
| 281 IPC::TestSink& sink = static_cast<content::MockRenderProcessHost*>( | 281 IPC::TestSink& sink = static_cast<content::MockRenderProcessHost*>( |
| 282 contents()->GetRenderViewHost()->GetProcess())->sink(); | 282 contents()->GetRenderViewHost()->GetProcess())->sink(); |
| 283 const IPC::Message* warning = sink.GetUniqueMessageMatching( | 283 const IPC::Message* warning = sink.GetUniqueMessageMatching( |
| 284 ExtensionMsg_AddMessageToConsole::ID); | 284 ExtensionMsg_AddMessageToConsole::ID); |
| 285 ASSERT_TRUE(warning); | 285 ASSERT_TRUE(warning); |
| 286 content::ConsoleMessageLevel level = content::CONSOLE_MESSAGE_LEVEL_DEBUG; | 286 ExtensionMsg_AddMessageToConsole::Param params; |
| 287 std::string message; | 287 ExtensionMsg_AddMessageToConsole::Read(warning, ¶ms); |
| 288 ExtensionMsg_AddMessageToConsole::Read(warning, &level, &message); | 288 content::ConsoleMessageLevel level = params.a; |
| 289 std::string message = params.b; |
| 289 EXPECT_EQ(content::CONSOLE_MESSAGE_LEVEL_WARNING, level); | 290 EXPECT_EQ(content::CONSOLE_MESSAGE_LEVEL_WARNING, level); |
| 290 EXPECT_THAT(message, testing::HasSubstr("delay is less than minimum of 1")); | 291 EXPECT_THAT(message, testing::HasSubstr("delay is less than minimum of 1")); |
| 291 } | 292 } |
| 292 | 293 |
| 293 TEST_F(ExtensionAlarmsTest, Get) { | 294 TEST_F(ExtensionAlarmsTest, Get) { |
| 294 test_clock_->SetNow(base::Time::FromDoubleT(4)); | 295 test_clock_->SetNow(base::Time::FromDoubleT(4)); |
| 295 | 296 |
| 296 // Create 2 alarms, and make sure we can query them. | 297 // Create 2 alarms, and make sure we can query them. |
| 297 CreateAlarms(2); | 298 CreateAlarms(2); |
| 298 | 299 |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 658 |
| 658 // The next poll should be the first poll that hasn't happened and is in-line | 659 // The next poll should be the first poll that hasn't happened and is in-line |
| 659 // with the original scheduling. | 660 // with the original scheduling. |
| 660 // Last poll was at 380 seconds; next poll should be at 480 seconds. | 661 // Last poll was at 380 seconds; next poll should be at 480 seconds. |
| 661 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + | 662 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + |
| 662 base::TimeDelta::FromSeconds(100)).ToJsTime(), | 663 base::TimeDelta::FromSeconds(100)).ToJsTime(), |
| 663 alarm_manager_->next_poll_time_.ToJsTime()); | 664 alarm_manager_->next_poll_time_.ToJsTime()); |
| 664 } | 665 } |
| 665 | 666 |
| 666 } // namespace extensions | 667 } // namespace extensions |
| OLD | NEW |