diff --git a/testing/web-platform/tests/resources/chromium/nfc-mock.js b/testing/web-platform/tests/resources/chromium/nfc-mock.js index 3a354eedf844c..76c31bf21dac1 100644 --- a/testing/web-platform/tests/resources/chromium/nfc-mock.js +++ b/testing/web-platform/tests/resources/chromium/nfc-mock.js @@ -79,6 +79,34 @@ record . recordType . +startsWith +( +' +: +' +) +) +{ +nfcRecord +. +category += +device +. +mojom +. +NDEFRecordTypeCategory +. +kLocal +; +} +else +if +( +record +. +recordType +. search ( ' diff --git a/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html b/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html index 9a3c81cb1e49b..1f4670a50a352 100644 --- a/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html +++ b/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html @@ -1295,9 +1295,12 @@ / The message +in +the +event contains only -an +the external type record @@ -1331,7 +1334,7 @@ . com : -payloadIsMessage +containsLocalRecord ' ' recordType @@ -1344,22 +1347,15 @@ external type record -' -s -payload -is -a -message -which contains only -a -text +the +local +type record . -const -embeddedRecords -= +assert_equals +( event . message @@ -1372,10 +1368,6 @@ toRecords ( ) -; -assert_equals -( -embeddedRecords . length 1 @@ -1383,31 +1375,75 @@ ; assert_equals ( -embeddedRecords +event +. +message +. +records +[ +0 +] +. +toRecords +( +) [ 0 ] . recordType ' -text +: +containsTextRecord ' ' recordType ' ) ; +/ +/ +The +local +type +record +contains +only +the +text +record +. assert_equals ( -embeddedRecords +event +. +message +. +records [ 0 ] . -mediaType -null +toRecords +( +) +[ +0 +] +. +toRecords +( +) +[ +0 +] +. +recordType +' +text ' -mediaType +' +recordType ' ) ; @@ -1425,7 +1461,25 @@ . decode ( -embeddedRecords +event +. +message +. +records +[ +0 +] +. +toRecords +( +) +[ +0 +] +. +toRecords +( +) [ 0 ] @@ -1463,8 +1517,32 @@ } ) ; +/ +/ +An +external +type +record +- +- +contains +- +> +a +local +type +record +- +- +contains +- +> +a +text +record +. const -payloadMessage +messageContainText = createMessage ( @@ -1477,6 +1555,23 @@ ) ; const +messageContainLocal += +createMessage +( +[ +createRecord +( +' +: +containsTextRecord +' +messageContainText +) +] +) +; +const message = createMessage @@ -1489,9 +1584,9 @@ . com : -payloadIsMessage +containsLocalRecord ' -payloadMessage +messageContainLocal ) ] ) diff --git a/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html b/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html index 2022178d792fe..90ec972fa6442 100644 --- a/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html +++ b/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html @@ -848,10 +848,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -1005,10 +1006,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -1195,10 +1197,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -1383,10 +1386,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2061,10 +2065,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2193,10 +2198,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2395,10 +2401,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2510,10 +2517,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2647,10 +2655,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2833,10 +2842,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -2948,10 +2958,11 @@ smart - poster -records -and external type +and +local +type records could have @@ -3562,70 +3573,115 @@ createRecord ( ' -EMptY +: +xyz ' +test_buffer_data ) ) ' -Unknown -record +The +local type -. +record +must +be +embedded +in +the +payload +of +another +record +( +smart +- +poster +external +or +local +) ' ) ; -assert_throws_js -( -TypeError -( -) +/ +/ +The +following +test +cases +use +an +external +type +record +embedding +our +target +local +type +record +. +const +local_record = -> -new -NDEFRecord -( createRecord ( ' -TeXt +: +xyz ' -test_text_data -) -) +undefined +/ +* +data +* +/ ' -Unknown -record -type -. +dummy_id_for_local_type ' ) ; -assert_throws_js -( -TypeError +const +payload_message += +createMessage ( +[ +local_record +] ) +; +const +external_record_embedding_local_record = -> -new -NDEFRecord -( createRecord ( ' -uRL -' -test_url_data -) -) -' -Unknown -record -type +example . +com +: +foo ' +payload_message ) ; +local_record +. +data += +" +A +string +is +not +a +BufferSource +or +NDEFMessageInit +" +; assert_throws_js ( TypeError @@ -3636,71 +3692,1207 @@ new NDEFRecord ( -createRecord -( -' -Mime -' -test_buffer_data -) +external_record_embedding_local_record ) ' -Unknown +Only +BufferSource +and +NDEFMessageInit +are +allowed +to +be +the record -type +data . ' ) ; -assert_throws_js +let +buffer += +new +ArrayBuffer ( -TypeError +4 +) +; +new +Uint8Array +( +buffer +) +. +set ( +[ +1 +2 +3 +4 +] ) +; +/ +/ +Feed +ArrayBuffer +. +{ +local_record +. +data += +buffer +; +const +record = -> new NDEFRecord ( -createRecord -( -' -sMart -- -PosTER -' -test_url_data -) +external_record_embedding_local_record ) -' -Unknown +; +const +embedded_records += record -type . -' +toRecords +( ) ; -} +assert_equals +( +embedded_records +. +length +1 ' -NDEFRecord -constructor -with +Only +the +one +embedded +local record -type -string -being -treated -as -case -sensitive +. ' ) ; -test -( +/ +/ +The +embedded +local +record +is +actually +from +| +local_record +| +. +assert_equals ( -) -= +embedded_records +[ +0 +] +. +recordType +' +: +xyz +' +' +recordType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +mediaType +null +' +mediaType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +id +' +dummy_id_for_local_type +' +' +id +' +) +; +assert_array_equals +( +new +Uint8Array +( +embedded_records +[ +0 +] +. +data +. +buffer +) +[ +1 +2 +3 +4 +] +' +data +has +the +same +content +with +the +original +buffer +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +toRecords +( +) +null +' +toRecords +( +) +returns +null +if +the +payload +is +not +an +NDEF +message +. +' +) +; +} +/ +/ +Feed +ArrayBufferView +. +{ +let +buffer_view += +new +Uint8Array +( +buffer +1 +) +; +local_record +. +data += +buffer_view +; +const +record += +new +NDEFRecord +( +external_record_embedding_local_record +) +; +const +embedded_records += +record +. +toRecords +( +) +; +assert_equals +( +embedded_records +. +length +1 +' +Only +the +one +embedded +local +record +. +' +) +; +/ +/ +The +embedded +local +record +is +actually +from +| +local_record +| +. +assert_equals +( +embedded_records +[ +0 +] +. +recordType +' +: +xyz +' +' +recordType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +mediaType +null +' +mediaType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +id +' +dummy_id_for_local_type +' +' +id +' +) +; +assert_array_equals +( +new +Uint8Array +( +embedded_records +[ +0 +] +. +data +. +buffer +) +[ +2 +3 +4 +] +' +data +has +the +same +content +with +the +original +buffer +view +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +toRecords +( +) +null +' +toRecords +( +) +returns +null +if +the +payload +is +not +an +NDEF +message +. +' +) +; +} +/ +/ +Feed +NDEFMessageInit +. +{ +const +payload_message += +createMessage +( +[ +createTextRecord +( +test_text_data +) +] +) +; +local_record +. +data += +payload_message +; +const +record += +new +NDEFRecord +( +external_record_embedding_local_record +) +; +const +embedded_records += +record +. +toRecords +( +) +; +assert_equals +( +embedded_records +. +length +1 +' +Only +the +one +embedded +local +record +. +' +) +; +/ +/ +The +embedded +local +record +is +actually +from +| +local_record +| +. +assert_equals +( +embedded_records +[ +0 +] +. +recordType +' +: +xyz +' +' +recordType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +mediaType +null +' +mediaType +' +) +; +assert_equals +( +embedded_records +[ +0 +] +. +id +' +dummy_id_for_local_type +' +' +id +' +) +; +/ +/ +The +embedded +local +record +embeds +another +text +record +that +' +s +from +| +payload_message +| +. +const +embedded_records_in_local_record += +embedded_records +[ +0 +] +. +toRecords +( +) +; +assert_equals +( +embedded_records_in_local_record +. +length +1 +' +Only +one +embedded +record +. +' +) +; +/ +/ +The +only +one +embedded +record +has +correct +content +. +assert_equals +( +embedded_records_in_local_record +[ +0 +] +. +recordType +' +text +' +' +recordType +' +) +; +assert_equals +( +embedded_records_in_local_record +[ +0 +] +. +mediaType +null +' +mediaType +' +) +; +assert_equals +( +embedded_records_in_local_record +[ +0 +] +. +id +test_record_id +' +id +' +) +; +const +decoder += +new +TextDecoder +( +) +; +assert_equals +( +decoder +. +decode +( +embedded_records_in_local_record +[ +0 +] +. +data +) +test_text_data +' +data +has +the +same +content +with +the +original +dictionary +' +) +; +} +} +' +NDEFRecord +constructor +with +local +record +type +' +) +; +test +( +( +) += +> +{ +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +EMptY +' +) +) +' +Unknown +record +type +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +TeXt +' +test_text_data +) +) +' +Unknown +record +type +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +uRL +' +test_url_data +) +) +' +Unknown +record +type +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +Mime +' +test_buffer_data +) +) +' +Unknown +record +type +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +sMart +- +PosTER +' +test_url_data +) +) +' +Unknown +record +type +. +' +) +; +} +' +NDEFRecord +constructor +with +record +type +string +being +treated +as +case +sensitive +' +) +; +test +( +( +) += +> +{ +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +example +. +com +: +hell +' +test_buffer_data +) +) +' +The +external +type +must +be +an +ASCII +string +. +' +) +; +/ +/ +Length +of +the +external +type +is +255 +OK +. +const +record += +new +NDEFRecord +( +createRecord +( +[ +. +. +. +Array +( +251 +) +] +. +map +( +_ += +> +' +a +' +) +. +join +( +' +' +) ++ +' +: +xyz +' +test_buffer_data +) +) +; +/ +/ +Exceeding +255 +Throws +. +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +[ +. +. +. +Array +( +252 +) +] +. +map +( +_ += +> +' +a +' +) +. +join +( +' +' +) ++ +' +: +xyz +' +test_buffer_data +) +) +' +The +external +type +should +not +be +longer +than +255 +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +xyz +' +test_buffer_data +) +) +' +The +external +type +must +have +a +\ +' +: +\ +' +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +: +xyz +' +test_buffer_data +) +) +' +The +domain +should +not +be +empty +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +example +. +com +: +' +test_buffer_data +) +) +' +The +type +should +not +be +empty +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +example +. +com +: +xyz +[ +' +test_buffer_data +) +) +' +The +type +should +not +contain +\ +' +[ +\ +' +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +example +. +com +: +xyz +~ +' +test_buffer_data +) +) +' +The +type +should +not +contain +\ +' +~ +\ +' +. +' +) +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +createRecord +( +' +example +. +com +: +xyz +/ +' +test_buffer_data +) +) +' +The +type +should +not +contain +\ +' +/ +\ +' +. +' +) +; +} +' +NDEFRecord +constructor +with +invalid +external +record +type +' +) +; +test +( +( +) += > { assert_throws_js @@ -3713,21 +4905,159 @@ new NDEFRecord ( -createRecord -( -' -example -. -com -: -hell -' -test_buffer_data -) +createRecord +( +' +: +xyz +' +test_buffer_data +) +) +' +The +local +type +record +must +be +embedded +in +the +payload +of +another +record +( +smart +- +poster +external +or +local +) +' +) +; +/ +/ +The +following +test +cases +use +an +external +type +record +embedding +our +target +local +type +record +. +const +local_record += +createRecord +( +' +: +xyz +' +test_buffer_data +) +; +const +payload_message += +createMessage +( +[ +local_record +] +) +; +const +external_record_embedding_local_record += +createRecord +( +' +example +. +com +: +foo +' +payload_message +) +; +/ +/ +OK +. +new +NDEFRecord +( +external_record_embedding_local_record +) +; +local_record +. +recordType += +' +: +xyZ123 +' +; +new +NDEFRecord +( +external_record_embedding_local_record +) +; +local_record +. +recordType += +' +: +123XYz +' +; +new +NDEFRecord +( +external_record_embedding_local_record +) +; +local_record +. +recordType += +' +: +hell +' +; +assert_throws_js +( +TypeError +( +) += +> +new +NDEFRecord +( +external_record_embedding_local_record ) ' The -external +local type must be @@ -3743,27 +5073,33 @@ Length of the -external +local type +excluding +the +prefix +' +: +' is 255 OK . -const -record +local_record +. +recordType = -new -NDEFRecord -( -createRecord -( +' +: +' ++ [ . . . Array ( -251 +255 ) ] . @@ -3782,13 +5118,14 @@ ' ' ) -+ -' -: -xyz -' -test_buffer_data -) +; +const +record_255 += +new +NDEFRecord +( +external_record_embedding_local_record ) ; / @@ -3797,25 +5134,21 @@ 255 Throws . -assert_throws_js -( -TypeError -( -) +local_record +. +recordType = -> -new -NDEFRecord -( -createRecord -( +' +: +' ++ [ . . . Array ( -252 +256 ) ] . @@ -3834,27 +5167,6 @@ ' ' ) -+ -' -: -xyz -' -test_buffer_data -) -) -' -The -external -type -should -not -be -longer -than -255 -. -' -) ; assert_throws_js ( @@ -3866,91 +5178,37 @@ new NDEFRecord ( -createRecord -( -' -xyz -' -test_buffer_data -) +external_record_embedding_local_record ) ' The -external +local type -must -have -a +excluding +the +prefix \ ' : \ ' -. -' -) -; -assert_throws_js -( -TypeError -( -) -= -> -new -NDEFRecord -( -createRecord -( -' -: -xyz -' -test_buffer_data -) -) -' -The -domain should not be -empty +longer +than +255 . ' ) ; -assert_throws_js -( -TypeError -( -) -= -> -new -NDEFRecord -( -createRecord -( -' -example +local_record . -com -: -' -test_buffer_data -) -) +recordType += ' -The -type -should -not -be -empty -. +xyz ' -) ; assert_throws_js ( @@ -3962,34 +5220,34 @@ new NDEFRecord ( -createRecord -( -' -example -. -com -: -xyz -[ -' -test_buffer_data -) +external_record_embedding_local_record ) ' The +local type -should -not -contain +must +start +with +a \ ' -[ +: \ ' . ' ) ; +local_record +. +recordType += +' +: +Xyz +' +; assert_throws_js ( TypeError @@ -4000,34 +5258,42 @@ new NDEFRecord ( -createRecord -( -' -example -. -com -: -xyz -~ -' -test_buffer_data -) +external_record_embedding_local_record ) ' The +local type -should -not -contain +must +have +a +lower +case +letter +or +digit +following +the +prefix \ ' -~ +: \ ' . ' ) ; +local_record +. +recordType += +' +: +- +xyz +' +; assert_throws_js ( TypeError @@ -4038,28 +5304,26 @@ new NDEFRecord ( -createRecord -( -' -example -. -com -: -xyz -/ -' -test_buffer_data -) +external_record_embedding_local_record ) ' The +local type -should -not -contain +must +have +a +lower +case +letter +or +digit +following +the +prefix \ ' -/ +: \ ' . @@ -4071,10 +5335,10 @@ NDEFRecord constructor with -invalid -external +various +local record -type +types ' ) ; diff --git a/testing/web-platform/tests/web-nfc/NDEFWriter_write.https.html b/testing/web-platform/tests/web-nfc/NDEFWriter_write.https.html index 30ed1bbbb3d23..a9d3371a2011f 100644 --- a/testing/web-platform/tests/web-nfc/NDEFWriter_write.https.html +++ b/testing/web-platform/tests/web-nfc/NDEFWriter_write.https.html @@ -714,7 +714,10 @@ record must be -ArrayBuffer +a +BufferSource +or +NDEFMessageInit . createMessage ( @@ -781,6 +784,108 @@ nfc / # +dfn +- +map +- +local +- +type +- +to +- +ndef +/ +/ +NDEFRecord +must +have +data +. +createMessage +( +[ +createRecord +( +' +: +xyz +' +) +] +) +/ +/ +NDEFRecord +. +data +for +local +type +record +must +be +a +BufferSource +or +NDEFMessageInit +. +createMessage +( +[ +createRecord +( +' +: +xyz +' +test_text_data +) +] +) +createMessage +( +[ +createRecord +( +' +: +xyz +' +test_number_data +) +] +) +createMessage +( +[ +createRecord +( +' +: +xyz +' +test_json_data +) +] +) +/ +/ +https +: +/ +/ +w3c +. +github +. +io +/ +web +- +nfc +/ +# ndef - record @@ -811,13 +916,10 @@ / / valid -custom -type -for -an external +/ +local type -record . createMessage ( @@ -2385,7 +2487,7 @@ > { const -payloadMessage +messageContainText = createMessage ( @@ -2401,15 +2503,46 @@ / Prepare a -message -containing +local +type +record +that +uses +| +messageContainText +| +as +its +payload +. +const +messageContainLocal += +createMessage +( +[ +createRecord +( +' +: +containsTextRecord +' +messageContainText +) +] +) +; +/ +/ +Prepare an external +type record that uses | -payloadMessage +messageContainLocal | as its @@ -2428,9 +2561,9 @@ . com : -payloadIsMessage +containsLocalRecord ' -payloadMessage +messageContainLocal ) ] ) @@ -2501,7 +2634,7 @@ . com : -payloadIsMessage +containsLocalRecord ' ' recordType @@ -2522,8 +2655,106 @@ the original | +messageContainLocal +| +/ +/ +containing +only +the +local +type +record +. +assert_array_equals +( +pushed_message +. +data +[ +0 +] +. +data +new +Uint8Array +( +0 +) +' +payloadMessage +is +used +instead +' +) +; +assert_equals +( +pushed_message +. +data +[ +0 +] +. +payloadMessage +. +data +. +length +1 +) +; +assert_equals +( +pushed_message +. +data +[ +0 +] +. payloadMessage +. +data +[ +0 +] +. +recordType +' +: +containsTextRecord +' +' +recordType +' +) +; +/ +/ +The +local +type +record +' +s +payload +is +from +the +original | +messageContainText +| +/ +/ +containing +only +the +text +record . assert_array_equals ( @@ -2534,6 +2765,13 @@ 0 ] . +payloadMessage +. +data +[ +0 +] +. data new Uint8Array @@ -2550,7 +2788,7 @@ ; assertNDEFMessagesEqual ( -payloadMessage +messageContainText pushed_message . data @@ -2559,6 +2797,13 @@ ] . payloadMessage +. +data +[ +0 +] +. +payloadMessage ) ; }