browser/base/content/test/newtab/browser_newtab_update.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Checks that newtab is updated as its links change.
michael@0 6 */
michael@0 7
michael@0 8 function runTests() {
michael@0 9 if (NewTabUtils.allPages.updateScheduledForHiddenPages) {
michael@0 10 // Wait for dynamic updates triggered by the previous test to finish.
michael@0 11 yield whenPagesUpdated(null, true);
michael@0 12 }
michael@0 13
michael@0 14 // First, start with an empty page. setLinks will trigger a hidden page
michael@0 15 // update because it calls clearHistory. We need to wait for that update to
michael@0 16 // happen so that the next time we wait for a page update below, we catch the
michael@0 17 // right update and not the one triggered by setLinks.
michael@0 18 //
michael@0 19 // Why this weird way of yielding? First, these two functions don't return
michael@0 20 // promises, they call TestRunner.next when done. Second, the point at which
michael@0 21 // setLinks is done is independent of when the page update will happen, so
michael@0 22 // calling whenPagesUpdated cannot wait until that time.
michael@0 23 setLinks([]);
michael@0 24 whenPagesUpdated(null, true);
michael@0 25 yield null;
michael@0 26 yield null;
michael@0 27
michael@0 28 // Strategy: Add some visits, open a new page, check the grid, repeat.
michael@0 29 fillHistory([link(1)]);
michael@0 30 yield whenPagesUpdated(null, true);
michael@0 31 yield addNewTabPageTab();
michael@0 32 checkGrid("1,,,,,,,,");
michael@0 33
michael@0 34 fillHistory([link(2)]);
michael@0 35 yield whenPagesUpdated(null, true);
michael@0 36 yield addNewTabPageTab();
michael@0 37 checkGrid("2,1,,,,,,,");
michael@0 38
michael@0 39 fillHistory([link(1)]);
michael@0 40 yield whenPagesUpdated(null, true);
michael@0 41 yield addNewTabPageTab();
michael@0 42 checkGrid("1,2,,,,,,,");
michael@0 43
michael@0 44 // Wait for fillHistory to add all links before waiting for an update
michael@0 45 yield fillHistory([link(2), link(3), link(4)], TestRunner.next);
michael@0 46 yield whenPagesUpdated(null, true);
michael@0 47 yield addNewTabPageTab();
michael@0 48 checkGrid("2,1,3,4,,,,,");
michael@0 49 }
michael@0 50
michael@0 51 function link(id) {
michael@0 52 return { url: "http://example.com/#" + id, title: "site#" + id };
michael@0 53 }

mercurial