Title: [206829] trunk
Revision
206829
Author
timothy_hor...@apple.com
Date
2016-10-05 14:14:17 -0700 (Wed, 05 Oct 2016)

Log Message

Make it possible to test ViewSnapshotStore behaviors
https://bugs.webkit.org/show_bug.cgi?id=162983

Reviewed by Simon Fraser.

Add two pieces of SPI to make it easier to test ViewSnapshotStore:

- [WKWebView _disableBackForwardSnapshotVolatilityForTesting]
    This makes it so that we don't make snapshots volatile after we
    take them, so that they won't get purged while the test is running
    and cause the test to be flaky.

- [WKBackForwardListItem _copySnapshotForTesting]
    This returns a CGImage with the content of the given back-forward
    item's current snapshot, if there is one.

* UIProcess/API/Cocoa/WKBackForwardListItem.mm:
(-[WKBackForwardListItem _copySnapshotForTesting]):
* UIProcess/API/Cocoa/WKBackForwardListItemInternal.h:
* UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h: Added.
Add WKBackForwardListItem SPI to retrieve the snapshot for a given back-forward list item.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _disableBackForwardSnapshotVolatilityForTesting]):
Add WKWebView SPI to disable volatility of snapshots, for testing purposes.

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::takeViewSnapshot):
Adopt ViewSnapshot::setVolatile instead of reaching into the surface.

* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::removeSwipeSnapshot):
Adopt ViewSnapshot::setVolatile instead of reaching into the surface.

* UIProcess/mac/ViewSnapshotStore.h:
(WebKit::ViewSnapshotStore::setDisableSnapshotVolatilityForTesting):
(WebKit::ViewSnapshotStore::disableSnapshotVolatilityForTesting):
* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshotStore::ViewSnapshotStore):
(WebKit::ViewSnapshot::setVolatile):
(WebKit::ViewSnapshot::asLayerContents):
Move all touching of snapshot volatility into the new setVolatile,
and short-circuit if the testing-only m_disableSnapshotVolatility bit is set

(WebKit::ViewSnapshot::asImageForTesting):
Make a CGImageRef for the aforementioned WKBackForwardListItem SPI.
This is currently not implemented for the iOS Simulator, because we
don't have access to the bits of the image in that case.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm: Added.
(-[SnapshotTestWKWebView init]):
(-[SnapshotTestWKWebView loadPageNamed:]):
(imagesAreEqual):
Add tests for existing basic snapshotting behavior:

- a back-forward item shouldn't have a snapshot
  until it is navigated away from

- causing a back-forward item to fall out of the
  back-forward list should remove the snapshot

- calling the explicit snapshotting SPI, then navigating away from the page,
  should result in the snapshot being retaken

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (206828 => 206829)


--- trunk/Source/WebKit2/ChangeLog	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/ChangeLog	2016-10-05 21:14:17 UTC (rev 206829)
@@ -1,3 +1,56 @@
+2016-10-05  Tim Horton  <timothy_hor...@apple.com>
+
+        Make it possible to test ViewSnapshotStore behaviors
+        https://bugs.webkit.org/show_bug.cgi?id=162983
+
+        Reviewed by Simon Fraser.
+
+        Add two pieces of SPI to make it easier to test ViewSnapshotStore:
+
+        - [WKWebView _disableBackForwardSnapshotVolatilityForTesting]
+            This makes it so that we don't make snapshots volatile after we
+            take them, so that they won't get purged while the test is running
+            and cause the test to be flaky.
+
+        - [WKBackForwardListItem _copySnapshotForTesting]
+            This returns a CGImage with the content of the given back-forward
+            item's current snapshot, if there is one.
+
+        * UIProcess/API/Cocoa/WKBackForwardListItem.mm:
+        (-[WKBackForwardListItem _copySnapshotForTesting]):
+        * UIProcess/API/Cocoa/WKBackForwardListItemInternal.h:
+        * UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h: Added.
+        Add WKBackForwardListItem SPI to retrieve the snapshot for a given back-forward list item.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _disableBackForwardSnapshotVolatilityForTesting]):
+        Add WKWebView SPI to disable volatility of snapshots, for testing purposes.
+        
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::takeViewSnapshot):
+        Adopt ViewSnapshot::setVolatile instead of reaching into the surface.
+
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::removeSwipeSnapshot):
+        Adopt ViewSnapshot::setVolatile instead of reaching into the surface.
+
+        * UIProcess/mac/ViewSnapshotStore.h:
+        (WebKit::ViewSnapshotStore::setDisableSnapshotVolatilityForTesting):
+        (WebKit::ViewSnapshotStore::disableSnapshotVolatilityForTesting):
+        * UIProcess/mac/ViewSnapshotStore.mm:
+        (WebKit::ViewSnapshotStore::ViewSnapshotStore):
+        (WebKit::ViewSnapshot::setVolatile):
+        (WebKit::ViewSnapshot::asLayerContents):
+        Move all touching of snapshot volatility into the new setVolatile,
+        and short-circuit if the testing-only m_disableSnapshotVolatility bit is set
+
+        (WebKit::ViewSnapshot::asImageForTesting):
+        Make a CGImageRef for the aforementioned WKBackForwardListItem SPI.
+        This is currently not implemented for the iOS Simulator, because we
+        don't have access to the bits of the image in that case.
+
 2016-10-05  Chris Dumez  <cdu...@apple.com>
 
         KeyboardEvent.getModifierState() should support "CapsLock" modifier

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -66,6 +66,13 @@
     return *_item;
 }
 
