OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "config.h" |
| 6 #include "core/dom/NthIndexCache.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 #include "core/html/HTMLElement.h" |
| 10 #include "core/testing/DummyPageHolder.h" |
| 11 #include <gtest/gtest.h> |
| 12 |
| 13 using namespace blink; |
| 14 |
| 15 namespace { |
| 16 |
| 17 class NthIndexCacheTest : public ::testing::Test { |
| 18 |
| 19 protected: |
| 20 virtual void SetUp() override; |
| 21 |
| 22 Document& document() const { return m_dummyPageHolder->document(); } |
| 23 void setHtmlInnerHTML(const char* htmlContent); |
| 24 |
| 25 private: |
| 26 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 27 }; |
| 28 |
| 29 void NthIndexCacheTest::SetUp() |
| 30 { |
| 31 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 32 } |
| 33 |
| 34 TEST_F(NthIndexCacheTest, NthIndex) |
| 35 { |
| 36 document().documentElement()->setInnerHTML("<body>" |
| 37 "<span id=first></span><span></span><span></span><span></span><span></sp
an>" |
| 38 "<span></span><span></span><span></span><span></span><span></span>" |
| 39 "Text does not count" |
| 40 "<span id=nth-last-child></span>" |
| 41 "<span id=nth-child></span>" |
| 42 "<span></span><span></span><span></span><span></span><span></span>" |
| 43 "<span></span><span></span><span></span><span></span><span id=last></spa
n>" |
| 44 "</body>", ASSERT_NO_EXCEPTION); |
| 45 |
| 46 Document::UseNthIndexCacheScope scope(document()); |
| 47 |
| 48 EXPECT_TRUE(document().nthIndexCache()); |
| 49 EXPECT_EQ(document().nthIndexCache()->nthChildIndex(*document().getElementBy
Id("nth-child")), 12U); |
| 50 EXPECT_EQ(document().nthIndexCache()->nthLastChildIndex(*document().getEleme
ntById("nth-last-child")), 12U); |
| 51 } |
| 52 |
| 53 } // namespace |
OLD | NEW |