test_searchable.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_searchable");
37 
38  // Tests with view media list
39  var list = library;
40  var view = list.createView();
41 
42  var search = LibraryUtils.createConstraint([
43  [
44  [SBProperties.artistName, ["AC/DC"]]
45  ]
46  ]);
47 
48  view.searchConstraint = search;
49  assertEqual(view.length, 10);
50 
51  search = LibraryUtils.createConstraint([
52  [
53  [SBProperties.trackName, ["Shoot", "Thrill"]],
54  ]
55  ]);
56  view.searchConstraint = search;
57  assertEqual(view.length, 1);
58 
59  view.searchConstraint = null;
60  assertEqual(view.length, library.length);
61 
62  // Test unsupported constraints
63  search = LibraryUtils.createConstraint([
64  [
65  [SBProperties.artistName, ["AC/DC"]],
66  [SBProperties.albumName, ["AC/DC"]]
67  ],
68  [
69  [SBProperties.artistName, ["Thrill"]],
70  [SBProperties.trackName, ["Thrill"]]
71  ]
72  ]);
73 
74  try {
75  view.searchConstraint = search;
76  fail("did not throw");
77  }
78  catch(e) {
79  assertEqual(e.result, Cr.NS_ERROR_INVALID_ARG);
80  }
81 
82  search = LibraryUtils.createConstraint([
83  [
84  [SBProperties.artistName, ["AC/DC"]],
85  [SBProperties.trackName, ["foo"]],
86  [SBProperties.albumName, ["foo"]]
87  ],
88  [
89  [SBProperties.artistName, ["Thrill"]],
90  [SBProperties.trackName, ["Thrill"]],
91  [SBProperties.albumName, ["Thrill"]]
92  ]
93  ]);
94 
95  try {
96  view.searchConstraint = search;
97  fail("did not throw");
98  }
99  catch(e) {
100  assertEqual(e.result, Cr.NS_ERROR_INVALID_ARG);
101  }
102 
103  // Test with simple media list
104  list = library.getMediaItem("7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
105  view = list.createView();
106  search = LibraryUtils.createConstraint([
107  [
108  [SBProperties.artistName, ["AC/DC"]]
109  ]
110  ]);
111  view.searchConstraint = search;
112  assertEqual(view.length, 10);
113 
114  view.searchConstraint = null;
115  assertEqual(view.length, 20);
116 
117  // Test the search box
118  searchBoxTest("ac dc", 10);
119  searchBoxTest("you ace", 4);
120  searchBoxTest("of to the", 1);
121 }
122 
123 function searchBoxTest(searchTerm, resultViewLength) {
124  var library = createLibrary("test_searchBoxset");
125  var view = library.createView();
126  var cfs = view.cascadeFilterSet;
127 
128  cfs.appendSearch(["*"], 1);
129  var searchArray = searchTerm.split(" ");
130  cfs.set(0, searchArray, searchArray.length);
131  assertEqual(view.length, resultViewLength);
132 }
133 
135  return Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
136  .createInstance(Ci.sbIMutablePropertyArray);
137 }
138 
const Cc
function fail(aMessage)
function createPropertyArray()
function assertEqual(aExpected, aActual, aMessage)
function searchBoxTest(searchTerm, resultViewLength)
function search(aFolderId, aSearchStr, aExpectedScopeButtonId)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
const Cr
const Ci
Javascript wrappers for common library tasks.
function runTest()
Test file.