test_rating.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 function runTest() {
26 
27  // from sbRatingPropertyInfo
28  var STAR_WIDTH = 14;
29  var ZERO_HIT_WIDTH = 4;
30 
31  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
32 
33  var propMan = Cc["@songbirdnest.com/Songbird/Properties/PropertyManager;1"]
34  .getService(Ci.sbIPropertyManager);
35  var info = propMan.getPropertyInfo(SBProperties.rating);
36 
37  // Test that a far left click nulls the value
38  var clickable = info.QueryInterface(Ci.sbIClickablePropertyInfo);
39  var value = clickable.getValueForClick("4", 0, 0, 0, 0);
40  assertEqual(value, null);
41 
42  // Test toggle
43  value = clickable.getValueForClick("4", 0, 0, ZERO_HIT_WIDTH + (STAR_WIDTH * 4) - 1, 0);
44  assertEqual(value, null);
45  value = clickable.getValueForClick("1", 0, 0, ZERO_HIT_WIDTH + (STAR_WIDTH * 1) - 1, 0);
46  assertEqual(value, null);
47 
48  // A zero rating is not valid
49  // XXXlone yes it is now, it is treated as null, remove when bug 8033 is fixed
50  assertTrue(info.validate(null));
51  assertTrue(info.validate("1"));
52  assertTrue(info.validate("5"));
53  assertTrue(info.validate("0"));
54  assertFalse(info.validate("1000"));
55  assertFalse(info.validate("foo"));
56 
57  // XXXsteve zeros should be treated as null. Remove when bug 8033 is fixed
58  assertEqual(info.format("0"), null);
59 
60 }
const Cc
#define STAR_WIDTH
function assertTrue(aTest, aMessage)
function runTest()
Advanced DataRemote unit tests.
Definition: test_rating.js:25
function assertEqual(aExpected, aActual, aMessage)
#define ZERO_HIT_WIDTH
return null
Definition: FeedWriter.js:1143
function assertFalse(aTest, aMessage)
countRef value
Definition: FeedWriter.js:1423
const Ci