| 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 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/dom/MainThreadTaskRunner.h" | 29 #include "core/dom/MainThreadTaskRunner.h" |
| 30 | 30 |
| 31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
| 32 #include "core/dom/ExecutionContextTask.h" | 32 #include "core/dom/ExecutionContextTask.h" |
| 33 #include "core/dom/SecurityContext.h" |
| 33 #include "core/events/EventQueue.h" | 34 #include "core/events/EventQueue.h" |
| 34 #include "core/testing/UnitTestHelpers.h" | 35 #include "core/testing/UnitTestHelpers.h" |
| 36 #include "wtf/Forward.h" |
| 35 #include <gtest/gtest.h> | 37 #include <gtest/gtest.h> |
| 36 | 38 |
| 37 using namespace WebCore; | 39 using namespace WebCore; |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 class NullEventQueue : public EventQueue { | 43 class NullEventQueue : public EventQueue { |
| 42 public: | 44 public: |
| 43 NullEventQueue() { } | 45 NullEventQueue() { } |
| 44 virtual ~NullEventQueue() { } | 46 virtual ~NullEventQueue() { } |
| 45 virtual bool enqueueEvent(PassRefPtrWillBeRawPtr<Event>) OVERRIDE { return t
rue; } | 47 virtual bool enqueueEvent(PassRefPtrWillBeRawPtr<Event>) OVERRIDE { return t
rue; } |
| 46 virtual bool cancelEvent(Event*) OVERRIDE { return true; } | 48 virtual bool cancelEvent(Event*) OVERRIDE { return true; } |
| 47 virtual void close() OVERRIDE { } | 49 virtual void close() OVERRIDE { } |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 class NullExecutionContext : public RefCountedWillBeGarbageCollectedFinalized<Nu
llExecutionContext>, public ExecutionContext { | 52 class NullExecutionContext : public RefCountedWillBeGarbageCollectedFinalized<Nu
llExecutionContext>, public SecurityContext, public ExecutionContext { |
| 51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NullExecutionContext); | 53 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(NullExecutionContext); |
| 52 public: | 54 public: |
| 53 void trace(Visitor* visitor) { ExecutionContext::trace(visitor); } | 55 void trace(Visitor* visitor) { ExecutionContext::trace(visitor); } |
| 54 #if !ENABLE(OILPAN) | 56 #if !ENABLE(OILPAN) |
| 55 using RefCounted<NullExecutionContext>::ref; | 57 using RefCounted<NullExecutionContext>::ref; |
| 56 using RefCounted<NullExecutionContext>::deref; | 58 using RefCounted<NullExecutionContext>::deref; |
| 57 | 59 |
| 60 virtual void reportBlockedScriptExecutionToInspector(const String& directive
Text) OVERRIDE { } |
| 61 |
| 62 virtual SecurityContext& securityContext() { return *this; } |
| 63 |
| 58 virtual void refExecutionContext() OVERRIDE { ref(); } | 64 virtual void refExecutionContext() OVERRIDE { ref(); } |
| 59 virtual void derefExecutionContext() OVERRIDE { deref(); } | 65 virtual void derefExecutionContext() OVERRIDE { deref(); } |
| 60 #endif | 66 #endif |
| 61 virtual EventQueue* eventQueue() const OVERRIDE { return m_queue.get(); } | 67 virtual EventQueue* eventQueue() const OVERRIDE { return m_queue.get(); } |
| 62 virtual bool tasksNeedSuspension() { return m_tasksNeedSuspension; } | 68 virtual bool tasksNeedSuspension() { return m_tasksNeedSuspension; } |
| 63 | 69 |
| 64 void setTasksNeedSuspention(bool flag) { m_tasksNeedSuspension = flag; } | 70 void setTasksNeedSuspention(bool flag) { m_tasksNeedSuspension = flag; } |
| 65 | 71 |
| 66 NullExecutionContext(); | 72 NullExecutionContext(); |
| 67 | 73 |
| 74 protected: |
| 75 virtual const KURL& virtualURL() const OVERRIDE { return m_dummyURL; } |
| 76 virtual KURL virtualCompleteURL(const String&) const OVERRIDE { return m_dum
myURL; } |
| 77 |
| 68 private: | 78 private: |
| 69 bool m_tasksNeedSuspension; | 79 bool m_tasksNeedSuspension; |
| 70 OwnPtr<EventQueue> m_queue; | 80 OwnPtr<EventQueue> m_queue; |
| 81 |
| 82 KURL m_dummyURL; |
| 71 }; | 83 }; |
| 72 | 84 |
| 73 NullExecutionContext::NullExecutionContext() | 85 NullExecutionContext::NullExecutionContext() |
| 74 : m_tasksNeedSuspension(false) | 86 : m_tasksNeedSuspension(false) |
| 75 , m_queue(adoptPtr(new NullEventQueue())) | 87 , m_queue(adoptPtr(new NullEventQueue())) |
| 76 { | 88 { |
| 77 } | 89 } |
| 78 | 90 |
| 79 class MarkingBooleanTask FINAL : public ExecutionContextTask { | 91 class MarkingBooleanTask FINAL : public ExecutionContextTask { |
| 80 public: | 92 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 bool isMarked = false; | 146 bool isMarked = false; |
| 135 | 147 |
| 136 context->setTasksNeedSuspention(true); | 148 context->setTasksNeedSuspention(true); |
| 137 runner->postTask(MarkingBooleanTask::create(&isMarked)); | 149 runner->postTask(MarkingBooleanTask::create(&isMarked)); |
| 138 runner.clear(); | 150 runner.clear(); |
| 139 WebCore::testing::runPendingTasks(); | 151 WebCore::testing::runPendingTasks(); |
| 140 EXPECT_FALSE(isMarked); | 152 EXPECT_FALSE(isMarked); |
| 141 } | 153 } |
| 142 | 154 |
| 143 } | 155 } |
| OLD | NEW |