test_viewinvalidation.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
31 function runTest () {
32 
33  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
34  Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
35 
36  var library = createLibrary("test_viewinvalidation", null, false);
37  library.clear();
38 
39  var items = [
40  ["The Beatles", "Abbey Road", "Come Together", "ROCK"],
41  ["The Beatles", "Abbey Road", "Sun King", "ROCK"],
42  ["The Beatles", "Let It Be", "Get Back", "POP"],
43  ["The Beatles", "Let It Be", "Two Of Us", "POP"],
44  ["The Doors", "L.A. Woman", "L.A. Woman", "ROCK"],
45  ["The Doors", "L.A. Woman", "Love Her Madly", "ROCK"]
46  ];
47 
48  function makeItem(i) {
49  var item = library.createMediaItem(
50  newURI("http://foo/" + i + ".mp3"),
51  SBProperties.createArray([
52  [SBProperties.artistName,items[i][0]],
53  [SBProperties.albumName, items[i][1]],
54  [SBProperties.trackName, items[i][2]],
55  [SBProperties.genre, items[i][3]]
56  ]));
57  return item;
58  }
59 
60  var item1 = makeItem(0);
61  var item2 = makeItem(1);
62  var item3 = makeItem(2);
63  var item4 = makeItem(3);
64  var item5 = makeItem(4);
65  var item6 = makeItem(5);
66 
67  var view = library.createView();
68 
69  view.filterConstraint = LibraryUtils.createConstraint([
70  [
71  [SBProperties.artistName, ["The Beatles"]]
72  ]
73  ]);
74 
75  assertEqual(view.length, 4);
76  item1.setProperty(SBProperties.artistName, "xxx");
77  assertEqual(view.length, 3);
78 
79  view.filterConstraint = null;
80  assertEqual(view.length, library.length);
81 
82  view.searchConstraint = LibraryUtils.createConstraint([
83  [
84  [SBProperties.artistName, ["Doors"]]
85  ]
86  ]);
87  assertEqual(view.length, 2);
88  item5.setProperty(SBProperties.artistName, "xxx");
89  assertEqual(view.length, 1);
90 
91  view.searchConstraint = null;
92  assertEqual(view.length, library.length);
93 
94  view.setSort(SBProperties.createArray([
95  [SBProperties.trackName, "a"]
96  ]));
97  assertTrue(view.getItemByIndex(0).equals(item1));
98  item1.setProperty(SBProperties.trackName, "xxx");
99  assertTrue(view.getItemByIndex(0).equals(item3));
100 }
101 
function runTest()
Test file.
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i