| OLD | NEW |
| 1 <script> | 1 <script> |
| 2 var expectedEventData; | 2 var expectedEventData; |
| 3 var capturedEventData; | 3 var capturedEventData; |
| 4 | 4 |
| 5 function expect(data) { | 5 function expect(data) { |
| 6 expectedEventData = data; | 6 expectedEventData = data; |
| 7 capturedEventData = []; | 7 capturedEventData = []; |
| 8 } | 8 } |
| 9 | 9 |
| 10 function checkExpectations() { | 10 function checkExpectations() { |
| 11 if (capturedEventData.length < expectedEventData.length) { | 11 if (capturedEventData.length < expectedEventData.length) { |
| 12 return; | 12 return; |
| 13 } | 13 } |
| 14 chrome.test.assertEq(JSON.stringify(expectedEventData), | 14 chrome.test.assertEq(JSON.stringify(expectedEventData), |
| 15 JSON.stringify(capturedEventData)); | 15 JSON.stringify(capturedEventData)); |
| 16 chrome.test.succeed(); | 16 chrome.test.succeed(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 chrome.experimental.webNavigation.onCommitted.addListener(function(details) { | 19 chrome.experimental.webNavigation.onBeforeNavigate.addListener( |
| 20 console.log('---onCommitted: ' + details.url); | 20 function(details) { |
| 21 console.log('---onBeforeNavigate: ' + details.url); |
| 21 // normalize details. | 22 // normalize details. |
| 22 details.timeStamp = 0; | 23 details.timeStamp = 0; |
| 23 if (details.frameId != 0) { | 24 if (details.frameId != 0) { |
| 24 details.frameId = 1; | 25 details.frameId = 1; |
| 25 } | 26 } |
| 26 capturedEventData.push(details); | 27 capturedEventData.push(["onBeforeNavigate", details]); |
| 28 checkExpectations(); |
| 29 }); |
| 30 |
| 31 chrome.experimental.webNavigation.onCommitted.addListener(function(details) { |
| 32 console.log('---onCommitted: ' + details.url); |
| 33 // normalize details. |
| 34 details.timeStamp = 0; |
| 35 if (details.frameId != 0) { |
| 36 details.frameId = 1; |
| 37 } |
| 38 capturedEventData.push(["onCommitted", details]); |
| 39 checkExpectations(); |
| 40 }); |
| 41 |
| 42 chrome.experimental.webNavigation.onErrorOccurred.addListener( |
| 43 function(details) { |
| 44 console.log('---onErrorOccurred: ' + details.url); |
| 45 // normalize details. |
| 46 details.timeStamp = 0; |
| 47 if (details.frameId != 0) { |
| 48 details.frameId = 1; |
| 49 } |
| 50 capturedEventData.push(["onErrorOccurred", details]); |
| 27 checkExpectations(); | 51 checkExpectations(); |
| 28 }); | 52 }); |
| 29 | 53 |
| 30 var getURL = chrome.extension.getURL; | 54 var getURL = chrome.extension.getURL; |
| 31 chrome.tabs.getSelected(null, function(tab) { | 55 chrome.tabs.getSelected(null, function(tab) { |
| 32 var tabId = tab.id; | 56 var tabId = tab.id; |
| 33 | 57 |
| 34 chrome.test.runTests([ | 58 chrome.test.runTests([ |
| 35 /* Navigates to an URL */ | 59 /* Navigates to an URL */ |
| 36 function simpleLoad() { | 60 function simpleLoad() { |
| 37 expect([ | 61 expect([ |
| 38 { frameId: 0, | 62 [ "onBeforeNavigate", |
| 39 tabId: tabId, | 63 { frameId: 0, |
| 40 timeStamp: 0, | 64 requestId: 0, |
| 41 transitionQualifiers: "", | 65 tabId: tabId, |
| 42 transitionType: "link", | 66 timeStamp: 0, |
| 43 url: getURL('simpleLoad/a.html') }]); | 67 url: getURL('simpleLoad/a.html') }], |
| 44 chrome.tabs.update(tabId, { url: getURL('simpleLoad/a.html') }); | 68 [ "onCommitted", |
| 45 }, | 69 { frameId: 0, |
| 46 | 70 tabId: tabId, |
| 47 /* Navigates to a.html that redirects to b.html (using javascript) | 71 timeStamp: 0, |
| 48 after a delay of 500ms, so the initial navigation is completed and | 72 transitionQualifiers: "", |
| 49 the redirection is marked as client_redirect */ | 73 transitionType: "link", |
| 50 function clientRedirect() { | 74 url: getURL('simpleLoad/a.html') }]]); |
| 51 expect([ | 75 chrome.tabs.update(tabId, { url: getURL('simpleLoad/a.html') }); |
| 52 { frameId: 0, | 76 }, |
| 53 tabId: tabId, | 77 |
| 54 timeStamp: 0, | 78 /* Navigates to a.html that redirects to b.html (using javascript) |
| 55 transitionQualifiers: "", | 79 after a delay of 500ms, so the initial navigation is completed and |
| 56 transitionType: "link", | 80 the redirection is marked as client_redirect */ |
| 57 url: getURL('clientRedirect/a.html') }, | 81 function clientRedirect() { |
| 58 { frameId: 0, | 82 expect([ |
| 59 tabId: tabId, | 83 [ "onBeforeNavigate", |
| 60 timeStamp: 0, | 84 { frameId: 0, |
| 61 transitionQualifiers: "client_redirect", | 85 requestId: 0, |
| 62 transitionType: "link", | 86 tabId: tabId, |
| 63 url: getURL('clientRedirect/b.html') }]); | 87 timeStamp: 0, |
| 64 chrome.tabs.update(tabId, { url: getURL('clientRedirect/a.html') }); | 88 url: getURL('clientRedirect/a.html') }], |
| 65 }, | 89 [ "onCommitted", |
| 66 | 90 { frameId: 0, |
| 67 /* First navigates to a.html which redirects to to b.html which uses | 91 tabId: tabId, |
| 68 history.back() to navigate back to a.html */ | 92 timeStamp: 0, |
| 69 function forwardBack() { | 93 transitionQualifiers: "", |
| 70 expect([ | 94 transitionType: "link", |
| 71 { frameId: 0, | 95 url: getURL('clientRedirect/a.html') }], |
| 72 tabId: tabId, | 96 [ "onBeforeNavigate", |
| 73 timeStamp: 0, | 97 { frameId: 0, |
| 74 transitionQualifiers: "", | 98 requestId: 0, |
| 75 transitionType: "link", | 99 tabId: tabId, |
| 76 url: getURL('forwardBack/a.html') }, | 100 timeStamp: 0, |
| 77 { frameId: 0, | 101 url: getURL('clientRedirect/b.html') }], |
| 78 tabId: tabId, | 102 [ "onCommitted", |
| 79 timeStamp: 0, | 103 { frameId: 0, |
| 80 transitionQualifiers: "client_redirect", | 104 tabId: tabId, |
| 81 transitionType: "link", | 105 timeStamp: 0, |
| 82 url: getURL('forwardBack/b.html') }, | 106 transitionQualifiers: "client_redirect", |
| 83 { frameId: 0, | 107 transitionType: "link", |
| 84 tabId: tabId, | 108 url: getURL('clientRedirect/b.html') }]]); |
| 85 timeStamp: 0, | 109 chrome.tabs.update(tabId, { url: getURL('clientRedirect/a.html') }); |
| 86 transitionQualifiers: "forward_back", | 110 }, |
| 87 transitionType: "link", | 111 |
| 88 url: getURL('forwardBack/a.html') }]); | 112 /* First navigates to a.html which redirects to to b.html which uses |
| 89 chrome.tabs.update(tabId, { url: getURL('forwardBack/a.html') }); | 113 history.back() to navigate back to a.html */ |
| 90 }, | 114 function forwardBack() { |
| 91 | 115 expect([ |
| 92 /* Navigates to a.html which includes b.html as an iframe. b.html | 116 [ "onBeforeNavigate", |
| 93 redirects to c.html. Note that all navigation entries are for | 117 { frameId: 0, |
| 94 a.html. Also, b.html does not generate a navigation entry. */ | 118 requestId: 0, |
| 95 function iframe() { | 119 tabId: tabId, |
| 96 expect([ | 120 timeStamp: 0, |
| 97 { frameId: 0, | 121 url: getURL('forwardBack/a.html') }], |
| 98 tabId: tabId, | 122 [ "onCommitted", |
| 99 timeStamp: 0, | 123 { frameId: 0, |
| 100 transitionQualifiers: "", | 124 tabId: tabId, |
| 101 transitionType: "link", | 125 timeStamp: 0, |
| 102 url: getURL('iframe/a.html') }, | 126 transitionQualifiers: "", |
| 103 { frameId: 1, | 127 transitionType: "link", |
| 104 tabId: tabId, | 128 url: getURL('forwardBack/a.html') }], |
| 105 timeStamp: 0, | 129 [ "onBeforeNavigate", |
| 106 transitionQualifiers: "", | 130 { frameId: 0, |
| 107 transitionType: "link", | 131 requestId: 0, |
| 108 url: getURL('iframe/a.html') }]); | 132 tabId: tabId, |
| 109 chrome.tabs.update(tabId, { url: getURL('iframe/a.html') }); | 133 timeStamp: 0, |
| 110 }, | 134 url: getURL('forwardBack/b.html') }], |
| 111 ]); | 135 [ "onCommitted", |
| 136 { frameId: 0, |
| 137 tabId: tabId, |
| 138 timeStamp: 0, |
| 139 transitionQualifiers: "client_redirect", |
| 140 transitionType: "link", |
| 141 url: getURL('forwardBack/b.html') }], |
| 142 [ "onBeforeNavigate", |
| 143 { frameId: 0, |
| 144 requestId: 0, |
| 145 tabId: tabId, |
| 146 timeStamp: 0, |
| 147 url: getURL('forwardBack/a.html') }], |
| 148 [ "onCommitted", |
| 149 { frameId: 0, |
| 150 tabId: tabId, |
| 151 timeStamp: 0, |
| 152 transitionQualifiers: "forward_back", |
| 153 transitionType: "link", |
| 154 url: getURL('forwardBack/a.html') }]]); |
| 155 chrome.tabs.update(tabId, { url: getURL('forwardBack/a.html') }); |
| 156 }, |
| 157 |
| 158 /* Navigates to a.html which includes b.html as an iframe. b.html |
| 159 redirects to c.html. */ |
| 160 function iframe() { |
| 161 expect([ |
| 162 [ "onBeforeNavigate", |
| 163 { frameId: 0, |
| 164 requestId: 0, |
| 165 tabId: tabId, |
| 166 timeStamp: 0, |
| 167 url: getURL('iframe/a.html') }], |
| 168 [ "onCommitted", |
| 169 { frameId: 0, |
| 170 tabId: tabId, |
| 171 timeStamp: 0, |
| 172 transitionQualifiers: "", |
| 173 transitionType: "link", |
| 174 url: getURL('iframe/a.html') }], |
| 175 [ "onBeforeNavigate", |
| 176 { frameId: 0, |
| 177 requestId: 0, |
| 178 tabId: tabId, |
| 179 timeStamp: 0, |
| 180 url: getURL('iframe/b.html') }], |
| 181 [ "onCommitted", |
| 182 { frameId: 0, |
| 183 tabId: tabId, |
| 184 timeStamp: 0, |
| 185 transitionQualifiers: "", |
| 186 transitionType: "auto_subframe", |
| 187 url: getURL('iframe/b.html') }], |
| 188 [ "onBeforeNavigate", |
| 189 { frameId: 0, |
| 190 requestId: 0, |
| 191 tabId: tabId, |
| 192 timeStamp: 0, |
| 193 url: getURL('iframe/c.html') }], |
| 194 [ "onCommitted", |
| 195 { frameId: 0, |
| 196 tabId: tabId, |
| 197 timeStamp: 0, |
| 198 transitionQualifiers: "", |
| 199 transitionType: "manual_subframe", |
| 200 url: getURL('iframe/c.html') }]]); |
| 201 chrome.tabs.update(tabId, { url: getURL('iframe/a.html') }); |
| 202 }, |
| 203 |
| 204 /* Navigates to a non-existant page. */ |
| 205 function nonExistant() { |
| 206 expect([ |
| 207 [ "onBeforeNavigate", |
| 208 { frameId: 0, |
| 209 requestId: 0, |
| 210 tabId: tabId, |
| 211 timeStamp: 0, |
| 212 url: getURL('nonexistant.html') }], |
| 213 [ "onErrorOccurred", |
| 214 { error: "net::ERR_FILE_NOT_FOUND", |
| 215 frameId: 0, |
| 216 tabId: tabId, |
| 217 timeStamp: 0, |
| 218 url: getURL('nonexistant.html') }], |
| 219 [ "onBeforeNavigate", |
| 220 { frameId: 0, |
| 221 requestId: 0, |
| 222 tabId: tabId, |
| 223 timeStamp: 0, |
| 224 url: "chrome://chromewebdata/"}], |
| 225 [ "onCommitted", |
| 226 { frameId: 0, |
| 227 tabId: tabId, |
| 228 timeStamp: 0, |
| 229 transitionQualifiers: "", |
| 230 transitionType: "link", |
| 231 url: getURL('nonexistant.html') }]]); |
| 232 chrome.tabs.update(tabId, { url: getURL('nonexistant.html') }); |
| 233 }, |
| 234 ]); |
| 112 }); | 235 }); |
| 113 </script> | 236 </script> |
| OLD | NEW |