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

Unified Diff: Source/core/editing/VisibleSelectionTest.cpp

Issue 1055633004: Revert "Re-factor VisibleSelectionTest for adding tests for composed tree version" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/testing/CoreTestHelpers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/VisibleSelectionTest.cpp
diff --git a/Source/core/editing/VisibleSelectionTest.cpp b/Source/core/editing/VisibleSelectionTest.cpp
index 568204f6233ddb2ee9342a6029ee896168f4866d..b8a87aa68628ca137b8c9eed5cc4e1c2c3a2f149 100644
--- a/Source/core/editing/VisibleSelectionTest.cpp
+++ b/Source/core/editing/VisibleSelectionTest.cpp
@@ -9,7 +9,6 @@
#include "core/dom/Range.h"
#include "core/dom/Text.h"
#include "core/html/HTMLElement.h"
-#include "core/testing/CoreTestHelpers.h"
#include "core/testing/DummyPageHolder.h"
#include <gtest/gtest.h>
@@ -27,138 +26,72 @@ class VisibleSelectionTest : public ::testing::Test {
protected:
virtual void SetUp() override;
- Document& document() const { return m_dummyPageHolder->document(); }
+ // Oilpan: wrapper object needed to be able to trace VisibleSelection.
+ class VisibleSelectionWrapper : public NoBaseWillBeGarbageCollectedFinalized<VisibleSelectionWrapper> {
+ public:
+ DEFINE_INLINE_TRACE()
+ {
+ visitor->trace(m_selection);
+ }
- static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSetInnerHTML(TreeScope&, const char* hostElementID, const char* shadowRootContent);
+ VisibleSelection m_selection;
+ };
- void setBodyContent(const char*);
- PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*);
+ Document& document() const { return m_dummyPageHolder->document(); }
+ Text* textNode() const { return m_textNode.get(); }
+ VisibleSelection& selection() { return m_wrap->m_selection; }
// Helper function to set the VisibleSelection base/extent.
- void setSelection(VisibleSelection& selection, int base) { setSelection(selection, base, base); }
+ void setSelection(int base) { setSelection(base, base); }
// Helper function to set the VisibleSelection base/extent.
- void setSelection(VisibleSelection& selection, int base, int extend)
+ void setSelection(int base, int extend)
{
- Node* node = document().body()->firstChild();
- selection.setBase(Position(node, base, Position::PositionIsOffsetInAnchor));
- selection.setExtent(Position(node, extend, Position::PositionIsOffsetInAnchor));
+ m_wrap->m_selection.setBase(Position(textNode(), base));
+ m_wrap->m_selection.setExtent(Position(textNode(), extend));
}
private:
OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ RefPtrWillBePersistent<Text> m_textNode;
+ OwnPtrWillBePersistent<VisibleSelectionWrapper> m_wrap;
};
-void VisibleSelectionTest::SetUp()
+void blink::VisibleSelectionTest::SetUp()
{
m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_textNode = document().createTextNode(LOREM_IPSUM);
+ m_wrap = adoptPtrWillBeNoop(new VisibleSelectionWrapper());
+ document().body()->appendChild(m_textNode.get());
}
-PassRefPtrWillBeRawPtr<ShadowRoot> VisibleSelectionTest::createShadowRootForElementWithIDAndSetInnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootContent)
-{
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicString::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION);
- shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCEPTION);
- return shadowRoot.release();
-}
+} // namespace blink
-void VisibleSelectionTest::setBodyContent(const char* bodyContent)
-{
- document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXCEPTION);
-}
+namespace {
-PassRefPtrWillBeRawPtr<ShadowRoot> VisibleSelectionTest::setShadowContent(const char* shadowContent)
-{
- return createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
-}
+using namespace blink;
TEST_F(VisibleSelectionTest, Initialisation)
{
- setBodyContent(LOREM_IPSUM);
+ setSelection(0);
- VisibleSelection selection;
- setSelection(selection, 0);
+ EXPECT_FALSE(selection().isNone());
+ EXPECT_TRUE(selection().isCaret());
- EXPECT_FALSE(selection.isNone());
- EXPECT_TRUE(selection.isCaret());
-
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(0, range->startOffset());
EXPECT_EQ(0, range->endOffset());
EXPECT_EQ("", range->text());
}
-TEST_F(VisibleSelectionTest, ShadowCrossing)
-{
- static const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
- static const char* shadowContent = "<a><span id='s4'>44</span><content select=#two></content><span id='s5'>55</span><content select=#one></content><span id='s6'>66</span></a>";
- setBodyContent(bodyContent);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO_EXCEPTION);
-
- VisibleSelection selection(Position::firstPositionInNode(one.get()), Position::lastPositionInNode(shadowRoot.get()));
-
- EXPECT_EQ(Position(host.get(), Position::PositionIsBeforeAnchor), selection.start());
- EXPECT_EQ(Position(one->firstChild(), 0, Position::PositionIsOffsetInAnchor), selection.end());
-}
-
-TEST_F(VisibleSelectionTest, ShadowDistributedNodes)
-{
- static const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
- static const char* shadowContent = "<a><span id='s4'>44</span><content select=#two></content><span id='s5'>55</span><content select=#one></content><span id='s6'>66</span></a>";
- setBodyContent(bodyContent);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_NO_EXCEPTION);
-
- VisibleSelection selection(Position::firstPositionInNode(one.get()), Position::lastPositionInNode(two.get()));
-
- EXPECT_EQ(Position(one->firstChild(), 0, Position::PositionIsOffsetInAnchor), selection.start());
- EXPECT_EQ(Position(two->firstChild(), 2, Position::PositionIsOffsetInAnchor), selection.end());
-}
-
-TEST_F(VisibleSelectionTest, ShadowNested)
-{
- static const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
- static const char* shadowContent = "<a><span id='s4'>44</span><content select=#two></content><span id='s5'>55</span><content select=#one></content><span id='s6'>66</span></a>";
- static const char* shadowContent2 = "<span id='s7'>77</span><content></content><span id='s8'>88</span>";
- setBodyContent(bodyContent);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot, "s5", shadowContent2);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> host2 = shadowRoot->querySelector("#host2", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT_NO_EXCEPTION);
-
- VisibleSelection selection(Position::firstPositionInNode(one.get()), Position::lastPositionInNode(shadowRoot2.get()));
-
- EXPECT_EQ(Position(host.get(), Position::PositionIsBeforeAnchor), selection.start());
- EXPECT_EQ(Position(one->firstChild(), 0, Position::PositionIsOffsetInAnchor), selection.end());
-}
-
TEST_F(VisibleSelectionTest, WordGranularity)
{
- setBodyContent(LOREM_IPSUM);
-
- VisibleSelection selection;
-
// Beginning of a word.
{
- setSelection(selection, 0);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(0);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(0, range->startOffset());
EXPECT_EQ(5, range->endOffset());
EXPECT_EQ("Lorem", range->text());
@@ -166,10 +99,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// Middle of a word.
{
- setSelection(selection, 8);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(8);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(6, range->startOffset());
EXPECT_EQ(11, range->endOffset());
EXPECT_EQ("ipsum", range->text());
@@ -179,10 +112,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// FIXME: that sounds buggy, we might want to select the word _before_ instead
// of the space...
{
- setSelection(selection, 5);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(5);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(5, range->startOffset());
EXPECT_EQ(6, range->endOffset());
EXPECT_EQ(" ", range->text());
@@ -192,10 +125,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// FIXME: that sounds buggy, we might want to select the word _before_ instead
// of the comma.
{
- setSelection(selection, 26);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(26);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(26, range->startOffset());
EXPECT_EQ(27, range->endOffset());
EXPECT_EQ(",", range->text());
@@ -203,10 +136,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// After comma.
{
- setSelection(selection, 27);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(27);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(27, range->startOffset());
EXPECT_EQ(28, range->endOffset());
EXPECT_EQ(" ", range->text());
@@ -214,10 +147,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// When selecting part of a word.
{
- setSelection(selection, 0, 1);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(0, 1);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(0, range->startOffset());
EXPECT_EQ(5, range->endOffset());
EXPECT_EQ("Lorem", range->text());
@@ -225,10 +158,10 @@ TEST_F(VisibleSelectionTest, WordGranularity)
// When selecting part of two words.
{
- setSelection(selection, 2, 8);
- selection.expandUsingGranularity(WordGranularity);
+ setSelection(2, 8);
+ selection().expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> range = selection.firstRange();
+ RefPtrWillBeRawPtr<Range> range = selection().firstRange();
EXPECT_EQ(0, range->startOffset());
EXPECT_EQ(11, range->endOffset());
EXPECT_EQ("Lorem ipsum", range->text());
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/testing/CoreTestHelpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698