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 "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/test/mock_render_process_host.h" | 10 #include "content/public/test/mock_render_process_host.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 CreateAlarm("[\"dup\", {\"delayInMinutes\": 1}]"); | 281 CreateAlarm("[\"dup\", {\"delayInMinutes\": 1}]"); |
282 CreateAlarm("[\"dup\", {\"delayInMinutes\": 7}]"); | 282 CreateAlarm("[\"dup\", {\"delayInMinutes\": 7}]"); |
283 | 283 |
284 alarm_manager_->GetAllAlarms( | 284 alarm_manager_->GetAllAlarms( |
285 extension()->id(), | 285 extension()->id(), |
286 base::Bind(ExtensionAlarmsTestCreateDupeGetAllAlarmsCallback)); | 286 base::Bind(ExtensionAlarmsTestCreateDupeGetAllAlarmsCallback)); |
287 } | 287 } |
288 | 288 |
289 TEST_F(ExtensionAlarmsTest, CreateDelayBelowMinimum) { | 289 TEST_F(ExtensionAlarmsTest, CreateDelayBelowMinimum) { |
290 // Create an alarm with delay below the minimum accepted value. | 290 // Create an alarm with delay below the minimum accepted value. |
291 CreateAlarm("[\"negative\", {\"delayInMinutes\": -0.2}]"); | |
292 IPC::TestSink& sink = | 291 IPC::TestSink& sink = |
293 static_cast<content::MockRenderProcessHost*>( | 292 static_cast<content::MockRenderProcessHost*>( |
294 contents()->GetRenderViewHost()->GetProcess())->sink(); | 293 contents()->GetRenderViewHost()->GetProcess())->sink(); |
| 294 size_t initial_message_count = sink.message_count(); |
| 295 CreateAlarm("[\"negative\", {\"delayInMinutes\": -0.2}]"); |
| 296 // A new message should have been added. |
| 297 ASSERT_GT(sink.message_count(), initial_message_count); |
| 298 |
| 299 // All of this would be cleaner if we could read the message as a |
| 300 // FrameMsg_AddMessageToConsole, but that would be a layering violation. |
| 301 // Better yet would be an observer method for frames adding console messages, |
| 302 // but it's not worth adding just for a test. |
295 const IPC::Message* warning = | 303 const IPC::Message* warning = |
296 sink.GetUniqueMessageMatching(ExtensionMsg_AddMessageToConsole::ID); | 304 sink.GetMessageAt(initial_message_count /* 0-based */); |
297 ASSERT_TRUE(warning); | 305 ASSERT_TRUE(warning); |
298 ExtensionMsg_AddMessageToConsole::Param params; | 306 |
299 ExtensionMsg_AddMessageToConsole::Read(warning, ¶ms); | 307 int level = 0; |
300 content::ConsoleMessageLevel level = base::get<0>(params); | 308 base::PickleIterator iter(*warning); |
301 std::string message = base::get<1>(params); | 309 ASSERT_TRUE(iter.ReadInt(&level)); |
302 EXPECT_EQ(content::CONSOLE_MESSAGE_LEVEL_WARNING, level); | 310 std::string message; |
| 311 ASSERT_TRUE(iter.ReadString(&message)); |
| 312 |
| 313 EXPECT_EQ(content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 314 static_cast<content::ConsoleMessageLevel>(level)); |
303 EXPECT_THAT(message, testing::HasSubstr("delay is less than minimum of 1")); | 315 EXPECT_THAT(message, testing::HasSubstr("delay is less than minimum of 1")); |
304 } | 316 } |
305 | 317 |
306 TEST_F(ExtensionAlarmsTest, Get) { | 318 TEST_F(ExtensionAlarmsTest, Get) { |
307 test_clock_->SetNow(base::Time::FromDoubleT(4)); | 319 test_clock_->SetNow(base::Time::FromDoubleT(4)); |
308 | 320 |
309 // Create 2 alarms, and make sure we can query them. | 321 // Create 2 alarms, and make sure we can query them. |
310 CreateAlarms(2); | 322 CreateAlarms(2); |
311 | 323 |
312 // Get the default one. | 324 // Get the default one. |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 689 |
678 // The next poll should be the first poll that hasn't happened and is in-line | 690 // The next poll should be the first poll that hasn't happened and is in-line |
679 // with the original scheduling. | 691 // with the original scheduling. |
680 // Last poll was at 380 seconds; next poll should be at 480 seconds. | 692 // Last poll was at 380 seconds; next poll should be at 480 seconds. |
681 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + | 693 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + |
682 base::TimeDelta::FromSeconds(100)).ToJsTime(), | 694 base::TimeDelta::FromSeconds(100)).ToJsTime(), |
683 alarm_manager_->next_poll_time_.ToJsTime()); | 695 alarm_manager_->next_poll_time_.ToJsTime()); |
684 } | 696 } |
685 | 697 |
686 } // namespace extensions | 698 } // namespace extensions |
OLD | NEW |