Title: [274202] branches/safari-612.1.5-branch
Revision
274202
Author
[email protected]
Date
2021-03-09 23:43:55 -0800 (Tue, 09 Mar 2021)

Log Message

Cherry-pick r273654. rdar://problem/75252578

    Restoring App Highlight crashes if no range is found.
    https://bugs.webkit.org/show_bug.cgi?id=222524

    Reviewed by Tim Horton.

    Source/WebCore:

    Test: TestWebKitAPI.AppHighlights.AppHighlightRestoreFailure

    * Modules/highlight/AppHighlightStorage.cpp:
    (WebCore::AppHighlightStorage::restoreAppHighlight):

    Tools:

    * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
    (TestWebKitAPI::TEST):

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-612.1.5-branch/Source/WebCore/ChangeLog (274201 => 274202)


--- branches/safari-612.1.5-branch/Source/WebCore/ChangeLog	2021-03-10 07:36:26 UTC (rev 274201)
+++ branches/safari-612.1.5-branch/Source/WebCore/ChangeLog	2021-03-10 07:43:55 UTC (rev 274202)
@@ -1,3 +1,38 @@
+2021-03-09  Russell Epstein  <[email protected]>
+
+        Cherry-pick r273654. rdar://problem/75252578
+
+    Restoring App Highlight crashes if no range is found.
+    https://bugs.webkit.org/show_bug.cgi?id=222524
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Test: TestWebKitAPI.AppHighlights.AppHighlightRestoreFailure
+    
+    * Modules/highlight/AppHighlightStorage.cpp:
+    (WebCore::AppHighlightStorage::restoreAppHighlight):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
+    (TestWebKitAPI::TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273654 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-03-01  Megan Gardner  <[email protected]>
+
+            Restoring App Highlight crashes if no range is found.
+            https://bugs.webkit.org/show_bug.cgi?id=222524
+
+            Reviewed by Tim Horton.
+
+            Test: TestWebKitAPI.AppHighlights.AppHighlightRestoreFailure
+
+            * Modules/highlight/AppHighlightStorage.cpp:
+            (WebCore::AppHighlightStorage::restoreAppHighlight):
+
 2021-03-05  Russell Epstein  <[email protected]>
 
         Cherry-pick r273866. rdar://problem/75115229

Modified: branches/safari-612.1.5-branch/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp (274201 => 274202)


--- branches/safari-612.1.5-branch/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-10 07:36:26 UTC (rev 274201)
+++ branches/safari-612.1.5-branch/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-10 07:43:55 UTC (rev 274202)
@@ -239,7 +239,9 @@
         return false;
 
     auto range = findRange(*appHighlightRangeData, *strongDocument);
-
+    
+    if (!range)
+        return false;
     strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
 
     return true;

Modified: branches/safari-612.1.5-branch/Tools/ChangeLog (274201 => 274202)


--- branches/safari-612.1.5-branch/Tools/ChangeLog	2021-03-10 07:36:26 UTC (rev 274201)
+++ branches/safari-612.1.5-branch/Tools/ChangeLog	2021-03-10 07:43:55 UTC (rev 274202)
@@ -1,3 +1,36 @@
+2021-03-09  Russell Epstein  <[email protected]>
+
+        Cherry-pick r273654. rdar://problem/75252578
+
+    Restoring App Highlight crashes if no range is found.
+    https://bugs.webkit.org/show_bug.cgi?id=222524
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Test: TestWebKitAPI.AppHighlights.AppHighlightRestoreFailure
+    
+    * Modules/highlight/AppHighlightStorage.cpp:
+    (WebCore::AppHighlightStorage::restoreAppHighlight):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
+    (TestWebKitAPI::TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273654 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-03-01  Megan Gardner  <[email protected]>
+
+            Restoring App Highlight crashes if no range is found.
+            https://bugs.webkit.org/show_bug.cgi?id=222524
+
+            Reviewed by Tim Horton.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm:
+            (TestWebKitAPI::TEST):
+
 2021-03-05  Russell Epstein  <[email protected]>
 
         Cherry-pick r273997. rdar://problem/75115235

Added: branches/safari-612.1.5-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm (0 => 274202)


--- branches/safari-612.1.5-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	                        (rev 0)
+++ branches/safari-612.1.5-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	2021-03-10 07:43:55 UTC (rev 274202)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2021 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"
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <WebKit/_WKAppHighlight.h>
+#import <WebKit/_WKAppHighlightDelegate.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
+
+#if ENABLE(APP_HIGHLIGHTS)
+
+@interface AppHighlightDelegate : NSObject <_WKAppHighlightDelegate>
+@property (nonatomic, copy) void (^storeAppHighlightCallback)(WKWebView *, _WKAppHighlight *, BOOL);
+@end
+
+@implementation AppHighlightDelegate
+- (void)_webView:(WKWebView *)webView storeAppHighlight:(_WKAppHighlight *)highlight inNewGroup:(BOOL)inNewGroup
+{
+    if (_storeAppHighlightCallback)
+        _storeAppHighlightCallback(webView, highlight, inNewGroup);
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(AppHighlights, AppHighlightCreateAndRestore)
+{
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
+    auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    [webViewCreate _setAppHighlightDelegate:delegate.get()];
+    [webViewCreate synchronouslyLoadHTMLString:@"Test"];
+    [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
+    __block bool finished = NO;
+    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup) {
+        EXPECT_EQ(delegateWebView, webViewCreate.get());
+        EXPECT_NOT_NULL(highlight);
+        EXPECT_WK_STREQ(highlight.text, @"Test");
+        EXPECT_NOT_NULL(highlight.highlight);
+        
+        [webViewRestore synchronouslyLoadHTMLString:@"Test"];
+        [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]];
+        
+        TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
+            return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1;
+        }, 2, @"Expected Highlights to be populated.");
+        
+        finished = YES;
+    }];
+    [webViewCreate _addAppHighlight];
+    TestWebKitAPI::Util::run(&finished);
+}
+
+TEST(AppHighlights, AppHighlightRestoreFailure)
+{
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    auto delegate = adoptNS([[AppHighlightDelegate alloc] init]);
+    auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);
+    [webViewCreate _setAppHighlightDelegate:delegate.get()];
+    [webViewCreate synchronouslyLoadHTMLString:@"Test"];
+    [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"];
+    __block bool finished = NO;
+    [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup) {
+        EXPECT_EQ(delegateWebView, webViewCreate.get());
+        EXPECT_NOT_NULL(highlight);
+        EXPECT_WK_STREQ(highlight.text, @"Test");
+        EXPECT_NOT_NULL(highlight.highlight);
+        
+        [webViewRestore synchronouslyLoadHTMLString:@"Not the same"];
+        [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]];
+        
+        TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool {
+            return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue;
+        }, 2, @"Expected Highlights to be populated.");
+        
+        finished = YES;
+    }];
+    [webViewCreate _addAppHighlight];
+    TestWebKitAPI::Util::run(&finished);
+}
+
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to