pageZoom/setPageZoom: should not be in a Mac-only part of WKWebView.mm
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 18:07:21 +0000 (18:07 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Nov 2019 18:07:21 +0000 (18:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204128

Reviewed by Alex Christensen.

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView setPageZoom:]):
(-[WKWebView pageZoom]):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/PageZoom.mm: Added.
(TestWebKitAPI::getClientWidth):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[WKWebView waitUntilClientWidthIs:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252458 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/PageZoom.mm [new file with mode: 0644]
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

index 41df77a..e723f5d 100644 (file)
@@ -1,3 +1,14 @@
+2019-11-14  Brady Eidson  <beidson@apple.com>
+
+        pageZoom/setPageZoom: should not be in a Mac-only part of WKWebView.mm
+        https://bugs.webkit.org/show_bug.cgi?id=204128
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView setPageZoom:]):
+        (-[WKWebView pageZoom]):
+
 2019-11-13  Per Arne Vollan  <pvollan@apple.com>
 
         REGRESSION: WKWebView navigation fails when navigating from about:blank
index b4f1a79..e7e5d27 100644 (file)
@@ -4441,16 +4441,6 @@ ALLOW_DEPRECATED_IMPLEMENTATIONS_END
 }
 #endif
 
-- (void)setPageZoom:(CGFloat)pageZoom
-{
-    _page->setPageZoomFactor(pageZoom);
-}
-
-- (CGFloat)pageZoom
-{
-    return _page->pageZoomFactor();
-}
-
 - (BOOL)_usePlatformFindUI
 {
     return _usePlatformFindUI;
@@ -5700,6 +5690,16 @@ static inline OptionSet<WebCore::LayoutMilestone> layoutMilestones(_WKRenderingP
     _page->setTextZoomFactor(zoomFactor);
 }
 
+- (void)setPageZoom:(CGFloat)pageZoom
+{
+    _page->setPageZoomFactor(pageZoom);
+}
+
+- (CGFloat)pageZoom
+{
+    return _page->pageZoomFactor();
+}
+
 - (double)_pageZoomFactor
 {
     return [self pageZoom];
index c96c87f..f6dcf2c 100644 (file)
@@ -1,3 +1,17 @@
+2019-11-14  Brady Eidson  <beidson@apple.com>
+
+        pageZoom/setPageZoom: should not be in a Mac-only part of WKWebView.mm
+        https://bugs.webkit.org/show_bug.cgi?id=204128
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/PageZoom.mm: Added.
+        (TestWebKitAPI::getClientWidth):
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+        (-[WKWebView waitUntilClientWidthIs:]):
+
 2019-11-14  Jonathan Bedard  <jbedard@apple.com>
 
         webkitpy: Clarify webkitpy/style/optparser_unittest.py by removing parse variables
index b46c7c4..3084bd4 100644 (file)
                5120C83D1E6751290025B250 /* WebsiteDataStoreCustomPaths.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5120C83C1E6750790025B250 /* WebsiteDataStoreCustomPaths.mm */; };
                5120C83E1E67678F0025B250 /* WebsiteDataStoreCustomPaths.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */; };
                51242CD52374E62500EED9C1 /* FindInPageAPI.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51242CD42374E61E00EED9C1 /* FindInPageAPI.mm */; };
