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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 #include "platform/geometry/FloatRect.h" | 81 #include "platform/geometry/FloatRect.h" |
82 #include "platform/network/ResourceError.h" | 82 #include "platform/network/ResourceError.h" |
83 #include "platform/scroll/ScrollbarTheme.h" | 83 #include "platform/scroll/ScrollbarTheme.h" |
84 #include "platform/testing/URLTestHelpers.h" | 84 #include "platform/testing/URLTestHelpers.h" |
85 #include "platform/testing/UnitTestHelpers.h" | 85 #include "platform/testing/UnitTestHelpers.h" |
86 #include "platform/weborigin/SchemeRegistry.h" | 86 #include "platform/weborigin/SchemeRegistry.h" |
87 #include "platform/weborigin/SecurityOrigin.h" | 87 #include "platform/weborigin/SecurityOrigin.h" |
88 #include "public/platform/Platform.h" | 88 #include "public/platform/Platform.h" |
89 #include "public/platform/WebFloatRect.h" | 89 #include "public/platform/WebFloatRect.h" |
90 #include "public/platform/WebSecurityOrigin.h" | 90 #include "public/platform/WebSecurityOrigin.h" |
91 #include "public/platform/WebSelectionBound.h" | |
92 #include "public/platform/WebThread.h" | 91 #include "public/platform/WebThread.h" |
93 #include "public/platform/WebURL.h" | 92 #include "public/platform/WebURL.h" |
94 #include "public/platform/WebURLResponse.h" | 93 #include "public/platform/WebURLResponse.h" |
95 #include "public/platform/WebUnitTestSupport.h" | 94 #include "public/platform/WebUnitTestSupport.h" |
96 #include "public/web/WebCache.h" | 95 #include "public/web/WebCache.h" |
97 #include "public/web/WebDataSource.h" | 96 #include "public/web/WebDataSource.h" |
98 #include "public/web/WebDocument.h" | 97 #include "public/web/WebDocument.h" |
99 #include "public/web/WebFindOptions.h" | 98 #include "public/web/WebFindOptions.h" |
100 #include "public/web/WebFormElement.h" | 99 #include "public/web/WebFormElement.h" |
101 #include "public/web/WebFrameClient.h" | 100 #include "public/web/WebFrameClient.h" |
102 #include "public/web/WebHistoryItem.h" | 101 #include "public/web/WebHistoryItem.h" |
103 #include "public/web/WebPrintParams.h" | 102 #include "public/web/WebPrintParams.h" |
104 #include "public/web/WebRange.h" | 103 #include "public/web/WebRange.h" |
105 #include "public/web/WebRemoteFrame.h" | 104 #include "public/web/WebRemoteFrame.h" |
106 #include "public/web/WebScriptSource.h" | 105 #include "public/web/WebScriptSource.h" |
107 #include "public/web/WebSearchableFormData.h" | 106 #include "public/web/WebSearchableFormData.h" |
108 #include "public/web/WebSecurityPolicy.h" | 107 #include "public/web/WebSecurityPolicy.h" |
| 108 #include "public/web/WebSelection.h" |
109 #include "public/web/WebSettings.h" | 109 #include "public/web/WebSettings.h" |
110 #include "public/web/WebSpellCheckClient.h" | 110 #include "public/web/WebSpellCheckClient.h" |
111 #include "public/web/WebTextCheckingCompletion.h" | 111 #include "public/web/WebTextCheckingCompletion.h" |
112 #include "public/web/WebTextCheckingResult.h" | 112 #include "public/web/WebTextCheckingResult.h" |
113 #include "public/web/WebViewClient.h" | 113 #include "public/web/WebViewClient.h" |
114 #include "web/WebLocalFrameImpl.h" | 114 #include "web/WebLocalFrameImpl.h" |
115 #include "web/WebRemoteFrameImpl.h" | 115 #include "web/WebRemoteFrameImpl.h" |
116 #include "web/WebViewImpl.h" | 116 #include "web/WebViewImpl.h" |
117 #include "web/tests/FrameTestHelpers.h" | 117 #include "web/tests/FrameTestHelpers.h" |
118 #include "wtf/Forward.h" | 118 #include "wtf/Forward.h" |
(...skipping 4073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4192 virtual void setDeviceScaleFactor(float) override { } | 4192 virtual void setDeviceScaleFactor(float) override { } |
4193 virtual float deviceScaleFactor() const override { return 1.f; } | 4193 virtual float deviceScaleFactor() const override { return 1.f; } |
4194 virtual void setBackgroundColor(WebColor) override { } | 4194 virtual void setBackgroundColor(WebColor) override { } |
4195 virtual void setHasTransparentBackground(bool) override { } | 4195 virtual void setHasTransparentBackground(bool) override { } |
4196 virtual void setVisible(bool) override { } | 4196 virtual void setVisible(bool) override { } |
4197 virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimu
m, float maximum) override { } | 4197 virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimu
m, float maximum) override { } |
4198 virtual void startPageScaleAnimation(const WebPoint& destination, bool useAn
chor, float newPageScale, double durationSec) override { } | 4198 virtual void startPageScaleAnimation(const WebPoint& destination, bool useAn
chor, float newPageScale, double durationSec) override { } |
4199 virtual void setNeedsAnimate() override { } | 4199 virtual void setNeedsAnimate() override { } |
4200 virtual bool commitRequested() const override { return false; } | 4200 virtual bool commitRequested() const override { return false; } |
4201 virtual void finishAllRendering() override { } | 4201 virtual void finishAllRendering() override { } |
4202 virtual void registerSelection(const WebSelectionBound& start, const WebSele
ctionBound& end) override | 4202 virtual void registerSelection(const WebSelection& selection) override |
4203 { | 4203 { |
4204 m_start = adoptPtr(new WebSelectionBound(start)); | 4204 m_selection = adoptPtr(new WebSelection(selection)); |
4205 m_end = adoptPtr(new WebSelectionBound(end)); | |
4206 } | 4205 } |
4207 virtual void clearSelection() override | 4206 virtual void clearSelection() override |
4208 { | 4207 { |
4209 m_selectionCleared = true; | 4208 m_selectionCleared = true; |
4210 m_start.clear(); | 4209 m_selection.clear(); |
4211 m_end.clear(); | |
4212 } | 4210 } |
4213 | 4211 |
4214 bool getAndResetSelectionCleared() | 4212 bool getAndResetSelectionCleared() |
4215 { | 4213 { |
4216 bool selectionCleared = m_selectionCleared; | 4214 bool selectionCleared = m_selectionCleared; |
4217 m_selectionCleared = false; | 4215 m_selectionCleared = false; |
4218 return selectionCleared; | 4216 return selectionCleared; |
4219 } | 4217 } |
4220 | 4218 |
4221 const WebSelectionBound* start() const { return m_start.get(); } | 4219 const WebSelection* selection() const { return m_selection.get(); } |
4222 const WebSelectionBound* end() const { return m_end.get(); } | 4220 const WebSelectionBound* start() const { return m_selection ? &m_selection->
start() : nullptr; } |
| 4221 const WebSelectionBound* end() const { return m_selection ? &m_selection->en
d() : nullptr; } |
4223 | 4222 |
4224 private: | 4223 private: |
4225 bool m_selectionCleared; | 4224 bool m_selectionCleared; |
4226 OwnPtr<WebSelectionBound> m_start; | 4225 OwnPtr<WebSelection> m_selection; |
4227 OwnPtr<WebSelectionBound> m_end; | |
4228 }; | 4226 }; |
4229 | 4227 |
4230 class CompositedSelectionBoundsTestWebViewClient : public FrameTestHelpers::Test
WebViewClient { | 4228 class CompositedSelectionBoundsTestWebViewClient : public FrameTestHelpers::Test
WebViewClient { |
4231 public: | 4229 public: |
4232 virtual ~CompositedSelectionBoundsTestWebViewClient() { } | 4230 virtual ~CompositedSelectionBoundsTestWebViewClient() { } |
4233 virtual WebLayerTreeView* layerTreeView() override { return &m_testLayerTree
View; } | 4231 virtual WebLayerTreeView* layerTreeView() override { return &m_testLayerTree
View; } |
4234 | 4232 |
4235 CompositedSelectionBoundsTestLayerTreeView& selectionLayerTreeView() { retur
n m_testLayerTreeView; } | 4233 CompositedSelectionBoundsTestLayerTreeView& selectionLayerTreeView() { retur
n m_testLayerTreeView; } |
4236 | 4234 |
4237 private: | 4235 private: |
(...skipping 13 matching lines...) Expand all Loading... |
4251 m_webViewHelper.webView()->setDefaultPageScaleLimits(1, 1); | 4249 m_webViewHelper.webView()->setDefaultPageScaleLimits(1, 1); |
4252 m_webViewHelper.webView()->resize(WebSize(640, 480)); | 4250 m_webViewHelper.webView()->resize(WebSize(640, 480)); |
4253 } | 4251 } |
4254 | 4252 |
4255 void runTest(const char* testFile) | 4253 void runTest(const char* testFile) |
4256 { | 4254 { |
4257 registerMockedHttpURLLoad(testFile); | 4255 registerMockedHttpURLLoad(testFile); |
4258 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), m_ba
seURL + testFile); | 4256 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), m_ba
seURL + testFile); |
4259 m_webViewHelper.webView()->layout(); | 4257 m_webViewHelper.webView()->layout(); |
4260 | 4258 |
| 4259 const WebSelection* selection = m_fakeSelectionLayerTreeView.selection()
; |
4261 const WebSelectionBound* selectStart = m_fakeSelectionLayerTreeView.star
t(); | 4260 const WebSelectionBound* selectStart = m_fakeSelectionLayerTreeView.star
t(); |
4262 const WebSelectionBound* selectEnd = m_fakeSelectionLayerTreeView.end(); | 4261 const WebSelectionBound* selectEnd = m_fakeSelectionLayerTreeView.end(); |
4263 | 4262 |
4264 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 4263 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
4265 v8::Handle<v8::Value> result = m_webViewHelper.webView()->mainFrame()->t
oWebLocalFrame()->executeScriptAndReturnValue(WebScriptSource("expectedResult"))
; | 4264 v8::Handle<v8::Value> result = m_webViewHelper.webView()->mainFrame()->t
oWebLocalFrame()->executeScriptAndReturnValue(WebScriptSource("expectedResult"))
; |
4266 if (result.IsEmpty() || (*result)->IsUndefined()) { | 4265 if (result.IsEmpty() || (*result)->IsUndefined()) { |
| 4266 EXPECT_FALSE(selection); |
4267 EXPECT_FALSE(selectStart); | 4267 EXPECT_FALSE(selectStart); |
4268 EXPECT_FALSE(selectEnd); | 4268 EXPECT_FALSE(selectEnd); |
4269 return; | 4269 return; |
4270 } | 4270 } |
4271 | 4271 |
| 4272 ASSERT_TRUE(selection); |
4272 ASSERT_TRUE(selectStart); | 4273 ASSERT_TRUE(selectStart); |
4273 ASSERT_TRUE(selectEnd); | 4274 ASSERT_TRUE(selectEnd); |
4274 | 4275 |
| 4276 EXPECT_FALSE(selection->isNone()); |
| 4277 |
4275 ASSERT_TRUE((*result)->IsArray()); | 4278 ASSERT_TRUE((*result)->IsArray()); |
4276 v8::Array& expectedResult = *v8::Array::Cast(*result); | 4279 v8::Array& expectedResult = *v8::Array::Cast(*result); |
4277 ASSERT_EQ(10u, expectedResult.Length()); | 4280 ASSERT_GE(expectedResult.Length(), 10u); |
4278 | 4281 |
4279 blink::Node* layerOwnerNodeForStart = blink::V8Node::toImplWithTypeCheck
(v8::Isolate::GetCurrent(), expectedResult.Get(0)); | 4282 blink::Node* layerOwnerNodeForStart = blink::V8Node::toImplWithTypeCheck
(v8::Isolate::GetCurrent(), expectedResult.Get(0)); |
4280 ASSERT_TRUE(layerOwnerNodeForStart); | 4283 ASSERT_TRUE(layerOwnerNodeForStart); |
4281 EXPECT_EQ(layerOwnerNodeForStart->layoutObject()->enclosingLayer()->encl
osingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(),
selectStart->layerId); | 4284 EXPECT_EQ(layerOwnerNodeForStart->layoutObject()->enclosingLayer()->encl
osingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(),
selectStart->layerId); |
4282 EXPECT_EQ(expectedResult.Get(1)->Int32Value(), selectStart->edgeTopInLay
er.x); | 4285 EXPECT_EQ(expectedResult.Get(1)->Int32Value(), selectStart->edgeTopInLay
er.x); |
4283 EXPECT_EQ(expectedResult.Get(2)->Int32Value(), selectStart->edgeTopInLay
er.y); | 4286 EXPECT_EQ(expectedResult.Get(2)->Int32Value(), selectStart->edgeTopInLay
er.y); |
4284 EXPECT_EQ(expectedResult.Get(3)->Int32Value(), selectStart->edgeBottomIn
Layer.x); | 4287 EXPECT_EQ(expectedResult.Get(3)->Int32Value(), selectStart->edgeBottomIn
Layer.x); |
4285 EXPECT_EQ(expectedResult.Get(4)->Int32Value(), selectStart->edgeBottomIn
Layer.y); | |
4286 | 4288 |
4287 blink::Node* layerOwnerNodeForEnd = blink::V8Node::toImplWithTypeCheck(v
8::Isolate::GetCurrent(), expectedResult.Get(5)); | 4289 blink::Node* layerOwnerNodeForEnd = blink::V8Node::toImplWithTypeCheck(v
8::Isolate::GetCurrent(), expectedResult.Get(5)); |
4288 ASSERT_TRUE(layerOwnerNodeForEnd); | 4290 ASSERT_TRUE(layerOwnerNodeForEnd); |
4289 EXPECT_EQ(layerOwnerNodeForEnd->layoutObject()->enclosingLayer()->enclos
ingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), s
electEnd->layerId); | 4291 EXPECT_EQ(layerOwnerNodeForEnd->layoutObject()->enclosingLayer()->enclos
ingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), s
electEnd->layerId); |
4290 EXPECT_EQ(expectedResult.Get(6)->Int32Value(), selectEnd->edgeTopInLayer
.x); | 4292 EXPECT_EQ(expectedResult.Get(6)->Int32Value(), selectEnd->edgeTopInLayer
.x); |
4291 EXPECT_EQ(expectedResult.Get(7)->Int32Value(), selectEnd->edgeTopInLayer
.y); | 4293 EXPECT_EQ(expectedResult.Get(7)->Int32Value(), selectEnd->edgeTopInLayer
.y); |
4292 EXPECT_EQ(expectedResult.Get(8)->Int32Value(), selectEnd->edgeBottomInLa
yer.x); | 4294 EXPECT_EQ(expectedResult.Get(8)->Int32Value(), selectEnd->edgeBottomInLa
yer.x); |
4293 EXPECT_EQ(expectedResult.Get(9)->Int32Value(), selectEnd->edgeBottomInLa
yer.y); | 4295 |
| 4296 // Platform differences can introduce small stylistic deviations in |
| 4297 // y-axis positioning, the details of which aren't relevant to |
| 4298 // selection behavior. However, such deviations from the expected value |
| 4299 // should be consistent for the corresponding y coordinates. |
| 4300 int yBottomEpsilon = 0; |
| 4301 if (expectedResult.Length() == 13) |
| 4302 yBottomEpsilon = expectedResult.Get(12)->Int32Value(); |
| 4303 int yBottomDeviation = expectedResult.Get(4)->Int32Value() - selectStart
->edgeBottomInLayer.y; |
| 4304 EXPECT_GE(yBottomEpsilon, std::abs(yBottomDeviation)); |
| 4305 EXPECT_EQ(yBottomDeviation, expectedResult.Get(9)->Int32Value() - select
End->edgeBottomInLayer.y); |
| 4306 |
| 4307 if (expectedResult.Length() >= 12) { |
| 4308 EXPECT_EQ(expectedResult.Get(10)->BooleanValue(), m_fakeSelectionLay
erTreeView.selection()->isEditable()); |
| 4309 EXPECT_EQ(expectedResult.Get(11)->BooleanValue(), m_fakeSelectionLay
erTreeView.selection()->isEmptyTextFormControl()); |
| 4310 } |
4294 } | 4311 } |
4295 | 4312 |
4296 void runTestWithMultipleFiles(const char* testFile, ...) | 4313 void runTestWithMultipleFiles(const char* testFile, ...) |
4297 { | 4314 { |
4298 va_list auxFiles; | 4315 va_list auxFiles; |
4299 va_start(auxFiles, testFile); | 4316 va_start(auxFiles, testFile); |
4300 while (const char* auxFile = va_arg(auxFiles, const char*)) | 4317 while (const char* auxFile = va_arg(auxFiles, const char*)) |
4301 registerMockedHttpURLLoad(auxFile); | 4318 registerMockedHttpURLLoad(auxFile); |
4302 va_end(auxFiles); | 4319 va_end(auxFiles); |
4303 | 4320 |
4304 runTest(testFile); | 4321 runTest(testFile); |
4305 } | 4322 } |
4306 | 4323 |
4307 CompositedSelectionBoundsTestWebViewClient m_fakeSelectionWebViewClient; | 4324 CompositedSelectionBoundsTestWebViewClient m_fakeSelectionWebViewClient; |
4308 CompositedSelectionBoundsTestLayerTreeView& m_fakeSelectionLayerTreeView; | 4325 CompositedSelectionBoundsTestLayerTreeView& m_fakeSelectionLayerTreeView; |
4309 FrameTestHelpers::WebViewHelper m_webViewHelper; | 4326 FrameTestHelpers::WebViewHelper m_webViewHelper; |
4310 }; | 4327 }; |
4311 | 4328 |
4312 TEST_F(CompositedSelectionBoundsTest, None) { runTest("composited_selection_boun
ds_none.html"); } | 4329 TEST_F(CompositedSelectionBoundsTest, None) { runTest("composited_selection_boun
ds_none.html"); } |
4313 TEST_F(CompositedSelectionBoundsTest, Basic) { runTest("composited_selection_bou
nds_basic.html"); } | 4330 TEST_F(CompositedSelectionBoundsTest, Basic) { runTest("composited_selection_bou
nds_basic.html"); } |
4314 TEST_F(CompositedSelectionBoundsTest, Transformed) { runTest("composited_selecti
on_bounds_transformed.html"); } | 4331 TEST_F(CompositedSelectionBoundsTest, Transformed) { runTest("composited_selecti
on_bounds_transformed.html"); } |
4315 TEST_F(CompositedSelectionBoundsTest, SplitLayer) { runTest("composited_selectio
n_bounds_split_layer.html"); } | 4332 TEST_F(CompositedSelectionBoundsTest, SplitLayer) { runTest("composited_selectio
n_bounds_split_layer.html"); } |
4316 TEST_F(CompositedSelectionBoundsTest, EmptyLayer) { runTest("composited_selectio
n_bounds_empty_layer.html"); } | 4333 TEST_F(CompositedSelectionBoundsTest, EmptyLayer) { runTest("composited_selectio
n_bounds_empty_layer.html"); } |
4317 TEST_F(CompositedSelectionBoundsTest, Iframe) { runTestWithMultipleFiles("compos
ited_selection_bounds_iframe.html", "composited_selection_bounds_basic.html", nu
llptr); } | 4334 TEST_F(CompositedSelectionBoundsTest, Iframe) { runTestWithMultipleFiles("compos
ited_selection_bounds_iframe.html", "composited_selection_bounds_basic.html", nu
llptr); } |
4318 TEST_F(CompositedSelectionBoundsTest, DetachedFrame) { runTest("composited_selec
tion_bounds_detached_frame.html"); } | 4335 TEST_F(CompositedSelectionBoundsTest, DetachedFrame) { runTest("composited_selec
tion_bounds_detached_frame.html"); } |
4319 | 4336 TEST_F(CompositedSelectionBoundsTest, Editable) { runTest("composited_selection_
bounds_editable.html"); } |
| 4337 TEST_F(CompositedSelectionBoundsTest, EditableDiv) { runTest("composited_selecti
on_bounds_editable_div.html"); } |
| 4338 TEST_F(CompositedSelectionBoundsTest, EmptyEditableInput) { runTest("composited_
selection_bounds_empty_editable_input.html"); } |
| 4339 TEST_F(CompositedSelectionBoundsTest, EmptyEditableArea) { runTest("composited_s
election_bounds_empty_editable_area.html"); } |
4320 | 4340 |
4321 TEST_F(WebFrameTest, CompositedSelectionBoundsCleared) | 4341 TEST_F(WebFrameTest, CompositedSelectionBoundsCleared) |
4322 { | 4342 { |
4323 RuntimeEnabledFeatures::setCompositedSelectionUpdateEnabled(true); | 4343 RuntimeEnabledFeatures::setCompositedSelectionUpdateEnabled(true); |
4324 | 4344 |
4325 registerMockedHttpURLLoad("select_range_basic.html"); | 4345 registerMockedHttpURLLoad("select_range_basic.html"); |
4326 registerMockedHttpURLLoad("select_range_scroll.html"); | 4346 registerMockedHttpURLLoad("select_range_scroll.html"); |
4327 | 4347 |
4328 int viewWidth = 500; | 4348 int viewWidth = 500; |
4329 int viewHeight = 500; | 4349 int viewHeight = 500; |
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7107 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; | 7127 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
7108 WebView* view = WebView::create(&viewClient); | 7128 WebView* view = WebView::create(&viewClient); |
7109 view->setMainFrame(remoteClient.frame()); | 7129 view->setMainFrame(remoteClient.frame()); |
7110 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; | 7130 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; |
7111 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); | 7131 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); |
7112 childFrame->detach(); | 7132 childFrame->detach(); |
7113 view->close(); | 7133 view->close(); |
7114 } | 7134 } |
7115 | 7135 |
7116 } // namespace blink | 7136 } // namespace blink |
OLD | NEW |