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