| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 // Description | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 var expectedEventData; | 4 * LICENSE file. |
| 5 var capturedEventData; | 5 --> |
| 6 var shouldIgnore; | 6 <script src="test.js"></script> |
| 7 | |
| 8 function expect(data, ignoreFunc) { | |
| 9 expectedEventData = data; | |
| 10 capturedEventData = []; | |
| 11 shouldIgnore = ignoreFunc; | |
| 12 } | |
| 13 | |
| 14 function checkExpectations() { | |
| 15 if (capturedEventData.length < expectedEventData.length) { | |
| 16 return; | |
| 17 } | |
| 18 chrome.test.assertEq(JSON.stringify(expectedEventData), | |
| 19 JSON.stringify(capturedEventData)); | |
| 20 chrome.test.succeed(); | |
| 21 } | |
| 22 | |
| 23 var getURL = chrome.extension.getURL; | |
| 24 | |
| 25 chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { | |
| 26 console.log('---onUpdated: ' + info.status + ', ' + info.url); | |
| 27 if (shouldIgnore && shouldIgnore(info)) { | |
| 28 return; | |
| 29 } | |
| 30 capturedEventData.push(info); | |
| 31 checkExpectations(); | |
| 32 }); | |
| 33 | |
| 34 chrome.test.runTests([ | |
| 35 function browserThenRendererInitiated() { | |
| 36 // Note that a.html will set it's location.href to b.html, creating a | |
| 37 // renderer-initiated navigation. | |
| 38 expect([ | |
| 39 { status: 'loading', url: getURL('browserThenRendererInitiated/a.html') }, | |
| 40 { status: 'complete' }, | |
| 41 { status: 'loading', url: getURL('browserThenRendererInitiated/b.html') }, | |
| 42 { status: 'complete' }, | |
| 43 ]); | |
| 44 | |
| 45 chrome.tabs.create({ url: getURL('browserThenRendererInitiated/a.html') });
| |
| 46 }, | |
| 47 | |
| 48 function newTab() { | |
| 49 // Test for crbug.com/27208. | |
| 50 expect([ | |
| 51 { status: 'loading', url: 'chrome://newtab/' }, | |
| 52 { status: 'complete' } | |
| 53 ]); | |
| 54 | |
| 55 chrome.tabs.create({ url: 'chrome://newtab/' }); | |
| 56 }, | |
| 57 | |
| 58 /* | |
| 59 // TODO(rafaelw) -- This is disabled because this test is flakey. | |
| 60 function updateDuringCreateCallback() { | |
| 61 // Test for crbug.com/27204. | |
| 62 // We have to ignore anything that comes before the about:blank loading | |
| 63 // status. | |
| 64 var ignore = true; | |
| 65 expect([ | |
| 66 { status: 'loading', url: 'about:blank' }, | |
| 67 { status: 'complete' } | |
| 68 ], function(info) { | |
| 69 if (info.status === 'loading' && info.url === 'about:blank') { | |
| 70 ignore = false; | |
| 71 } | |
| 72 return ignore; | |
| 73 }); | |
| 74 | |
| 75 chrome.tabs.create({ url: 'chrome://newtab/' }, function(tab) { | |
| 76 chrome.tabs.update(tab.id, { url: 'about:blank' }); | |
| 77 }); | |
| 78 }, */ | |
| 79 | |
| 80 function iframeNavigated() { | |
| 81 // The sequence of events goes like this: | |
| 82 // -a.html starts loading | |
| 83 // -while a.html is loading, iframe1.html (in it's onload) navigates to | |
| 84 // iframe2.html. This causes the page to continue to be in the loading state | |
| 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 |