WKPreferences should conform to NSCopying
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Aug 2017 20:34:40 +0000 (20:34 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Aug 2017 20:34:40 +0000 (20:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175303
<rdar://problem/33764939>

Reviewed by Dan Bernstein.

Source/WebKit:

* UIProcess/API/Cocoa/WKPreferencesPrivate.h:
Add conformance in the private header, as there is not consensus that this
needs to be API.

* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences copyWithZone:]):
Copy the wrapped WebPreferences instance and return its wrapper.

Tools:

Add unit test to make sure a WKPreference and its copy are
not aliased to each other or affect each other's properties.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/Copying.mm: Added.
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Copying.mm [new file with mode: 0644]

index 048eb31..0a98a3a 100644 (file)
@@ -1,3 +1,19 @@
+2017-08-10  Brian Burg  <bburg@apple.com>
+
+        WKPreferences should conform to NSCopying
+        https://bugs.webkit.org/show_bug.cgi?id=175303
+        <rdar://problem/33764939>
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
+        Add conformance in the private header, as there is not consensus that this
+        needs to be API.
+
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences copyWithZone:]):
+        Copy the wrapped WebPreferences instance and return its wrapper.
+
 2017-08-10  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         REGRESSION(r220515) [GTK][CMake] Build with ENABLE_GEOLOCATION fails on Debian Jessie
index c71ca2a..36da8d9 100644 (file)
     return self;
 }
 
+- (id)copyWithZone:(NSZone *)zone
+{
+    return wrapper(_preferences->copy().leakRef());
+}
+
 - (CGFloat)minimumFontSize
 {
     return _preferences->minimumFontSize();
index 70d9da4..b41bbda 100644 (file)
@@ -48,6 +48,9 @@ typedef NS_OPTIONS(NSUInteger, _WKJavaScriptRuntimeFlags) {
 
 @class _WKExperimentalFeature;
 
+@interface WKPreferences () <NSCopying>
+@end
+
 @interface WKPreferences (WKPrivate)
 
 // FIXME: This property should not have the verb "is" in it.
index fbc6dd7..ad9034d 100644 (file)
@@ -1,3 +1,18 @@
+2017-08-10  Brian Burg  <bburg@apple.com>
+
+        WKPreferences should conform to NSCopying
+        https://bugs.webkit.org/show_bug.cgi?id=175303
+        <rdar://problem/33764939>
+
+        Reviewed by Dan Bernstein.
+
+        Add unit test to make sure a WKPreference and its copy are
+        not aliased to each other or affect each other's properties.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/Copying.mm: Added.
+        (TEST):
+
 2017-08-10  Tim Horton  <timothy_horton@apple.com>
 
         Remove some unused lambda captures so that WebKit builds with -Wunused-lambda-capture
index 3d1e989..a671443 100644 (file)
                95646E5B1F1DB60E00DE0EB9 /* InspectorValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 953F47911F1DB40300E3D1E3 /* InspectorValue.cpp */; };
                9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */; };
                9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9984FACD1CFFB038008D198C /* editable-body.html */; };
+               9999108B1F393C96008AD455 /* Copying.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9999108A1F393C8B008AD455 /* Copying.mm */; };
                9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */; };
                9B19CDA01F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B19CD9E1F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm */; };
                9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
                953F47911F1DB40300E3D1E3 /* InspectorValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorValue.cpp; sourceTree = "<group>"; };
                9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewTextInput.mm; sourceTree = "<group>"; };
                9984FACD1CFFB038008D198C /* editable-body.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "editable-body.html"; sourceTree = "<group>"; };
+               9999108A1F393C8B008AD455 /* Copying.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Copying.mm; sourceTree = "<group>"; };
                9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen.cpp; sourceTree = "<group>"; };
                9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp; sourceTree = "<group>"; };
                9B19CD9E1F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkProcessCrashWithPendingConnection.mm; path = WebKit2/NetworkProcessCrashWithPendingConnection.mm; sourceTree = "<group>"; };
                                A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
                                A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
                                5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */,
