Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e35dc101a81007993edf2f40489157427bd8e838 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/web/tests/IntersectionObserverTest.cpp |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/dom/IntersectionObserver.h" |
| + |
| +#include "core/dom/IntersectionObserverCallback.h" |
| +#include "core/dom/IntersectionObserverInit.h" |
| +#include "platform/testing/UnitTestHelpers.h" |
| +#include "web/WebViewImpl.h" |
| +#include "web/tests/sim/SimCompositor.h" |
| +#include "web/tests/sim/SimDisplayItemList.h" |
| +#include "web/tests/sim/SimRequest.h" |
| +#include "web/tests/sim/SimTest.h" |
| +#include "wtf/CurrentTime.h" |
| + |
| +using testing::_; |
|
esprehn
2016/05/19 22:55:59
I don't think you use this?
szager1
2016/05/19 23:58:40
Removed.
|
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +class TestIntersectionObserverCallback : public IntersectionObserverCallback { |
| +public: |
| + TestIntersectionObserverCallback(Document& document) : m_document(document), m_callCount(0) { } |
| + void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, IntersectionObserver&) override { m_callCount++; } |
| + ExecutionContext* getExecutionContext() const override { return m_document; } |
| + int callCount() const { return m_callCount; } |
| + |
| + DEFINE_INLINE_TRACE() { |
| + IntersectionObserverCallback::trace(visitor); |
| + visitor->trace(m_document); |
| + } |
| + |
| +private: |
| + Member<Document> m_document; |
| + int m_callCount; |
| +}; |
| + |
| +} // namespace |
| + |
| +class IntersectionObserverTest : public SimTest { }; |
| + |
| +TEST_F(IntersectionObserverTest, ObserveSchedulesFrame) |
| +{ |
| + SimRequest mainResource("https://example.com/", "text/html"); |
| + loadURL("https://example.com/"); |
| + mainResource.complete("<div id='target'></div>"); |
| + |
| + IntersectionObserverInit observerInit; |
| + TestIntersectionObserverCallback observerCallback(document()); |
| + TrackExceptionState exceptionState; |
| + IntersectionObserver* observer(IntersectionObserver::create(observerInit, observerCallback, exceptionState)); |
| + ASSERT_FALSE(exceptionState.hadException()); |
| + |
| + compositor().beginFrame(); |
| + webView().updateAllLifecyclePhases(); |
|
esprehn
2016/05/19 22:55:59
remove this, beginFrame does it
szager1
2016/05/19 23:58:40
Done.
|
| + 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
|
| + EXPECT_FALSE(compositor().needsAnimate()); |
| + EXPECT_TRUE(observer->takeRecords().isEmpty()); |
| + EXPECT_EQ(observerCallback.callCount(), 0); |
| + |
| + Element* target = document().getElementById("target"); |
| + ASSERT_TRUE(target); |
| + observer->observe(target); |
| + EXPECT_TRUE(compositor().needsAnimate()); |
| +} |
| + |
| +} // namespace blink |