+               51242CDB237B7ACB00EED9C1 /* PageZoom.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51242CDA237B791E00EED9C1 /* PageZoom.mm */; };
                512C4C9E20EAA40D004945EA /* ResponsivenessTimerCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 512C4C9D20EAA405004945EA /* ResponsivenessTimerCrash.mm */; };
                51393E221523952D005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */; };
                51396E1A222E516000A42FCE /* LoadFileURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51396E19222E4E8600A42FCE /* LoadFileURL.mm */; };
                5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebsiteDataStoreCustomPaths.html; sourceTree = "<group>"; };
                5120C83C1E6750790025B250 /* WebsiteDataStoreCustomPaths.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebsiteDataStoreCustomPaths.mm; sourceTree = "<group>"; };
                51242CD42374E61E00EED9C1 /* FindInPageAPI.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindInPageAPI.mm; sourceTree = "<group>"; };
+               51242CDA237B791E00EED9C1 /* PageZoom.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageZoom.mm; sourceTree = "<group>"; };
                512C4C9D20EAA405004945EA /* ResponsivenessTimerCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResponsivenessTimerCrash.mm; sourceTree = "<group>"; };
                51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtensionBasic_Bundle.cpp; sourceTree = "<group>"; };
                51393E1E1523944A005F39C5 /* DOMWindowExtensionBasic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtensionBasic.cpp; sourceTree = "<group>"; };
                                CEBCA12E1E3A660100C73293 /* OverrideContentSecurityPolicy.mm */,
                                2DA2586E225C67DC00B45C1C /* OverrideViewportArguments.mm */,
                                2D3CA3A4221DF2390088E803 /* PageOverlayPlugin.mm */,
+                               51242CDA237B791E00EED9C1 /* PageZoom.mm */,
                                F44C79FB20F9E50C0014478C /* ParserYieldTokenPlugIn.mm */,
                                F44C79FD20F9E8710014478C /* ParserYieldTokenTests.h */,
                                F44C79FE20F9E8710014478C /* ParserYieldTokenTests.mm */,
                                7CCE7F081A411AE600447C4C /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
                                272A691022F012DA000FDABB /* PageLoadState.cpp in Sources */,
                                7CCE7EC71A411A7E00447C4C /* PageVisibilityStateWithWindowChanges.mm in Sources */,
+                               51242CDB237B7ACB00EED9C1 /* PageZoom.mm in Sources */,
                                7CCE7F091A411AE600447C4C /* ParentFrame.cpp in Sources */,
                                7C83E0511D0A641800FEBCF3 /* ParsedContentRange.cpp in Sources */,
                                AA96CAB621C7DB5000FD2F97 /* ParsedContentType.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/PageZoom.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/PageZoom.mm
new file mode 100644 (file)
index 0000000..469a590
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 Apple 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.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WKWebView, PageZoom)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<body>TEST</body>" baseURL:nil];
+
+    // On macOS this will be 400, per the size of the WKWebView.
+    // On iOS devices it will be a native device width, and we need to fetch that here.
+    unsigned beforeClientWidth = [webView waitUntilClientWidthIs:400];
+
+    webView.get().pageZoom = 2.0;
+
+    unsigned afterClientWidth = [webView waitUntilClientWidthIs:beforeClientWidth / 2];
+    EXPECT_EQ(beforeClientWidth / 2, afterClientWidth);
+}
+
+} // namespace TestWebKitAPI
index 1543e2f..2ad15ef 100644 (file)
@@ -63,6 +63,7 @@
 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script;
 - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script;
 - (id)objectByEvaluatingJavaScript:(NSString *)script;
+- (unsigned)waitUntilClientWidthIs:(unsigned)expectedClientWidth;
 @end
 
 @interface TestMessageHandler : NSObject <WKScriptMessageHandler>
index 603cb73..aaff25c 100644 (file)
@@ -183,6 +183,23 @@ SOFT_LINK_CLASS(UIKit, UIWindow)
     return [NSString stringWithFormat:@"%@", [self objectByEvaluatingJavaScript:script]];
 }
 
+- (unsigned)waitUntilClientWidthIs:(unsigned)expectedClientWidth
+{
+    int timeout = 10;
+    unsigned clientWidth = 0;
+    do {
+        if (timeout != 10)
+            TestWebKitAPI::Util::sleep(0.1);
+
+        id result = [self objectByEvaluatingJavaScript:@"function ___forceLayoutAndGetClientWidth___() { document.body.offsetTop; return document.body.clientWidth; }; ___forceLayoutAndGetClientWidth___();"];
+        clientWidth = [result integerValue];
+
+        --timeout;
+    } while (clientWidth != expectedClientWidth && timeout >= 0);
+
+    return clientWidth;
+}
+
 @end
 
 @implementation TestMessageHandler {