OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 19 matching lines...) Loading... |
30 | 30 |
31 #include "public/web/WebView.h" | 31 #include "public/web/WebView.h" |
32 | 32 |
33 #include <memory> | 33 #include <memory> |
34 | 34 |
35 #include "bindings/core/v8/V8Document.h" | 35 #include "bindings/core/v8/V8Document.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/dom/DocumentUserGestureToken.h" | 37 #include "core/dom/DocumentUserGestureToken.h" |
38 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
39 #include "core/dom/Fullscreen.h" | 39 #include "core/dom/Fullscreen.h" |
| 40 #include "core/dom/NodeComputedStyle.h" |
40 #include "core/editing/FrameSelection.h" | 41 #include "core/editing/FrameSelection.h" |
41 #include "core/editing/InputMethodController.h" | 42 #include "core/editing/InputMethodController.h" |
42 #include "core/editing/markers/DocumentMarkerController.h" | 43 #include "core/editing/markers/DocumentMarkerController.h" |
43 #include "core/frame/EventHandlerRegistry.h" | 44 #include "core/frame/EventHandlerRegistry.h" |
44 #include "core/frame/FrameHost.h" | 45 #include "core/frame/FrameHost.h" |
45 #include "core/frame/FrameView.h" | 46 #include "core/frame/FrameView.h" |
46 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
47 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
48 #include "core/frame/VisualViewport.h" | 49 #include "core/frame/VisualViewport.h" |
49 #include "core/html/HTMLIFrameElement.h" | 50 #include "core/html/HTMLIFrameElement.h" |
(...skipping 201 matching lines...) Loading... |
251 int expectedHeight, | 252 int expectedHeight, |
252 HorizontalScrollbarState expectedHorizontalState, | 253 HorizontalScrollbarState expectedHorizontalState, |
253 VerticalScrollbarState expectedVerticalState); | 254 VerticalScrollbarState expectedVerticalState); |
254 | 255 |
255 void testTextInputType(WebTextInputType expectedType, | 256 void testTextInputType(WebTextInputType expectedType, |
256 const std::string& htmlFile); | 257 const std::string& htmlFile); |
257 void testInputMode(WebTextInputMode expectedInputMode, | 258 void testInputMode(WebTextInputMode expectedInputMode, |
258 const std::string& htmlFile); | 259 const std::string& htmlFile); |
259 bool tapElement(WebInputEvent::Type, Element*); | 260 bool tapElement(WebInputEvent::Type, Element*); |
260 bool tapElementById(WebInputEvent::Type, const WebString& id); | 261 bool tapElementById(WebInputEvent::Type, const WebString& id); |
| 262 IntSize printICBSizeFromPageSize(const FloatSize& pageSize); |
261 | 263 |
262 std::string m_baseURL; | 264 std::string m_baseURL; |
263 FrameTestHelpers::WebViewHelper m_webViewHelper; | 265 FrameTestHelpers::WebViewHelper m_webViewHelper; |
264 }; | 266 }; |
265 | 267 |
266 static bool hitTestIsContentEditable(WebView* view, int x, int y) { | 268 static bool hitTestIsContentEditable(WebView* view, int x, int y) { |
267 WebPoint hitPoint(x, y); | 269 WebPoint hitPoint(x, y); |
268 WebHitTestResult hitTestResult = view->hitTestResultAt(hitPoint); | 270 WebHitTestResult hitTestResult = view->hitTestResultAt(hitPoint); |
269 return hitTestResult.isContentEditable(); | 271 return hitTestResult.isContentEditable(); |
270 } | 272 } |
(...skipping 1714 matching lines...) Loading... |
1985 } | 1987 } |
1986 | 1988 |
1987 bool WebViewTest::tapElementById(WebInputEvent::Type type, | 1989 bool WebViewTest::tapElementById(WebInputEvent::Type type, |
1988 const WebString& id) { | 1990 const WebString& id) { |
1989 DCHECK(m_webViewHelper.webView()); | 1991 DCHECK(m_webViewHelper.webView()); |
1990 Element* element = static_cast<Element*>( | 1992 Element* element = static_cast<Element*>( |
1991 m_webViewHelper.webView()->mainFrame()->document().getElementById(id)); | 1993 m_webViewHelper.webView()->mainFrame()->document().getElementById(id)); |
1992 return tapElement(type, element); | 1994 return tapElement(type, element); |
1993 } | 1995 } |
1994 | 1996 |
| 1997 IntSize WebViewTest::printICBSizeFromPageSize(const FloatSize& pageSize) { |
| 1998 // This needs to match printingMinimumShrinkFactor in PrintContext.cpp. The |
| 1999 // layout is scaled by this factor for printing. |
| 2000 constexpr float minimumShrinkFactor = 1.333f; |
| 2001 |
| 2002 // The expected layout size comes from the calculation done in |
| 2003 // resizePageRectsKeepingRatio which is used from PrintContext::begin to |
| 2004 // scale the page size. |
| 2005 const float ratio = pageSize.height() / (float)pageSize.width(); |
| 2006 const int icbWidth = floor(pageSize.width() * minimumShrinkFactor); |
| 2007 const int icbHeight = floor(icbWidth * ratio); |
| 2008 return IntSize(icbWidth, icbHeight); |
| 2009 } |
| 2010 |
1995 TEST_P(WebViewTest, DetectContentAroundPosition) { | 2011 TEST_P(WebViewTest, DetectContentAroundPosition) { |
1996 registerMockedHttpURLLoad("content_listeners.html"); | 2012 registerMockedHttpURLLoad("content_listeners.html"); |
1997 | 2013 |
1998 ContentDetectorClient client; | 2014 ContentDetectorClient client; |
1999 WebView* webView = m_webViewHelper.initializeAndLoad( | 2015 WebView* webView = m_webViewHelper.initializeAndLoad( |
2000 m_baseURL + "content_listeners.html", true, 0, &client); | 2016 m_baseURL + "content_listeners.html", true, 0, &client); |
2001 webView->resize(WebSize(500, 300)); | 2017 webView->resize(WebSize(500, 300)); |
2002 webView->updateAllLifecyclePhases(); | 2018 webView->updateAllLifecyclePhases(); |
2003 runPendingTasks(); | 2019 runPendingTasks(); |
2004 | 2020 |
(...skipping 2251 matching lines...) Loading... |
4256 Element* vwElement = document->getElementById("vw"); | 4272 Element* vwElement = document->getElementById("vw"); |
4257 | 4273 |
4258 EXPECT_EQ(800, vwElement->offsetWidth()); | 4274 EXPECT_EQ(800, vwElement->offsetWidth()); |
4259 | 4275 |
4260 FloatSize pageSize(300, 360); | 4276 FloatSize pageSize(300, 360); |
4261 | 4277 |
4262 WebPrintParams printParams; | 4278 WebPrintParams printParams; |
4263 printParams.printContentArea.width = pageSize.width(); | 4279 printParams.printContentArea.width = pageSize.width(); |
4264 printParams.printContentArea.height = pageSize.height(); | 4280 printParams.printContentArea.height = pageSize.height(); |
4265 | 4281 |
4266 // This needs to match printingMinimumShrinkFactor in PrintContext.cpp. The | 4282 IntSize expectedSize = printICBSizeFromPageSize(pageSize); |
4267 // layout is scaled by this factor for printing. | |
4268 constexpr float minimumShrinkFactor = 1.333f; | |
4269 | |
4270 // The expected layout size comes from the calculation done in | |
4271 // resizePageRectsKeepingRatio which is used from PrintContext::begin to | |
4272 // scale the page size. | |
4273 const float ratio = pageSize.height() / (float)pageSize.width(); | |
4274 const int expectedWidth = floor(pageSize.width() * minimumShrinkFactor); | |
4275 const int expectedHeight = floor(expectedWidth * ratio); | |
4276 | 4283 |
4277 frame->printBegin(printParams, WebNode()); | 4284 frame->printBegin(printParams, WebNode()); |
4278 | 4285 |
4279 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4286 EXPECT_EQ(expectedSize.width(), vwElement->offsetWidth()); |
4280 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4287 EXPECT_EQ(expectedSize.height(), vwElement->offsetHeight()); |
4281 | 4288 |
4282 webView->resize(flooredIntSize(pageSize)); | 4289 webView->resize(flooredIntSize(pageSize)); |
4283 | 4290 |
4284 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4291 EXPECT_EQ(expectedSize.width(), vwElement->offsetWidth()); |
4285 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4292 EXPECT_EQ(expectedSize.height(), vwElement->offsetHeight()); |
4286 | 4293 |
4287 webView->resize(WebSize(800, 600)); | 4294 webView->resize(WebSize(800, 600)); |
4288 frame->printEnd(); | 4295 frame->printEnd(); |
4289 | 4296 |
4290 EXPECT_EQ(800, vwElement->offsetWidth()); | 4297 EXPECT_EQ(800, vwElement->offsetWidth()); |
4291 } | 4298 } |
4292 | 4299 |
| 4300 TEST_P(WebViewTest, WidthMediaQueryWithPageZoomAfterPrinting) { |
| 4301 WebViewImpl* webView = m_webViewHelper.initialize(); |
| 4302 webView->resize(WebSize(800, 600)); |
| 4303 webView->setZoomLevel(WebView::zoomFactorToZoomLevel(2.0)); |
| 4304 |
| 4305 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
| 4306 FrameTestHelpers::loadHTMLString(webView->mainFrame(), |
| 4307 "<style>" |
| 4308 " @media (max-width: 600px) {" |
| 4309 " div { color: green }" |
| 4310 " }" |
| 4311 "</style>" |
| 4312 "<div id=d></div>", |
| 4313 baseURL); |
| 4314 |
| 4315 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 4316 Document* document = frame->frame()->document(); |
| 4317 Element* div = document->getElementById("d"); |
| 4318 |
| 4319 EXPECT_EQ(makeRGB(0, 128, 0), |
| 4320 div->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 4321 |
| 4322 FloatSize pageSize(300, 360); |
| 4323 |
| 4324 WebPrintParams printParams; |
| 4325 printParams.printContentArea.width = pageSize.width(); |
| 4326 printParams.printContentArea.height = pageSize.height(); |
| 4327 |
| 4328 frame->printBegin(printParams, WebNode()); |
| 4329 frame->printEnd(); |
| 4330 |
| 4331 EXPECT_EQ(makeRGB(0, 128, 0), |
| 4332 div->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 4333 } |
| 4334 |
| 4335 TEST_P(WebViewTest, ViewportUnitsPrintingWithPageZoom) { |
| 4336 WebViewImpl* webView = m_webViewHelper.initialize(); |
| 4337 webView->resize(WebSize(800, 600)); |
| 4338 webView->setZoomLevel(WebView::zoomFactorToZoomLevel(2.0)); |
| 4339 |
| 4340 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
| 4341 FrameTestHelpers::loadHTMLString(webView->mainFrame(), |
| 4342 "<style>" |
| 4343 " body { margin: 0 }" |
| 4344 " #t1 { width: 100% }" |
| 4345 " #t2 { width: 100vw }" |
| 4346 "</style>" |
| 4347 "<div id=t1></div>" |
| 4348 "<div id=t2></div>", |
| 4349 baseURL); |
| 4350 |
| 4351 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 4352 Document* document = frame->frame()->document(); |
| 4353 Element* t1 = document->getElementById("t1"); |
| 4354 Element* t2 = document->getElementById("t2"); |
| 4355 |
| 4356 EXPECT_EQ(400, t1->offsetWidth()); |
| 4357 EXPECT_EQ(400, t2->offsetWidth()); |
| 4358 |
| 4359 FloatSize pageSize(600, 720); |
| 4360 int expectedWidth = printICBSizeFromPageSize(pageSize).width(); |
| 4361 |
| 4362 WebPrintParams printParams; |
| 4363 printParams.printContentArea.width = pageSize.width(); |
| 4364 printParams.printContentArea.height = pageSize.height(); |
| 4365 |
| 4366 frame->printBegin(printParams, WebNode()); |
| 4367 |
| 4368 EXPECT_EQ(expectedWidth, t1->offsetWidth()); |
| 4369 EXPECT_EQ(expectedWidth, t2->offsetWidth()); |
| 4370 |
| 4371 frame->printEnd(); |
| 4372 } |
| 4373 |
4293 TEST_P(WebViewTest, DeviceEmulationResetScrollbars) { | 4374 TEST_P(WebViewTest, DeviceEmulationResetScrollbars) { |
4294 WebViewImpl* webView = m_webViewHelper.initialize(); | 4375 WebViewImpl* webView = m_webViewHelper.initialize(); |
4295 webView->resize(WebSize(800, 600)); | 4376 webView->resize(WebSize(800, 600)); |
4296 | 4377 |
4297 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); | 4378 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
4298 FrameTestHelpers::loadHTMLString(webView->mainFrame(), | 4379 FrameTestHelpers::loadHTMLString(webView->mainFrame(), |
4299 "<!doctype html>" | 4380 "<!doctype html>" |
4300 "<meta name='viewport'" | 4381 "<meta name='viewport'" |
4301 " content='width=device-width'>" | 4382 " content='width=device-width'>" |
4302 "<style>" | 4383 "<style>" |
(...skipping 30 matching lines...) Loading... |
4333 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars()); | 4414 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars()); |
4334 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 4415 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
4335 EXPECT_NE(nullptr, | 4416 EXPECT_NE(nullptr, |
4336 frameView->layoutViewportScrollableArea()->verticalScrollbar()); | 4417 frameView->layoutViewportScrollableArea()->verticalScrollbar()); |
4337 } else { | 4418 } else { |
4338 EXPECT_NE(nullptr, frameView->verticalScrollbar()); | 4419 EXPECT_NE(nullptr, frameView->verticalScrollbar()); |
4339 } | 4420 } |
4340 } | 4421 } |
4341 | 4422 |
4342 } // namespace blink | 4423 } // namespace blink |
OLD | NEW |