Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: Source/web/tests/WebFrameTest.cpp

Issue 929213004: Plumb selection bounds as a single unit (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix test Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 #include "platform/UserGestureIndicator.h" 80 #include "platform/UserGestureIndicator.h"
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/WebSelectionBound.h"
91 #include "public/platform/WebThread.h" 90 #include "public/platform/WebThread.h"
92 #include "public/platform/WebURL.h" 91 #include "public/platform/WebURL.h"
93 #include "public/platform/WebURLResponse.h" 92 #include "public/platform/WebURLResponse.h"
94 #include "public/platform/WebUnitTestSupport.h" 93 #include "public/platform/WebUnitTestSupport.h"
95 #include "public/web/WebCache.h" 94 #include "public/web/WebCache.h"
96 #include "public/web/WebDataSource.h" 95 #include "public/web/WebDataSource.h"
97 #include "public/web/WebDocument.h" 96 #include "public/web/WebDocument.h"
98 #include "public/web/WebFindOptions.h" 97 #include "public/web/WebFindOptions.h"
99 #include "public/web/WebFormElement.h" 98 #include "public/web/WebFormElement.h"
100 #include "public/web/WebFrameClient.h" 99 #include "public/web/WebFrameClient.h"
101 #include "public/web/WebHistoryItem.h" 100 #include "public/web/WebHistoryItem.h"
102 #include "public/web/WebPrintParams.h" 101 #include "public/web/WebPrintParams.h"
103 #include "public/web/WebRange.h" 102 #include "public/web/WebRange.h"
104 #include "public/web/WebRemoteFrame.h" 103 #include "public/web/WebRemoteFrame.h"
105 #include "public/web/WebScriptSource.h" 104 #include "public/web/WebScriptSource.h"
106 #include "public/web/WebSearchableFormData.h" 105 #include "public/web/WebSearchableFormData.h"
107 #include "public/web/WebSecurityOrigin.h" 106 #include "public/web/WebSecurityOrigin.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 4082 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 virtual void setDeviceScaleFactor(float) override { } 4201 virtual void setDeviceScaleFactor(float) override { }
4202 virtual float deviceScaleFactor() const override { return 1.f; } 4202 virtual float deviceScaleFactor() const override { return 1.f; }
4203 virtual void setBackgroundColor(WebColor) override { } 4203 virtual void setBackgroundColor(WebColor) override { }
4204 virtual void setHasTransparentBackground(bool) override { } 4204 virtual void setHasTransparentBackground(bool) override { }
4205 virtual void setVisible(bool) override { } 4205 virtual void setVisible(bool) override { }
4206 virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimu m, float maximum) override { } 4206 virtual void setPageScaleFactorAndLimits(float pageScaleFactor, float minimu m, float maximum) override { }
4207 virtual void startPageScaleAnimation(const WebPoint& destination, bool useAn chor, float newPageScale, double durationSec) override { } 4207 virtual void startPageScaleAnimation(const WebPoint& destination, bool useAn chor, float newPageScale, double durationSec) override { }
4208 virtual void setNeedsAnimate() override { } 4208 virtual void setNeedsAnimate() override { }
4209 virtual bool commitRequested() const override { return false; } 4209 virtual bool commitRequested() const override { return false; }
4210 virtual void finishAllRendering() override { } 4210 virtual void finishAllRendering() override { }
4211 virtual void registerSelection(const WebSelectionBound& start, const WebSele ctionBound& end) override 4211 virtual void registerSelection(const WebSelection& selection) override
4212 { 4212 {
4213 m_start = adoptPtr(new WebSelectionBound(start)); 4213 m_selection = adoptPtr(new WebSelection(selection));
4214 m_end = adoptPtr(new WebSelectionBound(end));
4215 } 4214 }
4216 virtual void clearSelection() override 4215 virtual void clearSelection() override
4217 { 4216 {
4218 m_selectionCleared = true; 4217 m_selectionCleared = true;
4219 m_start.clear(); 4218 m_selection.clear();
4220 m_end.clear();
4221 } 4219 }
4222 4220
4223 bool getAndResetSelectionCleared() 4221 bool getAndResetSelectionCleared()
4224 { 4222 {
4225 bool selectionCleared = m_selectionCleared; 4223 bool selectionCleared = m_selectionCleared;
4226 m_selectionCleared = false; 4224 m_selectionCleared = false;
4227 return selectionCleared; 4225 return selectionCleared;
4228 } 4226 }
4229 4227
4230 const WebSelectionBound* start() const { return m_start.get(); } 4228 const WebSelection* selection() const { return m_selection.get(); }
4231 const WebSelectionBound* end() const { return m_end.get(); } 4229 const WebSelectionBound* start() const { return m_selection ? &m_selection-> start() : nullptr; }
4230 const WebSelectionBound* end() const { return m_selection ? &m_selection->en d() : nullptr; }
4232 4231
4233 private: 4232 private:
4234 bool m_selectionCleared; 4233 bool m_selectionCleared;
4235 OwnPtr<WebSelectionBound> m_start; 4234 OwnPtr<WebSelection> m_selection;
4236 OwnPtr<WebSelectionBound> m_end;
4237 }; 4235 };
4238 4236
4239 class CompositedSelectionBoundsTestWebViewClient : public FrameTestHelpers::Test WebViewClient { 4237 class CompositedSelectionBoundsTestWebViewClient : public FrameTestHelpers::Test WebViewClient {
4240 public: 4238 public:
4241 virtual ~CompositedSelectionBoundsTestWebViewClient() { } 4239 virtual ~CompositedSelectionBoundsTestWebViewClient() { }
4242 virtual WebLayerTreeView* layerTreeView() override { return &m_testLayerTree View; } 4240 virtual WebLayerTreeView* layerTreeView() override { return &m_testLayerTree View; }
4243 4241
4244 CompositedSelectionBoundsTestLayerTreeView& selectionLayerTreeView() { retur n m_testLayerTreeView; } 4242 CompositedSelectionBoundsTestLayerTreeView& selectionLayerTreeView() { retur n m_testLayerTreeView; }
4245 4243
4246 private: 4244 private:
(...skipping 13 matching lines...) Expand all
4260 m_webViewHelper.webView()->setDefaultPageScaleLimits(1, 1); 4258 m_webViewHelper.webView()->setDefaultPageScaleLimits(1, 1);
4261 m_webViewHelper.webView()->resize(WebSize(640, 480)); 4259 m_webViewHelper.webView()->resize(WebSize(640, 480));
4262 } 4260 }
4263 4261
4264 void runTest(const char* testFile) 4262 void runTest(const char* testFile)
4265 { 4263 {
4266 registerMockedHttpURLLoad(testFile); 4264 registerMockedHttpURLLoad(testFile);
4267 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), m_ba seURL + testFile); 4265 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), m_ba seURL + testFile);
4268 m_webViewHelper.webView()->layout(); 4266 m_webViewHelper.webView()->layout();
4269 4267
4268 const WebSelection* selection = m_fakeSelectionLayerTreeView.selection() ;
4270 const WebSelectionBound* selectStart = m_fakeSelectionLayerTreeView.star t(); 4269 const WebSelectionBound* selectStart = m_fakeSelectionLayerTreeView.star t();
4271 const WebSelectionBound* selectEnd = m_fakeSelectionLayerTreeView.end(); 4270 const WebSelectionBound* selectEnd = m_fakeSelectionLayerTreeView.end();
4272 4271
4273 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 4272 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
4274 v8::Handle<v8::Value> result = m_webViewHelper.webView()->mainFrame()->t oWebLocalFrame()->executeScriptAndReturnValue(WebScriptSource("expectedResult")) ; 4273 v8::Handle<v8::Value> result = m_webViewHelper.webView()->mainFrame()->t oWebLocalFrame()->executeScriptAndReturnValue(WebScriptSource("expectedResult")) ;
4275 if (result.IsEmpty() || (*result)->IsUndefined()) { 4274 if (result.IsEmpty() || (*result)->IsUndefined()) {
4275 EXPECT_FALSE(selection);
4276 EXPECT_FALSE(selectStart); 4276 EXPECT_FALSE(selectStart);
4277 EXPECT_FALSE(selectEnd); 4277 EXPECT_FALSE(selectEnd);
4278 return; 4278 return;
4279 } 4279 }
4280 4280
4281 ASSERT_TRUE(selection);
4281 ASSERT_TRUE(selectStart); 4282 ASSERT_TRUE(selectStart);
4282 ASSERT_TRUE(selectEnd); 4283 ASSERT_TRUE(selectEnd);
4283 4284
4285 EXPECT_FALSE(selection->isNone());
4286
4284 ASSERT_TRUE((*result)->IsArray()); 4287 ASSERT_TRUE((*result)->IsArray());
4285 v8::Array& expectedResult = *v8::Array::Cast(*result); 4288 v8::Array& expectedResult = *v8::Array::Cast(*result);
4286 ASSERT_EQ(10u, expectedResult.Length()); 4289 ASSERT_GE(expectedResult.Length(), 10u);
4287 4290
4288 blink::Node* layerOwnerNodeForStart = blink::V8Node::toImplWithTypeCheck (v8::Isolate::GetCurrent(), expectedResult.Get(0)); 4291 blink::Node* layerOwnerNodeForStart = blink::V8Node::toImplWithTypeCheck (v8::Isolate::GetCurrent(), expectedResult.Get(0));
4289 ASSERT_TRUE(layerOwnerNodeForStart); 4292 ASSERT_TRUE(layerOwnerNodeForStart);
4290 EXPECT_EQ(layerOwnerNodeForStart->layoutObject()->enclosingLayer()->encl osingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), selectStart->layerId); 4293 EXPECT_EQ(layerOwnerNodeForStart->layoutObject()->enclosingLayer()->encl osingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), selectStart->layerId);
4291 EXPECT_EQ(expectedResult.Get(1)->Int32Value(), selectStart->edgeTopInLay er.x); 4294 EXPECT_EQ(expectedResult.Get(1)->Int32Value(), selectStart->edgeTopInLay er.x);
4292 EXPECT_EQ(expectedResult.Get(2)->Int32Value(), selectStart->edgeTopInLay er.y); 4295 EXPECT_EQ(expectedResult.Get(2)->Int32Value(), selectStart->edgeTopInLay er.y);
4293 EXPECT_EQ(expectedResult.Get(3)->Int32Value(), selectStart->edgeBottomIn Layer.x); 4296 EXPECT_EQ(expectedResult.Get(3)->Int32Value(), selectStart->edgeBottomIn Layer.x);
4294 EXPECT_EQ(expectedResult.Get(4)->Int32Value(), selectStart->edgeBottomIn Layer.y); 4297 EXPECT_EQ(expectedResult.Get(4)->Int32Value(), selectStart->edgeBottomIn Layer.y);
4295 4298
4296 blink::Node* layerOwnerNodeForEnd = blink::V8Node::toImplWithTypeCheck(v 8::Isolate::GetCurrent(), expectedResult.Get(5)); 4299 blink::Node* layerOwnerNodeForEnd = blink::V8Node::toImplWithTypeCheck(v 8::Isolate::GetCurrent(), expectedResult.Get(5));
4297 ASSERT_TRUE(layerOwnerNodeForEnd); 4300 ASSERT_TRUE(layerOwnerNodeForEnd);
4298 EXPECT_EQ(layerOwnerNodeForEnd->layoutObject()->enclosingLayer()->enclos ingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), s electEnd->layerId); 4301 EXPECT_EQ(layerOwnerNodeForEnd->layoutObject()->enclosingLayer()->enclos ingLayerForPaintInvalidation()->graphicsLayerBacking()->platformLayer()->id(), s electEnd->layerId);
4299 EXPECT_EQ(expectedResult.Get(6)->Int32Value(), selectEnd->edgeTopInLayer .x); 4302 EXPECT_EQ(expectedResult.Get(6)->Int32Value(), selectEnd->edgeTopInLayer .x);
4300 EXPECT_EQ(expectedResult.Get(7)->Int32Value(), selectEnd->edgeTopInLayer .y); 4303 EXPECT_EQ(expectedResult.Get(7)->Int32Value(), selectEnd->edgeTopInLayer .y);
4301 EXPECT_EQ(expectedResult.Get(8)->Int32Value(), selectEnd->edgeBottomInLa yer.x); 4304 EXPECT_EQ(expectedResult.Get(8)->Int32Value(), selectEnd->edgeBottomInLa yer.x);
4302 EXPECT_EQ(expectedResult.Get(9)->Int32Value(), selectEnd->edgeBottomInLa yer.y); 4305 EXPECT_EQ(expectedResult.Get(9)->Int32Value(), selectEnd->edgeBottomInLa yer.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 }
4303 } 4311 }
4304 4312
4305 void runTestWithMultipleFiles(const char* testFile, ...) 4313 void runTestWithMultipleFiles(const char* testFile, ...)
4306 { 4314 {
4307 va_list auxFiles; 4315 va_list auxFiles;
4308 va_start(auxFiles, testFile); 4316 va_start(auxFiles, testFile);
4309 while (const char* auxFile = va_arg(auxFiles, const char*)) 4317 while (const char* auxFile = va_arg(auxFiles, const char*))
4310 registerMockedHttpURLLoad(auxFile); 4318 registerMockedHttpURLLoad(auxFile);
4311 va_end(auxFiles); 4319 va_end(auxFiles);
4312 4320
4313 runTest(testFile); 4321 runTest(testFile);
4314 } 4322 }
4315 4323
4316 CompositedSelectionBoundsTestWebViewClient m_fakeSelectionWebViewClient; 4324 CompositedSelectionBoundsTestWebViewClient m_fakeSelectionWebViewClient;
4317 CompositedSelectionBoundsTestLayerTreeView& m_fakeSelectionLayerTreeView; 4325 CompositedSelectionBoundsTestLayerTreeView& m_fakeSelectionLayerTreeView;
4318 FrameTestHelpers::WebViewHelper m_webViewHelper; 4326 FrameTestHelpers::WebViewHelper m_webViewHelper;
4319 }; 4327 };
4320 4328
4321 TEST_F(CompositedSelectionBoundsTest, None) { runTest("composited_selection_boun ds_none.html"); } 4329 TEST_F(CompositedSelectionBoundsTest, None) { runTest("composited_selection_boun ds_none.html"); }
4322 TEST_F(CompositedSelectionBoundsTest, Basic) { runTest("composited_selection_bou nds_basic.html"); } 4330 TEST_F(CompositedSelectionBoundsTest, Basic) { runTest("composited_selection_bou nds_basic.html"); }
4323 TEST_F(CompositedSelectionBoundsTest, Transformed) { runTest("composited_selecti on_bounds_transformed.html"); } 4331 TEST_F(CompositedSelectionBoundsTest, Transformed) { runTest("composited_selecti on_bounds_transformed.html"); }
4324 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"); }
4325 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"); }
4326 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); }
4327 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"); }
4328 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"); }
4329 4340
4330 TEST_F(WebFrameTest, CompositedSelectionBoundsCleared) 4341 TEST_F(WebFrameTest, CompositedSelectionBoundsCleared)
4331 { 4342 {
4332 RuntimeEnabledFeatures::setCompositedSelectionUpdateEnabled(true); 4343 RuntimeEnabledFeatures::setCompositedSelectionUpdateEnabled(true);
4333 4344
4334 registerMockedHttpURLLoad("select_range_basic.html"); 4345 registerMockedHttpURLLoad("select_range_basic.html");
4335 registerMockedHttpURLLoad("select_range_scroll.html"); 4346 registerMockedHttpURLLoad("select_range_scroll.html");
4336 4347
4337 int viewWidth = 500; 4348 int viewWidth = 500;
4338 int viewHeight = 500; 4349 int viewHeight = 500;
(...skipping 2741 matching lines...) Expand 10 before | Expand all | Expand 10 after
7080 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; 7091 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
7081 WebView* view = WebView::create(&viewClient); 7092 WebView* view = WebView::create(&viewClient);
7082 view->setMainFrame(WebRemoteFrame::create(&remoteClient)); 7093 view->setMainFrame(WebRemoteFrame::create(&remoteClient));
7083 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; 7094 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient;
7084 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe moteChild("", WebSandboxFlags::None, &childFrameClient); 7095 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe moteChild("", WebSandboxFlags::None, &childFrameClient);
7085 childFrame->detach(); 7096 childFrame->detach();
7086 view->close(); 7097 view->close();
7087 } 7098 }
7088 7099
7089 } // namespace blink 7100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698