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

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

Issue 359593002: Selection should be updated after node is moved to another document (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..94d72834e71c120a4ee4bd86b59059b936b94740
--- /dev/null
+++ b/Source/core/editing/FrameSelectionTest.cpp
@@ -0,0 +1,130 @@
+/*
yosin_UTC9 2014/07/09 03:27:35 nit: You can use shorter copyright header: http://
tasak 2014/07/10 03:16:01 Done.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2005 Alexey Proskuryakov.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#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"
+#include "wtf/testing/WTFTestHelpers.h"
+#include <gtest/gtest.h>
+
+#define LOREM_IPSUM \
yosin_UTC9 2014/07/09 03:27:35 Can we use shorter text? It seems we need to set n
tasak 2014/07/10 03:16:02 Done.
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor " \
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \
+ "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \
+ "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." \
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " \
+ "mollit anim id est laborum."
+
+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;
+ RefPtr<Text> m_textNode;
+ OwnPtr<FrameSelection> m_frameSelection;
+};
+
+void FrameSelectionTest::SetUp()
+{
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
+ m_document = toHTMLDocument(&m_dummyPageHolder->document());
+ ASSERT(m_document);
+ m_textNode = m_document->createTextNode(LOREM_IPSUM);
+ m_document->body()->appendChild(m_textNode);
+
+ m_frameSelection = FrameSelection::create(&m_dummyPageHolder->frame());
+ 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);
+ RefPtr<Element> body = documentWithoutFrame->createElement(HTMLNames::bodyTag, false);
+ documentWithoutFrame->appendChild(body);
+ RefPtr<Text> anotherText = documentWithoutFrame->createTextNode("Hello, another world");
+ 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());
+}
+
+}
+
« no previous file with comments | « Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698