michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Checks that newtab is updated as its links change. michael@0: */ michael@0: michael@0: function runTests() { michael@0: if (NewTabUtils.allPages.updateScheduledForHiddenPages) { michael@0: // Wait for dynamic updates triggered by the previous test to finish. michael@0: yield whenPagesUpdated(null, true); michael@0: } michael@0: michael@0: // First, start with an empty page. setLinks will trigger a hidden page michael@0: // update because it calls clearHistory. We need to wait for that update to michael@0: // happen so that the next time we wait for a page update below, we catch the michael@0: // right update and not the one triggered by setLinks. michael@0: // michael@0: // Why this weird way of yielding? First, these two functions don't return michael@0: // promises, they call TestRunner.next when done. Second, the point at which michael@0: // setLinks is done is independent of when the page update will happen, so michael@0: // calling whenPagesUpdated cannot wait until that time. michael@0: setLinks([]); michael@0: whenPagesUpdated(null, true); michael@0: yield null; michael@0: yield null; michael@0: michael@0: // Strategy: Add some visits, open a new page, check the grid, repeat. michael@0: fillHistory([link(1)]); michael@0: yield whenPagesUpdated(null, true); michael@0: yield addNewTabPageTab(); michael@0: checkGrid("1,,,,,,,,"); michael@0: michael@0: fillHistory([link(2)]); michael@0: yield whenPagesUpdated(null, true); michael@0: yield addNewTabPageTab(); michael@0: checkGrid("2,1,,,,,,,"); michael@0: michael@0: fillHistory([link(1)]); michael@0: yield whenPagesUpdated(null, true); michael@0: yield addNewTabPageTab(); michael@0: checkGrid("1,2,,,,,,,"); michael@0: michael@0: // Wait for fillHistory to add all links before waiting for an update michael@0: yield fillHistory([link(2), link(3), link(4)], TestRunner.next); michael@0: yield whenPagesUpdated(null, true); michael@0: yield addNewTabPageTab(); michael@0: checkGrid("2,1,3,4,,,,,"); michael@0: } michael@0: michael@0: function link(id) { michael@0: return { url: "http://example.com/#" + id, title: "site#" + id }; michael@0: }