test_mainpresetprovider.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN NIGHTINGALE GPL
4 //
5 // This file is part of the Nightingale web player.
6 //
7 // http://getnightingale.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 NIGHTINGALE GPL
23 //
24 */
25 
26 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
27 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
28 
29 if (typeof(Cc) == "undefined")
30  this.Cc = Components.classes;
31 if (typeof(Ci) == "undefined")
32  this.Ci = Components.interfaces;
33 
34 function runTest() {
35  var mainProvider = Cc["@getnightingale.com/equalizer-presets/main-provider;1"]
36  .getService(Ci.ngIMainEqualizerPresetProvider);
37 
38  assertTrue(mainProvider.presets instanceof Ci.nsIArray, "Presets aren't an nsIArray");
39  var initialLength = mainProvider.presets.length;
40  var array = [0,0.1,0.2,-0.3,0.4,0.5,0.6,0.7,0.8,0.9];
41 
42  mainProvider.savePreset("test", convertArrayToSupportsDouble(array));
43  assertEqual(initialLength + 1,
44  mainProvider.presets.length,
45  "Preset isn't in the presets list after saving");
46 
47  var collection = mainProvider.QueryInterface(Ci.ngIEqualizerPresetCollection);
48  // verify that the collection functions work as intended
49  assertTrue(collection.hasPresetNamed("test"), "Preset isn't in the collection");
50  assertTrue(collection.getPresetByName("test") instanceof Ci.ngIEqualizerPreset,
51  "Returned preset doesn't implement ngIEqualizerPreset");
52 
53  // check if overwriting a preset works...
54  var otherArray = [-0.1,0,0,0,0,0,0,0,0,0];
55  mainProvider.savePreset("test", convertArrayToSupportsDouble(otherArray));
56 
57  var presetValues = ArrayConverter.JSArray(collection.getPresetByName("test").values);
58  presetValues.forEach(function(item, i) {
59  var value = item.QueryInterface(Ci.nsISupportsDouble).data;
60  assertEqual(value, otherArray[i], "Preset was not overwritten correctly");
61  });
62 
63 
64  mainProvider.deletePreset("test");
65  assertTrue(!collection.hasPresetNamed("test"), "Preset wasn't deleted");
66 
67  // test persistency accross restarts?
68  return;
69 }
70 
72  var ret = array.map(function(item) {
73  var double = Cc["@mozilla.org/supports-double;1"]
74  .createInstance(Ci.nsISupportsDouble);
75  double.data = item;
76  return double;
77  });
78  return ArrayConverter.nsIArray(ret);
79 }
const Cc
inArray array
function convertArrayToSupportsDouble(array)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
return ret
countRef value
Definition: FeedWriter.js:1423
const Ci
_getSelectedPageStyle s i