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

Unified 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 side-by-side diff with in-line comments
Download patch
« Source/core/dom/NthIndexCache.h ('K') | « Source/core/dom/NthIndexCache.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/NthIndexCacheTest.cpp
diff --git a/Source/core/dom/NthIndexCacheTest.cpp b/Source/core/dom/NthIndexCacheTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a7bbb5205f4ad8532d61caa4008ebd68eff32da4
--- /dev/null
+++ b/Source/core/dom/NthIndexCacheTest.cpp
@@ -0,0 +1,56 @@
+// Copyright 2015 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 "config.h"
+#include "core/dom/NthIndexCache.h"
+
+#include "core/dom/Document.h"
+#include "core/html/HTMLElement.h"
+#include "core/testing/DummyPageHolder.h"
+#include <gtest/gtest.h>
+
+using namespace blink;
+
+namespace {
+
+class NthIndexCacheTest : public ::testing::Test {
+
+protected:
+ virtual void SetUp() override;
+
+ Document& document() const { return *m_document; }
+ void setHtmlInnerHTML(const char* htmlContent);
+
+private:
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ Document* m_document;
+};
+
+void NthIndexCacheTest::SetUp()
+{
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
+ 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.
+ ASSERT(m_document);
+}
+
+TEST_F(NthIndexCacheTest, NthIndex)
+{
+ document().documentElement()->setInnerHTML("<body>"
+ "<span id=first></span><span></span><span></span><span></span><span></span>"
+ "<span></span><span></span><span></span><span></span><span></span>"
+ "Text does not count"
+ "<span id=nth-last-child></span>"
+ "<span id=nth-child></span>"
+ "<span></span><span></span><span></span><span></span><span></span>"
+ "<span></span><span></span><span></span><span></span><span id=last></span>"
+ "</body>", ASSERT_NO_EXCEPTION);
+
+ Document::UseNthIndexCacheScope scope(document());
+
+ EXPECT_TRUE(document().nthIndexCache());
+ EXPECT_EQ(document().nthIndexCache()->nthChildIndex(*document().getElementById("nth-child")), 12U);
+ EXPECT_EQ(document().nthIndexCache()->nthLastChildIndex(*document().getElementById("nth-last-child")), 12U);
+}
+
+} // namespace
« 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