+- (CGImageRef)_copySnapshotForTesting
+{
+    if (auto snapshot = _item->snapshot())
+        return snapshot->asImageForTesting().leakRef();
+    return nullptr;
+}
+
 #pragma mark WKObject protocol implementation
 
 - (API::Object&)_apiObject

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h	2016-10-05 21:14:17 UTC (rev 206829)
@@ -23,7 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import "WKBackForwardListItem.h"
+#import "WKBackForwardListItemPrivate.h"
 
 #if WK_API_ENABLED
 

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h (0 => 206829)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h	2016-10-05 21:14:17 UTC (rev 206829)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 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 <WebKit/WKBackForwardListItem.h>
+
+#if WK_API_ENABLED
+
+@interface WKBackForwardListItem (WKPrivate)
+
+// For testing only.
+- (CGImageRef)_copySnapshotForTesting WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+@end
+
+#endif

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -4612,6 +4612,11 @@
     });
 }
 
+- (void)_disableBackForwardSnapshotVolatilityForTesting
+{
+    WebKit::ViewSnapshotStore::singleton().setDisableSnapshotVolatilityForTesting(true);
+}
+
 @end
 
 

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-05 21:14:17 UTC (rev 206829)
@@ -287,6 +287,8 @@
 
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 
+- (void)_disableBackForwardSnapshotVolatilityForTesting WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -3175,9 +3175,11 @@
     auto surface = WebCore::IOSurface::createFromImage(croppedSnapshotImage.get());
     if (!surface)
         return nullptr;
-    surface->setIsVolatile(true);
 
-    return ViewSnapshot::create(WTFMove(surface));
+    RefPtr<ViewSnapshot> snapshot = ViewSnapshot::create(WTFMove(surface));
+    snapshot->setVolatile(true);
+
+    return snapshot;
 }
 
 void WebViewImpl::saveBackForwardSnapshotForCurrentItem()

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -799,8 +799,8 @@
     if (m_activeGestureType != ViewGestureType::Swipe)
         return;
 
-    if (m_currentSwipeSnapshot && m_currentSwipeSnapshot->surface())
-        m_currentSwipeSnapshot->surface()->setIsVolatile(true);
+    if (m_currentSwipeSnapshot)
+        m_currentSwipeSnapshot->setVolatile(true);
     m_currentSwipeSnapshot = nullptr;
 
     for (const auto& layer : m_currentSwipeLiveLayers)

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h	2016-10-05 21:14:17 UTC (rev 206829)
@@ -63,6 +63,7 @@
     void clearImage();
     bool hasImage() const;
     id asLayerContents();
+    RetainPtr<CGImageRef> asImageForTesting();
 
     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
     uint64_t renderTreeSize() const { return m_renderTreeSize; }
@@ -80,6 +81,8 @@
     WebCore::IntSize size() const { return m_surface ? m_surface->size() : WebCore::IntSize(); }
 
     void setSurface(std::unique_ptr<WebCore::IOSurface>);
+
+    WebCore::IOSurface::SurfaceState setVolatile(bool);
 #else
     WebCore::IntSize size() const { return m_size; }
     size_t imageSizeInBytes() const { return m_imageSizeInBytes; }
