Bug 1495986 [wpt PR 13325] - AppCache: Add WPTs for AppCache on iframes, a=testonly
authorHiroki Nakagawa <nhiroki@chromium.org>
Tue, 09 Oct 2018 04:13:25 +0000
changeset 498649 4ed3b308efc22ee34d57c9b926b9b82c6671f558
parent 498648 3b573a0ec2a1c250083bc0273f36b158408b5ffb
child 498650 9c5df0a2afe5deb235a4508a43da64baefa0c695
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1495986, 13325, 1245341, 596119
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495986 [wpt PR 13325] - AppCache: Add WPTs for AppCache on iframes, a=testonly Automatic update from web-platform-testsAppCache: Add WPTs for AppCache on iframes Cq-Include-Trybots: luci.chromium.try‚Äč:linux_mojo Change-Id: I6933b37bf1e876f5c622876dd1c84ff830436c6a Bug: n/a Reviewed-on: https://chromium-review.googlesource.com/c/1245341 Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org> Cr-Commit-Position: refs/heads/master@{#596119} -- wpt-commits: 5783f415ebbf2c9199f5d1b0b791fe425e61f57e wpt-pr: 13325
testing/web-platform/tests/html/browsers/offline/appcache/appcache-iframe.https.html
testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-data.py
testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-iframe.manifest
testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-iframe.py
testing/web-platform/tests/html/browsers/offline/appcache/workers/resources/appcache-worker.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/offline/appcache/appcache-iframe.https.html
@@ -0,0 +1,37 @@
+<html manifest="resources/appcache-iframe.manifest">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+const initPromise = new Promise(resolve => {
+  applicationCache.addEventListener('cached', resolve, false);
+  applicationCache.addEventListener('noupdate', resolve, false);
+});
+
+function with_iframe(url) {
+  return new Promise(resolve => {
+      let frame = document.createElement('iframe');
+      frame.src = url;
+      frame.onload = () => { resolve(frame); };
+      document.body.appendChild(frame);
+      add_result_callback(() => frame.remove());
+    });
+}
+
+promise_test(async t => {
+    await initPromise;
+    const frame =
+        await with_iframe('resources/appcache-iframe.py?type=cached');
+    const msgEvent = await new Promise(r => window.onmessage = r);
+    assert_equals(msgEvent.data, 'Done: cached');
+  }, 'iframe should be loaded from application caches.');
+
+promise_test(async t => {
+    await initPromise;
+    const frame =
+        await with_iframe('resources/appcache-iframe.py?type=fallingback');
+    const msgEvent = await new Promise(r => window.onmessage = r);
+    assert_equals(msgEvent.data, 'Done: fallbacked');
+  }, 'iframe should be loaded from application caches for fallback.');
+
+</script>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-data.py
@@ -0,0 +1,5 @@
+def main(request, response):
+    type = request.GET['type']
+    if request.GET['type'] == 'fallingback':
+        return 404, [('Content-Type', 'text/plain')], "Page not found"
+    return [('Content-Type', 'text/plain')], type
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-iframe.manifest
@@ -0,0 +1,8 @@
+CACHE MANIFEST
+
+appcache-iframe.py?type=cached
+appcache-data.py?type=cached
+
+FALLBACK:
+appcache-iframe.py?type=fallingback appcache-iframe.py?type=fallbacked
+appcache-data.py?type=fallingback appcache-data.py?type=fallbacked
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/offline/appcache/resources/appcache-iframe.py
@@ -0,0 +1,43 @@
+script = '''
+<script>
+function fetchCachedFileTest() {
+  return fetch('appcache-data.py?type=cached')
+    .then(res => res.text(),
+          _ => { throw new Error('Failed to fetch cached file'); })
+    .then(text => {
+      if (text != 'cached') {
+        throw new Error('cached file missmatch');
+      }
+    });
+}
+
+function fetchNotInCacheFileTest() {
+  return fetch('appcache-data.py?type=not-in-cache')
+    .then(_ => { throw new Error('Fetching not-in-cache file must fail'); },
+          _ => {});
+}
+
+function fetchFallbackFileTest() {
+  return fetch('appcache-data.py?type=fallingback')
+    .then(res => res.text(),
+          _ => { throw new Error('Failed to fetch fallingback file'); })
+    .then(text => {
+      if (text != 'fallbacked') {
+        throw new Error('fallbacked file miss match');
+      }
+    });
+}
+
+fetchCachedFileTest()
+  .then(fetchNotInCacheFileTest)
+  .then(fetchFallbackFileTest)
+  .then(_ => window.parent.postMessage('Done: %s'),
+        error => window.parent.postMessage(error.toString()));
+</script>
+'''
+
+def main(request, response):
+    type = request.GET['type']
+    if request.GET['type'] == 'fallingback':
+        return 404, [('Content-Type', 'text/plain')], "Page not found"
+    return [('Content-Type', 'text/html')], script % type
--- a/testing/web-platform/tests/html/browsers/offline/appcache/workers/resources/appcache-worker.py
+++ b/testing/web-platform/tests/html/browsers/offline/appcache/workers/resources/appcache-worker.py
@@ -86,16 +86,17 @@ function fetchFallbackFileTest() {
 }
 
 initPromise
   .then(importCachedScriptTest)
   .then(importNotInCacheScriptTest)
   .then(importFallbackScriptTest)
   .then(fetchCachedFileTest)
   .then(fetchNotInCacheFileTest)
+  .then(fetchFallbackFileTest)
   .then(_ => postMessage('Done: %s'),
         error => postMessage(error.toString()));
 '''
 
 def main(request, response):
     type = request.GET['type']
     if request.GET['type'] == 'fallingback':
         return 404, [('Content-Type', 'text/plain')], "Page not found"