1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function pageObjectEquals(a
, b
) {
6 return a
.url
== b
.url
&& a
.title
== b
.title
&& a
.pinned
== b
.pinned
;
9 function pageObjectArrayEquals(a
, b
) {
10 if (a
.length
!= b
.length
)
13 for (var i
= 0; i
< a
.length
; i
++) {
17 if (!pageObjectEquals(a
[i
], b
[i
]))
24 function refreshDataBasic() {
25 // Tests that we toss out pages that don't appear in the new data.
26 var oldData
= [{url
: 'foo'}];
27 var newData
= [{url
: 'bar'}];
28 var mergedData
= ntp
.refreshData(oldData
, newData
);
29 assertTrue(pageObjectArrayEquals(mergedData
, newData
));
32 function refreshDataOrdering() {
33 // Tests that the order of pages (based on URL) in the current list is
34 // preserved, but the other page data (like title) is copied from newData.
36 {url
: 'foo', title
: 'foo (1)'},
37 {url
: 'bar', title
: 'bar (1)'}];
40 {url
: 'bar', title
: 'bar (2)'},
41 {url
: 'foo', title
: 'foo (2)'}];
44 {url
: 'foo', title
: 'foo (2)'},
45 {url
: 'bar', title
: 'bar (2)'}];
47 var mergedData
= ntp
.refreshData(oldData
, newData
);
48 assertTrue(pageObjectArrayEquals(mergedData
, expectedData
));
51 function refreshDataPinning() {
52 // Tests that the 'pinned' attribute is always respected.
54 {url
: 'foo', title
: 'foo (1)'},
55 {url
: 'bar', title
: 'bar (1)'}];
58 {url
: 'bar', title
: 'bar (2)', pinned
: true},
59 {url
: 'foo', title
: 'foo (2)'}];
61 var mergedData
= ntp
.refreshData(oldData
, newData
);
62 assertTrue(pageObjectArrayEquals(mergedData
, newData
));
64 // Tests we don't choke on empty data before a pinned entry.
65 oldData
= [{url
: 'foo', title
: 'foo (1)'}];
66 newData
= [{}, {url
: 'foo', title
: 'foo (2)', pinned
: true}];
68 mergedData
= ntp
.refreshData(oldData
, newData
);
69 assertTrue(pageObjectArrayEquals(mergedData
, newData
));