| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(), 2); | 123 EXPECT_EQ(observerCallback->callCount(), 2); |
| 124 document().resumeScheduledTasks(); | 124 document().resumeScheduledTasks(); |
| 125 EXPECT_EQ(observerCallback->callCount(), 2); | 125 EXPECT_EQ(observerCallback->callCount(), 2); |
| 126 testing::runPendingTasks(); | 126 testing::runPendingTasks(); |
| 127 EXPECT_EQ(observerCallback->callCount(), 3); | 127 EXPECT_EQ(observerCallback->callCount(), 3); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(IntersectionObserverTest, DisconnectClearsNotifications) { |
| 131 webView().resize(WebSize(800, 600)); |
| 132 SimRequest mainResource("https://example.com/", "text/html"); |
| 133 loadURL("https://example.com/"); |
| 134 mainResource.complete( |
| 135 "<div id='leading-space' style='height: 700px;'></div>" |
| 136 "<div id='target'></div>" |
| 137 "<div id='trailing-space' style='height: 700px;'></div>"); |
| 138 |
| 139 IntersectionObserverInit observerInit; |
| 140 DummyExceptionStateForTesting exceptionState; |
| 141 TestIntersectionObserverCallback* observerCallback = |
| 142 new TestIntersectionObserverCallback(document()); |
| 143 IntersectionObserver* observer = IntersectionObserver::create( |
| 144 observerInit, *observerCallback, exceptionState); |
| 145 ASSERT_FALSE(exceptionState.hadException()); |
| 146 |
| 147 Element* target = document().getElementById("target"); |
| 148 ASSERT_TRUE(target); |
| 149 observer->observe(target, exceptionState); |
| 150 |
| 151 compositor().beginFrame(); |
| 152 testing::runPendingTasks(); |
| 153 EXPECT_EQ(observerCallback->callCount(), 1); |
| 154 |
| 155 // If disconnect() is called while an observer has unsent notifications, |
| 156 // those notifications should be discarded. |
| 157 document().view()->layoutViewportScrollableArea()->setScrollOffset( |
| 158 ScrollOffset(0, 300), ProgrammaticScroll); |
| 159 compositor().beginFrame(); |
| 160 observer->disconnect(); |
| 161 testing::runPendingTasks(); |
| 162 EXPECT_EQ(observerCallback->callCount(), 1); |
| 163 } |
| 164 |
| 130 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |