11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>Blob/Unicode interaction: normalization and encoding</title> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci<script> 71cb0ef41Sopenharmony_ci'use strict'; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst OMICRON_WITH_OXIA = '\u1F79'; // NFC normalized to U+3CC 101cb0ef41Sopenharmony_ciconst CONTAINS_UNPAIRED_SURROGATES = 'abc\uDC00def\uD800ghi'; 111cb0ef41Sopenharmony_ciconst REPLACED = 'abc\uFFFDdef\uFFFDghi'; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction readBlobAsPromise(blob) { 141cb0ef41Sopenharmony_ci return new Promise((resolve, reject) => { 151cb0ef41Sopenharmony_ci const reader = new FileReader(); 161cb0ef41Sopenharmony_ci reader.readAsText(blob); 171cb0ef41Sopenharmony_ci reader.onload = () => resolve(reader.result); 181cb0ef41Sopenharmony_ci reader.onerror = () => reject(reader.error); 191cb0ef41Sopenharmony_ci }); 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cipromise_test(async t => { 231cb0ef41Sopenharmony_ci const blob = new Blob([OMICRON_WITH_OXIA]); 241cb0ef41Sopenharmony_ci const result = await readBlobAsPromise(blob); 251cb0ef41Sopenharmony_ci assert_equals(result, OMICRON_WITH_OXIA, 'String should not be normalized'); 261cb0ef41Sopenharmony_ci}, 'Test that strings are not NFC normalized by Blob constructor'); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_cipromise_test(async t => { 291cb0ef41Sopenharmony_ci const file = new File([OMICRON_WITH_OXIA], 'name'); 301cb0ef41Sopenharmony_ci const result = await readBlobAsPromise(file); 311cb0ef41Sopenharmony_ci assert_equals(result, OMICRON_WITH_OXIA, 'String should not be normalized'); 321cb0ef41Sopenharmony_ci}, 'Test that strings are not NFC normalized by File constructor'); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cipromise_test(async t => { 351cb0ef41Sopenharmony_ci const blob = new Blob([CONTAINS_UNPAIRED_SURROGATES]); 361cb0ef41Sopenharmony_ci const result = await readBlobAsPromise(blob); 371cb0ef41Sopenharmony_ci assert_equals(result, REPLACED, 'Unpaired surrogates should be replaced.'); 381cb0ef41Sopenharmony_ci}, 'Test that unpaired surrogates are replaced by Blob constructor'); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cipromise_test(async t => { 411cb0ef41Sopenharmony_ci const file = new File([CONTAINS_UNPAIRED_SURROGATES], 'name'); 421cb0ef41Sopenharmony_ci const result = await readBlobAsPromise(file); 431cb0ef41Sopenharmony_ci assert_equals(result, REPLACED, 'Unpaired surrogates should be replaced.'); 441cb0ef41Sopenharmony_ci}, 'Test that unpaired surrogates are replaced by File constructor'); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci</script> 47