Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Side by Side Diff: Source/core/dom/NthIndexCacheTest.cpp

Issue 1023393002: Cache element indices for :nth-child and :nth-last-child selectors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clear cache after each operation Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_document; }
23 void setHtmlInnerHTML(const char* htmlContent);
24
25 private:
26 OwnPtr<DummyPageHolder> m_dummyPageHolder;
27 Document* m_document;
28 };
29
30 void NthIndexCacheTest::SetUp()
31 {
32 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
33 m_document = &m_dummyPageHolder->document();
sof 2015/03/28 08:34:00 Worth caching this Document* reference?
rune 2015/03/30 09:00:03 Done.
34 ASSERT(m_document);
35 }
36
37 TEST_F(NthIndexCacheTest, NthIndex)
38 {
39 document().documentElement()->setInnerHTML("<body>"
40 "<span id=first></span><span></span><span></span><span></span><span></sp an>"
41 "<span></span><span></span><span></span><span></span><span></span>"
42 "Text does not count"
43 "<span id=nth-last-child></span>"
44 "<span id=nth-child></span>"
45 "<span></span><span></span><span></span><span></span><span></span>"
46 "<span></span><span></span><span></span><span></span><span id=last></spa n>"
47 "</body>", ASSERT_NO_EXCEPTION);
48
49 Document::UseNthIndexCacheScope scope(document());
50
51 EXPECT_TRUE(document().nthIndexCache());
52 EXPECT_EQ(document().nthIndexCache()->nthChildIndex(*document().getElementBy Id("nth-child")), 12U);
53 EXPECT_EQ(document().nthIndexCache()->nthLastChildIndex(*document().getEleme ntById("nth-last-child")), 12U);
54 }
55
56 } // namespace
OLDNEW
« Source/core/dom/NthIndexCache.h ('K') | « Source/core/dom/NthIndexCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698