Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE HTML> | |
| 2 <title>SVGLengthList, replaceItem()</title> | |
| 3 <script src="../../resources/testharness.js"></script> | |
| 4 <script src="../../resources/testharnessreport.js"></script> | |
| 5 <svg width="200" height="200"> | |
| 6 <text id="text1" x="500 1000 1500" y="50"> ABC </text> | |
| 7 <text id="text2" x="500 100 150 50" y="75"> ABC </text> | |
| 8 <text id="text3" x="50 50 100 100 150" y="100"> ABC</text> | |
| 9 <text id="text4" x="100 50 150 150" y="125"> ABC</text> | |
| 10 </svg> | |
| 11 <script> | |
| 12 function assert_list(list, expectedValues) { | |
|
fs
2016/09/19 08:06:42
Could you move this to a helper .js file and use i
| |
| 13 assert_equals(list.numberOfItems, expectedValues.length); | |
| 14 for (var index = 0; index < expectedValues.length; ++index) | |
| 15 assert_equals(list.getItem(index).value, expectedValues[index]); | |
| 16 | |
| 17 assert_throws("IndexSizeError", function() { list.getItem(expectedValues.lengt h); }); | |
| 18 } | |
| 19 | |
| 20 test(function() { | |
| 21 // This is a test of the SVGLengthList.replaceItem() API. | |
| 22 | |
| 23 var svg = document.querySelector("svg"); | |
| 24 var list1 = document.getElementById("text1").x.baseVal; | |
| 25 var list2 = document.getElementById("text2").x.baseVal; | |
| 26 var list3 = document.getElementById("text3").x.baseVal; | |
| 27 var list4 = document.getElementById("text4").x.baseVal; | |
| 28 | |
| 29 // Create three SVGLength objects, with values=50,100,150. | |
| 30 var newLength1 = svg.createSVGLength(); | |
| 31 newLength1.value = 50; | |
| 32 assert_equals(newLength1.value, 50); | |
| 33 | |
| 34 var newLength2 = svg.createSVGLength(); | |
| 35 newLength2.value = 100; | |
| 36 assert_equals(newLength2.value, 100); | |
| 37 | |
| 38 var newLength3 = svg.createSVGLength(); | |
| 39 newLength3.value = 150; | |
| 40 assert_equals(newLength3.value, 150); | |
| 41 | |
| 42 // Check initial list state of text1. | |
| 43 assert_list(list1, [500, 1000, 1500]); | |
| 44 | |
| 45 // Replace the first three values in text1 x list with 'newLength1/2/3'. | |
| 46 assert_equals(list1.replaceItem(newLength1, 0).value, newLength1.value); | |
| 47 assert_equals(list1.replaceItem(newLength2, 1).value, newLength2.value); | |
| 48 assert_equals(list1.replaceItem(newLength3, 2).value, newLength3.value); | |
| 49 assert_throws("IndexSizeError", function() { list1.replaceItem(newLength3, -10 0); }); | |
| 50 assert_throws("IndexSizeError", function() { list1.replaceItem(newLength3, -1) ; }); | |
| 51 assert_throws("IndexSizeError", function() { list1.replaceItem(newLength3, 3); }); | |
| 52 assert_throws("IndexSizeError", function() { list1.replaceItem(newLength3, 100 ); }); | |
| 53 | |
| 54 // Verify that the text1 x value list is correct. | |
| 55 assert_list(list1, [50, 100, 150]); | |
| 56 | |
| 57 // Check initial list state of text2. | |
| 58 assert_list(list2, [500, 100, 150, 50]); | |
| 59 | |
| 60 // Spec: If newItem is already in a list, then a new object is created with th e same values as newItem and this item is inserted into the list. | |
| 61 // Otherwise, newItem itself is inserted into the list. | |
| 62 | |
| 63 // Replace the first item in text2 x list with the fourth item in the list/ | |
| 64 assert_equals(list2.replaceItem(list2.getItem(3), 0).value, 50); | |
| 65 assert_list(list2, [50, 100, 150, 50]); | |
| 66 | |
| 67 // Check initial list state of text3. | |
| 68 assert_list(list3, [50, 50, 100, 100, 150]); | |
| 69 | |
| 70 // Check initial list state of text4. | |
| 71 assert_list(list4, [100, 50, 150, 150]); | |
| 72 | |
| 73 // Replace the first item in text4 x list with the second item in the text3 x list. | |
| 74 assert_equals(list4.replaceItem(list3.getItem(1), 0).value, 50); | |
| 75 assert_list(list3, [50, 50, 100, 100, 150]); | |
| 76 assert_list(list4, [50, 50, 150, 150]); | |
| 77 | |
| 78 // Replace the second item in text4 x list with the third item in the text3 x list. | |
| 79 assert_equals(list4.replaceItem(list3.getItem(2), 1).value, 100); | |
| 80 assert_list(list4, [50, 100, 150, 150]); | |
| 81 | |
| 82 // Replace the items of text3 x list with the same text3 x list. | |
| 83 assert_equals(list3.replaceItem(list3.getItem(2), 1).value, 100); | |
| 84 assert_equals(list3.replaceItem(list3.getItem(4), 2).value, 150); | |
| 85 assert_list(list3, [50, 100, 150, 100, 150]); | |
| 86 | |
| 87 // Check final list state of text1. | |
| 88 assert_list(list1, [50, 100, 150]); | |
| 89 | |
| 90 // Check final list state of text2. | |
| 91 assert_list(list2, [50, 100, 150, 50]); | |
| 92 | |
| 93 // Check final list state of text3. | |
| 94 assert_list(list3, [50, 100, 150, 100, 150]); | |
| 95 | |
| 96 // Check final list state of text4. | |
| 97 assert_list(list4, [50, 100, 150, 150]); | |
| 98 }); | |
| 99 </script> | |
| OLD | NEW |