| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/ordered_simple_task_runner.h" | 5 #include "cc/test/ordered_simple_task_runner.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/test/test_pending_task.h" | 14 #include "base/test/test_pending_task_info.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 // We pass EXPECT_TRUE / EXPECT_FALSE macros rather than a boolean as on some | 17 // We pass EXPECT_TRUE / EXPECT_FALSE macros rather than a boolean as on some |
| 18 // compilers EXPECT_EQ(false, XXXX) fails to compile as gtest tries to convert | 18 // compilers EXPECT_EQ(false, XXXX) fails to compile as gtest tries to convert |
| 19 // the false value to null causing a -Werror=conversion-null error. | 19 // the false value to null causing a -Werror=conversion-null error. |
| 20 #define RUN_AND_CHECK_RESULT( \ | 20 #define RUN_AND_CHECK_RESULT( \ |
| 21 tasks_remain_expect_macro, run_func, expected_result) \ | 21 tasks_remain_expect_macro, run_func, expected_result) \ |
| 22 tasks_remain_expect_macro(task_runner_->run_func); \ | 22 tasks_remain_expect_macro(task_runner_->run_func); \ |
| 23 EXPECT_EQ(expected_result, executed_tasks_); \ | 23 EXPECT_EQ(expected_result, executed_tasks_); \ |
| 24 executed_tasks_ = ""; | 24 executed_tasks_ = ""; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 bool ReturnTrue() { | 28 bool ReturnTrue() { |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool ReturnFalse() { | 32 bool ReturnFalse() { |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 | 38 |
| 39 TEST(TestOrderablePendingTask, Ordering) { | 39 TEST(TestOrderablePendingTask, Ordering) { |
| 40 TestOrderablePendingTask a; | 40 TestOrderablePendingTaskInfo a; |
| 41 TestOrderablePendingTask b; | 41 TestOrderablePendingTaskInfo b; |
| 42 TestOrderablePendingTask c; | 42 TestOrderablePendingTaskInfo c; |
| 43 | 43 |
| 44 EXPECT_EQ(a, a); | 44 EXPECT_EQ(a, a); |
| 45 EXPECT_EQ(b, b); | 45 EXPECT_EQ(b, b); |
| 46 EXPECT_EQ(c, c); | 46 EXPECT_EQ(c, c); |
| 47 EXPECT_LT(a, b); | 47 EXPECT_LT(a, b); |
| 48 EXPECT_LT(b, c); | 48 EXPECT_LT(b, c); |
| 49 EXPECT_LT(a, c); | 49 EXPECT_LT(a, c); |
| 50 | 50 |
| 51 TestOrderablePendingTask a2 = a; | 51 TestOrderablePendingTaskInfo a2 = a; |
| 52 EXPECT_EQ(a, a2); | 52 EXPECT_EQ(a, a2); |
| 53 EXPECT_LT(a2, b); | 53 EXPECT_LT(a2, b); |
| 54 EXPECT_LT(b, c); | 54 EXPECT_LT(b, c); |
| 55 EXPECT_LT(a2, c); | 55 EXPECT_LT(a2, c); |
| 56 } | 56 } |
| 57 | 57 |
| 58 class OrderedSimpleTaskRunnerTest : public testing::Test { | 58 class OrderedSimpleTaskRunnerTest : public testing::Test { |
| 59 public: | 59 public: |
| 60 OrderedSimpleTaskRunnerTest() | 60 OrderedSimpleTaskRunnerTest() |
| 61 : now_src_(new base::SimpleTestTickClock()), | 61 : now_src_(new base::SimpleTestTickClock()), |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 task_runner_->SetRunTaskLimit(0); | 437 task_runner_->SetRunTaskLimit(0); |
| 438 RUN_AND_CHECK_RESULT(EXPECT_TRUE, RunUntilTime(run_to), ""); | 438 RUN_AND_CHECK_RESULT(EXPECT_TRUE, RunUntilTime(run_to), ""); |
| 439 | 439 |
| 440 task_runner_->SetRunTaskLimit(100); | 440 task_runner_->SetRunTaskLimit(100); |
| 441 RUN_AND_CHECK_RESULT(EXPECT_FALSE, RunUntilTime(run_to), "4(4ms) 5(5ms)"); | 441 RUN_AND_CHECK_RESULT(EXPECT_FALSE, RunUntilTime(run_to), "4(4ms) 5(5ms)"); |
| 442 EXPECT_EQ(run_to, now_src_->NowTicks()); | 442 EXPECT_EQ(run_to, now_src_->NowTicks()); |
| 443 } | 443 } |
| 444 | 444 |
| 445 } // namespace cc | 445 } // namespace cc |
| OLD | NEW |