+                               9999108A1F393C8B008AD455 /* Copying.mm */,
                                2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */,
                                CEC16EA41EE863BF00DE479A /* DecidePolicyForNavigationAction.mm */,
                                2DC60E221E79F88C00FA6C7D /* DoAfterNextPresentationUpdateAfterCrash.mm */,
                                51DB16CE1F085137001FA4C5 /* WebViewIconLoading.mm in Sources */,
                                7CCE7F1B1A411AE600447C4C /* WillLoad.cpp in Sources */,
                                7CCE7ED71A411A7E00447C4C /* WillPerformClientRedirectToURLCrash.mm in Sources */,
+                               9999108B1F393C96008AD455 /* Copying.mm in Sources */,
                                7CCE7F1C1A411AE600447C4C /* WillSendSubmitEvent.cpp in Sources */,
                                7CCE7ED81A411A7E00447C4C /* WillSendSubmitEvent.mm in Sources */,
                                7CCE7ED91A411A7E00447C4C /* WindowlessWebViewWithMedia.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Copying.mm b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Copying.mm
new file mode 100644 (file)
index 0000000..3101b2f
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import <wtf/RetainPtr.h>
+
+TEST(Copying, WKPreferences)
+{
+    // Change all defaults to something else.
+    RetainPtr<WKPreferences> a = adoptNS([[WKPreferences alloc] init]);
+    [a setMinimumFontSize:10];
+    [a setJavaScriptEnabled:NO];
+#if PLATFORM(IOS)
+    [a setJavaScriptCanOpenWindowsAutomatically:YES];
+#else
+    [a setJavaScriptCanOpenWindowsAutomatically:NO];
+    [a setJavaEnabled:YES];
+    [a setPlugInsEnabled:YES];
+    [a setTabFocusesLinks:YES];
+#endif
+
+    // Check that values are equal in both instances.
+    RetainPtr<WKPreferences> b = adoptNS([a copy]);
+    EXPECT_EQ([a minimumFontSize], [b minimumFontSize]);
+    EXPECT_EQ([a javaScriptEnabled], [b javaScriptEnabled]);
+    EXPECT_EQ([a javaScriptCanOpenWindowsAutomatically], [b javaScriptCanOpenWindowsAutomatically]);
+#if PLATFORM(MAC)
+    EXPECT_EQ([a javaEnabled], [b javaEnabled]);
+    EXPECT_EQ([a plugInsEnabled], [b plugInsEnabled]);
+    EXPECT_EQ([a tabFocusesLinks], [b tabFocusesLinks]);
+#endif
+
+    // Change all defaults on the copied instance.
+    [b setMinimumFontSize:13];
+    [b setJavaScriptEnabled:YES];
+#if PLATFORM(IOS)
+    [b setJavaScriptCanOpenWindowsAutomatically:NO];
+#else
+    [b setJavaScriptCanOpenWindowsAutomatically:YES];
+    [b setJavaEnabled:NO];
+    [b setPlugInsEnabled:NO];
+    [b setTabFocusesLinks:NO];
+#endif
+
+    // Check that the mutations of 'b' did not affect 'a'.
+    EXPECT_NE([a minimumFontSize], [b minimumFontSize]);
+    EXPECT_NE([a javaScriptEnabled], [b javaScriptEnabled]);
+    EXPECT_NE([a javaScriptCanOpenWindowsAutomatically], [b javaScriptCanOpenWindowsAutomatically]);
+#if PLATFORM(MAC)
+    EXPECT_NE([a javaEnabled], [b javaEnabled]);
+    EXPECT_NE([a plugInsEnabled], [b plugInsEnabled]);
+    EXPECT_NE([a tabFocusesLinks], [b tabFocusesLinks]);
+#endif
+
+}
+
+#endif