Skip to content

Commit

Permalink
Merge remote-tracking branch 'acheetham/FLUID-4572-template-path-for-…
Browse files Browse the repository at this point in the history
…tests'

* acheetham/FLUID-4572-template-path-for-tests:
  FLUID-4572: Cleaning up tests (doctype, namespace, remove simulate, add qunit license).
  FLUID-4572: Cleaning up tests: back to simple override of template path.
  FLUID-4572: Clean up unit test lib code; tidy the 'buildResourceSpec' function.
  FLUID-4572: Refactor valid template path to be default for all tests.
  FLUID-4572: Tests for a configurable template path (first tests).
  • Loading branch information
michelled committed Jan 10, 2012
2 parents a89f742 + a618887 commit 31a0123
Show file tree
Hide file tree
Showing 12 changed files with 2,121 additions and 8 deletions.
4 changes: 1 addition & 3 deletions demos/VideoPlayer.html
Expand Up @@ -69,10 +69,8 @@ <h1>Infusion HTML 5 Video Player</h1>
},
conversionServiceUrl: "http://royalgiz.fr/videoplayer/conversion_service/index.php",
currentTrack: "english"
},
states: {
fullscreen: false
}

}
});
</script>
Expand Down
11 changes: 10 additions & 1 deletion docs/index.html
Expand Up @@ -226,10 +226,19 @@ <h2>Supported Events</h2>
<tr>
<td>onTemplateReady</td>
<td>Default</td>
<td>Notice that all the templates have been loaded</td>
<td>Notice that all the templates have been successfully loaded. Note that if any one template fails to load, this event will not fire, and onTemplateLoadError will fire instead.</td>
<td></td>
<td></td>
</tr>
<tr>
<td>onTemplateLoadError</td>
<td>Default</td>
<td>Fires for any template that doesn't load.</td>
<td>key, href</td>
<td>key: the key related to the failed template<br />
href: the URL of the failed template
</td>
</tr>
<tr>
<td>onReadyToLoadCaptions</td>
<td>Default</td>
Expand Down
14 changes: 10 additions & 4 deletions js/VideoPlayer.js
@@ -1,14 +1,14 @@
/*
Copyright 2009 University of Toronto
Copyright 2011 Charly Molter
Copyright 2011 OCAD University
Copyright 2011-2012 OCAD University
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
You may obtain a copy of the ECL 2.0 License and BSD License at
https://source.fluidproject.org/svn/LICENSE.txt
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*/

