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 <stdint.h> |
| 8 |
8 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
9 #include "cc/test/scheduler_test_common.h" | 10 #include "cc/test/scheduler_test_common.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 base::TimeDelta Interval() { | 16 base::TimeDelta Interval() { |
16 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / | 17 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / |
17 60); | 18 60); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 423 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
423 new base::TestSimpleTaskRunner; | 424 new base::TestSimpleTaskRunner; |
424 FakeDelayBasedTimeSourceClient client; | 425 FakeDelayBasedTimeSourceClient client; |
425 scoped_ptr<FakeDelayBasedTimeSource> timer = | 426 scoped_ptr<FakeDelayBasedTimeSource> timer = |
426 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); | 427 FakeDelayBasedTimeSource::Create(Interval(), task_runner.get()); |
427 timer->SetClient(&client); | 428 timer->SetClient(&client); |
428 timer->SetActive(true); | 429 timer->SetActive(true); |
429 | 430 |
430 double total_frame_time = 0.0; | 431 double total_frame_time = 0.0; |
431 for (int i = 0; i < num_iterations; ++i) { | 432 for (int i = 0; i < num_iterations; ++i) { |
432 int64 delay_ms = task_runner->NextPendingTaskDelay().InMilliseconds(); | 433 int64_t delay_ms = task_runner->NextPendingTaskDelay().InMilliseconds(); |
433 | 434 |
434 // accumulate the "delay" | 435 // accumulate the "delay" |
435 total_frame_time += delay_ms / 1000.0; | 436 total_frame_time += delay_ms / 1000.0; |
436 | 437 |
437 // Run the callback exactly when asked | 438 // Run the callback exactly when asked |
438 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); | 439 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); |
439 task_runner->RunPendingTasks(); | 440 task_runner->RunPendingTasks(); |
440 } | 441 } |
441 double average_interval = | 442 double average_interval = |
442 total_frame_time / static_cast<double>(num_iterations); | 443 total_frame_time / static_cast<double>(num_iterations); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 timer->SetActive(true); | 520 timer->SetActive(true); |
520 task_runner->RunPendingTasks(); | 521 task_runner->RunPendingTasks(); |
521 | 522 |
522 // SetActive should return empty TimeTicks when the timer is deactivated. | 523 // SetActive should return empty TimeTicks when the timer is deactivated. |
523 base::TimeTicks missed_tick_time = timer->SetActive(false); | 524 base::TimeTicks missed_tick_time = timer->SetActive(false); |
524 EXPECT_TRUE(missed_tick_time.is_null()); | 525 EXPECT_TRUE(missed_tick_time.is_null()); |
525 } | 526 } |
526 | 527 |
527 } // namespace | 528 } // namespace |
528 } // namespace cc | 529 } // namespace cc |
OLD | NEW |