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