Source/WebKit2:
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 May 2015 17:45:51 +0000 (17:45 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 May 2015 17:45:51 +0000 (17:45 +0000)
Fix a couple of cases where the backForwardListState's currentIndex is not set correctly in WebBackForwardList::backForwardListState().
https://bugs.webkit.org/show_bug.cgi?id=144666

Reviewed by Darin Adler.

* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::backForwardListState):
If the first item is filtered out and the currentIndex is 0, don't decrement currentIndex.
If all the items are filtered out, set currentIndex to the uninitialized value.

Tools:
Add a test for WKPageCopySessionState() with filtering.
https://bugs.webkit.org/show_bug.cgi?id=144666

Reviewed by Darin Adler.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::setPageLoaderClient):
(TestWebKitAPI::filterFirstItemCallback):
(TestWebKitAPI::filterAllItemsCallback):
(TestWebKitAPI::createSessionStates):
(TestWebKitAPI::TEST):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebBackForwardList.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp [new file with mode: 0644]

index 78c9aed..d22fbf3 100644 (file)
@@ -1,3 +1,15 @@
+2015-05-07  Ada Chan  <adachan@apple.com>
+
+        Fix a couple of cases where the backForwardListState's currentIndex is not set correctly in WebBackForwardList::backForwardListState().
+        https://bugs.webkit.org/show_bug.cgi?id=144666
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::backForwardListState):
+        If the first item is filtered out and the currentIndex is 0, don't decrement currentIndex.
+        If all the items are filtered out, set currentIndex to the uninitialized value.
+
 2015-05-07  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [WK2] Remove Windows cruft
index de28212..0ee6469 100644 (file)
@@ -397,8 +397,9 @@ BackForwardListState WebBackForwardList::backForwardListState(const std::functio
         auto& entry = *m_entries[i];
 
         if (filter && !filter(entry)) {
-            if (backForwardListState.currentIndex && i <= backForwardListState.currentIndex.value())
-                --backForwardListState.currentIndex.value();
+            auto& currentIndex = backForwardListState.currentIndex;
+            if (currentIndex && i <= currentIndex.value() && currentIndex.value())
+                --currentIndex.value();
 
             continue;
         }
@@ -406,6 +407,9 @@ BackForwardListState WebBackForwardList::backForwardListState(const std::functio
         backForwardListState.items.append(entry.itemState());
     }
 
+    if (backForwardListState.items.isEmpty())
+        backForwardListState.currentIndex = Nullopt;
+
     return backForwardListState;
 }
 
index 195739e..1d5852c 100644 (file)
@@ -1,3 +1,19 @@
+2015-05-07  Ada Chan  <adachan@apple.com>
+
+        Add a test for WKPageCopySessionState() with filtering.
+        https://bugs.webkit.org/show_bug.cgi?id=144666
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp: Added.
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::setPageLoaderClient):
+        (TestWebKitAPI::filterFirstItemCallback):
+        (TestWebKitAPI::filterAllItemsCallback):
+        (TestWebKitAPI::createSessionStates):
+        (TestWebKitAPI::TEST):
+
 2015-05-06  Alexey Proskuryakov  <ap@apple.com>
 
         iOS build fix attempt
index 58776e4..bc13d16 100644 (file)
@@ -55,6 +55,7 @@
                524BBC9E19DF72C0002F1AF1 /* file-with-video.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 524BBC9B19DF3714002F1AF1 /* file-with-video.html */; };
                524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 524BBCA019E30C63002F1AF1 /* test.mp4 */; };
                52B8CF9815868D9100281053 /* SetDocumentURI.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 52B8CF9415868CF000281053 /* SetDocumentURI.html */; };
+               52D673EE1AFB127300FA19FE /* WKPageCopySessionStateWithFiltering.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52D673EC1AFB126800FA19FE /* WKPageCopySessionStateWithFiltering.cpp */; };
                52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */; };
                7673499D1930C5BB00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7673499A1930182E00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp */; };
                76E182DD1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76E182DC1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp */; };
                52B8CF9415868CF000281053 /* SetDocumentURI.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SetDocumentURI.html; sourceTree = "<group>"; };
                52B8CF9515868CF000281053 /* SetDocumentURI.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SetDocumentURI.mm; sourceTree = "<group>"; };
                52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
+               52D673EC1AFB126800FA19FE /* WKPageCopySessionStateWithFiltering.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPageCopySessionStateWithFiltering.cpp; sourceTree = "<group>"; };
                52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame.cpp; sourceTree = "<group>"; };
                52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame_Bundle.cpp; sourceTree = "<group>"; };
                7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheAddImageToCacheIOS.mm; sourceTree = "<group>"; };
                                A1FDFD2E19C288BB005148A4 /* WKImageCreateCGImageCrash.cpp */,
                                7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */,
                                7C89D2AA1A69B80D003A5FDE /* WKPageConfiguration.cpp */,
