unittests/tests/widgets/playerWidget.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 451 2217bd6fd068
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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() {    
427
440ffc18f827 changed the unit tests to reference a local video instead of youtube.
hamidouk
parents: 331
diff changeset
     6
    this.Popcorn = Popcorn("#popcorn-div");
234
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 */
427
440ffc18f827 changed the unit tests to reference a local video instead of youtube.
hamidouk
parents: 331
diff changeset
    22
    this.Popcorn = Popcorn("#popcorn-div");
234
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
  });
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
  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
    51
    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
    52
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    53
    var spy_callback = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    54
    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
    55
    this.Popcorn.listen("volumechange", spy_callback);    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    56
    
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    57
    player.draw();
250
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    58
         
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    59
    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
    60
    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
    61
    
250
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    62
    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
    63
    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
    64
    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
    65
  });
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
  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
    68
  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
    69
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    70
  var searchTerm = "blah";
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    71
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    72
  var spy_callback = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    73
  var spy_open = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    74
  var spy_closed = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    75
  var spy_cleared = this.spy();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    76
  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
    77
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    78
  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
    79
  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
    80
  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
    81
  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
    82
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    83
  player.draw();
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    84
     
250
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    85
  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
    86
  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
    87
  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
    88
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
    89
  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
    90
  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
    91
  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
    92
  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
    93
250
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    94
  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
    95
  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
    96
  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
    97
  
250
41683e7cb17a updated the playerWidget to use classes instead of id's in its elements.
hamidouk
parents: 234
diff changeset
    98
  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
    99
  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
   100
  
43b198dc932d reorganized the layout of the test directories to follow the layout the source
hamidouk
parents:
diff changeset
   101
  });
331
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   102
 
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   103
  test("test mouseover handler", function() {
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   104
    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
   105
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   106
    var spy_callback = this.spy();
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   107
    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
   108
    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
   109
    
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   110
    player.draw();
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   111
    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
   112
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   113
    if( document.createEvent ) {
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   114
      var evObj = document.createEvent('MouseEvents');
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   115
        evObj.initEvent( 'mouseover', true, false );
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   116
        elem.dispatchEvent(evObj);
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   117
    } else if( document.createEventObject ) {
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   118
        elem.fireEvent('onmouseover');
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   119
    }
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
     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
   122
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   123
     if( document.createEvent ) {
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   124
      var evObj = document.createEvent('MouseEvents');
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   125
        evObj.initEvent( 'mouseout', true, false );
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   126
        elem.dispatchEvent(evObj);
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   127
     } else if( document.createEventObject ) {
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   128
        elem.fireEvent('onmouseout');
ef3447aa6920 player widget now sends a special message when the mouse is hovering it.
hamidouk
parents: 250
diff changeset
   129
     }
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
     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
   132
  });
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
};