test_view_selection.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  var url = "data:application/vnd.mozilla.xul+xml," +
33  "<?xml-stylesheet href='chrome://global/skin' type='text/css'?>" +
34  "<?xml-stylesheet href='chrome://songbird/content/bindings/bindings.css' type='text/css'?>" +
35  "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'/>";
36 
38 }
39 
40 function setupPlaylist() {
41 
42  testWindow.resizeTo(200, 200);
43 
44  var databaseGUID = "test_view_selection";
45  var library = createLibrary(databaseGUID, false);
46 
47  const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
48 
49  var document = testWindow.document;
50 
51  var playlist = document.createElementNS(XUL_NS, "sb-playlist");
52  playlist.setAttribute("flex", "1");
53  document.documentElement.appendChild(playlist);
54  playlist.bind(library.createView(), null);
55 
56  // kick it off
57  continueWindowTest(testSelectAll, [library, playlist]);
58 
59 }
60 
61 function testSelectAll(library, playlist) {
62 
63  log("testSelectAll");
64 
65  playlist.mediaListView.selection.selectAll();
66 
67  safeSetTimeout(function() {
68 
69  // All of the visible rows should be selected
70  assertAllVisibleRowsSelected(playlist.tree);
71 
72  continueWindowTest(testSelectAllScrolled, [library, playlist]);
73  }, 1000);
74 
75 }
76 
77 function testSelectAllScrolled(library, playlist) {
78 
79  log("testSelectAllScrolled");
80  playlist.tree.boxObject.ensureRowIsVisible(library.length - 1);
81 
82  safeSetTimeout(function() {
83 
84  assertAllVisibleRowsSelected(playlist.tree);
85  continueWindowTest(testSelectSome, [library, playlist]);
86  }, 1000);
87 
88 }
89 
90 function testSelectSome(library, playlist) {
91 
92  log("testSelectSome");
93 
94  // select first and last
95  var selection = playlist.mediaListView.selection;
96  selection.select(0);
97  selection.toggle(library.length - 1);
98 
99  safeSetTimeout(function() {
100 
101  assertTrue(playlist.tree.view.selection.isSelected(library.length - 1));
102 
103  playlist.tree.boxObject.ensureRowIsVisible(0);
104 
105  continueWindowTest(testSelectSomeScrolled, [library, playlist]);
106  }, 1000);
107 }
108 
109 function testSelectSomeScrolled(library, playlist) {
110 
111  log("testSelectSomeScrolled");
112 
113  safeSetTimeout(function() {
114 
115  assertTrue(playlist.tree.view.selection.isSelected(0));
116 
117  endWindowTest();
118  }, 1000);
119 }
120 
122  return Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
123  .createInstance(Ci.sbIMutablePropertyArray);
124 }
125 
127  var selection = tree.view.selection;
128  var box = tree.boxObject;
129 
130  // getLastVisibleRow does not seem to be inclusive?
131  for (var i = box.getFirstVisibleRow(); i < box.getLastVisibleRow(); i++) {
132  assertTrue(selection.isSelected(i));
133  }
134 }
function safeSetTimeout(closure, timeout)
function runTest()
Test that changes in the view's selection are reflected into the tree.
const Cc
function endWindowTest(e)
const XUL_NS
Definition: FeedWriter.js:83
function log(s)
function beginWindowTest(url, continueFunction)
function assertTrue(aTest, aMessage)
function assertAllVisibleRowsSelected(tree)
function testSelectAll(library, playlist)
function createPropertyArray()
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function testSelectSome(library, playlist)
function testSelectAllScrolled(library, playlist)
var testWindow
Test file.
function url(spec)
function testSelectSomeScrolled(library, playlist)
const Ci
function setupPlaylist()
_getSelectedPageStyle s i
function continueWindowTest(fn, parameters)