| <!-- webkit-test-runner [ enableBackForwardCache=true ] --> |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/js-test-resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description('Tests that a page with pending DOMCache activity goes into the page cache.'); |
| jsTestIsAsync = true; |
| let restoredFromPageCache = false; |
| |
| window.addEventListener("pageshow", function(event) { |
| debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache"); |
| if (event.persisted) { |
| testPassed("Page was restored from Page Cache"); |
| restoredFromPageCache = true; |
| handle2 = setTimeout(() => { |
| testFailed("Page restored from cache but the promise was not resolved."); |
| finishJSTest(); |
| }, 10000); |
| } |
| }); |
| |
| function tryCache() |
| { |
| cache.add('../navigation/resources/blank.txt').then(() => { |
| if (!restoredFromPageCache) { |
| setTimeout(tryCache, 0); |
| return; |
| } |
| testPassed("Cache.add() succeeded after restoring from the cache"); |
| clearTimeout(handle2); |
| finishJSTest(); |
| }, (e) => { |
| setTimeout(tryCache, 0); |
| }); |
| } |
| |
| window.addEventListener("pagehide", function(event) { |
| debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache"); |
| if (!event.persisted) { |
| testFailed("Page failed to enter the Page Cache"); |
| finishJSTest(); |
| } |
| |
| tryCache(); |
| }); |
| |
| async function clearExistingCache() |
| { |
| try { |
| await self.caches.delete('page-cache-test'); |
| } catch (e) { |
| } |
| } |
| |
| onload = () => { |
| clearExistingCache(); |
| |
| setTimeout(() => { |
| handle1 = setTimeout(() => { |
| testFailed("Timed out while waiting for the cache to open"); |
| finishJSTest(); |
| }, 10000); |
| caches.open('page-cache-test').then((_cache) => { |
| clearTimeout(handle1); |
| cache = _cache; |
| testLink.click(); |
| }, (e) => { |
| testFailed("Failed to open the cache: " + e); |
| finishJSTest(); |
| }); |
| }, 0); |
| } |
| </script> |
| <a id="testLink" href="../navigation/resources/page-cache-helper.html" style="display: none">Link</a> |
| </body> |
| </html> |