| author | hamidouk |
| Fri, 25 Nov 2011 11:10:19 +0100 | |
| branch | popcorn-port |
| changeset 331 | ef3447aa6920 |
| parent 250 | 41683e7cb17a |
| child 427 | 440ffc18f827 |
| permissions | -rw-r--r-- |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
1 |
/* test module for the player widget */ |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
2 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
3 |
function test_player_widget() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
4 |
module("player widget testing", |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
5 |
{setup : function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
6 |
this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
7 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
8 |
this.dt = new IriSP.DataLoader(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
9 |
this.ser = new IriSP.MockSerializer(this.dt, "/url"); /* dummy serializer */ |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
10 |
this.lay = new IriSP.LayoutManager('widget-div'); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
11 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
12 |
this.config = { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
13 |
width:650, |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
14 |
height:1, |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
15 |
mode:'radio', |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
16 |
container:'widget-div', |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
17 |
debug:true, |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
18 |
css:'../src/css/LdtPlayer.css'} |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
19 |
}, |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
20 |
teardown: function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
21 |
/* free the popcorn object because it has signal handlers attached to it */ |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
22 |
this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
23 |
} |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
24 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
25 |
}); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
26 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
27 |
test("test player initialisation", function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
28 |
var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
29 |
player.draw(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
30 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
31 |
equal(IriSP.jQuery("#widget-div").length, 1, "test if the div has been added correctly"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
32 |
}); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
33 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
34 |
test("test play button event handler", function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
35 |
var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
36 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
37 |
var spy_callback = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
38 |
var spy_callback2 = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
39 |
this.Popcorn.listen("play", spy_callback); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
40 |
this.Popcorn.listen("pause", spy_callback2); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
41 |
sinon.spy(player, "playHandler"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
42 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
43 |
player.draw(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
44 |
|
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
45 |
player.selector.find(".ldt-CtrlPlay").trigger("click"); |
|
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
46 |
player.selector.find(".ldt-CtrlPlay").trigger("click"); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
47 |
ok(player.playHandler.calledTwice, "play handler called"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
48 |
ok(spy_callback2.calledOnce, "test if pause callback has been called"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
49 |
}); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
50 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
51 |
test("test mute button event handler", function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
52 |
var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
53 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
54 |
var spy_callback = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
55 |
var spy_handler = sinon.spy(player, "muteHandler"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
56 |
this.Popcorn.listen("volumechange", spy_callback); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
57 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
58 |
player.draw(); |
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
59 |
|
|
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
60 |
player.selector.find(".ldt-CtrlSound").trigger("click"); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
61 |
ok(this.Popcorn.muted(), "the player is muted"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
62 |
|
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
63 |
player.selector.find(".ldt-CtrlSound").trigger("click"); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
64 |
ok(!this.Popcorn.muted(), "the player is un muted"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
65 |
ok(spy_handler.called, "handling function has been called"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
66 |
}); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
67 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
68 |
test("test search button event handler", function() { |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
69 |
var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
70 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
71 |
var searchTerm = "blah"; |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
72 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
73 |
var spy_callback = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
74 |
var spy_open = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
75 |
var spy_closed = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
76 |
var spy_cleared = this.spy(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
77 |
var spy_handler = sinon.spy(player, "searchButtonHandler"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
78 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
79 |
player._Popcorn.listen("IriSP.search", spy_callback); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
80 |
player._Popcorn.listen("IriSP.search.open", spy_open); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
81 |
player._Popcorn.listen("IriSP.search.closed", spy_closed); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
82 |
player._Popcorn.listen("IriSP.search.cleared", spy_cleared); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
83 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
84 |
player.draw(); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
85 |
|
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
86 |
player.selector.find(".ldt-CtrlSearch").trigger("click"); |
|
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
87 |
player.selector.find(".LdtSearchInput").attr('value', searchTerm); |
|
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
88 |
player.selector.find(".LdtSearchInput").trigger('keyup'); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
89 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
90 |
ok(spy_handler.called, "search button handling function has been called"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
91 |
ok(spy_open.called, "open signal has been sent"); |
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
92 |
ok(spy_callback.called, "search typeahead function has been called"); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
93 |
ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
94 |
|
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
95 |
player.selector.find(".LdtSearchInput").attr('value', ""); |
|
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
96 |
player.selector.find(".LdtSearchInput").trigger('keyup'); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
97 |
ok(spy_cleared.called, "clear message has been sent"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
98 |
|
|
250
41683e7cb17a
updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents:
234
diff
changeset
|
99 |
player.selector.find(".ldt-CtrlSearch").trigger("click"); |
|
234
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
100 |
ok(spy_closed.called, "closed signal has been sent"); |
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
101 |
|
|
43b198dc932d
reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff
changeset
|
102 |
}); |
|
331
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
103 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
104 |
test("test mouseover handler", function() { |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
105 |
var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
106 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
107 |
var spy_callback = this.spy(); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
108 |
this.Popcorn.listen("IriSP.PlayerWidget.MouseOver", spy_callback); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
109 |
this.Popcorn.listen("IriSP.PlayerWidget.MouseOut", spy_callback); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
110 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
111 |
player.draw(); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
112 |
var elem = player.selector.get(0); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
113 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
114 |
if( document.createEvent ) { |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
115 |
var evObj = document.createEvent('MouseEvents'); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
116 |
evObj.initEvent( 'mouseover', true, false ); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
117 |
elem.dispatchEvent(evObj); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
118 |
} else if( document.createEventObject ) { |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
119 |
elem.fireEvent('onmouseover'); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
120 |
} |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
121 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
122 |
ok(spy_callback.called, "the MouseOver event has been fired"); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
123 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
124 |
if( document.createEvent ) { |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
125 |
var evObj = document.createEvent('MouseEvents'); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
126 |
evObj.initEvent( 'mouseout', true, false ); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
127 |
elem.dispatchEvent(evObj); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
128 |
} else if( document.createEventObject ) { |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
129 |
elem.fireEvent('onmouseout'); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
130 |
} |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
131 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
132 |
ok(spy_callback.calledTwice, "the MouseOver event has been fired"); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
133 |
}); |
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
134 |
|
|
ef3447aa6920
player widget now sends a special message when the mouse is hovering it.
hamidouk
parents:
250
diff
changeset
|
135 |
}; |