+                               52D673EC1AFB126800FA19FE /* WKPageCopySessionStateWithFiltering.cpp */,
                                51E93016156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp */,
                                524BBC9C19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp */,
                                BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
                                7CCE7EF31A411AE600447C4C /* Find.cpp in Sources */,
                                7CCE7EF41A411AE600447C4C /* FindMatches.mm in Sources */,
                                7CCE7EF51A411AE600447C4C /* ForceRepaint.cpp in Sources */,
+                               52D673EE1AFB127300FA19FE /* WKPageCopySessionStateWithFiltering.cpp in Sources */,
                                7CCE7EC01A411A7E00447C4C /* FragmentNavigation.mm in Sources */,
                                7CCE7EF61A411AE600447C4C /* FrameMIMETypeHTML.cpp in Sources */,
                                7CCE7EF71A411AE600447C4C /* FrameMIMETypePNG.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WKPageCopySessionStateWithFiltering.cpp
new file mode 100644 (file)
index 0000000..6ce49a1
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2015 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"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+static WKRetainPtr<WKSessionStateRef> sessionStateWithFirstItemRemoved;
+static WKRetainPtr<WKSessionStateRef> sessionStateWithAllItemsRemoved;
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+static void setPageLoaderClient(WKPageRef page)
+{
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+    WKPageSetPageLoaderClient(page, &loaderClient.base);
+}
+
+static bool filterFirstItemCallback(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context)
+{
+    if (!WKStringIsEqual(valueType, WKPageGetSessionBackForwardListItemValueType()))
+        return true;
+
+    ASSERT(WKGetTypeID(value) == WKBackForwardListItemGetTypeID());
+    WKBackForwardListItemRef backForwardListItem = static_cast<WKBackForwardListItemRef>(value);
+
+    WKRetainPtr<WKURLRef> url = adoptWK(WKBackForwardListItemCopyURL(backForwardListItem));
+    WKRetainPtr<WKStringRef> path = adoptWK(WKURLCopyLastPathComponent(url.get()));
+
+    return !WKStringIsEqualToUTF8CString(path.get(), "simple.html");
+}
+
+static bool filterAllItemsCallback(WKPageRef page, WKStringRef valueType, WKTypeRef value, void* context)
+{
+    return false;
+}
+
+static void createSessionStates(WKContextRef context)
+{
+    PlatformWebView webView(context);
+    setPageLoaderClient(webView.page());
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple2", "html")).get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple3", "html")).get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    WKPageGoBack(webView.page());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    WKPageGoBack(webView.page());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    // Should be back on simple.html at this point.
+
+    sessionStateWithFirstItemRemoved = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), filterFirstItemCallback)));
+    sessionStateWithAllItemsRemoved = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), filterAllItemsCallback)));
+}
+
+TEST(WebKit2, WKPageCopySessionStateWithFiltering)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+
+    createSessionStates(context.get());
+
+    EXPECT_NOT_NULL(sessionStateWithFirstItemRemoved);
+    PlatformWebView webView1(context.get());
+    setPageLoaderClient(webView1.page());
+    WKPageRestoreFromSessionState(webView1.page(), sessionStateWithFirstItemRemoved.get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    WKBackForwardListRef backForwardList1 = WKPageGetBackForwardList(webView1.page());
+    EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList1));
+    EXPECT_EQ(1u, WKBackForwardListGetForwardListCount(backForwardList1));
+
+    EXPECT_NOT_NULL(sessionStateWithAllItemsRemoved);
+    PlatformWebView webView2(context.get());
+    setPageLoaderClient(webView2.page());
+    WKPageRestoreFromSessionState(webView2.page(), sessionStateWithAllItemsRemoved.get());
+    // Because the session state ends up being empty, nothing is actually loaded.
+
+    WKBackForwardListRef backForwardList2 = WKPageGetBackForwardList(webView2.page());
+    EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList2));
+    EXPECT_EQ(0u, WKBackForwardListGetForwardListCount(backForwardList2));
+}
+
+} // namespace TestWebKitAPI
+
+#endif