Title: [273654] trunk
Revision
273654
Author
[email protected]
Date
2021-03-01 09:36:17 -0800 (Mon, 01 Mar 2021)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273653 => 273654)


--- trunk/Source/WebCore/ChangeLog	2021-03-01 17:29:51 UTC (rev 273653)
+++ trunk/Source/WebCore/ChangeLog	2021-03-01 17:36:17 UTC (rev 273654)
@@ -1,3 +1,15 @@
+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-01  Chris Lord  <[email protected]>
 
         CSSFontFace should not need its m_fontSelector data member

Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp (273653 => 273654)


--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-01 17:29:51 UTC (rev 273653)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-01 17:36:17 UTC (rev 273654)
@@ -239,7 +239,9 @@
         return false;
 
     auto range = findRange(*appHighlightRangeData, *strongDocument);
-
+    
+    if (!range)
+        return false;
     strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
 
     return true;

Modified: trunk/Tools/ChangeLog (273653 => 273654)


--- trunk/Tools/ChangeLog	2021-03-01 17:29:51 UTC (rev 273653)
+++ trunk/Tools/ChangeLog	2021-03-01 17:36:17 UTC (rev 273654)
@@ -1,3 +1,13 @@
+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-01  Aakash Jain  <[email protected]>
 
         [Python-3] Change shebang in runUnittests.py

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm (273653 => 273654)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	2021-03-01 17:29:51 UTC (rev 273653)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm	2021-03-01 17:36:17 UTC (rev 273654)
@@ -80,6 +80,35 @@
     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