/*global jQuery, window, swfobject, fluid*/
Expand Down Expand Up @@ -143,7 +143,8 @@ https://source.fluidproject.org/svn/LICENSE.txt
onCaptionnerReady: null,
afterTimeChange: null,
onStartTimeChange: null,
onOldBrowserDetected: null
onOldBrowserDetected: null,
onTemplateLoadError: null
},
listeners: {
onViewReady: "{videoPlayer}.refresh"
Expand Down Expand Up @@ -316,12 +317,15 @@ https://source.fluidproject.org/svn/LICENSE.txt
// If we aren't on an HTML 5 video-enabled browser, don't bother setting up the controller or captions.

fluid.fetchResources(that.options.templates, function (res) {
var fetchFailed = false;
for (var key in res) {
if (res[key].fetchError) {
fluid.log("couldn't fetch" + res[key].href);
fluid.log("status: " + res[key].fetchError.status +
", textStatus: " + res[key].fetchError.textStatus +
", errorThrown: " + res[key].fetchError.errorThrown);
that.events.onTemplateLoadError.fire(res[key].href);
fetchFailed = true;
} else if (key === "videoPlayer") {
if ($.browser.msie && $.browser.version < 9) {
that.events.onOldBrowserDetected.fire($.browser);
Expand All @@ -336,7 +340,9 @@ https://source.fluidproject.org/svn/LICENSE.txt
}
}
}
that.events.onTemplateReady.fire();
if (!fetchFailed) {
that.events.onTemplateReady.fire();
}
});

return that;
Expand Down
42 changes: 42 additions & 0 deletions tests/html/VideoPlayer-test.html
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Video Player Test Suite</title>

<link rel="stylesheet" type="text/css" media="screen" href="../lib/qunit/css/qunit.css" />

<script type="text/javascript" src="../../lib/infusion/MyInfusion.js"></script>
<script type="text/javascript" src="../../lib/jquery-ui/js/jquery.ui.button.js"></script>
<script type="text/javascript" src="../../js/VideoPlayer.js"></script>
<script type="text/javascript" src="../../js/VideoPlayer_captionner.js"></script>
<script type="text/javascript" src="../../js/VideoPlayer_captionLoader.js"></script>
<script type="text/javascript" src="../../js/VideoPlayer_controllers.js"></script>
<script type="text/javascript" src="../../js/VideoPlayer_media.js"></script>

<!-- jqUnit test framework js files -->
<script type="text/javascript" src="../lib/qunit/js/qunit.js"></script>
<script type="text/javascript" src="../lib/jqUnit/js/jqUnit.js"></script>
<script type="text/javascript" src="../lib/jquery-ui/js/jquery.simulate.js"></script>

<!-- These are tests that have been written using this page as data and test supports -->
<script type="text/javascript" src="../js/VideoPlayerTests.js"></script>

</head>
<body id="body">
<!-- This is the markup that jqUnit will look for when running tests and displaying the results -->
<h1 id="qunit-header">Video Player Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="main">

<div class="videoPlayer fl-videoPlayer">

</div>

</div> <!-- /main -->

</body>
</html>
86 changes: 86 additions & 0 deletions tests/js/VideoPlayerTests.js
@@ -0,0 +1,86 @@
/*
Copyright 2012 OCAD University
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*/

// Declare dependencies
/*global fluid, jqUnit, expect, jQuery, start*/

// JSLint options
/*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */

(function ($) {
$(document).ready(function () {

var videoPlayerTests = new jqUnit.TestCase("Video Player Tests");

var initVideoPlayer = function (testOptions) {
var opts = {
model: {
video: {
sources: [
{
src: "http://royalgiz.fr/videoplayer/video/Richard.Stallman.mp4",
type: "video/mp4"
}
]
}
},
templates: {
videoPlayer: {
// override the default template path
// TODO: We need to refactor the VideoPlayer to better support
// overriding the path without needing to know file names
href: "../../html/videoPlayer_template.html"
}
}
};
$.extend(true, opts, testOptions);
return fluid.videoPlayer(".videoPlayer", opts);
};

videoPlayerTests.asyncTest("Configurable template path (FLUID-4572): valid path", function () {
expect(1);
var vidPlayer = initVideoPlayer({
listeners: {
onTemplateReady: function () {
jqUnit.assertTrue("The template should load", true);
start();
},
onTemplateLoadError: function (href) {
jqUnit.assertTrue("Template Load Error should not fire", false);
start();
}
}
});
});

videoPlayerTests.asyncTest("Configurable template path (FLUID-4572): invalid path", function () {
expect(1);
var vidPlayer = initVideoPlayer({
templates: {
videoPlayer: {
href: "bad/test/path.html"
}
},
listeners: {
onTemplateReady: function () {
jqUnit.assertTrue("The template should not load", false);
start();
},
onTemplateLoadError: function (href) {
jqUnit.assertTrue("Event 'onTemplateLoadError' should fire", true);
start();
}
}
});
});
});
})(jQuery);
8 changes: 8 additions & 0 deletions tests/lib/README
@@ -0,0 +1,8 @@
Attribution:
* This is the unit testing suite from jQuery dual-licensed under the GPL and
MIT licenses. This code is redistributed in Infusion under the MIT license.
* The original is available at http://docs.jquery.com/Qunit

Instructions:
* To run the unit test suite, simply open any of the *-test.html pages in
your web browser.
36 changes: 36 additions & 0 deletions tests/lib/jqUnit/html/test-template.html
@@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Title Goes Here</title>

<!-- This is the jqUnit test css file -->
<link rel="stylesheet" media="screen" href="../../../lib/qunit/css/qunit.css" />

<!-- These are the required javascript modules -->
<script type="text/javascript" src="../../../../lib/jquery/core/js/jquery.js"></script>

<!-- These are the jqUnit test js files -->
<script type="text/javascript" src="../../../lib/qunit/js/qunit.js"></script>
<script type="text/javascript" src="../../../test-core/jqUnit/js/jqUnit.js"></script>

<!-- Include the javascript files you are testing here -->

<!-- Include the javascript tests here -->


</head>

<body id="body">
<h1 id="qunit-header">Test Title Goes Here</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>

<!-- Test HTML -->
<div id="main" style="display: none;">

</div>
</body>
</html>

0 comments on commit 31a0123

Please sign in to comment.