OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/editing/FrameSelection.h" | |
7 | |
8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | |
9 #include "core/dom/DOMImplementation.h" | |
10 #include "core/dom/Document.h" | |
11 #include "core/dom/Element.h" | |
12 #include "core/dom/Text.h" | |
13 #include "core/html/HTMLBodyElement.h" | |
14 #include "core/html/HTMLDocument.h" | |
15 #include "core/testing/DummyPageHolder.h" | |
16 #include "wtf/Compiler.h" | |
17 #include "wtf/OwnPtr.h" | |
18 #include "wtf/PassRefPtr.h" | |
19 #include "wtf/RefPtr.h" | |
20 #include "wtf/StdLibExtras.h" | |
21 #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.
| |
22 #include "wtf/testing/WTFTestHelpers.h" | |
23 #include <gtest/gtest.h> | |
24 | |
25 #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.
| |
26 | |
27 using namespace WebCore; | |
28 | |
29 namespace { | |
30 | |
31 class FrameSelectionTest : public ::testing::Test { | |
32 protected: | |
33 virtual void SetUp() OVERRIDE; | |
34 | |
35 HTMLDocument& document() const; | |
36 void setSelection(const VisibleSelection&); | |
37 const VisibleSelection& selection() const; | |
38 Text* textNode() { return m_textNode.get(); } | |
39 | |
40 private: | |
41 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
42 HTMLDocument* m_document; | |
tkent
2014/07/15 00:41:22
This should be RawPtrWillBePersistent<HTMLDocument
tasak
2014/07/25 09:23:35
Done.
| |
43 RefPtr<Text> m_textNode; | |
tkent
2014/07/15 00:41:22
RefPtrWillBePersistent<Text>
tasak
2014/07/25 09:23:35
Done.
| |
44 OwnPtr<FrameSelection> m_frameSelection; | |
tkent
2014/07/15 00:41:22
OwnPtrWillBePersistent<FrameSelection>
tasak
2014/07/25 09:23:34
Done.
| |
45 }; | |
46 | |
47 void FrameSelectionTest::SetUp() | |
48 { | |
49 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
50 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
51 ASSERT(m_document); | |
52 m_textNode = m_document->createTextNode(HELLO_WORLD); | |
53 m_document->body()->appendChild(m_textNode); | |
54 | |
55 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.
| |
56 ASSERT(m_frameSelection); | |
57 } | |
58 | |
59 HTMLDocument& FrameSelectionTest::document() const | |
60 { | |
61 return *m_document; | |
62 } | |
63 | |
64 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) | |
65 { | |
66 m_frameSelection->setSelection(newSelection); | |
67 } | |
68 | |
69 const VisibleSelection& FrameSelectionTest::selection() const | |
70 { | |
71 return m_frameSelection->selection(); | |
72 } | |
73 | |
74 TEST_F(FrameSelectionTest, SetValidSelection) | |
75 { | |
76 VisibleSelection validSelection(Position(textNode(), 0), Position(textNode() , 5)); | |
77 EXPECT_FALSE(validSelection.isNone()); | |
78 setSelection(validSelection); | |
79 EXPECT_FALSE(selection().isNone()); | |
80 } | |
81 | |
82 TEST_F(FrameSelectionTest, SetInvalidSelection) | |
83 { | |
84 // Create a new document without frame by using DOMImplementation. | |
85 DocumentInit dummy; | |
86 RefPtr<Document> documentWithoutFrame = DOMImplementation::createDocument("t ext/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.
| |
87 RefPtr<Element> body = documentWithoutFrame->createElement(HTMLNames::bodyTa g, false); | |
tkent
2014/07/15 00:41:22
RefPtrWillBeRawPtr<Element>
tasak
2014/07/25 09:23:35
Done.
| |
88 documentWithoutFrame->appendChild(body); | |
89 RefPtr<Text> anotherText = documentWithoutFrame->createTextNode("Hello, anot her world"); | |
tkent
2014/07/15 00:41:22
RefPtrWillBeRawPtr<Text>
tasak
2014/07/25 09:23:35
Done.
| |
90 body->appendChild(anotherText); | |
91 | |
92 // Create a new VisibleSelection for the new document without frame and | |
93 // update FrameSelection with the selection. | |
94 VisibleSelection invalidSelection; | |
95 invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(ano therText, 5)); | |
96 setSelection(invalidSelection); | |
97 | |
98 EXPECT_TRUE(selection().isNone()); | |
99 } | |
100 | |
101 } | |
OLD | NEW |