| OLD | NEW |
| 1 <script> | 1 <script> |
| 2 // Description | 2 // Description |
| 3 | 3 |
| 4 var expectedEventData; | 4 var expectedEventData; |
| 5 var capturedEventData; | 5 var capturedEventData; |
| 6 var shouldIgnore; | 6 var shouldIgnore; |
| 7 | 7 |
| 8 function expect(data, ignoreFunc) { | 8 function expect(data, ignoreFunc) { |
| 9 expectedEventData = data; | 9 expectedEventData = data; |
| 10 capturedEventData = []; | 10 capturedEventData = []; |
| 11 shouldIgnore = ignoreFunc; | 11 shouldIgnore = ignoreFunc; |
| 12 } | 12 } |
| 13 | 13 |
| 14 function checkExpectations() { | 14 function checkExpectations() { |
| 15 if (capturedEventData.length < expectedEventData.length) { | 15 if (capturedEventData.length < expectedEventData.length) { |
| 16 return; | 16 return; |
| 17 } | 17 } |
| 18 chrome.test.assertEq(JSON.stringify(expectedEventData), | 18 chrome.test.assertEq(JSON.stringify(expectedEventData), |
| 19 JSON.stringify(capturedEventData)); | 19 JSON.stringify(capturedEventData)); |
| 20 chrome.test.succeed(); | 20 chrome.test.succeed(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 var getURL = chrome.extension.getURL; | 23 var getURL = chrome.extension.getURL; |
| 24 | 24 |
| 25 chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { | 25 chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { |
| 26 console.log('---onUpdated: ' + info.status + ', ' + info.url); | 26 console.log('---onUpdated: status=' + info.status + ', url=' + info.url + |
| 27 ', socketAddress=' + tab.socketAddress); |
| 27 if (shouldIgnore && shouldIgnore(info)) { | 28 if (shouldIgnore && shouldIgnore(info)) { |
| 28 return; | 29 return; |
| 29 } | 30 } |
| 31 info.socketAddress = tab.socketAddress; // Makes comparing easier. |
| 30 capturedEventData.push(info); | 32 capturedEventData.push(info); |
| 31 checkExpectations(); | 33 checkExpectations(); |
| 32 }); | 34 }); |
| 33 | 35 |
| 34 chrome.test.runTests([ | 36 chrome.test.getConfig(function(config) { |
| 35 function browserThenRendererInitiated() { | 37 chrome.test.runTests([ |
| 36 // Note that a.html will set it's location.href to b.html, creating a | 38 function browserThenRendererInitiated() { |
| 37 // renderer-initiated navigation. | 39 // Note that a.html will set it's location.href to b.html, creating a |
| 38 expect([ | 40 // renderer-initiated navigation. |
| 39 { status: 'loading', url: getURL('browserThenRendererInitiated/a.html') }, | 41 expect([ |
| 40 { status: 'complete' }, | 42 { status: 'loading', |
| 41 { status: 'loading', url: getURL('browserThenRendererInitiated/b.html') }, | 43 url: getURL('browserThenRendererInitiated/a.html') }, |
| 42 { status: 'complete' }, | 44 { status: 'complete' }, |
| 43 ]); | 45 { status: 'loading', |
| 46 url: getURL('browserThenRendererInitiated/b.html') }, |
| 47 { status: 'complete' }, |
| 48 ]); |
| 44 | 49 |
| 45 chrome.tabs.create({ url: getURL('browserThenRendererInitiated/a.html') });
| 50 chrome.tabs.create({ |
| 46 }, | 51 url: getURL('browserThenRendererInitiated/a.html') }); |
| 52 }, |
| 47 | 53 |
| 48 function newTab() { | 54 function newTab() { |
| 49 // Test for crbug.com/27208. | 55 // Test for crbug.com/27208. |
| 50 expect([ | 56 expect([ |
| 51 { status: 'loading', url: 'chrome://newtab/' }, | 57 { status: 'loading', url: 'chrome://newtab/' }, |
| 52 { status: 'complete' } | 58 { status: 'complete' } |
| 53 ]); | 59 ]); |
| 54 | 60 |
| 55 chrome.tabs.create({ url: 'chrome://newtab/' }); | 61 chrome.tabs.create({ url: 'chrome://newtab/' }); |
| 56 }, | 62 }, |
| 57 | 63 |
| 58 /* | 64 /* |
| 59 // TODO(rafaelw) -- This is disabled because this test is flakey. | 65 // TODO(rafaelw) -- This is disabled because this test is flakey. |
| 60 function updateDuringCreateCallback() { | 66 function updateDuringCreateCallback() { |
| 61 // Test for crbug.com/27204. | 67 // Test for crbug.com/27204. |
| 62 // We have to ignore anything that comes before the about:blank loading | 68 // We have to ignore anything that comes before the about:blank loading |
| 63 // status. | 69 // status. |
| 64 var ignore = true; | 70 var ignore = true; |
| 65 expect([ | 71 expect([ |
| 66 { status: 'loading', url: 'about:blank' }, | 72 { status: 'loading', url: 'about:blank' }, |
| 67 { status: 'complete' } | 73 { status: 'complete' } |
| 68 ], function(info) { | 74 ], function(info) { |
| 69 if (info.status === 'loading' && info.url === 'about:blank') { | 75 if (info.status === 'loading' && info.url === 'about:blank') { |
| 70 ignore = false; | 76 ignore = false; |
| 77 } |
| 78 return ignore; |
| 79 }); |
| 80 |
| 81 chrome.tabs.create({ url: 'chrome://newtab/' }, function(tab) { |
| 82 chrome.tabs.update(tab.id, { url: 'about:blank' }); |
| 83 }); |
| 84 }, */ |
| 85 |
| 86 function iframeNavigated() { |
| 87 // The sequence of events goes like this: |
| 88 // -a.html starts loading |
| 89 // -while a.html is loading, iframe1.html (in it's onload) navigates to |
| 90 // iframe2.html. This causes the page to continue to be in the loading |
| 91 // state so the 'complete' status doesn't fire. |
| 92 // -iframe2.html does a setTimeout to navigate itself to iframe3.html. |
| 93 // This allows the page to stop loading and the 'complete' status to fire, |
| 94 // but when the timeout fires, the pages goes back into the loading state |
| 95 // which causes the new status: 'loading' event to fire without having |
| 96 // changed the url. |
| 97 expect([ |
| 98 { status: 'loading', url: getURL('iframeNavigated/a.html') }, |
| 99 { status: 'complete' }, |
| 100 { status: 'loading' }, |
| 101 { status: 'complete' }, |
| 102 ]); |
| 103 |
| 104 chrome.tabs.create({ url: getURL('iframeNavigated/a.html') }); |
| 105 }, |
| 106 |
| 107 function internalAnchorNavigated() { |
| 108 expect([ |
| 109 { status: 'loading', url: getURL('internalAnchorNavigated/a.html') }, |
| 110 { status: 'complete' }, |
| 111 { status: 'loading', url: getURL('internalAnchorNavigated/a.html#b') }, |
| 112 { status: 'complete' }, |
| 113 ]); |
| 114 |
| 115 chrome.tabs.create({ url: getURL('internalAnchorNavigated/a.html') }); |
| 116 }, |
| 117 |
| 118 function getSocketAddress() { |
| 119 function fixPort(url) { |
| 120 return url.replace(/PORT/, config.testServer.port); |
| 71 } | 121 } |
| 72 return ignore; | 122 var urlA = fixPort("http://a.com:PORT/files/extensions/test_file.html"); |
| 73 }); | 123 var sockAddr = fixPort("127.0.0.1:PORT"); |
| 74 | 124 |
| 75 chrome.tabs.create({ url: 'chrome://newtab/' }, function(tab) { | 125 expect([ |
| 76 chrome.tabs.update(tab.id, { url: 'about:blank' }); | 126 { status: 'loading', url: urlA }, |
| 77 }); | 127 { status: 'complete', socketAddress: sockAddr }, |
| 78 }, */ | 128 ]); |
| 79 | 129 |
| 80 function iframeNavigated() { | 130 chrome.tabs.create({ url: urlA }); |
| 81 // The sequence of events goes like this: | 131 } |
| 82 // -a.html starts loading | 132 ]); |
| 83 // -while a.html is loading, iframe1.html (in it's onload) navigates to | 133 }); |
| 84 // iframe2.html. This causes the page to continue to be in the loading state | 134 </script> |
| 85 // so the 'complete' status doesn't fire. | |
| 86 // -iframe2.html does a setTimeout to navigate itself to iframe3.html. This | |
| 87 // allows the page to stop loading and the 'complete' status to fire, but | |
| 88 // when the timeout fires, the pages goes back into the loading state | |
| 89 // which causes the new status: 'loading' event to fire without having | |
| 90 // changed the url. | |
| 91 expect([ | |
| 92 { status: 'loading', url: getURL('iframeNavigated/a.html') }, | |
| 93 { status: 'complete' }, | |
| 94 { status: 'loading' }, | |
| 95 { status: 'complete' }, | |
| 96 ]); | |
| 97 | |
| 98 chrome.tabs.create({ url: getURL('iframeNavigated/a.html') }); | |
| 99 }, | |
| 100 | |
| 101 function internalAnchorNavigated() { | |
| 102 expect([ | |
| 103 { status: 'loading', url: getURL('internalAnchorNavigated/a.html') }, | |
| 104 { status: 'complete' }, | |
| 105 { status: 'loading', url: getURL('internalAnchorNavigated/a.html#b') }, | |
| 106 { status: 'complete' }, | |
| 107 ]); | |
| 108 | |
| 109 chrome.tabs.create({ url: getURL('internalAnchorNavigated/a.html') }); | |
| 110 } | |
| 111 ]); | |
| 112 </script> | |
| OLD | NEW |