| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 class NullEventQueue : public EventQueue { | 41 class NullEventQueue : public EventQueue { |
| 42 public: | 42 public: |
| 43 NullEventQueue() { } | 43 NullEventQueue() { } |
| 44 virtual ~NullEventQueue() { } | 44 virtual ~NullEventQueue() { } |
| 45 virtual bool enqueueEvent(PassRefPtrWillBeRawPtr<Event>) OVERRIDE { return t
rue; } | 45 virtual bool enqueueEvent(PassRefPtrWillBeRawPtr<Event>) OVERRIDE { return t
rue; } |
| 46 virtual bool cancelEvent(Event*) OVERRIDE { return true; } | 46 virtual bool cancelEvent(Event*) OVERRIDE { return true; } |
| 47 virtual void close() OVERRIDE { } | 47 virtual void close() OVERRIDE { } |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class NullExecutionContext : public RefCountedWillBeGarbageCollectedFinalized<Nu
llExecutionContext>, public ExecutionContext { | 50 class NullExecutionContext : public ExecutionContext, public RefCounted<NullExec
utionContext> { |
| 51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NullExecutionContext); | |
| 52 public: | 51 public: |
| 53 void trace(Visitor* visitor) { ExecutionContext::trace(visitor); } | |
| 54 #if !ENABLE(OILPAN) | |
| 55 using RefCounted<NullExecutionContext>::ref; | 52 using RefCounted<NullExecutionContext>::ref; |
| 56 using RefCounted<NullExecutionContext>::deref; | 53 using RefCounted<NullExecutionContext>::deref; |
| 57 | 54 |
| 58 virtual void refExecutionContext() OVERRIDE { ref(); } | 55 virtual void refExecutionContext() OVERRIDE { ref(); } |
| 59 virtual void derefExecutionContext() OVERRIDE { deref(); } | 56 virtual void derefExecutionContext() OVERRIDE { deref(); } |
| 60 #endif | |
| 61 virtual EventQueue* eventQueue() const OVERRIDE { return m_queue.get(); } | 57 virtual EventQueue* eventQueue() const OVERRIDE { return m_queue.get(); } |
| 62 virtual bool tasksNeedSuspension() { return m_tasksNeedSuspension; } | 58 virtual bool tasksNeedSuspension() { return m_tasksNeedSuspension; } |
| 63 | 59 |
| 64 void setTasksNeedSuspention(bool flag) { m_tasksNeedSuspension = flag; } | 60 void setTasksNeedSuspention(bool flag) { m_tasksNeedSuspension = flag; } |
| 65 | 61 |
| 66 NullExecutionContext(); | 62 NullExecutionContext(); |
| 67 | 63 |
| 68 private: | 64 private: |
| 69 bool m_tasksNeedSuspension; | 65 bool m_tasksNeedSuspension; |
| 70 OwnPtr<EventQueue> m_queue; | 66 OwnPtr<EventQueue> m_queue; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 virtual void performTask(ExecutionContext* context) OVERRIDE | 88 virtual void performTask(ExecutionContext* context) OVERRIDE |
| 93 { | 89 { |
| 94 *m_toBeMarked = true; | 90 *m_toBeMarked = true; |
| 95 } | 91 } |
| 96 | 92 |
| 97 bool* m_toBeMarked; | 93 bool* m_toBeMarked; |
| 98 }; | 94 }; |
| 99 | 95 |
| 100 TEST(MainThreadTaskRunnerTest, PostTask) | 96 TEST(MainThreadTaskRunnerTest, PostTask) |
| 101 { | 97 { |
| 102 RefPtrWillBeRawPtr<NullExecutionContext> context = adoptRefWillBeNoop(new Nu
llExecutionContext()); | 98 RefPtr<NullExecutionContext> context = adoptRef(new NullExecutionContext()); |
| 103 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); | 99 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); |
| 104 bool isMarked = false; | 100 bool isMarked = false; |
| 105 | 101 |
| 106 runner->postTask(MarkingBooleanTask::create(&isMarked)); | 102 runner->postTask(MarkingBooleanTask::create(&isMarked)); |
| 107 EXPECT_FALSE(isMarked); | 103 EXPECT_FALSE(isMarked); |
| 108 WebCore::testing::runPendingTasks(); | 104 WebCore::testing::runPendingTasks(); |
| 109 EXPECT_TRUE(isMarked); | 105 EXPECT_TRUE(isMarked); |
| 110 } | 106 } |
| 111 | 107 |
| 112 TEST(MainThreadTaskRunnerTest, SuspendTask) | 108 TEST(MainThreadTaskRunnerTest, SuspendTask) |
| 113 { | 109 { |
| 114 RefPtrWillBeRawPtr<NullExecutionContext> context = adoptRefWillBeNoop(new Nu
llExecutionContext()); | 110 RefPtr<NullExecutionContext> context = adoptRef(new NullExecutionContext()); |
| 115 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); | 111 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); |
| 116 bool isMarked = false; | 112 bool isMarked = false; |
| 117 | 113 |
| 118 context->setTasksNeedSuspention(true); | 114 context->setTasksNeedSuspention(true); |
| 119 runner->postTask(MarkingBooleanTask::create(&isMarked)); | 115 runner->postTask(MarkingBooleanTask::create(&isMarked)); |
| 120 runner->suspend(); | 116 runner->suspend(); |
| 121 WebCore::testing::runPendingTasks(); | 117 WebCore::testing::runPendingTasks(); |
| 122 EXPECT_FALSE(isMarked); | 118 EXPECT_FALSE(isMarked); |
| 123 | 119 |
| 124 context->setTasksNeedSuspention(false); | 120 context->setTasksNeedSuspention(false); |
| 125 runner->resume(); | 121 runner->resume(); |
| 126 WebCore::testing::runPendingTasks(); | 122 WebCore::testing::runPendingTasks(); |
| 127 EXPECT_TRUE(isMarked); | 123 EXPECT_TRUE(isMarked); |
| 128 } | 124 } |
| 129 | 125 |
| 130 TEST(MainThreadTaskRunnerTest, RemoveRunner) | 126 TEST(MainThreadTaskRunnerTest, RemoveRunner) |
| 131 { | 127 { |
| 132 RefPtrWillBeRawPtr<NullExecutionContext> context = adoptRefWillBeNoop(new Nu
llExecutionContext()); | 128 RefPtr<NullExecutionContext> context = adoptRef(new NullExecutionContext()); |
| 133 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); | 129 OwnPtr<MainThreadTaskRunner> runner = MainThreadTaskRunner::create(context.g
et()); |
| 134 bool isMarked = false; | 130 bool isMarked = false; |
| 135 | 131 |
| 136 context->setTasksNeedSuspention(true); | 132 context->setTasksNeedSuspention(true); |
| 137 runner->postTask(MarkingBooleanTask::create(&isMarked)); | 133 runner->postTask(MarkingBooleanTask::create(&isMarked)); |
| 138 runner.clear(); | 134 runner.clear(); |
| 139 WebCore::testing::runPendingTasks(); | 135 WebCore::testing::runPendingTasks(); |
| 140 EXPECT_FALSE(isMarked); | 136 EXPECT_FALSE(isMarked); |
| 141 } | 137 } |
| 142 | 138 |
| 143 } | 139 } |
| OLD | NEW |