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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2237433004: Adds DevTools commands for forced viewport override. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adress Dmitry's comments + sync. Created 4 years, 3 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) 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
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 3506 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 ScopedPageLoadDeferrer deferrer2; 3615 ScopedPageLoadDeferrer deferrer2;
3611 EXPECT_TRUE(webView->page()->defersLoading()); 3616 EXPECT_TRUE(webView->page()->defersLoading());
3612 } 3617 }
3613 3618
3614 EXPECT_TRUE(webView->page()->defersLoading()); 3619 EXPECT_TRUE(webView->page()->defersLoading());
3615 } 3620 }
3616 3621
3617 EXPECT_FALSE(webView->page()->defersLoading()); 3622 EXPECT_FALSE(webView->page()->defersLoading());
3618 } 3623 }
3619 3624
3625 TEST_F(WebViewTest, ForceAndResetViewport)
3626 {
3627 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
3628 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
3629 webViewImpl->resize(WebSize(100, 150));
3630 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150));
3631 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
3632 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator();
3633
3634 TransformationMatrix expectedMatrix;
3635 expectedMatrix.makeIdentity();
3636 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3637 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting());
3638 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
3639
3640 // Override applies transform, sets visibleContentRect, and disables
3641 // visual viewport clipping.
3642 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f);
3643 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55);
3644 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3645 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting());
3646 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
3647
3648 // Setting new override discards previous one.
3649 devToolsEmulator->forceViewport(WebFloatPoint(5.4f, 10.5f), 1.5f);
3650 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f);
3651 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3652 EXPECT_EQ(IntRect(5, 10, 68, 101), *devToolsEmulator->visibleContentRectForP ainting());
3653 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
3654
3655 // Clearing override restores original transform, visibleContentRect and
3656 // visual viewport clipping.
3657 devToolsEmulator->resetViewport();
3658 expectedMatrix.makeIdentity();
3659 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3660 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting());
3661 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
3662 }
3663
3664 TEST_F(WebViewTest, ViewportOverrideIntegratesDeviceMetricsOffsetAndScale)
3665 {
3666 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
3667 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
3668 webViewImpl->resize(WebSize(100, 150));
3669
3670 TransformationMatrix expectedMatrix;
3671 expectedMatrix.makeIdentity();
3672 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3673
3674 WebDeviceEmulationParams emulationParams;
3675 emulationParams.offset = WebFloatPoint(50, 50);
3676 emulationParams.scale = 2.f;
3677 webViewImpl->enableDeviceEmulation(emulationParams);
3678 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f);
3679 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3680
3681 // Device metrics offset and scale are applied before viewport override.
3682 webViewImpl->devToolsEmulator()->forceViewport(WebFloatPoint(5, 10), 1.5f);
3683 expectedMatrix.makeIdentity().scale(1.5f).translate(-5, -10).translate(50, 5 0).scale(2.f);
3684 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3685 }
3686
3687 TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll)
3688 {
3689 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
3690 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
3691 webViewImpl->resize(WebSize(100, 150));
3692 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150));
3693 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
3694 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator();
3695
3696 TransformationMatrix expectedMatrix;
3697 expectedMatrix.makeIdentity();
3698 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3699
3700 // Initial transform takes current page scale and scroll position into
3701 // account.
3702 webViewImpl->setPageScaleFactor(1.5f);
3703 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, Scro llBehaviorInstant);
3704 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f);
3705 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(100, 150).scale(1. / 1.5f);
3706 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3707 // Page scroll and scale are irrelevant for visibleContentRect.
3708 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting());
3709
3710 // Transform adapts to scroll changes.
3711 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, Scroll BehaviorInstant);
3712 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5 5).scale(1. / 1.5f);
3713 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3714 // visibleContentRect doesn't change.
3715 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting());
3716
3717 // Transform adapts to page scale changes.
3718 webViewImpl->setPageScaleFactor(2.f);
3719 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5 5).scale(1. / 2.f);
3720 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
3721 // visibleContentRect doesn't change.
3722 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP ainting());
3723 }
3724
3620 } // namespace blink 3725 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698