Allow passing nil as session state to [WKWebView _restoreSessionState:]
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 02:17:26 +0000 (02:17 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 02:17:26 +0000 (02:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192789
<rdar://problem/46755277>

Reviewed by Alex Christensen.

Source/WebKit:

Allow passing nil as session state to [WKWebView _restoreSessionState:] instead of crashing.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _restoreSessionState:andNavigate:]):

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebKit/WKBackForwardList.mm:
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit/WKBackForwardList.mm

index 2db3ae7..782f81f 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-17  Chris Dumez  <cdumez@apple.com>
+
+        Allow passing nil as session state to [WKWebView _restoreSessionState:]
+        https://bugs.webkit.org/show_bug.cgi?id=192789
+        <rdar://problem/46755277>
+
+        Reviewed by Alex Christensen.
+
+        Allow passing nil as session state to [WKWebView _restoreSessionState:] instead of crashing.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _restoreSessionState:andNavigate:]):
+
 2018-12-17  Alex Christensen  <achristensen@webkit.org>
 
         Fix occasional null-dereference crash in WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame
index ba2048e..8dc30f1 100644 (file)
@@ -4712,7 +4712,7 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
 
 - (WKNavigation *)_restoreSessionState:(_WKSessionState *)sessionState andNavigate:(BOOL)navigate
 {
-    return wrapper(_page->restoreFromSessionState(sessionState->_sessionState, navigate));
+    return wrapper(_page->restoreFromSessionState(sessionState ? sessionState->_sessionState : WebKit::SessionState { }, navigate));
 }
 
 - (void)_close
index 8ad31a6..3507c36 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-17  Chris Dumez  <cdumez@apple.com>
+
+        Allow passing nil as session state to [WKWebView _restoreSessionState:]
+        https://bugs.webkit.org/show_bug.cgi?id=192789
+        <rdar://problem/46755277>
+
+        Reviewed by Alex Christensen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKit/WKBackForwardList.mm:
+        (TEST):
+
 2018-12-17  Simon Fraser  <simon.fraser@apple.com>
 
         Don't use more expensive layer backing store formats when subpixel text antialiasing is not enabled
index 14b80e3..71a5564 100644 (file)
@@ -103,6 +103,37 @@ TEST(WKBackForwardList, CanNotGoBackAfterRestoringEmptySessionState)
     EXPECT_EQ((NSUInteger)0, newList.forwardList.count);
 }
 
+TEST(WKBackForwardList, RestoringNilSessionState)
+{
+    auto webView = adoptNS([[WKWebView alloc] init]);
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]];
+    [webView _test_waitForDidFinishNavigation];
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL2]]];
+    [webView _test_waitForDidFinishNavigation];
+
+    WKBackForwardList *list = [webView backForwardList];
+    EXPECT_EQ(YES, [webView canGoBack]);
+    EXPECT_EQ(NO, [webView canGoForward]);
+    EXPECT_EQ((NSUInteger)1, list.backList.count);
+    EXPECT_EQ((NSUInteger)0, list.forwardList.count);
+
+    auto singlePageWebView = adoptNS([[WKWebView alloc] init]);
+
+    [singlePageWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]];
+    [singlePageWebView _test_waitForDidFinishNavigation];
+
+    [webView _restoreSessionState:nil andNavigate:NO];
+
+    WKBackForwardList *newList = [webView backForwardList];
+
+    EXPECT_EQ(YES, [webView canGoBack]);
+    EXPECT_EQ(NO, [webView canGoForward]);
+    EXPECT_EQ((NSUInteger)1, newList.backList.count);
+    EXPECT_EQ((NSUInteger)0, newList.forwardList.count);
+}
+
 static bool done;
 static size_t navigations;