OLD | NEW |
---|---|
(Empty) | |
1 /* | |
yosin_UTC9
2014/07/09 03:27:35
nit: You can use shorter copyright header: http://
tasak
2014/07/10 03:16:01
Done.
| |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. | |
3 * Copyright (C) 2005 Alexey Proskuryakov. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/editing/FrameSelection.h" | |
29 | |
30 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | |
31 #include "core/dom/DOMImplementation.h" | |
32 #include "core/dom/Document.h" | |
33 #include "core/dom/Element.h" | |
34 #include "core/dom/Text.h" | |
35 #include "core/html/HTMLBodyElement.h" | |
36 #include "core/html/HTMLDocument.h" | |
37 #include "core/testing/DummyPageHolder.h" | |
38 #include "wtf/Compiler.h" | |
39 #include "wtf/OwnPtr.h" | |
40 #include "wtf/PassRefPtr.h" | |
41 #include "wtf/RefPtr.h" | |
42 #include "wtf/StdLibExtras.h" | |
43 #include "wtf/Vector.h" | |
44 #include "wtf/testing/WTFTestHelpers.h" | |
45 #include <gtest/gtest.h> | |
46 | |
47 #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.
| |
48 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te mpor " \ | |
49 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \ | |
50 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \ | |
51 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null a pariatur." \ | |
52 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d eserunt " \ | |
53 "mollit anim id est laborum." | |
54 | |
55 using namespace WebCore; | |
56 | |
57 namespace { | |
58 | |
59 class FrameSelectionTest : public ::testing::Test { | |
60 protected: | |
61 virtual void SetUp() OVERRIDE; | |
62 | |
63 HTMLDocument& document() const; | |
64 void setSelection(const VisibleSelection&); | |
65 const VisibleSelection& selection() const; | |
66 Text* textNode() { return m_textNode.get(); } | |
67 | |
68 private: | |
69 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
70 HTMLDocument* m_document; | |
71 RefPtr<Text> m_textNode; | |
72 OwnPtr<FrameSelection> m_frameSelection; | |
73 }; | |
74 | |
75 void FrameSelectionTest::SetUp() | |
76 { | |
77 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
78 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
79 ASSERT(m_document); | |
80 m_textNode = m_document->createTextNode(LOREM_IPSUM); | |
81 m_document->body()->appendChild(m_textNode); | |
82 | |
83 m_frameSelection = FrameSelection::create(&m_dummyPageHolder->frame()); | |
84 ASSERT(m_frameSelection); | |
85 } | |
86 | |
87 HTMLDocument& FrameSelectionTest::document() const | |
88 { | |
89 return *m_document; | |
90 } | |
91 | |
92 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) | |
93 { | |
94 m_frameSelection->setSelection(newSelection); | |
95 } | |
96 | |
97 const VisibleSelection& FrameSelectionTest::selection() const | |
98 { | |
99 return m_frameSelection->selection(); | |
100 } | |
101 | |
102 TEST_F(FrameSelectionTest, SetValidSelection) | |
103 { | |
104 VisibleSelection validSelection(Position(textNode(), 0), Position(textNode() , 5)); | |
105 EXPECT_FALSE(validSelection.isNone()); | |
106 setSelection(validSelection); | |
107 EXPECT_FALSE(selection().isNone()); | |
108 } | |
109 | |
110 TEST_F(FrameSelectionTest, SetInvalidSelection) | |
111 { | |
112 // Create a new document without frame by using DOMImplementation. | |
113 DocumentInit dummy; | |
114 RefPtr<Document> documentWithoutFrame = DOMImplementation::createDocument("t ext/html", dummy, false); | |
115 RefPtr<Element> body = documentWithoutFrame->createElement(HTMLNames::bodyTa g, false); | |
116 documentWithoutFrame->appendChild(body); | |
117 RefPtr<Text> anotherText = documentWithoutFrame->createTextNode("Hello, anot her world"); | |
118 body->appendChild(anotherText); | |
119 | |
120 // Create a new VisibleSelection for the new document without frame and | |
121 // update FrameSelection with the selection. | |
122 VisibleSelection invalidSelection; | |
123 invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(ano therText, 5)); | |
124 setSelection(invalidSelection); | |
125 | |
126 EXPECT_TRUE(selection().isNone()); | |
127 } | |
128 | |
129 } | |
130 | |
OLD | NEW |