Make it possible to test ViewSnapshotStore behaviors
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 21:14:17 +0000 (21:14 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 21:14:17 +0000 (21:14 +0000)
commit1cc87a0f00fc01f80016826fe11b9add0d366d5d
treef93541c57bca4939f1283f28c092eb3303d7dd7e
parenta511ce77a5c554cc09bffdd04d96ae9bd352c969
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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206829 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItem.mm
Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemInternal.h
Source/WebKit2/UIProcess/API/Cocoa/WKBackForwardListItemPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/SnapshotStore.mm [new file with mode: 0644]