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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 #include "core/loader/FrameLoadRequest.h" | 50 #include "core/loader/FrameLoadRequest.h" |
51 #include "core/page/Page.h" | 51 #include "core/page/Page.h" |
52 #include "core/page/ScopedPageLoadDeferrer.h" | 52 #include "core/page/ScopedPageLoadDeferrer.h" |
53 #include "core/paint/PaintLayer.h" | 53 #include "core/paint/PaintLayer.h" |
54 #include "core/paint/PaintLayerPainter.h" | 54 #include "core/paint/PaintLayerPainter.h" |
55 #include "core/timing/DOMWindowPerformance.h" | 55 #include "core/timing/DOMWindowPerformance.h" |
56 #include "core/timing/Performance.h" | 56 #include "core/timing/Performance.h" |
57 #include "core/timing/PerformanceCompositeTiming.h" | 57 #include "core/timing/PerformanceCompositeTiming.h" |
58 #include "platform/KeyboardCodes.h" | 58 #include "platform/KeyboardCodes.h" |
59 #include "platform/UserGestureIndicator.h" | 59 #include "platform/UserGestureIndicator.h" |
60 #include "platform/geometry/IntRect.h" | |
60 #include "platform/geometry/IntSize.h" | 61 #include "platform/geometry/IntSize.h" |
61 #include "platform/graphics/Color.h" | 62 #include "platform/graphics/Color.h" |
62 #include "platform/graphics/GraphicsContext.h" | 63 #include "platform/graphics/GraphicsContext.h" |
63 #include "platform/graphics/paint/SkPictureBuilder.h" | 64 #include "platform/graphics/paint/SkPictureBuilder.h" |
65 #include "platform/scroll/ScrollTypes.h" | |
64 #include "platform/testing/URLTestHelpers.h" | 66 #include "platform/testing/URLTestHelpers.h" |
65 #include "platform/testing/UnitTestHelpers.h" | 67 #include "platform/testing/UnitTestHelpers.h" |
66 #include "public/platform/Platform.h" | 68 #include "public/platform/Platform.h" |
67 #include "public/platform/WebDisplayMode.h" | 69 #include "public/platform/WebDisplayMode.h" |
68 #include "public/platform/WebDragData.h" | 70 #include "public/platform/WebDragData.h" |
69 #include "public/platform/WebDragOperation.h" | 71 #include "public/platform/WebDragOperation.h" |
72 #include "public/platform/WebFloatPoint.h" | |
73 #include "public/platform/WebLayerTreeView.h" | |
70 #include "public/platform/WebMockClipboard.h" | 74 #include "public/platform/WebMockClipboard.h" |
71 #include "public/platform/WebSize.h" | 75 #include "public/platform/WebSize.h" |
72 #include "public/platform/WebThread.h" | 76 #include "public/platform/WebThread.h" |
73 #include "public/platform/WebURLLoaderMockFactory.h" | 77 #include "public/platform/WebURLLoaderMockFactory.h" |
74 #include "public/web/WebAutofillClient.h" | 78 #include "public/web/WebAutofillClient.h" |
75 #include "public/web/WebCache.h" | 79 #include "public/web/WebCache.h" |
76 #include "public/web/WebDateTimeChooserCompletion.h" | 80 #include "public/web/WebDateTimeChooserCompletion.h" |
77 #include "public/web/WebDeviceEmulationParams.h" | 81 #include "public/web/WebDeviceEmulationParams.h" |
78 #include "public/web/WebDocument.h" | 82 #include "public/web/WebDocument.h" |
79 #include "public/web/WebElement.h" | 83 #include "public/web/WebElement.h" |
80 #include "public/web/WebFrame.h" | 84 #include "public/web/WebFrame.h" |
81 #include "public/web/WebFrameClient.h" | 85 #include "public/web/WebFrameClient.h" |
82 #include "public/web/WebFrameContentDumper.h" | 86 #include "public/web/WebFrameContentDumper.h" |
83 #include "public/web/WebHitTestResult.h" | 87 #include "public/web/WebHitTestResult.h" |
84 #include "public/web/WebInputEvent.h" | 88 #include "public/web/WebInputEvent.h" |
85 #include "public/web/WebScriptSource.h" | 89 #include "public/web/WebScriptSource.h" |
86 #include "public/web/WebSettings.h" | 90 #include "public/web/WebSettings.h" |
87 #include "public/web/WebTreeScopeType.h" | 91 #include "public/web/WebTreeScopeType.h" |
88 #include "public/web/WebViewClient.h" | 92 #include "public/web/WebViewClient.h" |
89 #include "public/web/WebWidget.h" | 93 #include "public/web/WebWidget.h" |
90 #include "public/web/WebWidgetClient.h" | 94 #include "public/web/WebWidgetClient.h" |
91 #include "testing/gtest/include/gtest/gtest.h" | 95 #include "testing/gtest/include/gtest/gtest.h" |
92 #include "third_party/skia/include/core/SkBitmap.h" | 96 #include "third_party/skia/include/core/SkBitmap.h" |
93 #include "third_party/skia/include/core/SkCanvas.h" | 97 #include "third_party/skia/include/core/SkCanvas.h" |
98 #include "web/DevToolsEmulator.h" | |
94 #include "web/WebLocalFrameImpl.h" | 99 #include "web/WebLocalFrameImpl.h" |
95 #include "web/WebSettingsImpl.h" | 100 #include "web/WebSettingsImpl.h" |
96 #include "web/WebViewImpl.h" | 101 #include "web/WebViewImpl.h" |
97 #include "web/tests/FrameTestHelpers.h" | 102 #include "web/tests/FrameTestHelpers.h" |
98 #include "wtf/PtrUtil.h" | 103 #include "wtf/PtrUtil.h" |
99 #include <memory> | 104 #include <memory> |
100 | 105 |
101 #if OS(MACOSX) | 106 #if OS(MACOSX) |
102 #include "public/web/mac/WebSubstringUtil.h" | 107 #include "public/web/mac/WebSubstringUtil.h" |
103 #endif | 108 #endif |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); | 1076 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); |
1072 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); | 1077 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); |
1073 webViewImpl->resize(WebSize(200, 300)); | 1078 webViewImpl->resize(WebSize(200, 300)); |
1074 | 1079 |
1075 float pageScaleExpected = webViewImpl->pageScaleFactor(); | 1080 float pageScaleExpected = webViewImpl->pageScaleFactor(); |
1076 | 1081 |
1077 WebDeviceEmulationParams params; | 1082 WebDeviceEmulationParams params; |
1078 params.screenPosition = WebDeviceEmulationParams::Desktop; | 1083 params.screenPosition = WebDeviceEmulationParams::Desktop; |
1079 params.deviceScaleFactor = 0; | 1084 params.deviceScaleFactor = 0; |
1080 params.fitToView = false; | 1085 params.fitToView = false; |
1081 params.offset = WebFloatPoint(); | |
dgozman
2016/08/29 20:45:36
Please revert these.
Eric Seckler
2016/09/12 13:58:00
Done.
| |
1082 params.scale = 1; | |
1083 | 1086 |
1084 webViewImpl->enableDeviceEmulation(params); | 1087 webViewImpl->enableDeviceEmulation(params); |
1085 | 1088 |
1086 webViewImpl->setPageScaleFactor(2); | 1089 webViewImpl->setPageScaleFactor(2); |
1087 | 1090 |
1088 webViewImpl->disableDeviceEmulation(); | 1091 webViewImpl->disableDeviceEmulation(); |
1089 | 1092 |
1090 EXPECT_EQ(pageScaleExpected, webViewImpl->pageScaleFactor()); | 1093 EXPECT_EQ(pageScaleExpected, webViewImpl->pageScaleFactor()); |
1091 } | 1094 } |
1092 | 1095 |
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3279 ScopedPageLoadDeferrer deferrer2; | 3282 ScopedPageLoadDeferrer deferrer2; |
3280 EXPECT_TRUE(webView->page()->defersLoading()); | 3283 EXPECT_TRUE(webView->page()->defersLoading()); |
3281 } | 3284 } |
3282 | 3285 |
3283 EXPECT_TRUE(webView->page()->defersLoading()); | 3286 EXPECT_TRUE(webView->page()->defersLoading()); |
3284 } | 3287 } |
3285 | 3288 |
3286 EXPECT_FALSE(webView->page()->defersLoading()); | 3289 EXPECT_FALSE(webView->page()->defersLoading()); |
3287 } | 3290 } |
3288 | 3291 |
3292 TEST_F(WebViewTest, ForceAndResetViewport) | |
3293 { | |
3294 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); | |
3295 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); | |
3296 webViewImpl->resize(WebSize(100, 150)); | |
3297 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); | |
3298 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport(); | |
3299 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); | |
3300 | |
3301 TransformationMatrix expectedMatrix; | |
3302 expectedMatrix.makeIdentity(); | |
3303 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3304 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); | |
3305 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); | |
3306 | |
3307 // Override applies transform, sets visibleContentRect, and disables | |
3308 // visual viewport clipping. | |
3309 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); | |
3310 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55); | |
3311 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3312 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting()); | |
3313 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); | |
3314 | |
3315 // Setting new override discards previous one. | |
3316 devToolsEmulator->forceViewport(WebFloatPoint(5.4f, 10.5f), 1.5f); | |
3317 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f); | |
3318 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3319 EXPECT_EQ(IntRect(5, 10, 68, 101), *devToolsEmulator->visibleContentRectForP ainting()); | |
3320 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); | |
3321 | |
3322 // Clearing override restores original transform, visibleContentRect and | |
3323 // visual viewport clipping. | |
3324 devToolsEmulator->resetViewport(); | |
3325 expectedMatrix.makeIdentity(); | |
3326 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3327 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); | |
3328 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); | |
3329 } | |
3330 | |
3331 TEST_F(WebViewTest, ViewportOverrideIntegratesDeviceMetricsOffsetAndScale) | |
3332 { | |
3333 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); | |
3334 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); | |
3335 webViewImpl->resize(WebSize(100, 150)); | |
3336 | |
3337 TransformationMatrix expectedMatrix; | |
3338 expectedMatrix.makeIdentity(); | |
3339 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3340 | |
3341 WebDeviceEmulationParams emulationParams; | |
3342 emulationParams.offset = WebFloatPoint(50, 50); | |
3343 emulationParams.scale = 2.f; | |
3344 webViewImpl->enableDeviceEmulation(emulationParams); | |
3345 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f); | |
3346 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3347 | |
3348 // Device metrics offset and scale are applied before viewport override. | |
3349 webViewImpl->devToolsEmulator()->forceViewport(WebFloatPoint(5, 10), 1.5f); | |
3350 expectedMatrix.makeIdentity().scale(1.5f).translate(-5, -10).translate(50, 5 0).scale(2.f); | |
3351 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3352 } | |
3353 | |
3354 TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) | |
3355 { | |
3356 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); | |
3357 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); | |
3358 webViewImpl->resize(WebSize(100, 150)); | |
3359 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); | |
3360 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); | |
3361 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); | |
3362 | |
3363 TransformationMatrix expectedMatrix; | |
3364 expectedMatrix.makeIdentity(); | |
3365 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3366 | |
3367 // Initial transform takes current page scale and scroll position into | |
3368 // account. | |
3369 webViewImpl->setPageScaleFactor(1.5f); | |
3370 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, Scro llBehaviorInstant); | |
3371 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); | |
3372 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(100, 150).scale(1. / 1.5f); | |
3373 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3374 // Page scroll and scale are irrelevant for visibleContentRect. | |
3375 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting()); | |
3376 | |
3377 // Transform adapts to scroll changes. | |
3378 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, Scroll BehaviorInstant); | |
3379 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5 5).scale(1. / 1.5f); | |
3380 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3381 // visibleContentRect doesn't change. | |
3382 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting()); | |
3383 | |
3384 // Transform adapts to page scale changes. | |
3385 webViewImpl->setPageScaleFactor(2.f); | |
3386 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5 5).scale(1. / 2.f); | |
3387 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); | |
3388 // visibleContentRect doesn't change. | |
3389 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting()); | |
3390 } | |
3391 | |
3289 } // namespace blink | 3392 } // namespace blink |
OLD | NEW |