clearkey-update-non-ascii-input.js (2159B)
1 // This test is only applicable to clearkey 2 function runTest(config, qualifier) 3 { 4 var testname = testnamePrefix(qualifier, config.keysystem) + ' test handling of non-ASCII responses for update()'; 5 6 var configuration = getSimpleConfigurationForContent(config.content); 7 8 if (config.initDataType) { 9 configuration.initDataTypes = [config.initDataType]; 10 } 11 12 promise_test(function (test) { 13 var initDataType; 14 var initData; 15 var mediaKeySession; 16 var messageEventFired = false; 17 18 var p = navigator.requestMediaKeySystemAccess(config.keysystem, [configuration]).then(function (access) { 19 initDataType = access.getConfiguration().initDataTypes[0]; 20 initData = getInitData(config.content, initDataType); 21 return access.createMediaKeys(); 22 }).then(function (mediaKeys) { 23 mediaKeySession = mediaKeys.createSession(); 24 var eventWatcher = new EventWatcher(test, mediaKeySession, ['message']); 25 var promise = eventWatcher.wait_for('message'); 26 mediaKeySession.generateRequest(initDataType, initData); 27 return promise; 28 }).then(function (messageEvent) { 29 // |jwkSet| contains a non-ASCII character \uDC00. 30 var jwkSet = '{"keys":[{' 31 + '"kty":"oct",' 32 + '"k":"MDEyMzQ1Njc4OTAxMjM0NQ",' 33 + '"kid":"MDEyMzQ1Njc4O\uDC00TAxMjM0NQ"' 34 + '}]}'; 35 messageEventFired = true; 36 return messageEvent.target.update(stringToUint8Array(jwkSet)); 37 }).catch(function (error) { 38 // Ensure we reached the update() call we are trying to test. 39 if (!messageEventFired) { 40 assert_unreached( 41 `Failed to reach the update() call. Error: '${error.name}' '${error.message}'`); 42 } 43 44 // Propagate the error on through. 45 throw error; 46 }); 47 48 return promise_rejects_js( 49 test, TypeError, p, 50 'update() should fail because the processed message has non-ASCII character.'); 51 }, testname); 52 }