Index: Source/core/editing/FrameSelectionTest.cpp |
diff --git a/Source/core/editing/FrameSelectionTest.cpp b/Source/core/editing/FrameSelectionTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..28cd75f0e5ecc00f5215680f5927e7da13d08eb2 |
--- /dev/null |
+++ b/Source/core/editing/FrameSelectionTest.cpp |
@@ -0,0 +1,101 @@ |
+// Copyright 2014 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/editing/FrameSelection.h" |
+ |
+#include "bindings/core/v8/ExceptionStatePlaceholder.h" |
+#include "core/dom/DOMImplementation.h" |
+#include "core/dom/Document.h" |
+#include "core/dom/Element.h" |
+#include "core/dom/Text.h" |
+#include "core/html/HTMLBodyElement.h" |
+#include "core/html/HTMLDocument.h" |
+#include "core/testing/DummyPageHolder.h" |
+#include "wtf/Compiler.h" |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassRefPtr.h" |
+#include "wtf/RefPtr.h" |
+#include "wtf/StdLibExtras.h" |
+#include "wtf/Vector.h" |
Yuta Kitamura
2014/07/14 10:04:43
You aren't using a Vector, are you?
tasak
2014/07/25 09:23:35
Done.
|
+#include "wtf/testing/WTFTestHelpers.h" |
+#include <gtest/gtest.h> |
+ |
+#define HELLO_WORLD "Hello, World!" |
Yuta Kitamura
2014/07/14 10:04:43
Urm, well, I don't think you have to define this c
tasak
2014/07/25 09:23:35
Done.
|
+ |
+using namespace WebCore; |
+ |
+namespace { |
+ |
+class FrameSelectionTest : public ::testing::Test { |
+protected: |
+ virtual void SetUp() OVERRIDE; |
+ |
+ HTMLDocument& document() const; |
+ void setSelection(const VisibleSelection&); |
+ const VisibleSelection& selection() const; |
+ Text* textNode() { return m_textNode.get(); } |
+ |
+private: |
+ OwnPtr<DummyPageHolder> m_dummyPageHolder; |
+ HTMLDocument* m_document; |
tkent
2014/07/15 00:41:22
This should be RawPtrWillBePersistent<HTMLDocument
tasak
2014/07/25 09:23:35
Done.
|
+ RefPtr<Text> m_textNode; |
tkent
2014/07/15 00:41:22
RefPtrWillBePersistent<Text>
tasak
2014/07/25 09:23:35
Done.
|
+ OwnPtr<FrameSelection> m_frameSelection; |
tkent
2014/07/15 00:41:22
OwnPtrWillBePersistent<FrameSelection>
tasak
2014/07/25 09:23:34
Done.
|
+}; |
+ |
+void FrameSelectionTest::SetUp() |
+{ |
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
+ m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
+ ASSERT(m_document); |
+ m_textNode = m_document->createTextNode(HELLO_WORLD); |
+ m_document->body()->appendChild(m_textNode); |
+ |
+ m_frameSelection = FrameSelection::create(&m_dummyPageHolder->frame()); |
Yuta Kitamura
2014/07/14 10:04:43
You shouldn't create a FrameSelection instance you
tasak
2014/07/25 09:23:35
Done.
|
+ ASSERT(m_frameSelection); |
+} |
+ |
+HTMLDocument& FrameSelectionTest::document() const |
+{ |
+ return *m_document; |
+} |
+ |
+void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) |
+{ |
+ m_frameSelection->setSelection(newSelection); |
+} |
+ |
+const VisibleSelection& FrameSelectionTest::selection() const |
+{ |
+ return m_frameSelection->selection(); |
+} |
+ |
+TEST_F(FrameSelectionTest, SetValidSelection) |
+{ |
+ VisibleSelection validSelection(Position(textNode(), 0), Position(textNode(), 5)); |
+ EXPECT_FALSE(validSelection.isNone()); |
+ setSelection(validSelection); |
+ EXPECT_FALSE(selection().isNone()); |
+} |
+ |
+TEST_F(FrameSelectionTest, SetInvalidSelection) |
+{ |
+ // Create a new document without frame by using DOMImplementation. |
+ DocumentInit dummy; |
+ RefPtr<Document> documentWithoutFrame = DOMImplementation::createDocument("text/html", dummy, false); |
Yuta Kitamura
2014/07/14 10:04:43
Just calling Document::create() (with no argument)
tkent
2014/07/15 00:41:22
RefPtrWillBeRawPtr<Document>
tasak
2014/07/25 09:23:34
Done.
tasak
2014/07/25 09:23:35
Done.
|
+ RefPtr<Element> body = documentWithoutFrame->createElement(HTMLNames::bodyTag, false); |
tkent
2014/07/15 00:41:22
RefPtrWillBeRawPtr<Element>
tasak
2014/07/25 09:23:35
Done.
|
+ documentWithoutFrame->appendChild(body); |
+ RefPtr<Text> anotherText = documentWithoutFrame->createTextNode("Hello, another world"); |
tkent
2014/07/15 00:41:22
RefPtrWillBeRawPtr<Text>
tasak
2014/07/25 09:23:35
Done.
|
+ body->appendChild(anotherText); |
+ |
+ // Create a new VisibleSelection for the new document without frame and |
+ // update FrameSelection with the selection. |
+ VisibleSelection invalidSelection; |
+ invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(anotherText, 5)); |
+ setSelection(invalidSelection); |
+ |
+ EXPECT_TRUE(selection().isNone()); |
+} |
+ |
+} |