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 3259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 ScopedPageLoadDeferrer deferrer2; | 3368 ScopedPageLoadDeferrer deferrer2; |
3364 EXPECT_TRUE(webView->page()->defersLoading()); | 3369 EXPECT_TRUE(webView->page()->defersLoading()); |
3365 } | 3370 } |
3366 | 3371 |
3367 EXPECT_TRUE(webView->page()->defersLoading()); | 3372 EXPECT_TRUE(webView->page()->defersLoading()); |
3368 } | 3373 } |
3369 | 3374 |
3370 EXPECT_FALSE(webView->page()->defersLoading()); | 3375 EXPECT_FALSE(webView->page()->defersLoading()); |
3371 } | 3376 } |
3372 | 3377 |
| 3378 TEST_F(WebViewTest, ForceAndResetViewport) |
| 3379 { |
| 3380 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3381 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3382 webViewImpl->resize(WebSize(100, 150)); |
| 3383 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); |
| 3384 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie
wport(); |
| 3385 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); |
| 3386 |
| 3387 TransformationMatrix expectedMatrix; |
| 3388 expectedMatrix.makeIdentity(); |
| 3389 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3390 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); |
| 3391 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); |
| 3392 |
| 3393 // Override applies transform, sets visibleContentRect, and disables |
| 3394 // visual viewport clipping. |
| 3395 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); |
| 3396 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55); |
| 3397 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3398 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP
ainting()); |
| 3399 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); |
| 3400 |
| 3401 // Setting new override discards previous one. |
| 3402 devToolsEmulator->forceViewport(WebFloatPoint(5.4f, 10.5f), 1.5f); |
| 3403 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f); |
| 3404 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3405 EXPECT_EQ(IntRect(5, 10, 68, 101), *devToolsEmulator->visibleContentRectForP
ainting()); |
| 3406 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); |
| 3407 |
| 3408 // Clearing override restores original transform, visibleContentRect and |
| 3409 // visual viewport clipping. |
| 3410 devToolsEmulator->resetViewport(); |
| 3411 expectedMatrix.makeIdentity(); |
| 3412 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3413 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); |
| 3414 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); |
| 3415 } |
| 3416 |
| 3417 TEST_F(WebViewTest, ViewportOverrideIntegratesDeviceMetricsOffsetAndScale) |
| 3418 { |
| 3419 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3420 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3421 webViewImpl->resize(WebSize(100, 150)); |
| 3422 |
| 3423 TransformationMatrix expectedMatrix; |
| 3424 expectedMatrix.makeIdentity(); |
| 3425 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3426 |
| 3427 WebDeviceEmulationParams emulationParams; |
| 3428 emulationParams.offset = WebFloatPoint(50, 50); |
| 3429 emulationParams.scale = 2.f; |
| 3430 webViewImpl->enableDeviceEmulation(emulationParams); |
| 3431 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f); |
| 3432 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3433 |
| 3434 // Device metrics offset and scale are applied before viewport override. |
| 3435 webViewImpl->devToolsEmulator()->forceViewport(WebFloatPoint(5, 10), 1.5f); |
| 3436 expectedMatrix.makeIdentity().scale(1.5f).translate(-5, -10).translate(50, 5
0).scale(2.f); |
| 3437 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3438 } |
| 3439 |
| 3440 TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) |
| 3441 { |
| 3442 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3443 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3444 webViewImpl->resize(WebSize(100, 150)); |
| 3445 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); |
| 3446 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| 3447 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); |
| 3448 |
| 3449 TransformationMatrix expectedMatrix; |
| 3450 expectedMatrix.makeIdentity(); |
| 3451 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3452 |
| 3453 // Initial transform takes current page scale and scroll position into |
| 3454 // account. |
| 3455 webViewImpl->setPageScaleFactor(1.5f); |
| 3456 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, Scro
llBehaviorInstant); |
| 3457 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); |
| 3458 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(100,
150).scale(1. / 1.5f); |
| 3459 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3460 // Page scroll and scale are irrelevant for visibleContentRect. |
| 3461 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP
ainting()); |
| 3462 |
| 3463 // Transform adapts to scroll changes. |
| 3464 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, Scroll
BehaviorInstant); |
| 3465 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5
5).scale(1. / 1.5f); |
| 3466 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3467 // visibleContentRect doesn't change. |
| 3468 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP
ainting()); |
| 3469 |
| 3470 // Transform adapts to page scale changes. |
| 3471 webViewImpl->setPageScaleFactor(2.f); |
| 3472 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5
5).scale(1. / 2.f); |
| 3473 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3474 // visibleContentRect doesn't change. |
| 3475 EXPECT_EQ(IntRect(50, 55, 50, 75), *devToolsEmulator->visibleContentRectForP
ainting()); |
| 3476 } |
| 3477 |
3373 } // namespace blink | 3478 } // namespace blink |
OLD | NEW |