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 "wtf/OwnPtr.h" | 36 #include <memory> |
37 #include "wtf/PassOwnPtr.h" | |
38 | 37 |
39 namespace blink { | 38 namespace blink { |
40 | 39 |
41 static void markBoolean(bool* toBeMarked) | 40 static void markBoolean(bool* toBeMarked) |
42 { | 41 { |
43 *toBeMarked = true; | 42 *toBeMarked = true; |
44 } | 43 } |
45 | 44 |
46 TEST(MainThreadTaskRunnerTest, PostTask) | 45 TEST(MainThreadTaskRunnerTest, PostTask) |
47 { | 46 { |
48 NullExecutionContext* context = new NullExecutionContext(); | 47 NullExecutionContext* context = new NullExecutionContext(); |
49 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); | 48 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); |
50 bool isMarked = false; | 49 bool isMarked = false; |
51 | 50 |
52 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 51 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
53 EXPECT_FALSE(isMarked); | 52 EXPECT_FALSE(isMarked); |
54 blink::testing::runPendingTasks(); | 53 blink::testing::runPendingTasks(); |
55 EXPECT_TRUE(isMarked); | 54 EXPECT_TRUE(isMarked); |
56 } | 55 } |
57 | 56 |
58 TEST(MainThreadTaskRunnerTest, SuspendTask) | 57 TEST(MainThreadTaskRunnerTest, SuspendTask) |
59 { | 58 { |
60 NullExecutionContext* context = new NullExecutionContext(); | 59 NullExecutionContext* context = new NullExecutionContext(); |
61 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); | 60 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); |
62 bool isMarked = false; | 61 bool isMarked = false; |
63 | 62 |
64 context->setTasksNeedSuspension(true); | 63 context->setTasksNeedSuspension(true); |
65 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 64 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
66 runner->suspend(); | 65 runner->suspend(); |
67 blink::testing::runPendingTasks(); | 66 blink::testing::runPendingTasks(); |
68 EXPECT_FALSE(isMarked); | 67 EXPECT_FALSE(isMarked); |
69 | 68 |
70 context->setTasksNeedSuspension(false); | 69 context->setTasksNeedSuspension(false); |
71 runner->resume(); | 70 runner->resume(); |
72 blink::testing::runPendingTasks(); | 71 blink::testing::runPendingTasks(); |
73 EXPECT_TRUE(isMarked); | 72 EXPECT_TRUE(isMarked); |
74 } | 73 } |
75 | 74 |
76 TEST(MainThreadTaskRunnerTest, RemoveRunner) | 75 TEST(MainThreadTaskRunnerTest, RemoveRunner) |
77 { | 76 { |
78 NullExecutionContext* context = new NullExecutionContext(); | 77 NullExecutionContext* context = new NullExecutionContext(); |
79 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context); | 78 std::unique_ptr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(
context); |
80 bool isMarked = false; | 79 bool isMarked = false; |
81 | 80 |
82 context->setTasksNeedSuspension(true); | 81 context->setTasksNeedSuspension(true); |
83 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); | 82 runner->postTask(BLINK_FROM_HERE, createSameThreadTask(&markBoolean, &isMark
ed)); |
84 runner = nullptr; | 83 runner = nullptr; |
85 blink::testing::runPendingTasks(); | 84 blink::testing::runPendingTasks(); |
86 EXPECT_FALSE(isMarked); | 85 EXPECT_FALSE(isMarked); |
87 } | 86 } |
88 | 87 |
89 } // namespace blink | 88 } // namespace blink |
OLD | NEW |