Chromium Code Reviews| 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 using testing::_; | |
|
esprehn
2016/05/19 22:55:59
I don't think you use this?
szager1
2016/05/19 23:58:40
Removed.
| |
| 18 | |
| 19 namespace blink { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 class TestIntersectionObserverCallback : public IntersectionObserverCallback { | |
| 24 public: | |
| 25 TestIntersectionObserverCallback(Document& document) : m_document(document), m_callCount(0) { } | |
| 26 void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, Inter sectionObserver&) override { m_callCount++; } | |
| 27 ExecutionContext* getExecutionContext() const override { return m_document; } | |
| 28 int callCount() const { return m_callCount; } | |
| 29 | |
| 30 DEFINE_INLINE_TRACE() { | |
| 31 IntersectionObserverCallback::trace(visitor); | |
| 32 visitor->trace(m_document); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 Member<Document> m_document; | |
| 37 int m_callCount; | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 class IntersectionObserverTest : public SimTest { }; | |
| 43 | |
| 44 TEST_F(IntersectionObserverTest, ObserveSchedulesFrame) | |
| 45 { | |
| 46 SimRequest mainResource("https://example.com/", "text/html"); | |
| 47 loadURL("https://example.com/"); | |
| 48 mainResource.complete("<div id='target'></div>"); | |
| 49 | |
| 50 IntersectionObserverInit observerInit; | |
| 51 TestIntersectionObserverCallback observerCallback(document()); | |
| 52 TrackExceptionState exceptionState; | |
| 53 IntersectionObserver* observer(IntersectionObserver::create(observerInit, ob serverCallback, exceptionState)); | |
| 54 ASSERT_FALSE(exceptionState.hadException()); | |
| 55 | |
| 56 compositor().beginFrame(); | |
| 57 webView().updateAllLifecyclePhases(); | |
|
esprehn
2016/05/19 22:55:59
remove this, beginFrame does it
szager1
2016/05/19 23:58:40
Done.
| |
| 58 testing::runPendingTasks(); | |
|
esprehn
2016/05/19 22:55:59
Why do you need to run tasks?
szager1
2016/05/19 23:58:40
beginFrame() will schedule a task to generate a fr
esprehn
2016/05/20 00:38:34
beginFrame() doesn't schedule a task to generate a
szager1
2016/05/20 17:22:39
Indeed, I see you're right; I removed the call to
| |
| 59 EXPECT_FALSE(compositor().needsAnimate()); | |
| 60 EXPECT_TRUE(observer->takeRecords().isEmpty()); | |
| 61 EXPECT_EQ(observerCallback.callCount(), 0); | |
| 62 | |
| 63 Element* target = document().getElementById("target"); | |
| 64 ASSERT_TRUE(target); | |
| 65 observer->observe(target); | |
| 66 EXPECT_TRUE(compositor().needsAnimate()); | |
| 67 } | |
| 68 | |
| 69 } // namespace blink | |
| OLD | NEW |