| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "core/dom/ActiveDOMObject.h" | |
| 32 | |
| 33 #include "core/dom/Document.h" | |
| 34 #include "core/testing/DummyPageHolder.h" | |
| 35 #include "testing/gmock/include/gmock/gmock.h" | |
| 36 #include "testing/gtest/include/gtest/gtest.h" | |
| 37 #include <memory> | |
| 38 | |
| 39 namespace blink { | |
| 40 | |
| 41 class MockActiveDOMObject final | |
| 42 : public GarbageCollectedFinalized<MockActiveDOMObject>, | |
| 43 public ActiveDOMObject { | |
| 44 USING_GARBAGE_COLLECTED_MIXIN(MockActiveDOMObject); | |
| 45 | |
| 46 public: | |
| 47 explicit MockActiveDOMObject(ExecutionContext* context) | |
| 48 : ActiveDOMObject(context) {} | |
| 49 | |
| 50 DEFINE_INLINE_VIRTUAL_TRACE() { ActiveDOMObject::trace(visitor); } | |
| 51 | |
| 52 MOCK_METHOD0(suspend, void()); | |
| 53 MOCK_METHOD0(resume, void()); | |
| 54 MOCK_METHOD0(contextDestroyed, void()); | |
| 55 }; | |
| 56 | |
| 57 class ActiveDOMObjectTest : public ::testing::Test { | |
| 58 protected: | |
| 59 ActiveDOMObjectTest(); | |
| 60 | |
| 61 Document& srcDocument() const { return m_srcPageHolder->document(); } | |
| 62 Document& destDocument() const { return m_destPageHolder->document(); } | |
| 63 MockActiveDOMObject& activeDOMObject() { return *m_activeDOMObject; } | |
| 64 | |
| 65 private: | |
| 66 std::unique_ptr<DummyPageHolder> m_srcPageHolder; | |
| 67 std::unique_ptr<DummyPageHolder> m_destPageHolder; | |
| 68 Persistent<MockActiveDOMObject> m_activeDOMObject; | |
| 69 }; | |
| 70 | |
| 71 ActiveDOMObjectTest::ActiveDOMObjectTest() | |
| 72 : m_srcPageHolder(DummyPageHolder::create(IntSize(800, 600))), | |
| 73 m_destPageHolder(DummyPageHolder::create(IntSize(800, 600))), | |
| 74 m_activeDOMObject(new MockActiveDOMObject(&m_srcPageHolder->document())) { | |
| 75 m_activeDOMObject->suspendIfNeeded(); | |
| 76 } | |
| 77 | |
| 78 TEST_F(ActiveDOMObjectTest, NewContextObserved) { | |
| 79 unsigned initialSrcCount = srcDocument().activeDOMObjectCount(); | |
| 80 unsigned initialDestCount = destDocument().activeDOMObjectCount(); | |
| 81 | |
| 82 EXPECT_CALL(activeDOMObject(), resume()); | |
| 83 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | |
| 84 | |
| 85 EXPECT_EQ(initialSrcCount - 1, srcDocument().activeDOMObjectCount()); | |
| 86 EXPECT_EQ(initialDestCount + 1, destDocument().activeDOMObjectCount()); | |
| 87 } | |
| 88 | |
| 89 TEST_F(ActiveDOMObjectTest, MoveToActiveDocument) { | |
| 90 EXPECT_CALL(activeDOMObject(), resume()); | |
| 91 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | |
| 92 } | |
| 93 | |
| 94 TEST_F(ActiveDOMObjectTest, MoveToSuspendedDocument) { | |
| 95 destDocument().suspendScheduledTasks(); | |
| 96 | |
| 97 EXPECT_CALL(activeDOMObject(), suspend()); | |
| 98 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | |
| 99 } | |
| 100 | |
| 101 TEST_F(ActiveDOMObjectTest, MoveToStoppedDocument) { | |
| 102 destDocument().shutdown(); | |
| 103 | |
| 104 EXPECT_CALL(activeDOMObject(), contextDestroyed()); | |
| 105 activeDOMObject().didMoveToNewExecutionContext(&destDocument()); | |
| 106 } | |
| 107 | |
| 108 } // namespace blink | |
| OLD | NEW |