|
11 | 11 | <script> |
12 | 12 | promise_setup(async () => { |
13 | 13 | await waitForDocumentReady(); |
14 | | - console.log('Document ready'); |
15 | 14 | await test_driver.bidi.speculation.prefetch_status_updated.subscribe(); |
16 | | - console.log('Setup: Subscribed to prefetch_status_updated events'); |
17 | 15 | }); |
18 | 16 |
|
19 | 17 | promise_test(async t => { |
20 | | - console.log('Test 1: Starting basic prefetch test'); |
21 | 18 |
|
22 | 19 | const receivedEvents = []; |
23 | 20 | const expectedEvents = ['pending', 'ready']; |
|
32 | 29 | const validStatuses = ['pending', 'running', 'ready', 'success', 'failure']; |
33 | 30 | assert_true(validStatuses.includes(event.status), |
34 | 31 | `Event status should be one of ${validStatuses.join(', ')}, got: ${event.status}`); |
35 | | - |
36 | | - console.log("URL: " + event.url + " with event status: " + event.status + " received"); |
37 | 32 |
|
38 | 33 | // When we receive the ready event, clean up and resolve |
39 | 34 | if (event.status === 'ready') { |
40 | | - console.log('Received ready event, completing test'); |
41 | 35 | removeHandler(); |
42 | 36 | resolve(); |
43 | 37 | } |
|
61 | 55 |
|
62 | 56 | // Await the ready event |
63 | 57 | await readyEventPromise; |
64 | | - |
65 | | - console.log(`Test 1 completed, received ${receivedEvents.length} events`); |
66 | 58 |
|
67 | 59 | // Assert that we received the expected events |
68 | 60 | assert_true(receivedEvents.length >= 2, |
|
72 | 64 | expectedEvents, |
73 | 65 | 'Should have received pending and ready events in order' |
74 | 66 | ); |
75 | | - console.log('✅ Test 1 passed: received expected events'); |
76 | 67 |
|
77 | 68 | }, "prefetch_status_updated event subscription and structure validation"); |
78 | 69 |
|
79 | 70 | promise_test(async t => { |
80 | | - console.log('Test 2: Starting prefetch with navigation test'); |
81 | 71 |
|
82 | 72 | const receivedEvents = []; |
83 | 73 | const expectedEvents = ['pending', 'ready', 'success']; |
84 | 74 | let newWindow = null; |
85 | | - |
86 | | - console.log('Starting prefetch with navigation test'); |
87 | 75 |
|
88 | 76 | // Create a promise that resolves when we receive the 'success' event |
89 | 77 | const successEventPromise = new Promise((resolve, reject) => { |
90 | 78 | const removeHandler = test_driver.bidi.speculation.prefetch_status_updated.on((event) => { |
91 | | - console.log('Test 2: Received prefetch event:', event); |
92 | 79 | receivedEvents.push(event); |
93 | 80 |
|
94 | 81 | // Status should be one of the expected values |
95 | 82 | const validStatuses = ['pending', 'running', 'ready', 'success', 'failure']; |
96 | 83 | assert_true(validStatuses.includes(event.status), |
97 | 84 | `Event status should be one of ${validStatuses.join(', ')}, got: ${event.status}`); |
98 | | - |
99 | | - console.log("Test 2 - URL: " + event.url + " with event status: " + event.status + " received"); |
100 | 85 |
|
101 | 86 | // When we receive the ready event, navigate to trigger success |
102 | 87 | if (event.status === 'ready') { |
103 | | - console.log('Test 2: Received ready event, opening prefetched page in new window...'); |
104 | 88 | // Open the prefetched page in a new window to trigger success |
105 | 89 | newWindow = window.open(event.url, '_blank'); |
106 | 90 |
|
107 | 91 | } else if (event.status === 'success') { |
108 | | - console.log('Test 2: Received success event, completing test'); |
109 | 92 | removeHandler(); |
110 | 93 | resolve(); |
111 | 94 | } |
|
114 | 97 |
|
115 | 98 | // Create prefetch rules for our target page in resources (different URL to avoid caching) |
116 | 99 | const targetUrl = window.location.origin + "/infrastructure/testdriver/bidi/speculation/resources/target.html?test=2"; |
117 | | - console.log('Setting up prefetch for:', targetUrl); |
118 | 100 |
|
119 | 101 | const speculationRules = { |
120 | 102 | prefetch: [{ |
|
123 | 105 | }] |
124 | 106 | }; |
125 | 107 |
|
126 | | - console.log('Adding speculation rules:', JSON.stringify(speculationRules)); |
127 | | - |
128 | 108 | // Use helper function to add both speculation rules and link |
129 | 109 | const { script, link } = addSpeculationRulesAndLink(speculationRules, targetUrl); |
130 | | - |
131 | | - console.log('Speculation rules and link added, waiting for success event...'); |
132 | | - |
| 110 | + |
133 | 111 | // Await the success event |
134 | 112 | await successEventPromise; |
135 | | - |
136 | | - console.log(`Test 2 completed, received ${receivedEvents.length} events`); |
137 | 113 |
|
138 | 114 | // Assert that we received the expected events |
139 | 115 | assert_true(receivedEvents.length >= 3, |
|
143 | 119 | expectedEvents, |
144 | 120 | 'Should have received pending, ready, and success events in order' |
145 | 121 | ); |
146 | | - console.log('✅ Test 2 passed: received expected events including success'); |
147 | 122 |
|
148 | 123 | t.add_cleanup(() => { |
149 | 124 | if (newWindow && !newWindow.closed) { |
|
154 | 129 | }, "prefetch_status_updated event with navigation to success"); |
155 | 130 |
|
156 | 131 | promise_test(async t => { |
157 | | - console.log('Test 3: Starting prefetch failure test'); |
158 | | - |
| 132 | + |
159 | 133 | const receivedEvents = []; |
160 | 134 | const expectedEvents = ['pending', 'failure']; |
161 | | - |
162 | | - console.log('Starting prefetch failure test'); |
163 | 135 |
|
164 | 136 | // Create a promise that resolves when we receive the 'failure' event |
165 | 137 | const failureEventPromise = new Promise((resolve, reject) => { |
166 | 138 | const removeHandler = test_driver.bidi.speculation.prefetch_status_updated.on((event) => { |
167 | | - console.log('Test 3: Received prefetch event:', event); |
168 | 139 | receivedEvents.push(event); |
169 | 140 |
|
170 | 141 | // Status should be one of the expected values |
171 | 142 | const validStatuses = ['pending', 'running', 'ready', 'success', 'failure']; |
172 | 143 | assert_true(validStatuses.includes(event.status), |
173 | 144 | `Event status should be one of ${validStatuses.join(', ')}, got: ${event.status}`); |
174 | | - |
175 | | - console.log("Test 3 - URL: " + event.url + " with event status: " + event.status + " received"); |
176 | 145 |
|
177 | 146 | // When we receive the failure event, we're done |
178 | 147 | if (event.status === 'failure') { |
179 | | - console.log('Test 3: Received failure event, completing test'); |
180 | 148 | removeHandler(); |
181 | 149 | resolve(); |
182 | 150 | } |
|
185 | 153 |
|
186 | 154 | // Create prefetch rules for a non-existent page that should fail with 404 |
187 | 155 | const errorUrl = window.location.origin + "/infrastructure/testdriver/bidi/speculation/resources/nonexistent-404-page.html"; |
188 | | - console.log('Setting up prefetch for non-existent page:', errorUrl); |
189 | 156 |
|
190 | 157 | const speculationRules = { |
191 | 158 | prefetch: [{ |
|
194 | 161 | }] |
195 | 162 | }; |
196 | 163 |
|
197 | | - console.log('Adding speculation rules:', JSON.stringify(speculationRules)); |
198 | | - |
199 | 164 | // Use helper function to add both speculation rules and link |
200 | 165 | const { script, link } = addSpeculationRulesAndLink(speculationRules, errorUrl); |
201 | 166 |
|
202 | | - console.log('Speculation rules and link added, waiting for failure event...'); |
203 | | - |
204 | 167 | // Await the failure event |
205 | 168 | await failureEventPromise; |
206 | | - |
207 | | - console.log(`Test 3 completed, received ${receivedEvents.length} events`); |
208 | 169 |
|
209 | 170 | // Assert that we received the expected events |
210 | 171 | assert_true(receivedEvents.length >= 2, |
|
214 | 175 | expectedEvents, |
215 | 176 | 'Should have received pending and failure events in order' |
216 | 177 | ); |
217 | | - console.log('✅ Test 3 passed: received expected events including failure'); |
218 | 178 |
|
219 | 179 | }, "prefetch_status_updated event with prefetch failure"); |
220 | 180 |
|
|
0 commit comments