test_presetprovidermanager.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 providerManager = Cc["@getnightingale.com/equalizer-presets/manager;1"]
36  .getService(Ci.ngIEqualizerPresetProviderManager);
37 
38  assertTrue(providerManager.providers.length >= 2, "Not all providers were registered");
39  assertTrue(providerManager.presets.length >= 17, "Not all presets are offered by the manager");
40 
41  var presetName = providerManager.presets.enumerate().getNext()
42  .QueryInterface(Ci.ngIEqualizerPreset).name;
43 
44  var collection = providerManager.QueryInterface(Ci.ngIEqualizerPresetCollection);
45  assertTrue(collection.hasPresetNamed(presetName),
46  "Preset wasn't found even though it is in the presets array");
47  assertTrue(collection.getPresetByName(presetName) instanceof Ci.ngIEqualizerPreset,
48  "Preset returned by getPresetByName isn't actually a preset");
49 
50  var mainProvider = Cc["@getnightingale.com/equalizer-presets/main-provider;1"]
51  .getService(Ci.ngIMainEqualizerPresetProvider);
52  // test regeneration of presets list when saving a preset
53  var array = [0,0.1,0.2,-0.3,0.4,0.5,0.6,0.7,0.8,0.9];
54  mainProvider.savePreset("test", convertArrayToSupportsDouble(array));
55  assertTrue(collection.hasPresetNamed("test"),
56  "Presets list was not regenerated after a preset was saved");
57 
58  var otherArray = [-0.1,0,0,0,0,0,0,0,0,0];
59  mainProvider.savePreset("test", convertArrayToSupportsDouble(otherArray));
60 
61  var presetValues = ArrayConverter.JSArray(collection.getPresetByName("test").values);
62  presetValues.forEach(function(item, i) {
63  var value = item.QueryInterface(Ci.nsISupportsDouble).data;
64  assertEqual(value, otherArray[i], "Preset was not overwritten correctly");
65  });
66 
67  mainProvider.deletePreset("test");
68  assertTrue(!collection.hasPresetNamed("test"),
69  "Delete preset was not removed from collection");
70 
71  return;
72 }
73 
74 
76  var ret = array.map(function(item) {
77  var double = Cc["@mozilla.org/supports-double;1"]
78  .createInstance(Ci.nsISupportsDouble);
79  double.data = item;
80  return double;
81  });
82  return ArrayConverter.nsIArray(ret);
83 }
const Cc
inArray array
function convertArrayToSupportsDouble(array)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
return ret
countRef value
Definition: FeedWriter.js:1423
const Ci
_getSelectedPageStyle s i
function runTest()
Advanced DataRemote unit tests.