unittests/tests/playerWidget.js
author hamidouk
Tue, 18 Oct 2011 11:46:05 +0200
branchpopcorn-port
changeset 81 ed34f2c9d37f
parent 74 d7a7d7216371
child 83 1fb63a1a8ac3
permissions -rw-r--r--
html5 video files for testing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     1
/* test module for the player widget */
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     2
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     3
function test_player_widget() {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     4
  module("player widget testing", 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     5
  {setup : function() {    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     6
    this.Popcorn = Popcorn.youtube("#popcorn-div", "http://www.youtube.com/watch?v=QH2-TGUlwu4");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     7
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     8
    this.dt = new IriSP.DataLoader();
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
     9
    this.ser = new IriSP.Serializer(this.dt, "/url"); /* dummy serializer */
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    10
       
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    11
    this.config = {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    12
						metadata:{
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    13
							format:'cinelab',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    14
							src:'test.json',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    15
							load:'json'},
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    16
						gui:{
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    17
							width:650,
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    18
							height:1,
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    19
							mode:'radio',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    20
							container:'widget-div',
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    21
							debug:true,
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    22
							css:'../src/css/LdtPlayer.css'},
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    23
					};
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    24
  } });
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    25
  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    26
  test("test player initialisation", function() {  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    27
    var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    28
    player.draw();                               
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    29
    equal(IriSP.jQuery("#widget-div #Ldt-Root").length, 1, "test if the div has been added correctly"); 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    30
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    31
    var player2 = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    32
    player2.draw(); 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    33
    equal(IriSP.jQuery("#widget-div #Ldt-Root").length, 2, "test if the second div has been added correctly"); 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    34
  });
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    35
 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    36
  test("test play button event handler", function() {
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    37
    var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    38
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    39
    var spy_callback = this.spy();
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    40
    var spy_callback2 = this.spy();
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    41
    this.Popcorn.listen("play", spy_callback);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    42
    this.Popcorn.listen("pause", spy_callback2);
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    43
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    44
    player.draw();        
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    45
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    46
    /*
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    47
    Code seems to work but test doesn't. It must be a subtle race condition
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    48
    between Popcorn, the youtube plugin and QUnit. Anyway, it works for pause
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    49
    so WONTFIX
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    50
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    51
    IriSP.jQuery("#widget-div .Ldt-Control1 button:first").trigger("click");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    52
    ok(spy_callback.calledOnce, "test if play callback has been called");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    53
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    54
    */
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    55
    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    56
    IriSP.jQuery("#widget-div .Ldt-Control1 button:first").trigger("click");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    57
    IriSP.jQuery("#widget-div .Ldt-Control1 button:first").trigger("click");
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    58
                                                                  
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    59
    ok(spy_callback2.calledOnce, "test if pause callback has been called");                                                                    
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    60
  }); 
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents:
diff changeset
    61
  };