[Curl] Fix r222147
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / resource-timing / rt-performance-extensions.js
1 test(function(t) {
2     assert_greater_than(performance.getEntriesByType("resource").length, 0, "context should already have some resources");
3     performance.clearResourceTimings();
4     assert_equals(performance.getEntriesByType("resource").length, 0, "clearResourceTimings should have cleared the buffer");
5 }, "performance.clearResourceTimings clears the buffer");
6
7 test(function(t) {
8     performance.clearResourceTimings();
9     performance.clearResourceTimings();
10     performance.clearResourceTimings();
11     assert_equals(performance.getEntriesByType("resource").length, 0, "clearResourceTimings should have cleared the buffer");
12 }, "performance.clearResourceTimings called multiple times is okay");
13
14 promise_test(function(t) {
15     let bufferFullEventDispatched = false;
16     performance.onresourcetimingbufferfull = function(event) {
17         bufferFullEventDispatched = true;
18     };
19
20     return loadResources(3).then(function(entries) {
21         assert_equals(entries.length, 3, "context should have observed 3 resources");
22         assert_equals(performance.getEntriesByType("resource").length, 3, "context should have loaded 4 resources");
23         assert_false(bufferFullEventDispatched, "context should not have dispatched buffer full event");
24     });
25 }, "resourcetimingbufferfull event should not trigger for a small number of resources (browser default buffer size)", {timeout: 3000});
26
27 promise_test(function(t) {
28     restoreEnvironmentToCleanState();
29     assert_equals(performance.getEntriesByType("resource").length, 0, "context should have no resources");
30
31     performance.setResourceTimingBufferSize(1);
32
33     return loadResources(3).then(function(entries) {
34         assert_equals(entries.length, 3, "context should have observed 3 resources");
35         assert_equals(performance.getEntriesByType("resource").length, 1, "context global buffer should be full at 1 resource");
36     });
37 }, "PerformanceObserver sees all resource entries even after buffer is full", {timeout: 3000});
38
39 promise_test(function(t) {
40     restoreEnvironmentToCleanState();
41
42     performance.setResourceTimingBufferSize(3);
43
44     let bufferFullEventDispatched = false;
45     performance.onresourcetimingbufferfull = function(event) {
46         bufferFullEventDispatched = true;
47     };
48
49     return loadResources(2).then(function(entries) {
50         assert_equals(entries.length, 2, "context should have observed 3 resources");
51         assert_equals(performance.getEntriesByType("resource").length, 2, "context global buffer should have 2 resources when full");
52         assert_false(bufferFullEventDispatched, "context should not have dispatched buffer full event");
53     });
54 }, "resourcetimingbufferfull event should not trigger if less than the BufferSizeLimit number of resources are added to the buffer", {timeout: 3000});
55
56 promise_test(function(t) {
57     restoreEnvironmentToCleanState();
58
59     performance.setResourceTimingBufferSize(3);
60
61     let bufferFullEventDispatched = false;
62     performance.onresourcetimingbufferfull = function(event) {
63         bufferFullEventDispatched = true;
64     };
65
66     return loadResources(3).then(function(entries) {
67         assert_equals(entries.length, 3, "context should have observed 3 resources");
68         assert_equals(performance.getEntriesByType("resource").length, 3, "context global buffer should be full at 3 resources");
69         assert_true(bufferFullEventDispatched, "context should not have dispatched buffer full event");
70     });
71 }, "resourcetimingbufferfull event should not trigger if exactly the BufferSizeLimit number of resources are added to the buffer", {timeout: 3000});
72
73 promise_test(function(t) {
74     restoreEnvironmentToCleanState();
75     assert_equals(performance.getEntriesByType("resource").length, 0, "context should have no resources");
76
77     performance.setResourceTimingBufferSize(3);
78
79     let bufferFullEventDispatchedCount = 0;
80     performance.onresourcetimingbufferfull = function(event) {
81         bufferFullEventDispatchedCount++;
82     };
83
84     return loadResources(5).then(function(entries) {
85         assert_equals(entries.length, 5, "context should have observed 3 resources");
86         assert_equals(performance.getEntriesByType("resource").length, 3, "context global buffer should be full at 3 resources");
87         assert_equals(bufferFullEventDispatchedCount, 1, "context should have dispatched the buffer full event just once");
88     });
89 }, "resourcetimingbufferfull event should only trigger once if more than the BufferSizeLimit number of resources are added to the buffer", {timeout: 3000});
90
91 promise_test(function(t) {
92     restoreEnvironmentToCleanState();
93
94     performance.setResourceTimingBufferSize(1);
95
96     let bufferFullEvent = null;
97     performance.onresourcetimingbufferfull = function(event) {
98         bufferFullEvent = event;
99     };
100
101     return loadResources(1).then(function(entries) {
102         assert_equals(entries.length, 1, "context should have observed 1 resource");
103         assert_equals(performance.getEntriesByType("resource").length, 1, "context global buffer should be full at 1 resource");
104         assert_equals(bufferFullEvent.target, performance, "event should dispatch at the performance object");
105         assert_true(bufferFullEvent.bubbles, "event should bubble");
106     });
107 }, "resourcetimingbufferfull event properties", {timeout: 3000});
108
109 promise_test(function(t) {
110     restoreEnvironmentToCleanState();
111
112     performance.setResourceTimingBufferSize(100);
113
114     let bufferFullEventDispatched = false;
115     performance.onresourcetimingbufferfull = function(event) {
116         bufferFullEventDispatched = true;
117     };
118
119     return loadResources(3).then(function(entries) {
120         assert_equals(entries.length, 3, "context should have observed 1 resource");
121         assert_equals(performance.getEntriesByType("resource").length, 3, "context global buffer should be full at 3 resources");
122         assert_false(bufferFullEventDispatched, "event should not have been dispatched");
123
124         let bufferFullEventDispatchedWithSizeChange = false;
125         performance.onresourcetimingbufferfull = function(event) {
126             bufferFullEventDispatchedWithSizeChange = true;
127         };
128
129         performance.setResourceTimingBufferSize(1);
130         assert_false(bufferFullEventDispatchedWithSizeChange, "event should have been dispatched when size limit changed");
131         assert_equals(performance.getEntriesByType("resource").length, 3, "context global buffer should still have 3 resources"); 
132     });
133 }, "performance.setResourceTimingBufferSize set to value less than current BufferSize should not clear existing entries", {timeout: 3000});
134
135 // FIXME: Clarify behavior of setResourceTimingBufferSize
136 // <https://github.com/w3c/resource-timing/issues/96>