| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/IntersectionObserver.h" |
| 6 |
| 7 #include "core/dom/IntersectionObserverCallback.h" |
| 8 #include "core/dom/IntersectionObserverInit.h" |
| 9 #include "platform/testing/UnitTestHelpers.h" |
| 10 #include "web/WebViewImpl.h" |
| 11 #include "web/tests/sim/SimCompositor.h" |
| 12 #include "web/tests/sim/SimDisplayItemList.h" |
| 13 #include "web/tests/sim/SimRequest.h" |
| 14 #include "web/tests/sim/SimTest.h" |
| 15 #include "wtf/CurrentTime.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class TestIntersectionObserverCallback : public IntersectionObserverCallback { |
| 22 public: |
| 23 TestIntersectionObserverCallback(Document& document) : m_document(document),
m_callCount(0) { } |
| 24 void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, Inter
sectionObserver&) override { m_callCount++; } |
| 25 ExecutionContext* getExecutionContext() const override { return m_document;
} |
| 26 int callCount() const { return m_callCount; } |
| 27 |
| 28 DEFINE_INLINE_TRACE() { |
| 29 IntersectionObserverCallback::trace(visitor); |
| 30 visitor->trace(m_document); |
| 31 } |
| 32 |
| 33 private: |
| 34 Member<Document> m_document; |
| 35 int m_callCount; |
| 36 }; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 class IntersectionObserverTest : public SimTest { }; |
| 41 |
| 42 TEST_F(IntersectionObserverTest, ObserveSchedulesFrame) |
| 43 { |
| 44 SimRequest mainResource("https://example.com/", "text/html"); |
| 45 loadURL("https://example.com/"); |
| 46 mainResource.complete("<div id='target'></div>"); |
| 47 |
| 48 IntersectionObserverInit observerInit; |
| 49 TrackExceptionState exceptionState; |
| 50 TestIntersectionObserverCallback* observerCallback = new TestIntersectionObs
erverCallback(document()); |
| 51 IntersectionObserver* observer = IntersectionObserver::create(observerInit,
*observerCallback, exceptionState); |
| 52 ASSERT_FALSE(exceptionState.hadException()); |
| 53 |
| 54 compositor().beginFrame(); |
| 55 ASSERT_FALSE(compositor().needsAnimate()); |
| 56 EXPECT_TRUE(observer->takeRecords().isEmpty()); |
| 57 EXPECT_EQ(observerCallback->callCount(), 0); |
| 58 |
| 59 Element* target = document().getElementById("target"); |
| 60 ASSERT_TRUE(target); |
| 61 observer->observe(target); |
| 62 EXPECT_TRUE(compositor().needsAnimate()); |
| 63 } |
| 64 |
| 65 } // namespace blink |
| OLD | NEW |