add-error.tentative.https.html (3660B)
1 <!DOCTYPE html> 2 <title>Sub Apps: Error cases for add()</title> 3 <script src="/resources/testdriver.js"></script> 4 <script src="/resources/testdriver-vendor.js"></script> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/subapps-helpers.js"></script> 8 9 <body></body> 10 11 <script> 12 13 promise_test(async t => { 14 const iframe = document.createElement('iframe'); 15 document.body.appendChild(iframe); 16 17 const iframeNavigator = iframe.contentWindow.navigator; 18 const iframeDOMException = iframe.contentWindow.DOMException; 19 20 // Detach the frame. 21 iframe.remove(); 22 23 // At this point the iframe is detached and unloaded, and its execution 24 // context is gone. 25 await promise_rejects_dom(t, 'NotFoundError', iframeDOMException, iframeNavigator.subApps.add({})); 26 }, "The object is no longer associated to a document."); 27 28 promise_test(async t => { 29 const iframe = document.createElement('iframe'); 30 document.body.appendChild(iframe); 31 32 const iframeNavigator = iframe.contentWindow.navigator; 33 const iframeDOMException = iframe.contentWindow.DOMException; 34 t.add_cleanup(() => iframe.remove()); 35 36 await promise_rejects_dom(t, 'InvalidStateError', iframeDOMException, iframeNavigator.subApps.add({})); 37 }, "API is only supported in top-level browsing contexts."); 38 39 promise_test(async t => { 40 const url = '/sub-app'; 41 42 let subapp = { 43 [url]: { "installURL": url } 44 }; 45 46 await promise_rejects_dom(t, 'NotAllowedError', navigator.subApps.add(subapp)); 47 }, 'Missing user activation.'); 48 49 promise_test(async t => { 50 const base_url = '/sub-app-'; 51 52 let add_call_params = {}; 53 for (let i = 0; i < 8; i++) { 54 const url = base_url + i; 55 add_call_params[url] = { "installURL": url }; 56 } 57 58 await test_driver.bless("installing subapps", async function () { 59 await promise_rejects_dom(t, 'DataError', navigator.subApps.add(add_call_params)); 60 }); 61 }, 'Too many subapps at once.'); 62 63 promise_test(async t => { 64 const full_url = document.location.origin + '/sub-app'; 65 66 let add_call_params = { 67 [full_url]: { installURL: full_url }, 68 }; 69 70 await test_driver.bless("installing subapps", async function () { 71 await promise_rejects_dom(t, 'NotSupportedError', navigator.subApps.add(add_call_params)); 72 }); 73 }, 'API supports only root-relative paths.'); 74 75 promise_test(async t => { 76 const url_1 = '/sub-app-1'; 77 const url_2 = '/sub-app-2'; 78 79 let add_call_params = { 80 [url_1]: {installURL: url_1}, 81 [url_2]: {installURL: url_2}, 82 }; 83 84 let mocked_response = [ 85 { "manifestIdPath": url_1, "resultCode": Status.FAILURE }, 86 { "manifestIdPath": url_2, "resultCode": Status.FAILURE } 87 ]; 88 89 let expected_results = { 90 [url_1]: "failure", 91 [url_2]: "failure", 92 }; 93 94 await test_driver.bless("installing a subapp", async function () { 95 await subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results); 96 }); 97 }, 'Service failed to add two sub-apps.'); 98 99 promise_test(async t => { 100 const url_1 = '/sub-app-1'; 101 const url_2 = '/sub-app-2'; 102 103 let add_call_params = { 104 [url_1]: {installURL: url_1}, 105 [url_2]: {installURL: url_2}, 106 }; 107 108 let mocked_response = [ 109 { "manifestIdPath": url_1, "resultCode": Status.SUCCESS }, 110 { "manifestIdPath": url_2, "resultCode": Status.FAILURE } 111 ]; 112 113 let expected_results = { 114 [url_1]: "success", 115 [url_2]: "failure", 116 }; 117 118 await test_driver.bless("installing a subapp", async function () { 119 await subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results); 120 }); 121 }, 'Service added one sub-app failed to add another sub-app.'); 122 123 </script>