| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <meta charset="UTF-8" /> | |
| 5 <title>window.performance User Timing mark() method is working properly<
/title> | |
| 6 <link rel="author" title="Microsoft" href="http://www.microsoft.com/" /> | |
| 7 <link rel="help" href="http://127.0.0.1:8000/webperf/specs/UserTiming/#d
om-performance-mark"/> | |
| 8 <script src="/w3c/resources/testharness.js"></script> | |
| 9 <script src="/w3c/resources/testharnessreport.js"></script> | |
| 10 <script src="/w3c/webperf/resources/webperftestharness.js"></script> | |
| 11 | |
| 12 <script type="text/javascript"> | |
| 13 // test data | |
| 14 var markTestDelay = 200; | |
| 15 var testThreshold = 20; | |
| 16 var marks; | |
| 17 | |
| 18 var TEST_MARKS = | |
| 19 [ | |
| 20 { | |
| 21 name: "mark1", | |
| 22 expectedStartTime: undefined, | |
| 23 entryMatch: undefined | |
| 24 }, | |
| 25 { | |
| 26 name: "mark1", | |
| 27 expectedStartTime: undefined, | |
| 28 entryMatch: undefined | |
| 29 } | |
| 30 ]; | |
| 31 | |
| 32 setup({timeout:1000, explicit_done: true}); | |
| 33 | |
| 34 test_namespace(); | |
| 35 | |
| 36 function onload_test() | |
| 37 { | |
| 38 // test for existance of User Timing and Performance Timeline interf
ace | |
| 39 if (window.performance.mark == undefined || | |
| 40 window.performance.clearMarks == undefined || | |
| 41 window.performance.measure == undefined || | |
| 42 window.performance.clearMeasures == undefined || | |
| 43 window.performance.getEntriesByName == undefined || | |
| 44 window.performance.getEntriesByType == undefined || | |
| 45 window.performance.getEntries == undefined) | |
| 46 { | |
| 47 test_true(false, | |
| 48 "The User Timing and Performance Timeline interfaces,
which are required for this test, " + | |
| 49 "are defined."); | |
| 50 | |
| 51 done(); | |
| 52 } | |
| 53 else | |
| 54 { | |
| 55 // create first mark | |
| 56 window.performance.mark(TEST_MARKS[0].name); | |
| 57 | |
| 58 // record the time that this mark is created; this should corres
pond to the mark's startTime | |
| 59 TEST_MARKS[0].expectedStartTime = (new Date()) - window.performa
nce.timing.navigationStart; | |
| 60 | |
| 61 // create the duplicate mark using the test delay; the duplicate
mark's value should be equivalent to | |
| 62 // the loadEventStart navigation timing attribute plus the test
delay | |
| 63 setTimeout(mark_test_cb, markTestDelay); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 function mark_test_cb() | |
| 68 { | |
| 69 var getByNameScenarios = new Array(); | |
| 70 | |
| 71 // create second, duplicate mark | |
| 72 window.performance.mark(TEST_MARKS[1].name); | |
| 73 | |
| 74 // record the time that this mark is created; this should correspond
to the mark's startTime | |
| 75 TEST_MARKS[1].expectedStartTime = (new Date()) - window.performance.
timing.navigationStart; | |
| 76 | |
| 77 // test the test marks are returned by getEntriesByName | |
| 78 entries = window.performance.getEntriesByName(TEST_MARKS[0].name); | |
| 79 test_mark(entries[0], | |
| 80 "window.performance.getEntriesByName(\"" + TEST_MARKS[0].n
ame + "\")[0]", | |
| 81 TEST_MARKS[0].name, | |
| 82 TEST_MARKS[0].expectedStartTime); | |
| 83 TEST_MARKS[0].entryMatch = entries[0]; | |
| 84 | |
| 85 test_mark(entries[1], | |
| 86 "window.performance.getEntriesByName(\"" + TEST_MARKS[1].n
ame + "\")[1]", | |
| 87 TEST_MARKS[1].name, | |
| 88 TEST_MARKS[1].expectedStartTime); | |
| 89 TEST_MARKS[1].entryMatch = entries[1]; | |
| 90 | |
| 91 // test the test marks are returned by getEntriesByName with the ent
ryType parameter provided | |
| 92 entries = window.performance.getEntriesByName(TEST_MARKS[0].name, "m
ark"); | |
| 93 test_equals(entries[0].name, TEST_MARKS[0].name, | |
| 94 "window.performance.getEntriesByName(\"" + TEST_MARKS[0]
.name + "\", \"mark\") returns an " + | |
| 95 "object containing the \"" + TEST_MARKS[0].name + "\" ma
rk in the correct order"); | |
| 96 | |
| 97 test_equals(entries[1].name, TEST_MARKS[1].name, | |
| 98 "window.performance.getEntriesByName(\"" + TEST_MARKS[1]
.name + "\", \"mark\") returns an " + | |
| 99 "object containing the duplicate \"" + TEST_MARKS[1].nam
e + "\" mark in the correct order"); | |
| 100 | |
| 101 test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), | |
| 102 "The \"" + TEST_MARKS[0].name + "\" mark returned by " + | |
| 103 "window.performance.getEntriesByName(\"" + TEST_MARKS[0].n
ame + "\", \"mark\") matches the " + | |
| 104 "the \"" + TEST_MARKS[0].name + "\" mark returned by " + | |
| 105 "window.performance.getEntriesByName(\"" + TEST_MARKS[0].n
ame + "\")"); | |
| 106 | |
| 107 test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), | |
| 108 "The duplicate \"" + TEST_MARKS[1].name + "\" mark returne
d by " + | |
| 109 "window.performance.getEntriesByName(\"" + TEST_MARKS[1].n
ame + "\", \"mark\") matches the " + | |
| 110 "the duplicate \"" + TEST_MARKS[1].name + "\" mark returne
d by " + | |
| 111 "window.performance.getEntriesByName(\"" + TEST_MARKS[1].n
ame + "\")"); | |
| 112 | |
| 113 // test the test marks are returned by getEntries | |
| 114 entries = get_test_entries(window.performance.getEntries(), "mark"); | |
| 115 | |
| 116 test_equals(entries[0].name, TEST_MARKS[0].name, | |
| 117 "window.performance.getEntries() returns an object conta
ining the original \"" + | |
| 118 TEST_MARKS[0].name + "\" mark in the correct order"); | |
| 119 | |
| 120 test_equals(entries[1].name, TEST_MARKS[1].name, | |
| 121 "window.performance.getEntries() returns an object conta
ining the duplicate \"" + | |
| 122 TEST_MARKS[1].name + "\" mark in the correct order"); | |
| 123 | |
| 124 test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), | |
| 125 "The \"" + TEST_MARKS[0].name + "\" mark returned by " + | |
| 126 "window.performance.getEntries() matches the the \"" + TES
T_MARKS[0].name + "\" mark returned " + | |
| 127 "by window.performance.getEntriesByName(\"" + TEST_MARKS[0
].name + "\")"); | |
| 128 | |
| 129 test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), | |
| 130 "The \"" + TEST_MARKS[1].name + "\" mark returned by " + | |
| 131 "window.performance.getEntries() matches the the duplicate
\"" + TEST_MARKS[1].name + "\" mark " + | |
| 132 "returned by window.performance.getEntriesByName(\"" + TES
T_MARKS[1].name + "\")"); | |
| 133 | |
| 134 // test the test marks are returned by getEntriesByType | |
| 135 entries = window.performance.getEntriesByType("mark"); | |
| 136 | |
| 137 test_equals(entries[0].name, TEST_MARKS[0].name, | |
| 138 "window.performance.getEntriesByType(\"mark\") returns a
n object containing the original \"" + | |
| 139 TEST_MARKS[0].name + "\" mark in the correct order"); | |
| 140 | |
| 141 test_equals(entries[1].name, TEST_MARKS[1].name, | |
| 142 "window.performance.getEntriesByType(\"mark\") returns a
n object containing the duplicate \"" + | |
| 143 TEST_MARKS[1].name + "\" mark in the correct order"); | |
| 144 | |
| 145 test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), | |
| 146 "The \"" + TEST_MARKS[0].name + "\" mark returned by " + | |
| 147 "window.performance.getEntriesByType(\"mark\") matches the
the \"" + TEST_MARKS[0].name + | |
| 148 "\" mark returned by window.performance.getEntriesByName(\
"" + TEST_MARKS[0].name + "\")"); | |
| 149 | |
| 150 test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), | |
| 151 "The \"" + TEST_MARKS[1].name + "\" mark returned by " + | |
| 152 "window.performance.getEntriesByType(\"mark\") matches the
the duplicate \"" + | |
| 153 TEST_MARKS[1].name + "\" mark returned by window.performan
ce.getEntriesByName(\"" + | |
| 154 TEST_MARKS[1].name + "\")"); | |
| 155 | |
| 156 done(); | |
| 157 } | |
| 158 | |
| 159 function match_entries(entry1, entry2) | |
| 160 { | |
| 161 var pass = true; | |
| 162 | |
| 163 // match name | |
| 164 pass = pass && (entry1.name == entry2.name); | |
| 165 | |
| 166 // match startTime | |
| 167 pass = pass && (entry1.startTime == entry2.startTime); | |
| 168 | |
| 169 // match entryType | |
| 170 pass = pass && (entry1.entryType == entry2.entryType); | |
| 171 | |
| 172 // match duration | |
| 173 pass = pass && (entry1.duration == entry2.duration); | |
| 174 | |
| 175 return pass; | |
| 176 } | |
| 177 | |
| 178 function test_mark(markEntry, markEntryCommand, expectedName, expectedSt
artTime) | |
| 179 { | |
| 180 // test name | |
| 181 test_equals(markEntry.name, expectedName, markEntryCommand + ".name
== \"" + expectedName + "\""); | |
| 182 | |
| 183 // test startTime, allow for an acceptable threshold in the differen
ce between the startTime and the | |
| 184 // expected value for the startTime (loadEventStart + markTestDelay) | |
| 185 test_true(Math.abs(markEntry.startTime - expectedStartTime) <= testT
hreshold, | |
| 186 markEntryCommand + ".startTime ~== " + " (up to " + testT
hreshold + | |
| 187 "ms difference allowed)"); | |
| 188 | |
| 189 // verify entryType | |
| 190 test_equals(markEntry.entryType, "mark", markEntryCommand + ".entryT
ype == \"mark\""); | |
| 191 | |
| 192 // verify duration | |
| 193 test_equals(markEntry.duration, 0, markEntryCommand + ".duration ==
0"); | |
| 194 } | |
| 195 | |
| 196 function get_test_entries(entryList, entryType) | |
| 197 { | |
| 198 var testEntries = new Array(); | |
| 199 | |
| 200 // filter entryList | |
| 201 for (var i in entryList) | |
| 202 { | |
| 203 if (entryList[i].entryType == entryType) | |
| 204 { | |
| 205 testEntries.push(entryList[i]); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 return testEntries; | |
| 210 } | |
| 211 </script> | |
| 212 </head> | |
| 213 <body onload="onload_test();"> | |
| 214 <h1>Description</h1> | |
| 215 <p>This test validates that the performance.mark() method is working pro
perly. This test creates the | |
| 216 following marks to test this method: | |
| 217 <ul> | |
| 218 <li>"mark1": created using a normal mark() call</li> | |
| 219 <li>"mark1": duplicate of the first mark, used to confirm names
can be re-used</li> | |
| 220 </ul> | |
| 221 After creating each mark, the existence of these marks is validated b
y calling | |
| 222 performance.getEntriesByName() (both with and without the entryType p
arameter provided), | |
| 223 performance.getEntriesByType(), and performance.getEntries() | |
| 224 </p> | |
| 225 | |
| 226 <div id="log"></div> | |
| 227 </body> | |
| 228 </html> | |
| OLD | NEW |