| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/SuspendableObject.h" |
| 32 | 32 |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/testing/DummyPageHolder.h" | 34 #include "core/testing/DummyPageHolder.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include <memory> | 37 #include <memory> |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 class MockActiveDOMObject final | 41 class MockSuspendableObject final |
| 42 : public GarbageCollectedFinalized<MockActiveDOMObject>, | 42 : public GarbageCollectedFinalized<MockSuspendableObject>, |
| 43 public ActiveDOMObject { | 43 public SuspendableObject { |
| 44 USING_GARBAGE_COLLECTED_MIXIN(MockActiveDOMObject); | 44 USING_GARBAGE_COLLECTED_MIXIN(MockSuspendableObject); |
| 45 | 45 |
| 46 public: | 46 public: |
| 47 explicit MockActiveDOMObject(ExecutionContext* context) | 47 explicit MockSuspendableObject(ExecutionContext* context) |
| 48 : ActiveDOMObject(context) {} | 48 : SuspendableObject(context) {} |
| 49 | 49 |
| 50 DEFINE_INLINE_VIRTUAL_TRACE() { ActiveDOMObject::trace(visitor); } | 50 DEFINE_INLINE_VIRTUAL_TRACE() { SuspendableObject::trace(visitor); } |
| 51 | 51 |
| 52 MOCK_METHOD0(suspend, void()); | 52 MOCK_METHOD0(suspend, void()); |
| 53 MOCK_METHOD0(resume, void()); | 53 MOCK_METHOD0(resume, void()); |
| 54 MOCK_METHOD0(contextDestroyed, void()); | 54 MOCK_METHOD0(contextDestroyed, void()); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class ActiveDOMObjectTest : public ::testing::Test { | 57 class SuspendableObjectTest : public ::testing::Test { |
| 58 protected: | 58 protected: |
| 59 ActiveDOMObjectTest(); | 59 SuspendableObjectTest(); |
| 60 | 60 |
| 61 Document& srcDocument() const { return m_srcPageHolder->document(); } | 61 Document& srcDocument() const { return m_srcPageHolder->document(); } |
| 62 Document& destDocument() const { return m_destPageHolder->document(); } | 62 Document& destDocument() const { return m_destPageHolder->document(); } |
| 63 MockActiveDOMObject& activeDOMObject() { return *m_activeDOMObject; } | 63 MockSuspendableObject& activeDOMObject() { return *m_activeDOMObject; } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 std::unique_ptr<DummyPageHolder> m_srcPageHolder; | 66 std::unique_ptr<DummyPageHolder> m_srcPageHolder; |
| 67 std::unique_ptr<DummyPageHolder> m_destPageHolder; | 67 std::unique_ptr<DummyPageHolder> m_destPageHolder; |
| 68 Persistent<MockActiveDOMObject> m_activeDOMObject; | 68 Persistent<MockSuspendableObject> m_activeDOMObject; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 ActiveDOMObjectTest::ActiveDOMObjectTest() | 71 SuspendableObjectTest::SuspendableObjectTest() |
| 72 : m_srcPageHolder(DummyPageHolder::create(IntSize(800, 600))), | 72 : m_srcPageHolder(DummyPageHolder::create(IntSize(800, 600))), |
| 73 m_destPageHolder(DummyPageHolder::create(IntSize(800, 600))), | 73 m_destPageHolder(DummyPageHolder::create(IntSize(800, 600))), |
| 74 m_activeDOMObject(new MockActiveDOMObject(&m_srcPageHolder->document())) { | 74 m_activeDOMObject( |
| 75 new MockSuspendableObject(&m_srcPageHolder->document())) { |
| 75 m_activeDOMObject->suspendIfNeeded(); | 76 m_activeDOMObject->suspendIfNeeded(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 TEST_F(ActiveDOMObjectTest, NewContextObserved) { | 79 TEST_F(SuspendableObjectTest, NewContextObserved) { |
| 79 unsigned initialSrcCount = srcDocument().activeDOMObjectCount(); | 80 unsigned initialSrcCount = srcDocument().activeDOMObjectCount(); |
| 80 unsigned initialDestCount = destDocument().activeDOMObjectCount(); | 81 unsigned initialDestCount = destDocument().activeDOMObjectCount(); |
| 81 | 82 |
| 82 EXPECT_CALL(activeDOMObject(), resume()); | 83 EXPECT_CALL(activeDOMObject(), resume()); |
| 83 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | 84 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); |
| 84 | 85 |
| 85 EXPECT_EQ(initialSrcCount - 1, srcDocument().activeDOMObjectCount()); | 86 EXPECT_EQ(initialSrcCount - 1, srcDocument().activeDOMObjectCount()); |
| 86 EXPECT_EQ(initialDestCount + 1, destDocument().activeDOMObjectCount()); | 87 EXPECT_EQ(initialDestCount + 1, destDocument().activeDOMObjectCount()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 TEST_F(ActiveDOMObjectTest, MoveToActiveDocument) { | 90 TEST_F(SuspendableObjectTest, MoveToActiveDocument) { |
| 90 EXPECT_CALL(activeDOMObject(), resume()); | 91 EXPECT_CALL(activeDOMObject(), resume()); |
| 91 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | 92 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 TEST_F(ActiveDOMObjectTest, MoveToSuspendedDocument) { | 95 TEST_F(SuspendableObjectTest, MoveToSuspendedDocument) { |
| 95 destDocument().suspendScheduledTasks(); | 96 destDocument().suspendScheduledTasks(); |
| 96 | 97 |
| 97 EXPECT_CALL(activeDOMObject(), suspend()); | 98 EXPECT_CALL(activeDOMObject(), suspend()); |
| 98 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | 99 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TEST_F(ActiveDOMObjectTest, MoveToStoppedDocument) { | 102 TEST_F(SuspendableObjectTest, MoveToStoppedDocument) { |
| 102 destDocument().shutdown(); | 103 destDocument().shutdown(); |
| 103 | 104 |
| 104 EXPECT_CALL(activeDOMObject(), contextDestroyed()); | 105 EXPECT_CALL(activeDOMObject(), contextDestroyed()); |
| 105 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | 106 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); |
| 106 } | 107 } |
| 107 | 108 |
| 108 } // namespace blink | 109 } // namespace blink |
| OLD | NEW |