unittests/tests/init.js
branchpopcorn-port
changeset 287 5c7495102bd7
parent 179 7b46fbf4cf6c
child 423 748cce3d80d4
equal deleted inserted replaced
286:6252f951d11c 287:5c7495102bd7
     1 function test_init() {
     1 function test_init() {
     2 	module("test initialization routines", 
     2 	module("test initialization routines",
     3   {
     3   {
     4     setup: function() {
     4     setup: function() {
     5       IriSP.jQuery("#widget-div").append("<div id='LdtPlayer'></div>");
     5       IriSP.jQuery("#widget-div").append("<div id='LdtPlayer'></div>");
     6       this.popcornOptions = {
     6       this.popcornOptions = {
     7           container: "LdtPlayer",
     7           container: "LdtPlayer",
     8           type: "jwplayer", file : "video/franceculture/franceculture_retourdudimanche20100620.flv", 
     8           type: "jwplayer", file : "video/franceculture/franceculture_retourdudimanche20100620.flv",
     9           streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/", 
     9           streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/",
    10           flashplayer : '../libs/player.swf',
    10           flashplayer : '../libs/player.swf',
    11           live: true, 
    11           live: true,
    12           "controlbar.position" : "none", 
    12           "controlbar.position" : "none",
    13           height: 300, 
    13           height: 300,
    14           width: 200, 
    14           width: 200,
    15           provider: "rtmp" 
    15           provider: "rtmp"
    16         };
    16         };
    17         
    17 
    18         this.widgetOptions = {
    18         this.widgetOptions = {
    19 						width:650,
    19 						width:650,
    20 						height:480,							
    20 						height:480,
    21 						container:'LdtPlayer',
    21 						container:'LdtPlayer',
    22 						css:'../../src/css/LdtPlayer.css',
    22 						css:'../../src/css/LdtPlayer.css',
    23             widgets: [
    23             widgets: [
    24               {type: "PlayerWidget",
    24               {type: "PlayerWidget",
    25                mode: "radio",
    25                mode: "radio",
    26                metadata:{
    26                metadata:{
    27                 format:'cinelab',
    27                 format:'cinelab',
    28                 src:'test.json',
    28                 src:'test.json',
    29                 type:'dummy'}
    29                 type:'dummy'}
    30               },
    30               },
    31              {type: "SegmentsWidget", 
    31              {type: "SegmentsWidget",
    32                metadata:{
    32                metadata:{
    33                 format:'cinelab',
    33                 format:'cinelab',
    34                 src:'test.json',
    34                 src:'test.json',
    35                 type:'dummy'}
    35                 type:'dummy'}
    36               },
    36               },
    37              {type: "AnnotationsWidget", 
    37              {type: "AnnotationsWidget",
    38                metadata:{
    38                metadata:{
    39                 format:'cinelab',
    39                 format:'cinelab',
    40                 src:'test.json',
    40                 src:'test.json',
    41                 type:'dummy'}
    41                 type:'dummy'}
    42               },
    42               },
    43             ]};
    43             ]};
    44     }
    44     }
    45   });
    45   });
    46   
    46 
    47   test("test the creation of a correct popcorn object", function() {
    47   test("test the creation of a correct popcorn object", function() {
    48 
    48 
    49     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    49     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    50     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    50     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    51     notDeepEqual(pop, undefined, "returned object is not undefined");
    51     notDeepEqual(pop, undefined, "returned object is not undefined");
    52     
    52 
    53     /* FIXME: add more test options ? */
    53     /* FIXME: add more test options ? */
    54     equal(pop.options.type, "jwplayer", "the player is of the correct type.");
    54     equal(pop.options.type, "jwplayer", "the player is of the correct type.");
    55   });
    55   });
    56   
    56 
    57   test("test the creation of a video tag", function() {
    57   test("test the creation of a video tag", function() {
    58   
    58 
    59     var popcornOptions = {
    59     var popcornOptions = {
    60             type: "html5",
    60             type: "html5",
    61             file: "demo.mp4"
    61             file: "demo.mp4"
    62           };
    62           };
    63     
    63 
    64     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    64     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    65     var pop = IriSP.configurePopcorn(layoutManager, popcornOptions);
    65     var pop = IriSP.configurePopcorn(layoutManager, popcornOptions);
    66     
    66 
    67     var elem = IriSP.jQuery("#LdtPlayer").find("video");
    67     var elem = IriSP.jQuery("#LdtPlayer").find("video");
    68     notDeepEqual(elem, [], "the element is not null");
    68     notDeepEqual(elem, [], "the element is not null");
    69     equal(elem.attr("src"), popcornOptions.file, "the src attribute is set correctly");    
    69     equal(elem.attr("src"), popcornOptions.file, "the src attribute is set correctly");
    70   });
    70   });
    71   
    71 
    72   test("test the instantiation of a single widget without dependencies", function() {
    72   test("test the instantiation of a single widget without dependencies", function() {
    73     
    73 
    74     var dt = new IriSP.DataLoader();
    74     var dt = new IriSP.DataLoader();
    75     var serialFactory = new IriSP.SerializerFactory(dt);
    75     var serialFactory = new IriSP.SerializerFactory(dt);
    76  
    76 
    77     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    77     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    78     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    78     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    79     var conf = {type: "PlayerWidget",
    79     var conf = {type: "PlayerWidget",
    80                mode: "radio",
    80                mode: "radio",
    81                metadata:{
    81                metadata:{
    82                 format:'cinelab',
    82                 format:'cinelab',
    83                 src:'test.json',
    83                 src:'test.json',
    84                 type:'dummy'}
    84                 type:'dummy'}
    85               };
    85               };
    86               
    86 
    87     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);    
    87     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);
    88     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
    88     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
    89     equal(res._config.mode, "radio", "the parameters not interpreted by the config are copied into the object");
    89     equal(res._config.mode, "radio", "the parameters not interpreted by the config are copied into the object");
    90   });  
    90   });
    91   
    91 
    92   test("test the instantiation of a single widget with one dependency", function() {
    92   test("test the instantiation of a single widget with one dependency", function() {
    93     var dt = new IriSP.DataLoader();
    93     var dt = new IriSP.DataLoader();
    94     var serialFactory = new IriSP.SerializerFactory(dt);
    94     var serialFactory = new IriSP.SerializerFactory(dt);
    95  
    95 
    96     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});    
    96     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
    97     
    97 
    98     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    98     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
    99     var conf = {type: "PlayerWidget",
    99     var conf = {type: "PlayerWidget",
   100                mode: "radio",
   100                mode: "radio",
   101                metadata:{
   101                metadata:{
   102                 format:'cinelab',
   102                 format:'cinelab',
   109                     format:'cinelab',
   109                     format:'cinelab',
   110                     src:'test.json',
   110                     src:'test.json',
   111                     type:'dummy'
   111                     type:'dummy'
   112                 } }]
   112                 } }]
   113               };
   113               };
   114     
   114 
   115     
   115 
   116     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);
   116     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);
   117     
   117 
   118     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
   118     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
   119     ok(res.PlayerWidget instanceof IriSP.PlayerWidget, "the dependency widget is accessible from the parent");
   119     ok(res.PlayerWidget instanceof IriSP.PlayerWidget, "the dependency widget is accessible from the parent");
   120   });
   120   });
   121   
   121 
   122   test("test the instantiation of a bunch of widgets", function() {
   122   test("test the instantiation of a bunch of widgets", function() {
   123   
   123 
   124     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
   124     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
   125     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
   125     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
   126     
   126 
   127     var widgets = IriSP.configureWidgets(pop, layoutManager, this.widgetOptions);
   127     var widgets = IriSP.configureWidgets(pop, layoutManager, this.widgetOptions);
   128 
   128 
   129     ok(widgets[0] instanceof IriSP.PlayerWidget, "first widget is a player widget");       
   129     ok(widgets[0] instanceof IriSP.PlayerWidget, "first widget is a player widget");
   130     ok(widgets[1] instanceof IriSP.SegmentsWidget, "second widget is a segments widget");
   130     ok(widgets[1] instanceof IriSP.SegmentsWidget, "second widget is a segments widget");
   131     ok(widgets[2] instanceof IriSP.AnnotationsWidget, "third widget is an annotation widget");
   131     ok(widgets[2] instanceof IriSP.AnnotationsWidget, "third widget is an annotation widget");
   132     equal(IriSP.jQuery("#" + this.widgetOptions.container).length, 1, "a new dom element has been created");
   132     equal(IriSP.jQuery("#" + this.widgetOptions.container).length, 1, "a new dom element has been created");
   133   });
   133   });
   134   
   134 
   135 
   135 
   136 }
   136 }