@@ -116,6 +119,9 @@
 
     void discardSnapshotImages();
 
+    void setDisableSnapshotVolatilityForTesting(bool disable) { m_disableSnapshotVolatility = disable; }
+    bool disableSnapshotVolatilityForTesting() const { return m_disableSnapshotVolatility; }
+
 #if !USE(IOSURFACE)
     static CAContext *snapshottingContext();
 #endif
@@ -125,9 +131,10 @@
     void willRemoveImageFromSnapshot(ViewSnapshot&);
     void pruneSnapshots(WebPageProxy&);
 
-    size_t m_snapshotCacheSize;
+    size_t m_snapshotCacheSize { 0 };
 
     ListHashSet<ViewSnapshot*> m_snapshotsWithImages;
+    bool m_disableSnapshotVolatility { false };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm (206828 => 206829)


--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -46,7 +46,6 @@
 namespace WebKit {
 
 ViewSnapshotStore::ViewSnapshotStore()
-    : m_snapshotCacheSize(0)
 {
 }
 
@@ -201,6 +200,19 @@
 #endif
 }
 
+#if USE(IOSURFACE)
+WebCore::IOSurface::SurfaceState ViewSnapshot::setVolatile(bool becomeVolatile)
+{
+    if (ViewSnapshotStore::singleton().disableSnapshotVolatilityForTesting())
+        return WebCore::IOSurface::SurfaceState::Valid;
+
+    if (!m_surface)
+        return WebCore::IOSurface::SurfaceState::Empty;
+
+    return m_surface->setIsVolatile(becomeVolatile);
+}
+#endif
+
 id ViewSnapshot::asLayerContents()
 {
 #if USE(IOSURFACE)
@@ -207,7 +219,7 @@
     if (!m_surface)
         return nullptr;
 
-    if (m_surface->setIsVolatile(false) != WebCore::IOSurface::SurfaceState::Valid) {
+    if (setVolatile(false) != WebCore::IOSurface::SurfaceState::Valid) {
         clearImage();
         return nullptr;
     }
@@ -218,4 +230,18 @@
 #endif
 }
 
+RetainPtr<CGImageRef> ViewSnapshot::asImageForTesting()
+{
+#if USE(IOSURFACE)
+    if (!m_surface)
+        return nullptr;
+
+    ASSERT(ViewSnapshotStore::singleton().disableSnapshotVolatilityForTesting());
+    return m_surface->createImage();
+#else
+    // FIXME: Implement this in the slot case.
+    return nullptr;
+#endif
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (206828 => 206829)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-10-05 21:14:17 UTC (rev 206829)
@@ -712,6 +712,7 @@
 		2DF9EEEE1A786EAD00B6CFBE /* APINavigationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DF9EEED1A786EAD00B6CFBE /* APINavigationResponse.h */; };
 		2DFC7DBB1BCCC19500C1548C /* WebViewImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DFC7DB91BCCC19500C1548C /* WebViewImpl.h */; };
 		2DFC7DBC1BCCC19500C1548C /* WebViewImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DFC7DBA1BCCC19500C1548C /* WebViewImpl.mm */; };
+		2DFF7B6F1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2E7A944A1BBD97C300945547 /* _WKFocusedElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E7A94491BBD95C600945547 /* _WKFocusedElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		31099973146C75A20029DEB9 /* WebNotificationClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31099971146C759B0029DEB9 /* WebNotificationClient.cpp */; };
 		310999C7146C9E3D0029DEB9 /* WebNotificationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 31099968146C71F50029DEB9 /* WebNotificationClient.h */; };
@@ -2764,6 +2765,7 @@
 		2DF9EEED1A786EAD00B6CFBE /* APINavigationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APINavigationResponse.h; sourceTree = "<group>"; };
 		2DFC7DB91BCCC19500C1548C /* WebViewImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewImpl.h; sourceTree = "<group>"; };
 		2DFC7DBA1BCCC19500C1548C /* WebViewImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewImpl.mm; sourceTree = "<group>"; };
+		2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItemPrivate.h; sourceTree = "<group>"; };
 		2E7A94491BBD95C600945547 /* _WKFocusedElementInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKFocusedElementInfo.h; sourceTree = "<group>"; };
 		31099968146C71F50029DEB9 /* WebNotificationClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebNotificationClient.h; sourceTree = "<group>"; };
 		31099971146C759B0029DEB9 /* WebNotificationClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationClient.cpp; sourceTree = "<group>"; };
@@ -5219,6 +5221,7 @@
 				37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */,
 				37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */,
 				37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */,
+				2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */,
 				1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */,
 				1AF4592D19464B2000F9D4A2 /* WKError.h */,
 				1AF4592C19464B2000F9D4A2 /* WKError.mm */,
@@ -8104,6 +8107,7 @@
 				51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */,
 				7CBB81211AA0F970006B1942 /* WKBundleFileHandleRef.h in Headers */,
 				BCD25F1711D6BDE100169B0E /* WKBundleFrame.h in Headers */,
+				2DFF7B6F1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h in Headers */,
 				BCF049E611FE20F600F86A58 /* WKBundleFramePrivate.h in Headers */,
 				BC49862F124D18C100D834E1 /* WKBundleHitTestResult.h in Headers */,
 				BC204EF211C83EC8008F3375 /* WKBundleInitialize.h in Headers */,

Modified: trunk/Tools/ChangeLog (206828 => 206829)


--- trunk/Tools/ChangeLog	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Tools/ChangeLog	2016-10-05 21:14:17 UTC (rev 206829)
@@ -1,3 +1,26 @@
+2016-10-05  Tim Horton  <timothy_hor...@apple.com>
+
+        Make it possible to test ViewSnapshotStore behaviors
+        https://bugs.webkit.org/show_bug.cgi?id=162983
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm: Added.
+        (-[SnapshotTestWKWebView init]):
+        (-[SnapshotTestWKWebView loadPageNamed:]):
+        (imagesAreEqual):
+        Add tests for existing basic snapshotting behavior:
+
+        - a back-forward item shouldn't have a snapshot
+          until it is navigated away from
+
+        - causing a back-forward item to fall out of the
+          back-forward list should remove the snapshot
+
+        - calling the explicit snapshotting SPI, then navigating away from the page,
+          should result in the snapshot being retaken
+
 2016-10-05  Chris Dumez  <cdu...@apple.com>
 
         KeyboardEvent.getModifierState() should support "CapsLock" modifier

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (206828 => 206829)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-10-05 21:12:51 UTC (rev 206828)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-10-05 21:14:17 UTC (rev 206829)
@@ -60,6 +60,7 @@
 		2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
 		2DE71AFE1D49C0BD00904094 /* AnimatedResize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */; };
 		2DE71B001D49C3ED00904094 /* blinking-div.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DE71AFF1D49C2F000904094 /* blinking-div.html */; };
+		2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */; };
 		2E131C181D83A98A001BA36C /* wide-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */; };
 		2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */; };
 		2E1B7B001D41ABA7007558B4 /* large-video-seek-after-ending.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */; };
@@ -788,6 +789,7 @@
 		2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "lots-of-text-vertical-lr.html"; sourceTree = "<group>"; };
 		2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnimatedResize.mm; sourceTree = "<group>"; };
 		2DE71AFF1D49C2F000904094 /* blinking-div.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "blinking-div.html"; sourceTree = "<group>"; };
+		2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SnapshotStore.mm; sourceTree = "<group>"; };
 		2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "wide-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-seek-after-ending.html"; sourceTree = "<group>"; };
@@ -1393,6 +1395,7 @@
 				CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
+				2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
 				515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
 				7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
 				7C882E031C80C624006BF731 /* UserContentWorld.mm */,
@@ -2481,6 +2484,7 @@
 				7CCE7ED31A411A7E00447C4C /* TypingStyleCrash.mm in Sources */,
 				7CCE7EDE1A411A9200447C4C /* URL.cpp in Sources */,
 				7CCE7EB01A411A4400447C4C /* URLExtras.mm in Sources */,
