test_eq_preset_list.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 const Cu = Components.utils;
27 
28 var XUL_NS = XUL_NS ||
29  "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
30 
31 Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
32 
33 function runTest () {
34  var url = "data:application/vnd.mozilla.xul+xml," +
35  "<?xml-stylesheet href='chrome://global/skin' type='text/css'?>" +
36  "<?xml-stylesheet href='chrome://songbird/content/bindings/bindings.css' type='text/css'?>" +
37  "<window xmlns='"+XUL_NS+"'/>";
38 
39  beginWindowTest(url, setup);
40 }
41 
42 function setup () {
43 
44  testWindow.resizeTo(200,200);
45 
46  var document = testWindow.document;
47 
48  function createElement(aType) {
49  var element = document.createElementNS(XUL_NS, aType);
50  element.setAttribute("flex", "1");
51  document.documentElement.appendChild(element);
52  return element;
53  }
54 
55  continueWindowTest(test_save, [ createElement("ng-eq-preset-list") ]);
56 }
57 
58 function test_save(aPresetList) {
59  var currentPreset = aPresetList.preset;
60  aPresetList.save();
61  assertEqual(currentPreset, aPresetList.preset, "Saving the preset changed its name");
62  var resetButton = aPresetList.ownerDocument.getAnonymousElementByAttribute(aPresetList, "anonid", "eq-preset-reset");
63  assertTrue(!resetButton.hasAttribute("disabled") && !resetButton.hasAttribute("hidden"), "Reset button hasn't been activated")
64 
65  continueWindowTest(test_delete, [ aPresetList ]);
66 }
67 
68 function test_delete(aPresetList) {
69  var currentPreset = aPresetList.preset;
70  aPresetList.delete();
71  assertEqual(currentPreset, aPresetList.preset, "Deleting the preset changed its name (we saved an already existing preset and then deleted the custom version of it)");
72  var resetButton = aPresetList.ownerDocument.getAnonymousElementByAttribute(aPresetList, "anonid", "eq-preset-reset");
73  assertTrue(resetButton.hasAttribute("disabled") && resetButton.hasAttribute("hidden"), "Reset button hasn't been disabled")
74 
75  continueWindowTest(test_change, [ aPresetList ]);
76 }
77 
78 function test_change(aPresetList) {
79  var eqPresets = ArrayConverter.JSArray(Cc["@getnightingale.com/equalizer-presets/manager;1"]
80  .getService(Ci.ngIEqualizerPresetProviderManager).presets),
81  preset = aPresetList.preset,
82  newPreset;
83  assertTrue(eqPresets.some(function(item) {
84  if(item.QueryInterface(Ci.ngIEqualizerPreset).name != preset) {
85  newPreset = item.QueryInterface(Ci.ngIEqualizerPreset).name;
86  return true;
87  }
88  return false;
89  }), "No eq preset with a different name than the current name was found");
90  aPresetList.preset = newPreset;
91  assertEqual(aPresetList.preset, newPreset, "EQ preset was not applied successfully");
92 
93  Cc["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
94  .getService(Ci.sbIMediacoreManager).equalizer.currentPresetName = preset;
95  assertEqual(aPresetList.preset, preset, "EQ preset change did not populate to GUI");
96 
97  endWindowTest();
98 }
const Cc
function endWindowTest(e)
function setup()
function test_save(aPresetList)
function test_delete(aPresetList)
function beginWindowTest(url, continueFunction)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
var XUL_NS
function runTest()
Advanced DataRemote unit tests.
var testWindow
Test file.
function url(spec)
const Ci
function test_change(aPresetList)
function continueWindowTest(fn, parameters)
const Cu