| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.sub.js"></script> |
| 5 <body> | 5 <body> |
| 6 <script> | 6 <script> |
| 7 | 7 |
| 8 var INSTALL_APPCACHE_URL = "resources/appcache-ordering.install.html"; | 8 var INSTALL_APPCACHE_URL = "resources/appcache-ordering.install.html"; |
| 9 var IS_APPCACHED_URL = "resources/appcache-ordering.is-appcached.html"; | 9 var IS_APPCACHED_URL = "resources/appcache-ordering.is-appcached.html"; |
| 10 var SERVICE_WORKER_SCOPE = "resources/appcache-ordering"; | 10 var SERVICE_WORKER_SCOPE = "resources/appcache-ordering"; |
| 11 var SERVICE_WORKER_SCRIPT = "resources/empty-worker.js"; | 11 var SERVICE_WORKER_SCRIPT = "resources/empty-worker.js"; |
| 12 | 12 |
| 13 var resolve_install_appcache = undefined; | 13 var resolve_install_appcache = undefined; |
| 14 var reject_install_appcache = undefined; | 14 var reject_install_appcache = undefined; |
| 15 | 15 |
| 16 var frames = []; |
| 17 |
| 16 // Called by the INSTALL_APPCACHE_URL child frame. | 18 // Called by the INSTALL_APPCACHE_URL child frame. |
| 17 function notify_appcache_installed(success) { | 19 function notify_appcache_installed(success) { |
| 18 if (success) | 20 if (success) |
| 19 resolve_install_appcache(); | 21 resolve_install_appcache(); |
| 20 else | 22 else |
| 21 reject_install_appcache(); | 23 reject_install_appcache(); |
| 22 } | 24 } |
| 23 | 25 |
| 24 function install_appcache() { | 26 function install_appcache() { |
| 25 return new Promise(function(resolve, reject) { | 27 return new Promise(function(resolve, reject) { |
| 26 var frame = document.createElement('iframe'); | 28 var frame = document.createElement('iframe'); |
| 29 frames.push(frame); |
| 27 frame.src = INSTALL_APPCACHE_URL; | 30 frame.src = INSTALL_APPCACHE_URL; |
| 28 document.body.appendChild(frame); | 31 document.body.appendChild(frame); |
| 29 resolve_install_appcache = function() { | 32 resolve_install_appcache = function() { |
| 30 document.body.removeChild(frame); | 33 document.body.removeChild(frame); |
| 31 resolve(); | 34 resolve(); |
| 32 }; | 35 }; |
| 33 reject_install_appcache = function() { | 36 reject_install_appcache = function() { |
| 34 document.body.removeChild(frame); | 37 document.body.removeChild(frame); |
| 35 reject(); | 38 reject(); |
| 36 }; | 39 }; |
| 37 }); | 40 }); |
| 38 } | 41 } |
| 39 | 42 |
| 40 var resolve_is_appcached = undefined; | 43 var resolve_is_appcached = undefined; |
| 41 | 44 |
| 42 // Called by the IS_APPCACHED_URL child frame. | 45 // Called by the IS_APPCACHED_URL child frame. |
| 43 function notify_is_appcached(is) { | 46 function notify_is_appcached(is) { |
| 44 resolve_is_appcached(is); | 47 resolve_is_appcached(is); |
| 45 } | 48 } |
| 46 | 49 |
| 47 function is_appcached() { | 50 function is_appcached() { |
| 48 return new Promise(function(resolve) { | 51 return new Promise(function(resolve) { |
| 49 var frame = document.createElement('iframe'); | 52 var frame = document.createElement('iframe'); |
| 53 frames.push(frame); |
| 50 frame.src = IS_APPCACHED_URL; | 54 frame.src = IS_APPCACHED_URL; |
| 51 document.body.appendChild(frame); | 55 document.body.appendChild(frame); |
| 52 resolve_is_appcached = function(is) { | 56 resolve_is_appcached = function(is) { |
| 53 document.body.removeChild(frame); | 57 document.body.removeChild(frame); |
| 54 resolve(is); | 58 resolve(is); |
| 55 }; | 59 }; |
| 56 }); | 60 }); |
| 57 } | 61 } |
| 58 | 62 |
| 59 async_test(function(t) { | 63 async_test(function(t) { |
| 60 service_worker_unregister(t, SERVICE_WORKER_SCOPE) | 64 service_worker_unregister(t, SERVICE_WORKER_SCOPE) |
| 61 .then(function() { | 65 .then(function() { |
| 62 return install_appcache(); | 66 return install_appcache(); |
| 63 }) | 67 }) |
| 64 .then(function() { | 68 .then(function() { |
| 65 return is_appcached(); | 69 return is_appcached(); |
| 66 }) | 70 }) |
| 67 .then(function(result) { | 71 .then(function(result) { |
| 68 assert_true(result, 'appcache should initially be utilized'); | 72 assert_true(result, 'appcache should initially be utilized'); |
| 69 return service_worker_unregister_and_register( | 73 return service_worker_unregister_and_register( |
| 70 t, SERVICE_WORKER_SCRIPT, SERVICE_WORKER_SCOPE); | 74 t, SERVICE_WORKER_SCRIPT, SERVICE_WORKER_SCOPE); |
| 71 }) | 75 }) |
| 72 .then(function(r) { | 76 .then(function(r) { |
| 73 return wait_for_state(t, r.installing, 'activated'); | 77 return wait_for_state(t, r.installing, 'activated'); |
| 74 }) | 78 }) |
| 75 .then(function() { | 79 .then(function() { |
| 76 return is_appcached(); | 80 return is_appcached(); |
| 77 }) | 81 }) |
| 78 .then(function(result) { | 82 .then(function(result) { |
| 79 assert_false(result, 'but serviceworkers should take priority'); | 83 assert_false(result, 'but serviceworkers should take priority'); |
| 84 frames.forEach(function(f) { f.remove(); }); |
| 80 service_worker_unregister_and_done(t, SERVICE_WORKER_SCOPE); | 85 service_worker_unregister_and_done(t, SERVICE_WORKER_SCOPE); |
| 81 }) | 86 }) |
| 82 .catch(unreached_rejection(t)); | 87 .catch(unreached_rejection(t)); |
| 83 }, 'serviceworkers take priority over appcaches'); | 88 }, 'serviceworkers take priority over appcaches'); |
| 84 | 89 |
| 85 </script> | 90 </script> |
| 86 </body> | 91 </body> |
| OLD | NEW |