2 Distributed under both the W3C Test Suite License [1] and the W3C
3 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
4 policies and contribution forms [3].
6 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
7 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
8 [3] http://www.w3.org/2004/10/27-testcases
20 ['aaa', 'navigationStart', ''],
23 function test_method_exists(method, method_name, properties)
26 if (typeof method === 'function')
27 msg = 'performance.' + method.name + ' is supported!';
29 msg = 'performance.' + method_name + ' is supported!';
30 wp_test(function() { assert_true(typeof method === 'function', msg); }, msg, properties);
33 function test_method_throw_exception(func_str, exception, msg)
35 var exception_name = typeof exception === "object" ? exception.name : exception;
36 var msg = 'Invocation of ' + func_str + ' should throw ' + exception_name + ' Exception.';
37 wp_test(function() { assert_throws(exception, function() {eval(func_str)}, msg); }, msg);
40 function test_noless_than(value, greater_than, msg, properties)
42 wp_test(function () { assert_true(value >= greater_than, msg); }, msg, properties);
45 function test_fail(msg, properties)
47 wp_test(function() { assert_unreached(); }, msg, properties);
50 function test_resource_entries(entries, expected_entries)
52 // This is slightly convoluted so that we can sort the output.
53 var actual_entries = {};
54 var origin = window.location.protocol + "//" + window.location.host;
56 for (var i = 0; i < entries.length; ++i) {
57 var entry = entries[i];
59 for (var expected_entry in expected_entries) {
60 if (entry.name == origin + expected_entry) {
62 if (expected_entry in actual_entries) {
63 test_fail(expected_entry + ' is not expected to have duplicate entries');
65 actual_entries[expected_entry] = entry;
70 test_fail(entries[i].name + ' is not expected to be in the Resource Timing buffer');
75 for (var i in actual_entries) {
79 for (var i in sorted_urls) {
80 var url = sorted_urls[i];
81 test_equals(actual_entries[url].initiatorType,
82 expected_entries[url],
83 origin + url + ' is expected to have initiatorType ' + expected_entries[url]);
85 for (var j in expected_entries) {
86 if (!(j in actual_entries)) {
87 test_fail(origin + j + ' is expected to be in the Resource Timing buffer');
91 function performance_entrylist_checker(type)
95 function entry_check(entry, expectedNames)
97 var msg = 'Entry \"' + entry.name + '\" should be one that we have set.';
98 wp_test(function() { assert_in_array(entry.name, expectedNames, msg); }, msg);
99 test_equals(entry.entryType, entryType, 'entryType should be \"' + entryType + '\".');
100 if (type === "measure") {
101 test_true(isFinite(entry.startTime), 'startTime should be a number.');
102 test_true(isFinite(entry.duration), 'duration should be a number.');
103 } else if (type === "mark") {
104 test_greater_than(entry.startTime, 0, 'startTime should greater than 0.');
105 test_equals(entry.duration, 0, 'duration of mark should be 0.');
109 function entrylist_order_check(entryList)
112 for (var i = 0; i < entryList.length - 1; ++i)
114 if (entryList[i + 1].startTime < entryList[i].startTime) {
122 function entrylist_check(entryList, expectedLength, expectedNames)
124 test_equals(entryList.length, expectedLength, 'There should be ' + expectedLength + ' entries.');
125 test_true(entrylist_order_check(entryList), 'Entries in entrylist should be in order.');
126 for (var i = 0; i < entryList.length; ++i)
128 entry_check(entryList[i], expectedNames);
132 return{"entrylist_check":entrylist_check};
135 function PerformanceContext(context)
137 this.performanceContext = context;
140 PerformanceContext.prototype =
143 initialMeasures: function(item, index, array)
145 this.performanceContext.measure.apply(this.performanceContext, item);
150 this.performanceContext.mark.apply(this.performanceContext, arguments);
155 this.performanceContext.measure.apply(this.performanceContext, arguments);
158 clearMarks: function()
160 this.performanceContext.clearMarks.apply(this.performanceContext, arguments);
164 clearMeasures: function()
166 this.performanceContext.clearMeasures.apply(this.performanceContext, arguments);
170 getEntries: function()
172 return this.performanceContext.getEntries.apply(this.performanceContext, arguments);
175 getEntriesByType: function()
177 return this.performanceContext.getEntriesByType.apply(this.performanceContext, arguments);
180 getEntriesByName: function()
182 return this.performanceContext.getEntriesByName.apply(this.performanceContext, arguments);
185 setResourceTimingBufferSize: function()
187 return this.performanceContext.setResourceTimingBufferSize.apply(this.performanceContext, arguments);
190 registerResourceTimingBufferFullCallback: function(func)
192 this.performanceContext.onresourcetimingbufferfull = func;
195 clearResourceTimings: function()
197 this.performanceContext.clearResourceTimings.apply(this.performanceContext, arguments);