edit-context-textformat.tentative.html (1985B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>EditContext: The TextFormat property</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 </head> 8 <body> 9 <script> 10 test(function() { 11 const textFormat = new TextFormat(); 12 13 assert_equals(textFormat.rangeStart, 0); 14 assert_equals(textFormat.rangeEnd, 0); 15 assert_equals(textFormat.underlineStyle, "none"); 16 assert_equals(textFormat.underlineThickness, "none"); 17 }, 'Test default values of TextFormat attributes'); 18 19 test(function(){ 20 const validUnderlineStyles = ["none", "solid", "dotted", "dashed", "wavy"]; 21 const validUnderlineThicknesses = ["none", "thin", "thick"]; 22 23 // Invalid value should throw type error. 24 assert_throws_js(TypeError, function() { 25 const textFormat = new TextFormat({underlineStyle: "Solid"}); 26 }, 'TextFormat must throw a TypeError when underlineStyle is set to an invalid value'); 27 assert_throws_js(TypeError, function() { 28 const textFormat = new TextFormat({underlineThickness: "Thick"}); 29 }, 'TextFormat must throw a TypeError when underlineThickness is set to an invalid value'); 30 31 // Verify valid values. 32 for (const style of validUnderlineStyles) { 33 const textFormat = new TextFormat({underlineStyle: style}); 34 assert_equals(textFormat.underlineStyle, style, `underlineStyle should accept "${style}"`); 35 assert_equals(textFormat.underlineThickness, "none", 'default value of underlineThickness should be "none"'); 36 } 37 for (const thickness of validUnderlineThicknesses) { 38 const textFormat = new TextFormat({underlineThickness: thickness}); 39 assert_equals(textFormat.underlineStyle, "none", 'default value of underlineStyle should be "none"'); 40 assert_equals(textFormat.underlineThickness, thickness, `underlineThickness should accept "${thickness}"`); 41 } 42 }, 'Test valid values of TextFormat underlineStyle and underlineThickness'); 43 </script> 44 </body> 45 </html>