| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/IntersectionObserver.h" | 5 #include "core/dom/IntersectionObserver.h" |
| 6 | 6 |
| 7 #include "core/dom/IntersectionObserverCallback.h" | 7 #include "core/dom/IntersectionObserverCallback.h" |
| 8 #include "core/dom/IntersectionObserverInit.h" | 8 #include "core/dom/IntersectionObserverInit.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 IntersectionObserver* observer = IntersectionObserver::create( | 84 IntersectionObserver* observer = IntersectionObserver::create( |
| 85 observerInit, *observerCallback, exceptionState); | 85 observerInit, *observerCallback, exceptionState); |
| 86 ASSERT_FALSE(exceptionState.hadException()); | 86 ASSERT_FALSE(exceptionState.hadException()); |
| 87 | 87 |
| 88 Element* target = document().getElementById("target"); | 88 Element* target = document().getElementById("target"); |
| 89 ASSERT_TRUE(target); | 89 ASSERT_TRUE(target); |
| 90 observer->observe(target, exceptionState); | 90 observer->observe(target, exceptionState); |
| 91 | 91 |
| 92 compositor().beginFrame(); | 92 compositor().beginFrame(); |
| 93 testing::runPendingTasks(); | 93 testing::runPendingTasks(); |
| 94 EXPECT_EQ(observerCallback->callCount(), 0); | 94 EXPECT_EQ(observerCallback->callCount(), 1); |
| 95 | 95 |
| 96 // When document is not suspended, beginFrame() will generate notifications | 96 // When document is not suspended, beginFrame() will generate notifications |
| 97 // and post a task to deliver them. | 97 // and post a task to deliver them. |
| 98 document().view()->layoutViewportScrollableArea()->setScrollOffset( | 98 document().view()->layoutViewportScrollableArea()->setScrollOffset( |
| 99 ScrollOffset(0, 300), ProgrammaticScroll); | 99 ScrollOffset(0, 300), ProgrammaticScroll); |
| 100 compositor().beginFrame(); | 100 compositor().beginFrame(); |
| 101 EXPECT_EQ(observerCallback->callCount(), 0); | 101 EXPECT_EQ(observerCallback->callCount(), 1); |
| 102 testing::runPendingTasks(); | 102 testing::runPendingTasks(); |
| 103 EXPECT_EQ(observerCallback->callCount(), 1); | 103 EXPECT_EQ(observerCallback->callCount(), 2); |
| 104 | 104 |
| 105 // When a document is suspended, beginFrame() will generate a notification, | 105 // When a document is suspended, beginFrame() will generate a notification, |
| 106 // but it will not be delivered. The notification will, however, be | 106 // but it will not be delivered. The notification will, however, be |
| 107 // available via takeRecords(); | 107 // available via takeRecords(); |
| 108 document().suspendScheduledTasks(); | 108 document().suspendScheduledTasks(); |
| 109 document().view()->layoutViewportScrollableArea()->setScrollOffset( | 109 document().view()->layoutViewportScrollableArea()->setScrollOffset( |
| 110 ScrollOffset(0, 0), ProgrammaticScroll); | 110 ScrollOffset(0, 0), ProgrammaticScroll); |
| 111 compositor().beginFrame(); | 111 compositor().beginFrame(); |
| 112 EXPECT_EQ(observerCallback->callCount(), 1); | 112 EXPECT_EQ(observerCallback->callCount(), 2); |
| 113 testing::runPendingTasks(); | 113 testing::runPendingTasks(); |
| 114 EXPECT_EQ(observerCallback->callCount(), 1); | 114 EXPECT_EQ(observerCallback->callCount(), 2); |
| 115 EXPECT_FALSE(observer->takeRecords(exceptionState).isEmpty()); | 115 EXPECT_FALSE(observer->takeRecords(exceptionState).isEmpty()); |
| 116 | 116 |
| 117 // Generate a notification while document is suspended; then resume document. | 117 // Generate a notification while document is suspended; then resume document. |
| 118 // Notification should happen in a post task. | 118 // Notification should happen in a post task. |
| 119 document().view()->layoutViewportScrollableArea()->setScrollOffset( | 119 document().view()->layoutViewportScrollableArea()->setScrollOffset( |
| 120 ScrollOffset(0, 300), ProgrammaticScroll); | 120 ScrollOffset(0, 300), ProgrammaticScroll); |
| 121 compositor().beginFrame(); | 121 compositor().beginFrame(); |
| 122 testing::runPendingTasks(); | 122 testing::runPendingTasks(); |
| 123 EXPECT_EQ(observerCallback->callCount(), 1); | 123 EXPECT_EQ(observerCallback->callCount(), 2); |
| 124 document().resumeScheduledTasks(); | 124 document().resumeScheduledTasks(); |
| 125 EXPECT_EQ(observerCallback->callCount(), 1); | 125 EXPECT_EQ(observerCallback->callCount(), 2); |
| 126 testing::runPendingTasks(); | 126 testing::runPendingTasks(); |
| 127 EXPECT_EQ(observerCallback->callCount(), 2); | 127 EXPECT_EQ(observerCallback->callCount(), 3); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |