<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[207602] branches/safari-602-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207602">207602</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2016-10-20 02:59:48 -0700 (Thu, 20 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/206829">r206829</a>. rdar://problem/28634858</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebKit2ChangeLog">branches/safari-602-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemmm">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemInternalh">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewmm">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessCocoaWebViewImplmm">branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessmacViewGestureControllerMacmm">branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessmacViewSnapshotStoreh">branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h</a></li>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessmacViewSnapshotStoremm">branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm</a></li>
<li><a href="#branchessafari602branchSourceWebKit2WebKit2xcodeprojprojectpbxproj">branches/safari-602-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari602branchToolsChangeLog">branches/safari-602-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemPrivateh">branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h</a></li>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaSnapshotStoremm">branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/ChangeLog (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/ChangeLog        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/ChangeLog        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -1,5 +1,62 @@
</span><span class="cx"> 2016-10-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r206829. rdar://problem/28634858
+
+    2016-10-05  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+            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-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r206247. rdar://problem/28216256
</span><span class="cx"> 
</span><span class="cx">     2016-09-21  Dan Bernstein  &lt;mitz@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -66,6 +66,13 @@
</span><span class="cx">     return *_item;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (CGImageRef)_copySnapshotForTesting
+{
+    if (auto snapshot = _item-&gt;snapshot())
+        return snapshot-&gt;asImageForTesting().leakRef();
+    return nullptr;
+}
+
</ins><span class="cx"> #pragma mark WKObject protocol implementation
</span><span class="cx"> 
</span><span class="cx"> - (API::Object&amp;)_apiObject
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemInternalh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#import &quot;WKBackForwardListItem.h&quot;
</del><ins>+#import &quot;WKBackForwardListItemPrivate.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemPrivatehfromrev207601branchessafari602branchSourceWebKit2UIProcessAPICocoaWKBackForwardListItemInternalh"></a>
<div class="copfile"><h4>Copied: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h (from rev 207601, branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h) (0 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h                                (rev 0)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+/*
+ * 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 &lt;WebKit/WKBackForwardListItem.h&gt;
+
+#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
</ins></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -4607,6 +4607,11 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_disableBackForwardSnapshotVolatilityForTesting
+{
+    WebKit::ViewSnapshotStore::singleton().setDisableSnapshotVolatilityForTesting(true);
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -281,6 +281,8 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
</span><span class="cx"> 
</span><ins>+- (void)_disableBackForwardSnapshotVolatilityForTesting WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -3168,9 +3168,11 @@
</span><span class="cx">     auto surface = WebCore::IOSurface::createFromImage(croppedSnapshotImage.get());
</span><span class="cx">     if (!surface)
</span><span class="cx">         return nullptr;
</span><del>-    surface-&gt;setIsVolatile(true);
</del><span class="cx"> 
</span><del>-    return ViewSnapshot::create(WTFMove(surface));
</del><ins>+    RefPtr&lt;ViewSnapshot&gt; snapshot = ViewSnapshot::create(WTFMove(surface));
+    snapshot-&gt;setVolatile(true);
+
+    return snapshot;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebViewImpl::saveBackForwardSnapshotForCurrentItem()
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessmacViewGestureControllerMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -814,8 +814,8 @@
</span><span class="cx">     if (m_activeGestureType != ViewGestureType::Swipe)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_currentSwipeSnapshot &amp;&amp; m_currentSwipeSnapshot-&gt;surface())
-        m_currentSwipeSnapshot-&gt;surface()-&gt;setIsVolatile(true);
</del><ins>+    if (m_currentSwipeSnapshot)
+        m_currentSwipeSnapshot-&gt;setVolatile(true);
</ins><span class="cx">     m_currentSwipeSnapshot = nullptr;
</span><span class="cx"> 
</span><span class="cx">     for (const auto&amp; layer : m_currentSwipeLiveLayers)
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessmacViewSnapshotStoreh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx">     void clearImage();
</span><span class="cx">     bool hasImage() const;
</span><span class="cx">     id asLayerContents();
</span><ins>+    RetainPtr&lt;CGImageRef&gt; asImageForTesting();
</ins><span class="cx"> 
</span><span class="cx">     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
</span><span class="cx">     uint64_t renderTreeSize() const { return m_renderTreeSize; }
</span><span class="lines">@@ -81,6 +82,8 @@
</span><span class="cx">     WebCore::IntSize size() const { return m_surface ? m_surface-&gt;size() : WebCore::IntSize(); }
</span><span class="cx"> 
</span><span class="cx">     void setSurface(std::unique_ptr&lt;WebCore::IOSurface&gt;);
</span><ins>+
+    WebCore::IOSurface::SurfaceState setVolatile(bool);
</ins><span class="cx"> #else
</span><span class="cx">     WebCore::IntSize size() const { return m_size; }
</span><span class="cx">     size_t imageSizeInBytes() const { return m_imageSizeInBytes; }
</span><span class="lines">@@ -117,6 +120,9 @@
</span><span class="cx"> 
</span><span class="cx">     void discardSnapshotImages();
</span><span class="cx"> 
</span><ins>+    void setDisableSnapshotVolatilityForTesting(bool disable) { m_disableSnapshotVolatility = disable; }
+    bool disableSnapshotVolatilityForTesting() const { return m_disableSnapshotVolatility; }
+
</ins><span class="cx"> #if !USE(IOSURFACE)
</span><span class="cx">     static CAContext *snapshottingContext();
</span><span class="cx"> #endif
</span><span class="lines">@@ -126,9 +132,10 @@
</span><span class="cx">     void willRemoveImageFromSnapshot(ViewSnapshot&amp;);
</span><span class="cx">     void pruneSnapshots(WebPageProxy&amp;);
</span><span class="cx"> 
</span><del>-    size_t m_snapshotCacheSize;
</del><ins>+    size_t m_snapshotCacheSize { 0 };
</ins><span class="cx"> 
</span><span class="cx">     ListHashSet&lt;ViewSnapshot*&gt; m_snapshotsWithImages;
</span><ins>+    bool m_disableSnapshotVolatility { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2UIProcessmacViewSnapshotStoremm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -46,7 +46,6 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> ViewSnapshotStore::ViewSnapshotStore()
</span><del>-    : m_snapshotCacheSize(0)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -201,6 +200,19 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#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-&gt;setIsVolatile(becomeVolatile);
+}
+#endif
+
</ins><span class="cx"> id ViewSnapshot::asLayerContents()
</span><span class="cx"> {
</span><span class="cx"> #if USE(IOSURFACE)
</span><span class="lines">@@ -207,7 +219,7 @@
</span><span class="cx">     if (!m_surface)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    if (m_surface-&gt;setIsVolatile(false) != WebCore::IOSurface::SurfaceState::Valid) {
</del><ins>+    if (setVolatile(false) != WebCore::IOSurface::SurfaceState::Valid) {
</ins><span class="cx">         clearImage();
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="lines">@@ -218,4 +230,18 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RetainPtr&lt;CGImageRef&gt; ViewSnapshot::asImageForTesting()
+{
+#if USE(IOSURFACE)
+    if (!m_surface)
+        return nullptr;
+
+    ASSERT(ViewSnapshotStore::singleton().disableSnapshotVolatilityForTesting());
+    return m_surface-&gt;createImage();
+#else
+    // FIXME: Implement this in the slot case.
+    return nullptr;
+#endif
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="branchessafari602branchSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -715,6 +715,7 @@
</span><span class="cx">                 2DFC7DBB1BCCC19500C1548C /* WebViewImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DFC7DB91BCCC19500C1548C /* WebViewImpl.h */; };
</span><span class="cx">                 2DFC7DBC1BCCC19500C1548C /* WebViewImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DFC7DBA1BCCC19500C1548C /* WebViewImpl.mm */; };
</span><span class="cx">                 2E0B8A7A1BC59A590044B32D /* _WKFormDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E0B8A791BC59A590044B32D /* _WKFormDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                2DFF7B6F1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 2E7A944A1BBD97C300945547 /* _WKFocusedElementInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E7A94491BBD95C600945547 /* _WKFocusedElementInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 31099973146C75A20029DEB9 /* WebNotificationClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31099971146C759B0029DEB9 /* WebNotificationClient.cpp */; };
</span><span class="cx">                 310999C7146C9E3D0029DEB9 /* WebNotificationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 31099968146C71F50029DEB9 /* WebNotificationClient.h */; };
</span><span class="lines">@@ -2738,6 +2739,7 @@
</span><span class="cx">                 2DFC7DB91BCCC19500C1548C /* WebViewImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewImpl.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DFC7DBA1BCCC19500C1548C /* WebViewImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewImpl.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E0B8A791BC59A590044B32D /* _WKFormDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKFormDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItemPrivate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2E7A94491BBD95C600945547 /* _WKFocusedElementInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKFocusedElementInfo.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 31099968146C71F50029DEB9 /* WebNotificationClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebNotificationClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 31099971146C759B0029DEB9 /* WebNotificationClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationClient.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -5164,6 +5166,7 @@
</span><span class="cx">                                 37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */,
</span><span class="cx">                                 37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */,
</span><span class="cx">                                 37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */,
</span><ins>+                                2DFF7B6E1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h */,
</ins><span class="cx">                                 1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */,
</span><span class="cx">                                 1AF4592D19464B2000F9D4A2 /* WKError.h */,
</span><span class="cx">                                 1AF4592C19464B2000F9D4A2 /* WKError.mm */,
</span><span class="lines">@@ -7957,6 +7960,7 @@
</span><span class="cx">                                 51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */,
</span><span class="cx">                                 7CBB81211AA0F970006B1942 /* WKBundleFileHandleRef.h in Headers */,
</span><span class="cx">                                 BCD25F1711D6BDE100169B0E /* WKBundleFrame.h in Headers */,
</span><ins>+                                2DFF7B6F1DA4CFAF00814614 /* WKBackForwardListItemPrivate.h in Headers */,
</ins><span class="cx">                                 BCF049E611FE20F600F86A58 /* WKBundleFramePrivate.h in Headers */,
</span><span class="cx">                                 BC49862F124D18C100D834E1 /* WKBundleHitTestResult.h in Headers */,
</span><span class="cx">                                 BC204EF211C83EC8008F3375 /* WKBundleInitialize.h in Headers */,
</span></span></pre></div>
<a id="branchessafari602branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/ChangeLog (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/ChangeLog        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Tools/ChangeLog        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -1,5 +1,32 @@
</span><span class="cx"> 2016-10-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r206829. rdar://problem/28634858
+
+    2016-10-05  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+            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-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r205329. rdar://problem/28634858
</span><span class="cx"> 
</span><span class="cx">     2016-09-01  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (207601 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-10-20 09:59:42 UTC (rev 207601)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx">                 2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
</span><span class="cx">                 2DE71AFE1D49C0BD00904094 /* AnimatedResize.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */; };
</span><span class="cx">                 2DE71B001D49C3ED00904094 /* blinking-div.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DE71AFF1D49C2F000904094 /* blinking-div.html */; };
</span><ins>+                2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */; };
</ins><span class="cx">                 2E131C181D83A98A001BA36C /* wide-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */; };
</span><span class="cx">                 2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */; };
</span><span class="cx">                 2E1B7B001D41ABA7007558B4 /* large-video-seek-after-ending.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */; };
</span><span class="lines">@@ -758,6 +759,7 @@
</span><span class="cx">                 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = &quot;lots-of-text-vertical-lr.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnimatedResize.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2DE71AFF1D49C2F000904094 /* blinking-div.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;blinking-div.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SnapshotStore.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;wide-autoplaying-video-with-audio.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;autoplaying-video-with-audio.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2E1B7AFF1D41A95F007558B4 /* large-video-seek-after-ending.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;large-video-seek-after-ending.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1340,6 +1342,7 @@
</span><span class="cx">                                 CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
</span><span class="cx">                                 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
</span><span class="cx">                                 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
</span><ins>+                                2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
</ins><span class="cx">                                 515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
</span><span class="cx">                                 7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
</span><span class="cx">                                 7C882E031C80C624006BF731 /* UserContentWorld.mm */,
</span><span class="lines">@@ -2399,6 +2402,7 @@
</span><span class="cx">                                 7CCE7EDE1A411A9200447C4C /* URL.cpp in Sources */,
</span><span class="cx">                                 7CCE7EB01A411A4400447C4C /* URLExtras.mm in Sources */,
</span><span class="cx">                                 7C882E0A1C80C764006BF731 /* UserContentWorld.mm in Sources */,
</span><ins>+                                2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */,
</ins><span class="cx">                                 7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
</span><span class="cx">                                 7C83E04F1D0A641800FEBCF3 /* FileSystem.cpp in Sources */,
</span><span class="cx">                                 7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */,
</span></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaSnapshotStoremm"></a>
<div class="addfile"><h4>Added: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm (0 => 207602)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm                                (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm        2016-10-20 09:59:48 UTC (rev 207602)
</span><span class="lines">@@ -0,0 +1,156 @@
</span><ins>+/*
+ * 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 &quot;config.h&quot;
+#import &lt;WebKit/WKFoundation.h&gt;
+
+#if WK_API_ENABLED &amp;&amp; PLATFORM(MAC)
+
+#import &quot;JavaScriptTest.h&quot;
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;Test.h&quot;
+#import &quot;TestNavigationDelegate.h&quot;
+#import &quot;TestWKWebViewMac.h&quot;
+#import &lt;WebKit/WKBackForwardListItemPrivate.h&gt;
+#import &lt;WebKit/WKWebView.h&gt;
+#import &lt;WebKit/WKWebViewPrivate.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+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:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]]];
+    [self _test_waitForDidFinishNavigation];
+}
+
+@end
+
+static bool imagesAreEqual(CGImageRef first, CGImageRef second)
+{
+    RetainPtr&lt;NSData&gt; firstData = adoptNS((NSData *)CGDataProviderCopyData(CGImageGetDataProvider(first)));
+    RetainPtr&lt;NSData&gt; secondData = adoptNS((NSData *)CGDataProviderCopyData(CGImageGetDataProvider(second)));
+
+    return [firstData isEqualTo:secondData.get()];
+}
+
+TEST(SnapshotStore, SnapshotUponNavigation)
+{
+    RetainPtr&lt;SnapshotTestWKWebView&gt; webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@&quot;simple&quot;];
+
+    RetainPtr&lt;WKBackForwardListItem&gt; firstItem = [[webView backForwardList] currentItem];
+
+    RetainPtr&lt;CGImageRef&gt; imageBeforeNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NULL(imageBeforeNavigation.get());
+
+    [webView loadPageNamed:@&quot;lots-of-text&quot;];
+
+    // After navigating, the first item should have a valid back-forward snapshot.
+    RetainPtr&lt;CGImageRef&gt; imageAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(imageAfterNavigation.get());
+    EXPECT_EQ(CGImageGetWidth(imageAfterNavigation.get()), (unsigned long)800);
+}
+
+TEST(SnapshotStore, SnapshotClearedWhenItemIsRemoved)
+{
+    RetainPtr&lt;SnapshotTestWKWebView&gt; webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@&quot;simple&quot;];
+    [webView loadPageNamed:@&quot;lots-of-text&quot;];
+
+    RetainPtr&lt;WKBackForwardListItem&gt; item = [[webView backForwardList] currentItem];
+
+    [webView loadPageNamed:@&quot;simple&quot;];
+
+    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:@&quot;lots-of-text&quot;];
+
+    // 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&lt;SnapshotTestWKWebView&gt; webView = adoptNS([[SnapshotTestWKWebView alloc] init]);
+
+    [webView loadPageNamed:@&quot;lots-of-text&quot;];
+
+    RetainPtr&lt;WKBackForwardListItem&gt; firstItem = [[webView backForwardList] currentItem];
+    [webView _saveBackForwardSnapshotForItem:firstItem.get()];
+
+    RetainPtr&lt;CGImageRef&gt; initialSnapshot = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(initialSnapshot);
+
+    EXPECT_JS_EQ([webView _pageForTesting], &quot;window.scrollTo(0,100)&quot;, &quot;undefined&quot;);
+    [webView loadPageNamed:@&quot;simple&quot;];
+
+    // After navigating, the first item's snapshot should change.
+    RetainPtr&lt;CGImageRef&gt; snapshotAfterNavigation = adoptCF([firstItem _copySnapshotForTesting]);
+    EXPECT_NOT_NULL(snapshotAfterNavigation.get());
+    EXPECT_FALSE(imagesAreEqual(initialSnapshot.get(), snapshotAfterNavigation.get()));
+}
+
+#endif // WK_API_ENABLED &amp;&amp; PLATFORM(MAC)
</ins></span></pre>
</div>
</div>

</body>
</html>