+				2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */,
 				5C6E65441D5CEFD400F7862E /* URLParser.cpp in Sources */,
 				7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
 				7CCE7F2D1A411B1000447C4C /* UserContentTest.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm (0 => 206829)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm	2016-10-05 21:14:17 UTC (rev 206829)
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2016 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED && PLATFORM(MAC)
+
+#import "_javascript_Test.h"
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebViewMac.h"
+#import <WebKit/WKBackForwardListItemPrivate.h>
+#import <WebKit/WKWebView.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+using namespace TestWebKitAPI;
+
+@interface NSWindow ()
+- (void)_setWindowResolution:(CGFloat)resolution displayIfChanged:(BOOL)displayIfChanged;
+@end
+
+@interface WKWebView ()
+- (WKPageRef)_pageForTesting;
+@end
+
+@interface SnapshotTestWKWebView : TestWKWebView
+
+@end
+
+@implementation SnapshotTestWKWebView
+
+- (instancetype)init
+{
+    self = [super initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    if (self) {
+        [self _setOverrideDeviceScaleFactor:1];
+        [self _disableBackForwardSnapshotVolatilityForTesting];
+        [self setAllowsBackForwardNavigationGestures:YES];
+        [self _setWindowOcclusionDetectionEnabled:NO];
+
+        [self.window _setWindowResolution:1 displayIfChanged:YES];
+        [self.window orderBack:nil];
+    }
+    return self;
+}
+
+- (void)loadPageNamed:(NSString *)pageName
+{
+    [self loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:pageName withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+    [self _test_waitForDidFinishNavigation];
+}
+
+@end
+
+static bool imagesAreEqual(CGImageRef first, CGImageRef second)
+{
+    RetainPtr<NSData> firstData = adoptNS((NSData *)CGDataProviderCopyData(CGImageGetDataProvider(first)));
+    RetainPtr<NSData> secondData = adoptNS((NSData *)CGDataProviderCopyData(CGImageGetDataProvider(second)));
+
+    return [firstData isEqualTo:secondData.get()];
+}
+
+TEST(SnapshotStore, SnapshotUponNavigation)
+{
+    RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@"simple"];
+
+    RetainPtr<WKBackForwardListItem> firstItem = [[webView backForwardList] currentItem];
+
+    RetainPtr<CGImageRef> imageBeforeNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NULL(imageBeforeNavigation.get());
+
+    [webView loadPageNamed:@"lots-of-text"];
+
+    // After navigating, the first item should have a valid back-forward snapshot.
+    RetainPtr<CGImageRef> imageAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(imageAfterNavigation.get());
+    EXPECT_EQ(CGImageGetWidth(imageAfterNavigation.get()), (unsigned long)800);
+}
+
+TEST(SnapshotStore, SnapshotClearedWhenItemIsRemoved)
+{
+    RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@"simple"];
+    [webView loadPageNamed:@"lots-of-text"];
+
+    RetainPtr<WKBackForwardListItem> item = [[webView backForwardList] currentItem];
+
+    [webView loadPageNamed:@"simple"];
+
+    EXPECT_NOT_NULL(adoptCF([item _copySnapshotForTesting]).get());
+
+    [webView goBack];
+    [webView _test_waitForDidFinishNavigation];
+    [webView goBack];
+    [webView _test_waitForDidFinishNavigation];
+
+    // The original second item is still in the forward list, and should still have a snapshot.
+    EXPECT_NOT_NULL(adoptCF([item _copySnapshotForTesting]).get());
+
+    [webView loadPageNamed:@"lots-of-text"];
+
+    // The original second item shouldn't have an image anymore, because it was invalidated
+    // by navigating back past it and then doing another load.
+    EXPECT_NULL(adoptCF([item _copySnapshotForTesting]).get());
+}
+
+TEST(SnapshotStore, ExplicitSnapshotsChangeUponNavigation)
+{
+    RetainPtr<SnapshotTestWKWebView> webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@"lots-of-text"];
+
+    RetainPtr<WKBackForwardListItem> firstItem = [[webView backForwardList] currentItem];
+    [webView _saveBackForwardSnapshotForItem:firstItem.get()];
+
+    RetainPtr<CGImageRef> initialSnapshot = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(initialSnapshot);
+
+    EXPECT_JS_EQ([webView _pageForTesting], "window.scrollTo(0,100)", "undefined");
+    [webView loadPageNamed:@"simple"];
+
+    // After navigating, the first item's snapshot should change.
+    RetainPtr<CGImageRef> snapshotAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(snapshotAfterNavigation.get());
+    EXPECT_FALSE(imagesAreEqual(initialSnapshot.get(), snapshotAfterNavigation.get()));
+}
+
+#endif // WK_API_ENABLED && PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to