1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/newtab/browser_newtab_update.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Checks that newtab is updated as its links change. 1.9 + */ 1.10 + 1.11 +function runTests() { 1.12 + if (NewTabUtils.allPages.updateScheduledForHiddenPages) { 1.13 + // Wait for dynamic updates triggered by the previous test to finish. 1.14 + yield whenPagesUpdated(null, true); 1.15 + } 1.16 + 1.17 + // First, start with an empty page. setLinks will trigger a hidden page 1.18 + // update because it calls clearHistory. We need to wait for that update to 1.19 + // happen so that the next time we wait for a page update below, we catch the 1.20 + // right update and not the one triggered by setLinks. 1.21 + // 1.22 + // Why this weird way of yielding? First, these two functions don't return 1.23 + // promises, they call TestRunner.next when done. Second, the point at which 1.24 + // setLinks is done is independent of when the page update will happen, so 1.25 + // calling whenPagesUpdated cannot wait until that time. 1.26 + setLinks([]); 1.27 + whenPagesUpdated(null, true); 1.28 + yield null; 1.29 + yield null; 1.30 + 1.31 + // Strategy: Add some visits, open a new page, check the grid, repeat. 1.32 + fillHistory([link(1)]); 1.33 + yield whenPagesUpdated(null, true); 1.34 + yield addNewTabPageTab(); 1.35 + checkGrid("1,,,,,,,,"); 1.36 + 1.37 + fillHistory([link(2)]); 1.38 + yield whenPagesUpdated(null, true); 1.39 + yield addNewTabPageTab(); 1.40 + checkGrid("2,1,,,,,,,"); 1.41 + 1.42 + fillHistory([link(1)]); 1.43 + yield whenPagesUpdated(null, true); 1.44 + yield addNewTabPageTab(); 1.45 + checkGrid("1,2,,,,,,,"); 1.46 + 1.47 + // Wait for fillHistory to add all links before waiting for an update 1.48 + yield fillHistory([link(2), link(3), link(4)], TestRunner.next); 1.49 + yield whenPagesUpdated(null, true); 1.50 + yield addNewTabPageTab(); 1.51 + checkGrid("2,1,3,4,,,,,"); 1.52 +} 1.53 + 1.54 +function link(id) { 1.55 + return { url: "http://example.com/#" + id, title: "site#" + id }; 1.56 +}