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