/* * Copyright (C) 2021 Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #import "config.h" #import "PlatformUtilities.h" #import "TestWKWebView.h" #import #import static double evaluateForNumber(RetainPtr& webView, NSString *script) { return [(NSNumber *)[webView objectByEvaluatingJavaScript:script] doubleValue]; } static double dimensionOfElement(RetainPtr& webView, NSString *element, NSString *dimension) { return evaluateForNumber(webView, [NSString stringWithFormat:@"%@.getBoundingClientRect().%@", element, dimension]); } static double widthOfElementWithID(RetainPtr& webView, NSString *elementID) { return dimensionOfElement(webView, [NSString stringWithFormat:@"document.getElementById('%@')", elementID], @"width"); } static double heightOfElementWithID(RetainPtr& webView, NSString *elementID) { return dimensionOfElement(webView, [NSString stringWithFormat:@"document.getElementById('%@')", elementID], @"height"); } static double viewportUnitLength(RetainPtr& webView, NSString *viewportUnit) { return heightOfElementWithID(webView, viewportUnit); } static void changeCSSPropertyOfElements(RetainPtr& webView, NSString *selector, NSString *property, NSString *value) { [webView objectByEvaluatingJavaScript:[NSString stringWithFormat:@"document.querySelectorAll('%@').forEach((element) => element.style['%@'] = %@)", selector, property, value]]; } #if PLATFORM(MAC) constexpr auto scrollbarSize = 15; #else constexpr auto scrollbarSize = 0; #endif TEST(CSSViewportUnits, AllSame) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } #if PLATFORM(IOS_FAMILY) [webView scrollView].zoomScale = 2; #elif PLATFORM(MAC) [webView setAllowsMagnification:YES]; [webView setMagnification:2]; #endif [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } #if USE(APPKIT) #define CocoaEdgeInsetsMake NSEdgeInsetsMake #endif #if PLATFORM(IOS_FAMILY) #define CocoaEdgeInsetsMake UIEdgeInsetsMake #endif #define CocoaEdgeInsetsZero CocoaEdgeInsetsMake(0, 0, 0, 0) TEST(CSSViewportUnits, NegativeMinimumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); bool didThrow = false; @try { [webView setMinimumViewportInset:CocoaEdgeInsetsMake(-11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; } @catch (NSException *exception) { didThrow = true; } EXPECT_TRUE(didThrow); } TEST(CSSViewportUnits, NegativeMaximumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); bool didThrow = false; @try { [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(-12, 22, 32, 42)]; } @catch (NSException *exception) { didThrow = true; } EXPECT_TRUE(didThrow); } TEST(CSSViewportUnits, MinimumViewportInsetLargerThanMaximumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); bool didThrow = false; @try { [webView setMinimumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42) maximumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41)]; } @catch (NSException *exception) { didThrow = true; } EXPECT_TRUE(didThrow); } TEST(CSSViewportUnits, MinimumViewportInsetThanLargerFrame) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); bool didThrow = false; @try { [webView setMinimumViewportInset:CocoaEdgeInsetsMake(1100, 2100, 3100, 4100) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; } @catch (NSException *exception) { didThrow = true; } EXPECT_TRUE(didThrow); } TEST(CSSViewportUnits, MaximumViewportInsetThanLargerFrame) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); bool didThrow = false; @try { [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(1200, 2200, 3200, 4200)]; } @catch (NSException *exception) { didThrow = true; } EXPECT_TRUE(didThrow); } TEST(CSSViewportUnits, MinimumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MinimumViewportInsetWithZoom) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; #if PLATFORM(IOS_FAMILY) [webView scrollView].zoomScale = 2; #elif PLATFORM(MAC) [webView setAllowsMagnification:YES]; [webView setMagnification:2]; #endif [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithZoom) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; #if PLATFORM(IOS_FAMILY) [webView scrollView].zoomScale = 2; #elif PLATFORM(MAC) [webView setAllowsMagnification:YES]; [webView setMagnification:2]; #endif [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MinimumViewportInsetWithWritingMode) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed"); // No vertical overflow. double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithWritingMode) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed"); // No vertical overflow. double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MinimumViewportInsetWithFrame) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView setFrame:CGRectMake(0, 0, 220, 400)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(158, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(358, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(158, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(358, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(358, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(158, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithFrame) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView setFrame:CGRectMake(0, 0, 220, 400)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(356, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(156, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(400, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(220, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MinimumViewportInsetWithBounds) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView setBounds:CGRectMake(50, 60, 320, 500)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithBounds) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView setBounds:CGRectMake(50, 60, 320, 500)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed"); // No horizontal overflow. EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } #if PLATFORM(IOS_FAMILY) TEST(CSSViewportUnits, MinimumViewportInsetWithContentInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView scrollView].contentInset = CocoaEdgeInsetsMake(50, 60, 70, 80); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithContentInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView scrollView].contentInset = CocoaEdgeInsetsMake(50, 60, 70, 80); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MinimumViewportInsetWithSafeAreaInsets) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; auto viewController = adoptNS([[UIViewController alloc] init]); [viewController setAdditionalSafeAreaInsets:CocoaEdgeInsetsMake(50, 60, 70, 80)]; [viewController setView:webView.get()]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(458, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(258, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, MaximumViewportInsetWithSafeAreaInsets) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; auto viewController = adoptNS([[UIViewController alloc] init]); [viewController setAdditionalSafeAreaInsets:CocoaEdgeInsetsMake(50, 60, 70, 80)]; [viewController setView:webView.get()]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(456, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(256, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(500, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(320, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, UnobscuredSizeOverridesIgnoreMinimumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsMake(11, 21, 31, 41) maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView _overrideLayoutParametersWithMinimumLayoutSize:CGSizeMake(10.5, 20.5) maximumUnobscuredSizeOverride:CGSizeMake(30.5, 40.5)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, UnobscuredSizeOverridesIgnoreMaximumViewportInset) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView setMinimumViewportInset:CocoaEdgeInsetsZero maximumViewportInset:CocoaEdgeInsetsMake(12, 22, 32, 42)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView _overrideLayoutParametersWithMinimumLayoutSize:CGSizeMake(10.5, 20.5) maximumUnobscuredSizeOverride:CGSizeMake(30.5, 40.5)]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, EmptyUnobscuredSizeOverrides) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView _overrideLayoutParametersWithMinimumLayoutSize:CGSizeMake(10.5, 20.5) maximumUnobscuredSizeOverride:CGSizeZero]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } [webView scrollView].zoomScale = 2; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, SameUnobscuredSizeOverrides) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView _overrideLayoutParametersWithMinimumLayoutSize:CGSizeMake(10.5, 20.5) maximumUnobscuredSizeOverride:CGSizeMake(10.5, 20.5)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } [webView scrollView].zoomScale = 2; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } TEST(CSSViewportUnits, DifferentUnobscuredSizeOverrides) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView _overrideLayoutParametersWithMinimumLayoutSize:CGSizeMake(10.5, 20.5) maximumUnobscuredSizeOverride:CGSizeMake(30.5, 40.5)]; [webView synchronouslyLoadTestPageNamed:@"CSSViewportUnits"]; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } [webView scrollView].zoomScale = 2; [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"body", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"div", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"vi")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svw")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svh")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(20.5, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(10.5, viewportUnitLength(webView, @"svi")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvw")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvh")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(40.5, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(30.5, viewportUnitLength(webView, @"lvi")); { double fixedWidth = widthOfElementWithID(webView, @"fixed") + scrollbarSize; double fixedHeight = heightOfElementWithID(webView, @"fixed") + scrollbarSize; EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvw")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvh")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(fixedHeight, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(fixedWidth, viewportUnitLength(webView, @"dvi")); } } #endif // PLATFORM(IOS_FAMILY) TEST(CSSViewportUnits, SVGDocument) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"CSSViewportUnits" withExtension:@"svg" subdirectory:@"TestWebKitAPI.resources"]]]; [webView _test_waitForDidFinishNavigation]; [webView waitForNextPresentationUpdate]; { double vw = viewportUnitLength(webView, @"vw"); double vh = viewportUnitLength(webView, @"vh"); EXPECT_GE(vw, 320); EXPECT_GE(vh, 500); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vi")); double svw = viewportUnitLength(webView, @"svw"); double svh = viewportUnitLength(webView, @"svh"); EXPECT_FLOAT_EQ(vw, svw); EXPECT_FLOAT_EQ(vh, svh); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svi")); double lvw = viewportUnitLength(webView, @"lvw"); double lvh = viewportUnitLength(webView, @"lvh"); EXPECT_FLOAT_EQ(vw, lvw); EXPECT_FLOAT_EQ(vh, lvh); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvi")); double dvw = viewportUnitLength(webView, @"dvw"); double dvh = viewportUnitLength(webView, @"dvh"); EXPECT_FLOAT_EQ(widthOfElementWithID(webView, @"fixed"), dvw); EXPECT_FLOAT_EQ(heightOfElementWithID(webView, @"fixed"), dvh); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvi")); }; #if PLATFORM(IOS_FAMILY) [webView scrollView].zoomScale = 2; #elif PLATFORM(MAC) [webView setAllowsMagnification:YES]; [webView setMagnification:2]; #endif [webView waitForNextPresentationUpdate]; { double vw = viewportUnitLength(webView, @"vw"); double vh = viewportUnitLength(webView, @"vh"); EXPECT_GE(vw, 320); EXPECT_GE(vh, 500); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vi")); double svw = viewportUnitLength(webView, @"svw"); double svh = viewportUnitLength(webView, @"svh"); EXPECT_FLOAT_EQ(vw, svw); EXPECT_FLOAT_EQ(vh, svh); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svi")); double lvw = viewportUnitLength(webView, @"lvw"); double lvh = viewportUnitLength(webView, @"lvh"); EXPECT_FLOAT_EQ(vw, lvw); EXPECT_FLOAT_EQ(vh, lvh); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvi")); double dvw = viewportUnitLength(webView, @"dvw"); double dvh = viewportUnitLength(webView, @"dvh"); EXPECT_FLOAT_EQ(widthOfElementWithID(webView, @"fixed") + scrollbarSize, dvw); EXPECT_FLOAT_EQ(heightOfElementWithID(webView, @"fixed") + scrollbarSize, dvh); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"svg", @"writingMode", @"'vertical-lr'"); [webView waitForNextPresentationUpdate]; { double vw = viewportUnitLength(webView, @"vw"); double vh = viewportUnitLength(webView, @"vh"); EXPECT_GE(vw, 320); EXPECT_GE(vh, 500); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vi")); double svw = viewportUnitLength(webView, @"svw"); double svh = viewportUnitLength(webView, @"svh"); EXPECT_FLOAT_EQ(vw, svw); EXPECT_FLOAT_EQ(vh, svh); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svi")); double lvw = viewportUnitLength(webView, @"lvw"); double lvh = viewportUnitLength(webView, @"lvh"); EXPECT_FLOAT_EQ(vw, lvw); EXPECT_FLOAT_EQ(vh, lvh); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvi")); double dvw = viewportUnitLength(webView, @"dvw"); double dvh = viewportUnitLength(webView, @"dvh"); EXPECT_FLOAT_EQ(widthOfElementWithID(webView, @"fixed") + scrollbarSize, dvw); EXPECT_FLOAT_EQ(heightOfElementWithID(webView, @"fixed") + scrollbarSize, dvh); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvi")); } changeCSSPropertyOfElements(webView, @"rect", @"writingMode", @"'horizontal-tb'"); [webView waitForNextPresentationUpdate]; { double vw = viewportUnitLength(webView, @"vw"); double vh = viewportUnitLength(webView, @"vh"); EXPECT_GE(vw, 320); EXPECT_GE(vh, 500); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vmin")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vmax")); EXPECT_FLOAT_EQ(vh, viewportUnitLength(webView, @"vb")); EXPECT_FLOAT_EQ(vw, viewportUnitLength(webView, @"vi")); double svw = viewportUnitLength(webView, @"svw"); double svh = viewportUnitLength(webView, @"svh"); EXPECT_FLOAT_EQ(vw, svw); EXPECT_FLOAT_EQ(vh, svh); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svmin")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svmax")); EXPECT_FLOAT_EQ(svh, viewportUnitLength(webView, @"svb")); EXPECT_FLOAT_EQ(svw, viewportUnitLength(webView, @"svi")); double lvw = viewportUnitLength(webView, @"lvw"); double lvh = viewportUnitLength(webView, @"lvh"); EXPECT_FLOAT_EQ(vw, lvw); EXPECT_FLOAT_EQ(vh, lvh); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvmin")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvmax")); EXPECT_FLOAT_EQ(lvh, viewportUnitLength(webView, @"lvb")); EXPECT_FLOAT_EQ(lvw, viewportUnitLength(webView, @"lvi")); double dvw = viewportUnitLength(webView, @"dvw"); double dvh = viewportUnitLength(webView, @"dvh"); EXPECT_FLOAT_EQ(widthOfElementWithID(webView, @"fixed") + scrollbarSize, dvw); EXPECT_FLOAT_EQ(heightOfElementWithID(webView, @"fixed") + scrollbarSize, dvh); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvmin")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvmax")); EXPECT_FLOAT_EQ(dvh, viewportUnitLength(webView, @"dvb")); EXPECT_FLOAT_EQ(dvw, viewportUnitLength(webView, @"dvi")); } }