run-url-selection-operation.tentative.https.sub.html (7713B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/common/utils.js"></script> 5 <script src="/shared-storage/resources/util.js"></script> 6 <script src="/fenced-frame/resources/utils.js"></script> 7 8 <body> 9 <script> 10 'use strict'; 11 12 for (const resolve_to_config of [true, false]) { 13 promise_test(async () => { 14 const ancestor_key = token(); 15 let url0 = generateURL("/shared-storage/resources/frame0.html", 16 [ancestor_key]); 17 let url1 = generateURL("/shared-storage/resources/frame1.html", 18 [ancestor_key]); 19 20 await addModuleOnce("/shared-storage/resources/simple-module.js"); 21 22 let select_url_result0 = await sharedStorage.selectURL( 23 "test-url-selection-operation", [{url: url0}, {url: url1}], 24 {data: {'mockResult': 0}, resolveToConfig: resolve_to_config, 25 keepAlive: true}); 26 assert_true(validateSelectURLResult(select_url_result0, resolve_to_config)); 27 attachFencedFrame(select_url_result0, 'opaque-ads'); 28 const result0 = await nextValueFromServer(ancestor_key); 29 assert_equals(result0, "frame0_loaded"); 30 31 let select_url_result1 = await sharedStorage.selectURL( 32 "test-url-selection-operation", [{url: url0}, {url: url1}], 33 {data: {'mockResult': 1}, resolveToConfig: resolve_to_config, 34 keepAlive: true}); 35 assert_true(validateSelectURLResult(select_url_result1, resolve_to_config)); 36 attachFencedFrame(select_url_result1, 'opaque-ads'); 37 const result1 = await nextValueFromServer(ancestor_key); 38 assert_equals(result1, "frame1_loaded"); 39 40 let select_url_result2 = await sharedStorage.selectURL( 41 "test-url-selection-operation", [{url: url0}, {url: url1}], 42 {data: {'mockResult': -1}, resolveToConfig: resolve_to_config, 43 keepAlive: true}); 44 assert_true(validateSelectURLResult(select_url_result2, resolve_to_config)); 45 attachFencedFrame(select_url_result2, 'opaque-ads'); 46 const result2 = await nextValueFromServer(ancestor_key); 47 assert_equals(result2, "frame0_loaded"); 48 }, 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 49 50 promise_test(async t => { 51 try { 52 await addModuleOnce("/shared-storage/resources/simple-module.js"); 53 await sharedStorage.selectURL( 54 "test-url-selection-operation", 55 [{url: "1"}, {url: "2"}, {url: "3"}, {url: "4"}, {url: "5"}, 56 {url: "6"}, {url: "7"}, {url: "8"}, {url: "9"}], 57 {resolveToConfig: resolve_to_config, keepAlive: true}); 58 } catch (e) { 59 assert_equals(e.name, 'DataError'); 60 assert_equals(e.message, 'Length of the \"urls\" parameter is not valid.'); 61 return; 62 } 63 assert_unreached("did not reject"); 64 }, 'selectURL() with urls array length too big, ' + 65 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 66 67 promise_test(async t => { 68 try { 69 await addModuleOnce("/shared-storage/resources/simple-module.js"); 70 await sharedStorage.selectURL( 71 "test-url-selection-operation", 72 [], 73 {resolveToConfig: resolve_to_config, keepAlive: true}); 74 } catch (e) { 75 assert_equals(e.name, 'DataError'); 76 assert_equals(e.message, 'Length of the \"urls\" parameter is not valid.'); 77 return; 78 } 79 assert_unreached("did not reject"); 80 }, 'selectURL() with empty urls array, ' + 81 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 82 83 promise_test(async t => { 84 try { 85 await addModuleOnce("/shared-storage/resources/simple-module.js"); 86 await sharedStorage.selectURL( 87 "test-url-selection-operation", [{ 88 reportingMetadata: { 89 'click': "https://google.com" 90 } 91 }], 92 {resolveToConfig: resolve_to_config, keepAlive: true}); 93 } catch (e) { 94 assert_equals(e.name, 'TypeError'); 95 assert_equals(true, e.message.startsWith( 96 'Failed to execute \'selectURL\' on \'SharedStorage\': ' + 97 'Failed to read the \'url\' property from ' + 98 '\'SharedStorageUrlWithMetadata\':') && 99 e.message.endsWith('Failed to read the \'url\' property from ' + 100 '\'SharedStorageUrlWithMetadata\': Required member is undefined.')); 101 return; 102 } 103 assert_unreached("did not reject"); 104 }, 'selectURL() with missing url, ' + 105 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 106 107 promise_test(async t => { 108 try { 109 await addModuleOnce("/shared-storage/resources/simple-module.js"); 110 await sharedStorage.selectURL( 111 "test-url-selection-operation", [{ 112 url: "https://#" 113 }], 114 {resolveToConfig: resolve_to_config, keepAlive: true}); 115 } catch (e) { 116 assert_equals(e.name, 'DataError'); 117 assert_equals(e.message, 118 'The url \"https://#\" is invalid.'); 119 return; 120 } 121 assert_unreached("did not reject"); 122 }, 'selectURL() with invalid url, ' + 123 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 124 125 promise_test(async t => { 126 try { 127 await addModuleOnce("/shared-storage/resources/simple-module.js"); 128 await sharedStorage.selectURL( 129 "test-url-selection-operation", [{ 130 url: "/shared-storage/resources/frame0.html", 131 reportingMetadata: { 132 'click': "https://#" 133 } 134 }], 135 {resolveToConfig: resolve_to_config, keepAlive: true}); 136 } catch (e) { 137 assert_equals(e.name, 'DataError'); 138 assert_equals(e.message, 139 'The metadata for the url at index 0 has an invalid ' + 140 'or non-HTTPS report_url parameter \"https://#\".'); 141 return; 142 } 143 assert_unreached("did not reject"); 144 }, 'selectURL() with invalid report url ' + 145 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 146 147 promise_test(async t => { 148 try { 149 await addModuleOnce("/shared-storage/resources/simple-module.js"); 150 await sharedStorage.selectURL( 151 "test-url-selection-operation", [{ 152 url: "/shared-storage/resources/frame0.html", 153 reportingMetadata: { 154 'click': "http://google.com" 155 } 156 }], 157 {resolveToConfig: resolve_to_config, keepAlive: true}); 158 } catch (e) { 159 assert_equals(e.name, 'DataError'); 160 assert_equals(e.message, 'The metadata for the url at index 0 has an ' + 161 'invalid or non-HTTPS report_url parameter \"http://google.com\".'); 162 return; 163 } 164 assert_unreached("did not reject"); 165 }, 'selectURL() with http report url, ' + 166 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 167 168 promise_test(async t => { 169 try { 170 await addModuleOnce("/shared-storage/resources/simple-module.js"); 171 await sharedStorage.selectURL( 172 "test-url-selection-operation", [{ 173 url: "/shared-storage/resources/frame0.html", 174 reportingMetadata: {} 175 }], 176 {resolveToConfig: resolve_to_config, keepAlive: true}); 177 } catch (e) { 178 assert_equals(e.name, 'DataError'); 179 assert_equals(e.message, 'selectURL could not get reportingMetadata ' + 180 'object attributes'); 181 return; 182 } 183 assert_unreached("did not reject"); 184 }, 'selectURL() with invalid reportingMetadata ' + 185 'selectURL() resolves to ' + (resolve_to_config ? 'config' : 'urn:uuid')); 186 } 187 188 </script> 189 </body>