OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/dom/Text.h" | 8 #include "core/dom/Text.h" |
9 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
11 #include "core/frame/Settings.h" | 11 #include "core/frame/Settings.h" |
12 #include "core/html/HTMLBodyElement.h" | 12 #include "core/html/HTMLBodyElement.h" |
13 #include "core/html/HTMLDocument.h" | |
14 #include "core/html/HTMLSpanElement.h" | 13 #include "core/html/HTMLSpanElement.h" |
15 #include "core/testing/DummyPageHolder.h" | 14 #include "core/testing/DummyPageHolder.h" |
16 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
19 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
20 #include "wtf/StdLibExtras.h" | 19 #include "wtf/StdLibExtras.h" |
21 #include <memory> | 20 #include <memory> |
22 | 21 |
23 namespace blink { | 22 namespace blink { |
(...skipping 10 matching lines...) Expand all Loading... |
34 return result; | 33 return result; |
35 } | 34 } |
36 | 35 |
37 using TextNodeVector = HeapVector<Member<Text>>; | 36 using TextNodeVector = HeapVector<Member<Text>>; |
38 | 37 |
39 class GranularityStrategyTest : public ::testing::Test { | 38 class GranularityStrategyTest : public ::testing::Test { |
40 protected: | 39 protected: |
41 void SetUp() override; | 40 void SetUp() override; |
42 | 41 |
43 DummyPageHolder& dummyPageHolder() const { return *m_dummyPageHolder; } | 42 DummyPageHolder& dummyPageHolder() const { return *m_dummyPageHolder; } |
44 HTMLDocument& document() const; | 43 Document& document() const; |
45 void setSelection(const VisibleSelection&); | 44 void setSelection(const VisibleSelection&); |
46 FrameSelection& selection() const; | 45 FrameSelection& selection() const; |
47 Text* appendTextNode(const String& data); | 46 Text* appendTextNode(const String& data); |
48 int layoutCount() const { return m_dummyPageHolder->frameView().layoutCount(
); } | 47 int layoutCount() const { return m_dummyPageHolder->frameView().layoutCount(
); } |
49 void setInnerHTML(const char*); | 48 void setInnerHTML(const char*); |
50 // Parses the text node, appending the info to m_letterPos and m_wordMiddles
. | 49 // Parses the text node, appending the info to m_letterPos and m_wordMiddles
. |
51 void parseText(Text*); | 50 void parseText(Text*); |
52 void parseText(const TextNodeVector&); | 51 void parseText(const TextNodeVector&); |
53 | 52 |
54 Text* setupTranslateZ(String); | 53 Text* setupTranslateZ(String); |
55 Text* setupTransform(String); | 54 Text* setupTransform(String); |
56 Text* setupRotate(String); | 55 Text* setupRotate(String); |
57 void setupTextSpan(String str1, String str2, String str3, size_t selBegin, s
ize_t selEnd); | 56 void setupTextSpan(String str1, String str2, String str3, size_t selBegin, s
ize_t selEnd); |
58 void setupVerticalAlign(String str1, String str2, String str3, size_t selBeg
in, size_t selEnd); | 57 void setupVerticalAlign(String str1, String str2, String str3, size_t selBeg
in, size_t selEnd); |
59 void setupFontSize(String str1, String str2, String str3, size_t selBegin, s
ize_t selEnd); | 58 void setupFontSize(String str1, String str2, String str3, size_t selBegin, s
ize_t selEnd); |
60 | 59 |
61 void testDirectionExpand(); | 60 void testDirectionExpand(); |
62 void testDirectionShrink(); | 61 void testDirectionShrink(); |
63 void testDirectionSwitchSide(); | 62 void testDirectionSwitchSide(); |
64 | 63 |
65 // Pixel coordinates of the positions for each letter within the text being
tested. | 64 // Pixel coordinates of the positions for each letter within the text being
tested. |
66 Vector<IntPoint> m_letterPos; | 65 Vector<IntPoint> m_letterPos; |
67 // Pixel coordinates of the middles of the words in the text being tested. | 66 // Pixel coordinates of the middles of the words in the text being tested. |
68 // (y coordinate is based on y coordinates of m_letterPos) | 67 // (y coordinate is based on y coordinates of m_letterPos) |
69 Vector<IntPoint> m_wordMiddles; | 68 Vector<IntPoint> m_wordMiddles; |
70 | 69 |
71 private: | 70 private: |
72 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 71 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
73 Persistent<HTMLDocument> m_document; | 72 Persistent<Document> m_document; |
74 }; | 73 }; |
75 | 74 |
76 void GranularityStrategyTest::SetUp() | 75 void GranularityStrategyTest::SetUp() |
77 { | 76 { |
78 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 77 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
79 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 78 m_document = &m_dummyPageHolder->document(); |
80 DCHECK(m_document); | 79 DCHECK(m_document); |
81 dummyPageHolder().frame().settings()->setDefaultFontSize(12); | 80 dummyPageHolder().frame().settings()->setDefaultFontSize(12); |
82 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy
::Direction); | 81 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy
::Direction); |
83 } | 82 } |
84 | 83 |
85 HTMLDocument& GranularityStrategyTest::document() const | 84 Document& GranularityStrategyTest::document() const |
86 { | 85 { |
87 return *m_document; | 86 return *m_document; |
88 } | 87 } |
89 | 88 |
90 void GranularityStrategyTest::setSelection(const VisibleSelection& newSelection) | 89 void GranularityStrategyTest::setSelection(const VisibleSelection& newSelection) |
91 { | 90 { |
92 m_dummyPageHolder->frame().selection().setSelection(newSelection); | 91 m_dummyPageHolder->frame().selection().setSelection(newSelection); |
93 } | 92 } |
94 | 93 |
95 FrameSelection& GranularityStrategyTest::selection() const | 94 FrameSelection& GranularityStrategyTest::selection() const |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 652 |
654 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, | 653 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, |
655 // > means end). | 654 // > means end). |
656 selection().setSelection(VisibleSelection(Position(text, 15), Position(text,
22))); | 655 selection().setSelection(VisibleSelection(Position(text, 15), Position(text,
22))); |
657 EXPECT_EQ_SELECTED_TEXT("mnopqr "); | 656 EXPECT_EQ_SELECTED_TEXT("mnopqr "); |
658 selection().moveRangeSelectionExtent(m_wordMiddles[4]); | 657 selection().moveRangeSelectionExtent(m_wordMiddles[4]); |
659 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); | 658 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); |
660 } | 659 } |
661 | 660 |
662 } // namespace blink | 661 } // namespace blink |
OLD | NEW |