OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 #include "cc/scheduler/delay_based_time_source.h" | 5 #include "cc/scheduler/delay_based_time_source.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
9 #include "cc/test/scheduler_test_common.h" | 9 #include "cc/test/scheduler_test_common.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // Task will be pending anyway, run it. | 501 // Task will be pending anyway, run it. |
502 task_runner->RunPendingTasks(); | 502 task_runner->RunPendingTasks(); |
503 | 503 |
504 // Start the timer again, but before the next tick time the timer previously | 504 // Start the timer again, but before the next tick time the timer previously |
505 // planned on using. That same tick time should still be targeted. | 505 // planned on using. That same tick time should still be targeted. |
506 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); | 506 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); |
507 timer->SetActive(true); | 507 timer->SetActive(true); |
508 EXPECT_EQ(13, task_runner->NextPendingTaskDelay().InMilliseconds()); | 508 EXPECT_EQ(13, task_runner->NextPendingTaskDelay().InMilliseconds()); |
509 } | 509 } |
510 | 510 |
511 TEST(DelayBasedTimeSourceTest, TestOverflow) { | |
512 // int(big_now / interval) < 0, so this causes a crash if the number of | |
513 // intervals elapsed is attempted to be stored in an int. | |
514 base::TimeDelta interval = base::TimeDelta::FromInternalValue(4000); | |
515 base::TimeTicks big_now = base::TimeTicks::FromInternalValue(8635916564000); | |
516 | |
517 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | |
518 new base::TestSimpleTaskRunner; | |
519 FakeTimeSourceClient client; | |
520 scoped_refptr<FakeDelayBasedTimeSource> timer = | |
521 FakeDelayBasedTimeSource::Create(interval, task_runner.get()); | |
522 timer->SetClient(&client); | |
523 timer->SetNow(big_now); | |
524 timer->SetActive(true); | |
525 EXPECT_EQ(0, task_runner->NextPendingTaskDelay().InMilliseconds()); | |
526 } | |
527 | |
528 TEST(DelayBasedTimeSourceTest, TestReturnValueWhenTimerIsDeActivated) { | 511 TEST(DelayBasedTimeSourceTest, TestReturnValueWhenTimerIsDeActivated) { |
529 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 512 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
530 new base::TestSimpleTaskRunner; | 513 new base::TestSimpleTaskRunner; |
531 FakeTimeSourceClient client; | 514 FakeTimeSourceClient client; |
532 scoped_refptr<FakeDelayBasedTimeSource> timer = | 515 scoped_refptr<FakeDelayBasedTimeSource> timer = |
533 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); | 516 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); |
534 timer->SetClient(&client); | 517 timer->SetClient(&client); |
535 | 518 |
536 timer->SetActive(true); | 519 timer->SetActive(true); |
537 task_runner->RunPendingTasks(); | 520 task_runner->RunPendingTasks(); |
538 | 521 |
539 // SetActive should return empty TimeTicks when the timer is deactivated. | 522 // SetActive should return empty TimeTicks when the timer is deactivated. |
540 base::TimeTicks missed_tick_time = timer->SetActive(false); | 523 base::TimeTicks missed_tick_time = timer->SetActive(false); |
541 EXPECT_TRUE(missed_tick_time.is_null()); | 524 EXPECT_TRUE(missed_tick_time.is_null()); |
542 } | 525 } |
543 | 526 |
544 } // namespace | 527 } // namespace |
545 } // namespace cc | 528 } // namespace cc |
OLD | NEW |