OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 3181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3192 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3192 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3193 webViewHelper.initializeAndLoad(m_baseURL + "sometext.html"); | 3193 webViewHelper.initializeAndLoad(m_baseURL + "sometext.html"); |
3194 webViewHelper.resize(WebSize(640, 480)); | 3194 webViewHelper.resize(WebSize(640, 480)); |
3195 | 3195 |
3196 webViewHelper.webViewImpl()->setPageScaleFactor(2); | 3196 webViewHelper.webViewImpl()->setPageScaleFactor(2); |
3197 webViewHelper.webViewImpl()->setVisualViewportOffset(WebFloatPoint(50, 60)); | 3197 webViewHelper.webViewImpl()->setVisualViewportOffset(WebFloatPoint(50, 60)); |
3198 | 3198 |
3199 WebRect baseRect; | 3199 WebRect baseRect; |
3200 WebRect extentRect; | 3200 WebRect extentRect; |
3201 | 3201 |
3202 WebFrame* mainFrame = webViewHelper.webViewImpl()->mainFrame(); | 3202 WebLocalFrame* mainFrame = webViewHelper.webViewImpl()->mainFrame()->toWebLo
calFrame(); |
3203 size_t ix = mainFrame->characterIndexForPoint(WebPoint(320, 388)); | 3203 size_t ix = mainFrame->characterIndexForPoint(WebPoint(320, 388)); |
3204 | 3204 |
3205 EXPECT_EQ(2ul, ix); | 3205 EXPECT_EQ(2ul, ix); |
3206 } | 3206 } |
3207 | 3207 |
3208 TEST_P(ParameterizedWebFrameTest, FirstRectForCharacterRangeWithPinchZoom) | 3208 TEST_P(ParameterizedWebFrameTest, FirstRectForCharacterRangeWithPinchZoom) |
3209 { | 3209 { |
3210 registerMockedHttpURLLoad("textbox.html"); | 3210 registerMockedHttpURLLoad("textbox.html"); |
3211 | 3211 |
3212 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3212 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3213 webViewHelper.initializeAndLoad(m_baseURL + "textbox.html", true); | 3213 webViewHelper.initializeAndLoad(m_baseURL + "textbox.html", true); |
3214 webViewHelper.resize(WebSize(640, 480)); | 3214 webViewHelper.resize(WebSize(640, 480)); |
3215 | 3215 |
3216 WebFrame* mainFrame = webViewHelper.webViewImpl()->mainFrame(); | 3216 WebLocalFrame* mainFrame = webViewHelper.webViewImpl()->mainFrame()->toWebLo
calFrame(); |
3217 mainFrame->executeScript(WebScriptSource("selectRange();")); | 3217 mainFrame->executeScript(WebScriptSource("selectRange();")); |
3218 | 3218 |
3219 WebRect oldRect; | 3219 WebRect oldRect; |
3220 mainFrame->firstRectForCharacterRange(0, 5, oldRect); | 3220 mainFrame->firstRectForCharacterRange(0, 5, oldRect); |
3221 | 3221 |
3222 WebFloatPoint visualOffset(100, 130); | 3222 WebFloatPoint visualOffset(100, 130); |
3223 float scale = 2; | 3223 float scale = 2; |
3224 webViewHelper.webViewImpl()->setPageScaleFactor(scale); | 3224 webViewHelper.webViewImpl()->setPageScaleFactor(scale); |
3225 webViewHelper.webViewImpl()->setVisualViewportOffset(visualOffset); | 3225 webViewHelper.webViewImpl()->setVisualViewportOffset(visualOffset); |
3226 | 3226 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3661 // Get the frame text where the subframe separator falls on the boundary of | 3661 // Get the frame text where the subframe separator falls on the boundary of |
3662 // what we'll take. There used to be a crash in this case. | 3662 // what we'll take. There used to be a crash in this case. |
3663 text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webView(), 12)
; | 3663 text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webView(), 12)
; |
3664 EXPECT_EQ("Hello world", text.utf8()); | 3664 EXPECT_EQ("Hello world", text.utf8()); |
3665 } | 3665 } |
3666 | 3666 |
3667 TEST_P(ParameterizedWebFrameTest, GetFullHtmlOfPage) | 3667 TEST_P(ParameterizedWebFrameTest, GetFullHtmlOfPage) |
3668 { | 3668 { |
3669 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3669 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3670 webViewHelper.initializeAndLoad("about:blank", true); | 3670 webViewHelper.initializeAndLoad("about:blank", true); |
3671 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 3671 WebLocalFrame* frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame
(); |
3672 | 3672 |
3673 // Generate a simple test case. | 3673 // Generate a simple test case. |
3674 const char simpleSource[] = "<p>Hello</p><p>World</p>"; | 3674 const char simpleSource[] = "<p>Hello</p><p>World</p>"; |
3675 KURL testURL = toKURL("about:blank"); | 3675 KURL testURL = toKURL("about:blank"); |
3676 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); | 3676 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); |
3677 | 3677 |
3678 WebString text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webV
iew(), std::numeric_limits<size_t>::max()); | 3678 WebString text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webV
iew(), std::numeric_limits<size_t>::max()); |
3679 EXPECT_EQ("Hello\n\nWorld", text.utf8()); | 3679 EXPECT_EQ("Hello\n\nWorld", text.utf8()); |
3680 | 3680 |
3681 const std::string html = WebFrameContentDumper::dumpAsMarkup(frame->toWebLoc
alFrame()).utf8(); | 3681 const std::string html = WebFrameContentDumper::dumpAsMarkup(frame).utf8(); |
3682 | 3682 |
3683 // Load again with the output html. | 3683 // Load again with the output html. |
3684 FrameTestHelpers::loadHTMLString(frame, html, testURL); | 3684 FrameTestHelpers::loadHTMLString(frame, html, testURL); |
3685 | 3685 |
3686 EXPECT_EQ(html, WebFrameContentDumper::dumpAsMarkup(frame->toWebLocalFrame()
).utf8()); | 3686 EXPECT_EQ(html, WebFrameContentDumper::dumpAsMarkup(frame).utf8()); |
3687 | 3687 |
3688 text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webView(), std
::numeric_limits<size_t>::max()); | 3688 text = WebFrameContentDumper::dumpWebViewAsText(webViewHelper.webView(), std
::numeric_limits<size_t>::max()); |
3689 EXPECT_EQ("Hello\n\nWorld", text.utf8()); | 3689 EXPECT_EQ("Hello\n\nWorld", text.utf8()); |
3690 | 3690 |
3691 // Test selection check | 3691 // Test selection check |
3692 EXPECT_FALSE(frame->hasSelection()); | 3692 EXPECT_FALSE(frame->hasSelection()); |
3693 frame->executeCommand(WebString::fromUTF8("SelectAll")); | 3693 frame->executeCommand(WebString::fromUTF8("SelectAll")); |
3694 EXPECT_TRUE(frame->hasSelection()); | 3694 EXPECT_TRUE(frame->hasSelection()); |
3695 frame->executeCommand(WebString::fromUTF8("Unselect")); | 3695 frame->executeCommand(WebString::fromUTF8("Unselect")); |
3696 EXPECT_FALSE(frame->hasSelection()); | 3696 EXPECT_FALSE(frame->hasSelection()); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4124 return WebPoint(rect.x + rect.width - 1, rect.y + rect.height - 1); | 4124 return WebPoint(rect.x + rect.width - 1, rect.y + rect.height - 1); |
4125 } | 4125 } |
4126 | 4126 |
4127 static WebRect elementBounds(WebFrame* frame, const WebString& id) | 4127 static WebRect elementBounds(WebFrame* frame, const WebString& id) |
4128 { | 4128 { |
4129 return frame->document().getElementById(id).boundsInViewport(); | 4129 return frame->document().getElementById(id).boundsInViewport(); |
4130 } | 4130 } |
4131 | 4131 |
4132 static std::string selectionAsString(WebFrame* frame) | 4132 static std::string selectionAsString(WebFrame* frame) |
4133 { | 4133 { |
4134 return frame->selectionAsText().utf8(); | 4134 return frame->toWebLocalFrame()->selectionAsText().utf8(); |
4135 } | 4135 } |
4136 | 4136 |
4137 TEST_P(ParameterizedWebFrameTest, SelectRange) | 4137 TEST_P(ParameterizedWebFrameTest, SelectRange) |
4138 { | 4138 { |
4139 WebFrame* frame; | 4139 WebLocalFrame* frame; |
4140 WebRect startWebRect; | 4140 WebRect startWebRect; |
4141 WebRect endWebRect; | 4141 WebRect endWebRect; |
4142 | 4142 |
4143 registerMockedHttpURLLoad("select_range_basic.html"); | 4143 registerMockedHttpURLLoad("select_range_basic.html"); |
4144 registerMockedHttpURLLoad("select_range_scroll.html"); | 4144 registerMockedHttpURLLoad("select_range_scroll.html"); |
4145 | 4145 |
4146 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4146 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4147 initializeTextSelectionWebView(m_baseURL + "select_range_basic.html", &webVi
ewHelper); | 4147 initializeTextSelectionWebView(m_baseURL + "select_range_basic.html", &webVi
ewHelper); |
4148 frame = webViewHelper.webView()->mainFrame(); | 4148 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4149 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); | 4149 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); |
4150 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4150 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4151 frame->executeCommand(WebString::fromUTF8("Unselect")); | 4151 frame->executeCommand(WebString::fromUTF8("Unselect")); |
4152 EXPECT_EQ("", selectionAsString(frame)); | 4152 EXPECT_EQ("", selectionAsString(frame)); |
4153 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 4153 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
4154 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. | 4154 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. |
4155 std::string selectionString = selectionAsString(frame); | 4155 std::string selectionString = selectionAsString(frame); |
4156 EXPECT_TRUE(selectionString == "Some test text for testing." | 4156 EXPECT_TRUE(selectionString == "Some test text for testing." |
4157 || selectionString == "Some test text for testing"); | 4157 || selectionString == "Some test text for testing"); |
4158 | 4158 |
4159 initializeTextSelectionWebView(m_baseURL + "select_range_scroll.html", &webV
iewHelper); | 4159 initializeTextSelectionWebView(m_baseURL + "select_range_scroll.html", &webV
iewHelper); |
4160 frame = webViewHelper.webView()->mainFrame(); | 4160 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4161 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; | 4161 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; |
4162 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4162 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4163 frame->executeCommand(WebString::fromUTF8("Unselect")); | 4163 frame->executeCommand(WebString::fromUTF8("Unselect")); |
4164 EXPECT_EQ("", selectionAsString(frame)); | 4164 EXPECT_EQ("", selectionAsString(frame)); |
4165 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 4165 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
4166 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. | 4166 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. |
4167 selectionString = selectionAsString(frame); | 4167 selectionString = selectionAsString(frame); |
4168 EXPECT_TRUE(selectionString == "Some offscreen test text for testing." | 4168 EXPECT_TRUE(selectionString == "Some offscreen test text for testing." |
4169 || selectionString == "Some offscreen test text for testing"); | 4169 || selectionString == "Some offscreen test text for testing"); |
4170 } | 4170 } |
4171 | 4171 |
4172 TEST_P(ParameterizedWebFrameTest, SelectRangeInIframe) | 4172 TEST_P(ParameterizedWebFrameTest, SelectRangeInIframe) |
4173 { | 4173 { |
4174 WebFrame* frame; | 4174 WebFrame* frame; |
4175 WebRect startWebRect; | 4175 WebRect startWebRect; |
4176 WebRect endWebRect; | 4176 WebRect endWebRect; |
4177 | 4177 |
4178 registerMockedHttpURLLoad("select_range_iframe.html"); | 4178 registerMockedHttpURLLoad("select_range_iframe.html"); |
4179 registerMockedHttpURLLoad("select_range_basic.html"); | 4179 registerMockedHttpURLLoad("select_range_basic.html"); |
4180 | 4180 |
4181 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4181 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4182 initializeTextSelectionWebView(m_baseURL + "select_range_iframe.html", &webV
iewHelper); | 4182 initializeTextSelectionWebView(m_baseURL + "select_range_iframe.html", &webV
iewHelper); |
4183 frame = webViewHelper.webView()->mainFrame(); | 4183 frame = webViewHelper.webView()->mainFrame(); |
4184 WebFrame* subframe = frame->firstChild(); | 4184 WebLocalFrame* subframe = frame->firstChild()->toWebLocalFrame(); |
4185 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); | 4185 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); |
4186 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4186 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4187 subframe->executeCommand(WebString::fromUTF8("Unselect")); | 4187 subframe->executeCommand(WebString::fromUTF8("Unselect")); |
4188 EXPECT_EQ("", selectionAsString(subframe)); | 4188 EXPECT_EQ("", selectionAsString(subframe)); |
4189 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)
); | 4189 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)
); |
4190 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. | 4190 // On some devices, the above bottomRightMinusOne() causes the ending '.' no
t selected. |
4191 std::string selectionString = selectionAsString(subframe); | 4191 std::string selectionString = selectionAsString(subframe); |
4192 EXPECT_TRUE(selectionString == "Some test text for testing." | 4192 EXPECT_TRUE(selectionString == "Some test text for testing." |
4193 || selectionString == "Some test text for testing"); | 4193 || selectionString == "Some test text for testing"); |
4194 } | 4194 } |
4195 | 4195 |
4196 TEST_P(ParameterizedWebFrameTest, SelectRangeDivContentEditable) | 4196 TEST_P(ParameterizedWebFrameTest, SelectRangeDivContentEditable) |
4197 { | 4197 { |
4198 WebFrame* frame; | 4198 WebLocalFrame* frame; |
4199 WebRect startWebRect; | 4199 WebRect startWebRect; |
4200 WebRect endWebRect; | 4200 WebRect endWebRect; |
4201 | 4201 |
4202 registerMockedHttpURLLoad("select_range_div_editable.html"); | 4202 registerMockedHttpURLLoad("select_range_div_editable.html"); |
4203 | 4203 |
4204 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. | 4204 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. |
4205 // The selection range should be clipped to the bounds of the editable eleme
nt. | 4205 // The selection range should be clipped to the bounds of the editable eleme
nt. |
4206 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4206 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4207 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); | 4207 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); |
4208 frame = webViewHelper.webView()->mainFrame(); | 4208 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4209 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 4209 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
4210 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4210 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4211 | 4211 |
4212 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); | 4212 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); |
4213 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); | 4213 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); |
4214 | 4214 |
4215 // As above, but extending the selection to the bottom of the document. | 4215 // As above, but extending the selection to the bottom of the document. |
4216 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); | 4216 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); |
4217 frame = webViewHelper.webView()->mainFrame(); | 4217 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4218 | 4218 |
4219 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4219 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4220 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 4220 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
4221 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 4221 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
4222 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4222 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4223 | 4223 |
4224 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4224 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4225 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); | 4225 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); |
4226 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); | 4226 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); |
4227 } | 4227 } |
4228 | 4228 |
4229 // positionForPoint returns the wrong values for contenteditable spans. See | 4229 // positionForPoint returns the wrong values for contenteditable spans. See |
4230 // http://crbug.com/238334. | 4230 // http://crbug.com/238334. |
4231 TEST_P(ParameterizedWebFrameTest, DISABLED_SelectRangeSpanContentEditable) | 4231 TEST_P(ParameterizedWebFrameTest, DISABLED_SelectRangeSpanContentEditable) |
4232 { | 4232 { |
4233 WebFrame* frame; | 4233 WebLocalFrame* frame; |
4234 WebRect startWebRect; | 4234 WebRect startWebRect; |
4235 WebRect endWebRect; | 4235 WebRect endWebRect; |
4236 | 4236 |
4237 registerMockedHttpURLLoad("select_range_span_editable.html"); | 4237 registerMockedHttpURLLoad("select_range_span_editable.html"); |
4238 | 4238 |
4239 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. | 4239 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. |
4240 // The selection range should be clipped to the bounds of the editable eleme
nt. | 4240 // The selection range should be clipped to the bounds of the editable eleme
nt. |
4241 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4241 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4242 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); | 4242 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); |
4243 frame = webViewHelper.webView()->mainFrame(); | 4243 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4244 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 4244 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
4245 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4245 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4246 | 4246 |
4247 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); | 4247 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); |
4248 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); | 4248 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); |
4249 | 4249 |
4250 // As above, but extending the selection to the bottom of the document. | 4250 // As above, but extending the selection to the bottom of the document. |
4251 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); | 4251 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); |
4252 frame = webViewHelper.webView()->mainFrame(); | 4252 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4253 | 4253 |
4254 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4254 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4255 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 4255 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
4256 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 4256 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
4257 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4257 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4258 | 4258 |
4259 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 4259 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
4260 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); | 4260 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
4261 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); | 4261 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); |
4262 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); | 4262 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); |
4263 } | 4263 } |
4264 | 4264 |
4265 TEST_P(ParameterizedWebFrameTest, SelectRangeCanMoveSelectionStart) | 4265 TEST_P(ParameterizedWebFrameTest, SelectRangeCanMoveSelectionStart) |
4266 { | 4266 { |
4267 registerMockedHttpURLLoad("text_selection.html"); | 4267 registerMockedHttpURLLoad("text_selection.html"); |
4268 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4268 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4269 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); | 4269 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); |
4270 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 4270 WebLocalFrame* frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame
(); |
4271 | 4271 |
4272 // Select second span. We can move the start to include the first span. | 4272 // Select second span. We can move the start to include the first span. |
4273 frame->executeScript(WebScriptSource("selectElement('header_2');")); | 4273 frame->executeScript(WebScriptSource("selectElement('header_2');")); |
4274 EXPECT_EQ("Header 2.", selectionAsString(frame)); | 4274 EXPECT_EQ("Header 2.", selectionAsString(frame)); |
4275 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to
pLeft(elementBounds(frame, "header_1"))); | 4275 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to
pLeft(elementBounds(frame, "header_1"))); |
4276 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); | 4276 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); |
4277 | 4277 |
4278 // We can move the start and end together. | 4278 // We can move the start and end together. |
4279 frame->executeScript(WebScriptSource("selectElement('header_1');")); | 4279 frame->executeScript(WebScriptSource("selectElement('header_1');")); |
4280 EXPECT_EQ("Header 1.", selectionAsString(frame)); | 4280 EXPECT_EQ("Header 1.", selectionAsString(frame)); |
(...skipping 27 matching lines...) Expand all Loading... |
4308 // positionForPoint returns the wrong values for contenteditable spans. See | 4308 // positionForPoint returns the wrong values for contenteditable spans. See |
4309 // http://crbug.com/238334. | 4309 // http://crbug.com/238334. |
4310 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); | 4310 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); |
4311 } | 4311 } |
4312 | 4312 |
4313 TEST_P(ParameterizedWebFrameTest, SelectRangeCanMoveSelectionEnd) | 4313 TEST_P(ParameterizedWebFrameTest, SelectRangeCanMoveSelectionEnd) |
4314 { | 4314 { |
4315 registerMockedHttpURLLoad("text_selection.html"); | 4315 registerMockedHttpURLLoad("text_selection.html"); |
4316 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4316 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4317 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); | 4317 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); |
4318 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 4318 WebLocalFrame* frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame
(); |
4319 | 4319 |
4320 // Select first span. We can move the end to include the second span. | 4320 // Select first span. We can move the end to include the second span. |
4321 frame->executeScript(WebScriptSource("selectElement('header_1');")); | 4321 frame->executeScript(WebScriptSource("selectElement('header_1');")); |
4322 EXPECT_EQ("Header 1.", selectionAsString(frame)); | 4322 EXPECT_EQ("Header 1.", selectionAsString(frame)); |
4323 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin
usOne(elementBounds(frame, "header_2"))); | 4323 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin
usOne(elementBounds(frame, "header_2"))); |
4324 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); | 4324 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); |
4325 | 4325 |
4326 // We can move the start and end together. | 4326 // We can move the start and end together. |
4327 frame->executeScript(WebScriptSource("selectElement('header_2');")); | 4327 frame->executeScript(WebScriptSource("selectElement('header_2');")); |
4328 EXPECT_EQ("Header 2.", selectionAsString(frame)); | 4328 EXPECT_EQ("Header 2.", selectionAsString(frame)); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4710 | 4710 |
4711 FrameTestHelpers::WebViewHelper webViewHelper(this); | 4711 FrameTestHelpers::WebViewHelper webViewHelper(this); |
4712 webViewHelper.initialize(true, nullptr, &fakeSelectionWebViewClient, nullptr
); | 4712 webViewHelper.initialize(true, nullptr, &fakeSelectionWebViewClient, nullptr
); |
4713 webViewHelper.webView()->settings()->setDefaultFontSize(12); | 4713 webViewHelper.webView()->settings()->setDefaultFontSize(12); |
4714 webViewHelper.webView()->setDefaultPageScaleLimits(1, 1); | 4714 webViewHelper.webView()->setDefaultPageScaleLimits(1, 1); |
4715 webViewHelper.resize(WebSize(viewWidth, viewHeight)); | 4715 webViewHelper.resize(WebSize(viewWidth, viewHeight)); |
4716 webViewHelper.webView()->setFocus(true); | 4716 webViewHelper.webView()->setFocus(true); |
4717 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "select_range_basic.html"); | 4717 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "select_range_basic.html"); |
4718 | 4718 |
4719 // The frame starts with no selection. | 4719 // The frame starts with no selection. |
4720 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 4720 WebLocalFrame* frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame
(); |
4721 ASSERT_TRUE(frame->hasSelection()); | 4721 ASSERT_TRUE(frame->hasSelection()); |
4722 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); | 4722 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); |
4723 | 4723 |
4724 // The selection cleared notification should be triggered upon layout. | 4724 // The selection cleared notification should be triggered upon layout. |
4725 frame->executeCommand(WebString::fromUTF8("Unselect")); | 4725 frame->executeCommand(WebString::fromUTF8("Unselect")); |
4726 ASSERT_FALSE(frame->hasSelection()); | 4726 ASSERT_FALSE(frame->hasSelection()); |
4727 EXPECT_FALSE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); | 4727 EXPECT_FALSE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); |
4728 webViewHelper.webView()->updateAllLifecyclePhases(); | 4728 webViewHelper.webView()->updateAllLifecyclePhases(); |
4729 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); | 4729 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); |
4730 | 4730 |
(...skipping 10 matching lines...) Expand all Loading... |
4741 WebRect startWebRect; | 4741 WebRect startWebRect; |
4742 WebRect endWebRect; | 4742 WebRect endWebRect; |
4743 webViewHelper.webViewImpl()->selectionBounds(startWebRect, endWebRect); | 4743 webViewHelper.webViewImpl()->selectionBounds(startWebRect, endWebRect); |
4744 WebPoint movedEnd(bottomRightMinusOne(endWebRect)); | 4744 WebPoint movedEnd(bottomRightMinusOne(endWebRect)); |
4745 endWebRect.x -= 20; | 4745 endWebRect.x -= 20; |
4746 frame->selectRange(topLeft(startWebRect), movedEnd); | 4746 frame->selectRange(topLeft(startWebRect), movedEnd); |
4747 webViewHelper.webView()->updateAllLifecyclePhases(); | 4747 webViewHelper.webView()->updateAllLifecyclePhases(); |
4748 ASSERT_TRUE(frame->hasSelection()); | 4748 ASSERT_TRUE(frame->hasSelection()); |
4749 EXPECT_FALSE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); | 4749 EXPECT_FALSE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); |
4750 | 4750 |
4751 frame = webViewHelper.webView()->mainFrame(); | 4751 frame = webViewHelper.webView()->mainFrame()->toWebLocalFrame(); |
4752 frame->executeCommand(WebString::fromUTF8("Unselect")); | 4752 frame->executeCommand(WebString::fromUTF8("Unselect")); |
4753 webViewHelper.webView()->updateAllLifecyclePhases(); | 4753 webViewHelper.webView()->updateAllLifecyclePhases(); |
4754 ASSERT_FALSE(frame->hasSelection()); | 4754 ASSERT_FALSE(frame->hasSelection()); |
4755 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); | 4755 EXPECT_TRUE(fakeSelectionLayerTreeView.getAndResetSelectionCleared()); |
4756 } | 4756 } |
4757 | 4757 |
4758 class DisambiguationPopupTestWebViewClient : public FrameTestHelpers::TestWebVie
wClient { | 4758 class DisambiguationPopupTestWebViewClient : public FrameTestHelpers::TestWebVie
wClient { |
4759 public: | 4759 public: |
4760 bool didTapMultipleTargets(const WebSize&, const WebRect&, const WebVector<W
ebRect>& targetRects) override | 4760 bool didTapMultipleTargets(const WebSize&, const WebRect&, const WebVector<W
ebRect>& targetRects) override |
4761 { | 4761 { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5139 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f
rame starts with triggers this. | 5139 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f
rame starts with triggers this. |
5140 } | 5140 } |
5141 | 5141 |
5142 TEST_P(ParameterizedWebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSele
ction) | 5142 TEST_P(ParameterizedWebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSele
ction) |
5143 { | 5143 { |
5144 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5144 FrameTestHelpers::WebViewHelper webViewHelper(this); |
5145 webViewHelper.initializeAndLoad("about:blank", true); | 5145 webViewHelper.initializeAndLoad("about:blank", true); |
5146 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 5146 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
5147 | 5147 |
5148 // This test passes if this doesn't crash. | 5148 // This test passes if this doesn't crash. |
5149 frame->moveCaretSelection(WebPoint(0, 0)); | 5149 frame->toWebLocalFrame()->moveCaretSelection(WebPoint(0, 0)); |
5150 } | 5150 } |
5151 | 5151 |
5152 class SpellCheckClient : public WebSpellCheckClient { | 5152 class SpellCheckClient : public WebSpellCheckClient { |
5153 public: | 5153 public: |
5154 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_
hash(hash) { } | 5154 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_
hash(hash) { } |
5155 virtual ~SpellCheckClient() { } | 5155 virtual ~SpellCheckClient() { } |
5156 void requestCheckingOfText(const WebString&, const WebVector<uint32_t>&, con
st WebVector<unsigned>&, WebTextCheckingCompletion* completion) override | 5156 void requestCheckingOfText(const WebString&, const WebVector<uint32_t>&, con
st WebVector<unsigned>&, WebTextCheckingCompletion* completion) override |
5157 { | 5157 { |
5158 ++m_numberOfTimesChecked; | 5158 ++m_numberOfTimesChecked; |
5159 Vector<WebTextCheckingResult> results; | 5159 Vector<WebTextCheckingResult> results; |
(...skipping 3657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8817 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); | 8817 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); |
8818 helper.webViewImpl()->mainFrame()->toWebLocalFrame()->loadRequest(request); | 8818 helper.webViewImpl()->mainFrame()->toWebLocalFrame()->loadRequest(request); |
8819 | 8819 |
8820 // Normally, the result of the JS url replaces the existing contents on the | 8820 // Normally, the result of the JS url replaces the existing contents on the |
8821 // Document. However, if the JS triggers a navigation, the contents should | 8821 // Document. However, if the JS triggers a navigation, the contents should |
8822 // not be replaced. | 8822 // not be replaced. |
8823 EXPECT_EQ("", toLocalFrame(helper.webViewImpl()->page()->mainFrame())->docum
ent()->documentElement()->innerText()); | 8823 EXPECT_EQ("", toLocalFrame(helper.webViewImpl()->page()->mainFrame())->docum
ent()->documentElement()->innerText()); |
8824 } | 8824 } |
8825 | 8825 |
8826 } // namespace blink | 8826 } // namespace blink |
OLD | NEW |