| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "core/dom/MainThreadTaskRunner.h" | 28 #include "core/dom/MainThreadTaskRunner.h" |
| 29 | 29 |
| 30 #include "core/dom/ExecutionContextTask.h" | 30 #include "core/dom/ExecutionContextTask.h" |
| 31 #include "core/testing/NullExecutionContext.h" | 31 #include "core/testing/NullExecutionContext.h" |
| 32 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 33 #include "platform/testing/UnitTestHelpers.h" | 33 #include "platform/testing/UnitTestHelpers.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
| 36 #include <memory> | 36 #include "wtf/OwnPtr.h" |
| 37 #include "wtf/PassOwnPtr.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 static void markBoolean(bool* toBeMarked) | 41 static void markBoolean(bool* toBeMarked) |
| 41 { | 42 { |
| 42 *toBeMarked = true; | 43 *toBeMarked = true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 TEST(MainThreadTaskRunnerTest, PostTask) | 46 TEST(MainThreadTaskRunnerTest, PostTask) |
| 46 { | 47 { |
| 47 NullExecutionContext* context = new NullExecutionContext(); | 48 NullExecutionContext* context = new NullExecutionContext(); |
| 48 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); | 49 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); |
| 49 bool isMarked = false; | 50 bool isMarked = false; |
| 50 | 51 |
| 51 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 52 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
| 52 EXPECT_FALSE(isMarked); | 53 EXPECT_FALSE(isMarked); |
| 53 blink::testing::runPendingTasks(); | 54 blink::testing::runPendingTasks(); |
| 54 EXPECT_TRUE(isMarked); | 55 EXPECT_TRUE(isMarked); |
| 55 } | 56 } |
| 56 | 57 |
| 57 TEST(MainThreadTaskRunnerTest, SuspendTask) | 58 TEST(MainThreadTaskRunnerTest, SuspendTask) |
| 58 { | 59 { |
| 59 NullExecutionContext* context = new NullExecutionContext(); | 60 NullExecutionContext* context = new NullExecutionContext(); |
| 60 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); | 61 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); |
| 61 bool isMarked = false; | 62 bool isMarked = false; |
| 62 | 63 |
| 63 context->setTasksNeedSuspension(true); | 64 context->setTasksNeedSuspension(true); |
| 64 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 65 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
| 65 runner->suspend(); | 66 runner->suspend(); |
| 66 blink::testing::runPendingTasks(); | 67 blink::testing::runPendingTasks(); |
| 67 EXPECT_FALSE(isMarked); | 68 EXPECT_FALSE(isMarked); |
| 68 | 69 |
| 69 context->setTasksNeedSuspension(false); | 70 context->setTasksNeedSuspension(false); |
| 70 runner->resume(); | 71 runner->resume(); |
| 71 blink::testing::runPendingTasks(); | 72 blink::testing::runPendingTasks(); |
| 72 EXPECT_TRUE(isMarked); | 73 EXPECT_TRUE(isMarked); |
| 73 } | 74 } |
| 74 | 75 |
| 75 TEST(MainThreadTaskRunnerTest, RemoveRunner) | 76 TEST(MainThreadTaskRunnerTest, RemoveRunner) |
| 76 { | 77 { |
| 77 NullExecutionContext* context = new NullExecutionContext(); | 78 NullExecutionContext* context = new NullExecutionContext(); |
| 78 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); | 79 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); |
| 79 bool isMarked = false; | 80 bool isMarked = false; |
| 80 | 81 |
| 81 context->setTasksNeedSuspension(true); | 82 context->setTasksNeedSuspension(true); |
| 82 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 83 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
| 83 runner = nullptr; | 84 runner = nullptr; |
| 84 blink::testing::runPendingTasks(); | 85 blink::testing::runPendingTasks(); |
| 85 EXPECT_FALSE(isMarked); | 86 EXPECT_FALSE(isMarked); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |