2 |
3 |
4 |
5 |
6 |
7 | VideoJS Workbench
8 |
9 |
10 |
11 |
12 |
256 |
257 |
258 |
259 |
260 |
261 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 | currentTime
285 | n/a
286 |
287 |
288 | time
289 | n/a
290 |
291 |
292 | defaultPlaybackRate
293 | 1
294 |
295 |
296 | duration
297 | n/a
298 |
299 |
300 | ended
301 | n/a
302 |
303 |
304 | paused
305 | n/a
306 |
307 |
308 | muted
309 | n/a
310 |
311 |
312 | volume
313 | n/a
314 |
315 |
316 | seeking
317 | n/a
318 |
319 |
320 | networkState
321 | n/a
322 |
323 |
324 | readyState
325 | n/a
326 |
327 |
328 | bufferedBytesStart
329 | 0
330 |
331 |
332 | bufferedBytesEnd
333 | n/a
334 |
335 |
336 | bytesTotal
337 | 0
338 |
339 |
340 | videoWidth
341 | 0
342 |
343 |
344 | videoHeight
345 | 0
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
359 |
360 |
Simple Controls
361 |
Once playback has started, the SWF's control methods will work:
362 |
pause()
363 |
resume()
364 |
seek(5)
365 |
366 |
367 |
368 |
369 |
370 |
--------------------------------------------------------------------------------
/tests/manual/manual_full.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | VideoJS Workbench
8 |
9 |
10 |
11 |
12 |
268 |
269 |
270 |
271 |
272 |
273 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 | currentTime
297 | n/a
298 |
299 |
300 | time
301 | n/a
302 |
303 |
304 | defaultPlaybackRate
305 | 1
306 |
307 |
308 | duration
309 | n/a
310 |
311 |
312 | ended
313 | n/a
314 |
315 |
316 | paused
317 | n/a
318 |
319 |
320 | muted
321 | n/a
322 |
323 |
324 | volume
325 | n/a
326 |
327 |
328 | seeking
329 | n/a
330 |
331 |
332 | networkState
333 | n/a
334 |
335 |
336 | readyState
337 | n/a
338 |
339 |
340 | bufferedBytesStart
341 | 0
342 |
343 |
344 | bufferedBytesEnd
345 | n/a
346 |
347 |
348 | bytesTotal
349 | 0
350 |
351 |
352 | videoWidth
353 | 0
354 |
355 |
356 | videoHeight
357 | 0
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
Step 1: Instantiation
368 |
Create the swf object and provide the name of the JavaScript function that's called when the player has been instanced with a 'readyFunctionName' flashvars parameter.
369 |
(the src and autoplay properties are able to be set at this time, but we won't do that here)
370 |
Create the SWF
371 |
372 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
Step 2: Configuration & Playback
384 |
Once the swf has been fully instanced, we have access to all of its methods and properties.
385 |
Let's set some basic properties:
386 |
387 | eventProxyFunction: "onSWFEvent"
388 | errorEventProxyFunction: "onSWFErrorEvent"
389 | poster: "img/testPattern_ussr_480x360.png"
390 |
391 |
Set Properties
392 |
Next, we'll call src() to let the swf know where the media asset can be found:
393 |
src("http://vjs.zencdn.net/v/oceans.mp4?")
394 |
If the SWF's autoplay property had been set to true at any point prior to this src() call, loading and playback would begin.
395 |
To begin loading without playing, call load():
396 |
load()
397 |
To begin playback, call play():
398 |
play()
399 |
400 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
--------------------------------------------------------------------------------
/tests/qunit/.gitignore:
--------------------------------------------------------------------------------
1 | .project
2 | *~
3 | *.diff
4 | *.patch
5 | .DS_Store
6 | .settings
7 |
8 |
--------------------------------------------------------------------------------
/tests/qunit/README.md:
--------------------------------------------------------------------------------
1 | [QUnit](http://docs.jquery.com/QUnit) - A JavaScript Unit Testing framework.
2 | ================================
3 |
4 | QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery
5 | project to test its code and plugins but is capable of testing any generic
6 | JavaScript code (and even capable of testing JavaScript code on the server-side).
7 |
8 | QUnit is especially useful for regression testing: Whenever a bug is reported,
9 | write a test that asserts the existence of that particular bug. Then fix it and
10 | commit both. Every time you work on the code again, run the tests. If the bug
11 | comes up again - a regression - you'll spot it immediately and know how to fix
12 | it, because you know what code you just changed.
13 |
14 | Having good unit test coverage makes safe refactoring easy and cheap. You can
15 | run the tests after each small refactoring step and always know what change
16 | broke something.
17 |
18 | QUnit is similar to other unit testing frameworks like JUnit, but makes use of
19 | the features JavaScript provides and helps with testing code in the browser, eg.
20 | with it's stop/start facilities for testing asynchronous code.
21 |
22 | If you are interested in helping developing QUnit, you are in the right place.
23 | For related discussions, visit the
24 | [QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing).
25 |
26 | Planning for a qunitjs.com site and other testing tools related work now happens
27 | on the [jQuery Testing Team planning wiki](http://jquerytesting.pbworks.com/w/page/41556026/FrontPage).
28 |
--------------------------------------------------------------------------------
/tests/qunit/addons/canvas/README.md:
--------------------------------------------------------------------------------
1 | Canvas - A QUnit Addon For Testing Canvas Rendering
2 | ================================
3 |
4 | This addon for QUnit adds a pixelEqual method that allows you to assert
5 | individual pixel values in a given canvas.
6 |
7 | Usage:
8 |
9 | pixelEqual(canvas, x, y, r, g, b, a, message)
10 |
11 | Where:
12 |
13 | * canvas: Reference to a canvas element
14 | * x, y: Coordinates of the pixel to test
15 | * r, g, b, a: The color and opacity value of the pixel that you except
16 | * message: Optional message, same as for other assertions
17 |
--------------------------------------------------------------------------------
/tests/qunit/addons/canvas/canvas-test.js:
--------------------------------------------------------------------------------
1 | test("Canvas pixels", function () {
2 | var canvas = document.getElementById('qunit-canvas'), context;
3 | try {
4 | context = canvas.getContext('2d');
5 | } catch(e) {
6 | // propably no canvas support, just exit
7 | return;
8 | }
9 | context.fillStyle = 'rgba(0, 0, 0, 0)';
10 | context.fillRect(0, 0, 5, 5);
11 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
12 | context.clearRect(0,0,5,5);
13 | context.fillStyle = 'rgba(255, 0, 0, 0)';
14 | context.fillRect(0, 0, 5, 5);
15 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
16 | context.clearRect(0,0,5,5);
17 | context.fillStyle = 'rgba(0, 255, 0, 0)';
18 | context.fillRect(0, 0, 5, 5);
19 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
20 | context.clearRect(0,0,5,5);
21 | context.fillStyle = 'rgba(0, 0, 255, 0)';
22 | context.fillRect(0, 0, 5, 5);
23 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0);
24 | context.clearRect(0,0,5,5);
25 |
26 | context.fillStyle = 'rgba(0, 0, 0, 0.5)';
27 | context.fillRect(0, 0, 5, 5);
28 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 127);
29 | context.clearRect(0,0,5,5);
30 | context.fillStyle = 'rgba(255, 0, 0, 0.5)';
31 | context.fillRect(0, 0, 5, 5);
32 | QUnit.pixelEqual(canvas, 0, 0, 255, 0, 0, 127);
33 | context.clearRect(0,0,5,5);
34 | context.fillStyle = 'rgba(0, 255, 0, 0.5)';
35 | context.fillRect(0, 0, 5, 5);
36 | QUnit.pixelEqual(canvas, 0, 0, 0, 255, 0, 127);
37 | context.clearRect(0,0,5,5);
38 | context.fillStyle = 'rgba(0, 0, 255, 0.5)';
39 | context.fillRect(0, 0, 5, 5);
40 | QUnit.pixelEqual(canvas, 0, 0, 0, 0, 255, 127);
41 | context.clearRect(0,0,5,5);
42 |
43 | context.fillStyle = 'rgba(0, 0, 0, 0.5)';
44 | context.fillRect(0, 0, 5, 5);
45 | QUnit.pixelEqual(canvas, 2, 2, 0, 0, 0, 127);
46 | context.clearRect(0,0,5,5);
47 | context.fillStyle = 'rgba(255, 0, 0, 0.5)';
48 | context.fillRect(0, 0, 5, 5);
49 | QUnit.pixelEqual(canvas, 2, 2, 255, 0, 0, 127);
50 | context.clearRect(0,0,5,5);
51 | context.fillStyle = 'rgba(0, 255, 0, 0.5)';
52 | context.fillRect(0, 0, 5, 5);
53 | QUnit.pixelEqual(canvas, 2, 2, 0, 255, 0, 127);
54 | context.clearRect(0,0,5,5);
55 | context.fillStyle = 'rgba(0, 0, 255, 0.5)';
56 | context.fillRect(0, 0, 5, 5);
57 | QUnit.pixelEqual(canvas, 2, 2, 0, 0, 255, 127);
58 | context.clearRect(0,0,5,5);
59 |
60 | context.fillStyle = 'rgba(0, 0, 0, 1)';
61 | context.fillRect(0, 0, 5, 5);
62 | QUnit.pixelEqual(canvas, 4, 4, 0, 0, 0, 255);
63 | context.clearRect(0,0,5,5);
64 | context.fillStyle = 'rgba(255, 0, 0, 1)';
65 | context.fillRect(0, 0, 5, 5);
66 | QUnit.pixelEqual(canvas, 4, 4, 255, 0, 0, 255);
67 | context.clearRect(0,0,5,5);
68 | context.fillStyle = 'rgba(0, 255, 0, 1)';
69 | context.fillRect(0, 0, 5, 5);
70 | QUnit.pixelEqual(canvas, 4, 4, 0, 255, 0, 255);
71 | context.clearRect(0,0,5,5);
72 | context.fillStyle = 'rgba(0, 0, 255, 1)';
73 | context.fillRect(0, 0, 5, 5);
74 | QUnit.pixelEqual(canvas, 4, 4, 0, 0, 255, 255);
75 | context.clearRect(0,0,5,5);
76 | });
77 |
--------------------------------------------------------------------------------
/tests/qunit/addons/canvas/canvas.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Test Suite - Canvas Addon
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/qunit/addons/canvas/qunit-canvas.js:
--------------------------------------------------------------------------------
1 | QUnit.extend( QUnit, {
2 | pixelEqual: function(canvas, x, y, r, g, b, a, message) {
3 | var actual = Array.prototype.slice.apply(canvas.getContext('2d').getImageData(x, y, 1, 1).data), expected = [r, g, b, a];
4 | QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
5 | }
6 | });
7 |
--------------------------------------------------------------------------------
/tests/qunit/addons/close-enough/README.md:
--------------------------------------------------------------------------------
1 | Close-Enough - A QUnit Addon For Number Approximations
2 | ================================
3 |
4 | This addon for QUnit adds close and notClose assertion methods, to test that
5 | numbers are close enough (or different enough) from an expected number, with
6 | a specified accuracy.
7 |
8 | Usage:
9 |
10 | close(actual, expected, maxDifference, message)
11 | notClose(actual, expected, minDifference, message)
12 |
13 | Where:
14 |
15 | * maxDifference: the maximum inclusive difference allowed between the actual and expected numbers
16 | * minDifference: the minimum exclusive difference allowed between the actual and expected numbers
17 | * actual, expected, message: The usual
18 |
--------------------------------------------------------------------------------
/tests/qunit/addons/close-enough/close-enough-test.js:
--------------------------------------------------------------------------------
1 | test("Close Numbers", function () {
2 |
3 | QUnit.close(7, 7, 0);
4 | QUnit.close(7, 7.1, 0.1);
5 | QUnit.close(7, 7.1, 0.2);
6 |
7 | QUnit.close(3.141, Math.PI, 0.001);
8 | QUnit.close(3.1, Math.PI, 0.1);
9 |
10 | var halfPi = Math.PI / 2;
11 | QUnit.close(halfPi, 1.57, 0.001);
12 |
13 | var sqrt2 = Math.sqrt(2);
14 | QUnit.close(sqrt2, 1.4142, 0.0001);
15 |
16 | QUnit.close(Infinity, Infinity, 1);
17 |
18 | });
19 |
20 | test("Distant Numbers", function () {
21 |
22 | QUnit.notClose(6, 7, 0);
23 | QUnit.notClose(7, 7.2, 0.1);
24 | QUnit.notClose(7, 7.2, 0.19999999999);
25 |
26 | QUnit.notClose(3.141, Math.PI, 0.0001);
27 | QUnit.notClose(3.1, Math.PI, 0.001);
28 |
29 | var halfPi = Math.PI / 2;
30 | QUnit.notClose(halfPi, 1.57, 0.0001);
31 |
32 | var sqrt2 = Math.sqrt(2);
33 | QUnit.notClose(sqrt2, 1.4142, 0.00001);
34 |
35 | QUnit.notClose(Infinity, -Infinity, 5);
36 |
37 | });
--------------------------------------------------------------------------------
/tests/qunit/addons/close-enough/close-enough.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Test Suite - Close Enough Addon
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tests/qunit/addons/close-enough/qunit-close-enough.js:
--------------------------------------------------------------------------------
1 | QUnit.extend( QUnit, {
2 | /**
3 | * Checks that the first two arguments are equal, or are numbers close enough to be considered equal
4 | * based on a specified maximum allowable difference.
5 | *
6 | * @example close(3.141, Math.PI, 0.001);
7 | *
8 | * @param Number actual
9 | * @param Number expected
10 | * @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers)
11 | * @param String message (optional)
12 | */
13 | close: function(actual, expected, maxDifference, message) {
14 | var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
15 | QUnit.push(passes, actual, expected, message);
16 | },
17 |
18 | /**
19 | * Checks that the first two arguments are numbers with differences greater than the specified
20 | * minimum difference.
21 | *
22 | * @example notClose(3.1, Math.PI, 0.001);
23 | *
24 | * @param Number actual
25 | * @param Number expected
26 | * @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers)
27 | * @param String message (optional)
28 | */
29 | notClose: function(actual, expected, minDifference, message) {
30 | QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message);
31 | }
32 | });
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/README.md:
--------------------------------------------------------------------------------
1 | Composite - A QUnit Addon For Running Multiple Test Files
2 | ================================
3 |
4 | Composite is a QUnit addon that, when handed an array of files, will
5 | open each of those files inside of an iframe, run the tests and
6 | display the results as a single suite of QUnit tests.
7 |
8 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/composite-demo-test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit SubsuiteRunner Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/composite-test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Core Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | test markup
19 |
20 |
21 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/composite-test.js:
--------------------------------------------------------------------------------
1 | module( "testSuites tests", (function(){
2 | var asyncTest = QUnit.asyncTest,
3 | runSuite = QUnit.runSuite;
4 |
5 | return {
6 | setup: function(){
7 | //proxy asyncTest and runSuite
8 | QUnit.asyncTest = window.asyncTest = function( name, callback ){
9 | ok( true, "asyncTestCalled for each suite" );
10 | callback(); //don't acutally create tests, just call callback
11 | };
12 | QUnit.runSuite = window.runSuite = function(){
13 | ok( true, "runSuite called for each suite" );
14 | };
15 | //ensure that subsuite's done doesn't run
16 | this.oldDone = QUnit.done;
17 | },
18 | teardown: function(){
19 | //restore
20 | QUnit.asyncTest = window.asyncTest = asyncTest;
21 | QUnit.runSuite = window.runSuite = runSuite;
22 | QUnit.done = this.oldDone;
23 | }
24 | };
25 | })());
26 |
27 | test( "proper number of asyncTest and runSuite calls", function(){
28 | expect( 6 );
29 | QUnit.testSuites( ["one.html", "two.html", "three.html"] );
30 | });
31 |
32 | test( "done callback changed", function(){
33 | QUnit.testSuites( ["dummy.html"] );
34 | notEqual( this.oldDone, QUnit.done, "done callback should be set" );
35 | });
36 |
37 | module( "testStart tests", (function(){
38 | var id = QUnit.id;
39 | return {
40 | setup: function(){
41 | //proxy id
42 | var fakeElem = this.fakeElem = document.createElement( "div" );
43 |
44 | QUnit.id = function(){
45 | return fakeElem;
46 | }
47 | },
48 | teardown: function(){
49 | QUnit.id = id;
50 | }
51 | };
52 | })());
53 |
54 | test( "running message printed", function(){
55 | var hello = "hello world",
56 | expected = "Running " + hello + "... ";
57 | QUnit.testStart( {name: hello} );
58 | equal( this.fakeElem.innerHTML, expected, "innerHTML was set correctly by testStart" );
59 | });
60 |
61 | module( "testDone tests", (function(){
62 | var id = QUnit.id;
63 | return {
64 | setup: function(){
65 | //proxy id
66 | var fakeElem = this.fakeElem = document.createElement( "div" );
67 | fakeElem.appendChild( document.createElement( "ol" ) );
68 | fakeElem.appendChild( document.createElement( "ol" ) );
69 | QUnit.id = function(){
70 | return fakeElem;
71 | }
72 | },
73 | teardown: function(){
74 | QUnit.id = id;
75 | }
76 | };
77 | })());
78 |
79 | test( "test expansions are hidden", function(){
80 | QUnit.testDone();
81 | equal( this.fakeElem.children[0].style.display, "none", "first ol display is none" );
82 | equal( this.fakeElem.children[1].style.display, "none", "second ol display is none" );
83 | });
84 |
85 | test( "non-ol elements aren't hidden", function(){
86 | this.fakeElem.appendChild( document.createElement( "span" ) );
87 |
88 | QUnit.testDone();
89 | notEqual( this.fakeElem.children[2].style.display, "none", "first ol display is none" );
90 | });
91 |
92 | module( "runSuite tests", (function(){
93 | var getElementsByTagName = document.getElementsByTagName,
94 | createElement = document.createElement,
95 | runSuite = QUnit.runSuite;
96 |
97 | return {
98 | setup: function(){
99 | //proxy getElementsByTagName and createElement
100 | var setAttributeCall = this.setAttributeCall = {},
101 | appendChildCall = this.appendChildCall = {called: 0},
102 | iframeLoad = this.iframeLoad = {},
103 | iframeQUnitObject = this.iframeQUnitObject = {},
104 | fakeElement = {
105 | appendChild: function(){appendChildCall.called++},
106 | setAttribute: function(){setAttributeCall.args = arguments},
107 | addEventListener: function( type, callback ){iframeLoad.callback = callback;},
108 | contentWindow: {QUnit: iframeQUnitObject},
109 | className: "",
110 | };
111 |
112 | document.getElementsByTagName = function(){
113 | return [fakeElement];
114 | };
115 | document.createElement = function(){
116 | return fakeElement;
117 | }
118 |
119 | },
120 | teardown: function(){
121 | document.getElementsByTagName = getElementsByTagName;
122 | document.createElement = createElement;
123 | //must restore even though we didn't proxy; the runner overwrites upon first call
124 | QUnit.runSuite = runSuite;
125 | }
126 | };
127 | })());
128 |
129 | test( "runSuite different after first run", function(){
130 | var before = QUnit.runSuite,
131 | after;
132 | QUnit.runSuite();
133 | after = QUnit.runSuite;
134 | notEqual( before, after, "runSuite changed after initial run" );
135 | });
136 |
137 | test( "iframe only created once", function(){
138 | QUnit.runSuite();
139 | equal( this.appendChildCall.called, 1, "append child called once" );
140 | QUnit.runSuite();
141 | equal( this.appendChildCall.called, 1, "append child only ever called once" );
142 | });
143 |
144 | test( "iframe's QUnit object is modified when iframe source loads", function(){
145 | var before = this.iframeQUnitObject,
146 | after;
147 | QUnit.runSuite();
148 | this.iframeLoad.callback();
149 | notEqual( before, after, "iframe's qunit object is modified upon load");
150 | });
151 |
152 | test( "iframe src set to suite passed", function(){
153 | var pages = ["testing.html", "subsuiteRunner.html"];
154 | QUnit.runSuite( pages[0] );
155 | equal( this.setAttributeCall.args[0], "src", "src attribute set" );
156 | equal( this.setAttributeCall.args[1], pages[0], "src attribute set" );
157 | QUnit.runSuite( pages[1] );
158 | equal( this.setAttributeCall.args[1], pages[1], "src attribute set" );
159 | });
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/dummy-qunit-test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Core Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | test markup
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/dummy-same-test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Same Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | test markup
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Composite
6 |
7 |
8 | Composite
9 | A QUnit Addon For Running Multiple Test Files
10 | Composite is a QUnit addon that, when handed an array of
11 | files, will open each of those files inside of an iframe, run
12 | the tests and display the results as a single suite of QUnit
13 | tests.
14 | Using Composite
15 | To use Composite, setup a standard QUnit html page as you
16 | would with other QUnit tests. Remember to include composite.js
17 | and composite.css. Then, inside of either an external js file,
18 | or a script block call the only new method that Composite
19 | exposes, QUnit.testSuites().
QUnit.testSuites() is
20 | passed an array of test files to run as follows:
21 |
22 | QUnit.testSuites([
23 | "test-file-1.html",
24 | "test-file-2.html",
25 | "test-file-3.html"
26 | ]);
27 |
28 | Tests
29 | Composite has tests of it's own.
30 |
31 | Composite Test : A suite which tests the implementation of composite.
32 | Composite Demo : A suite which demoes how Compisite is bootstrapped and run.
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/qunit-composite.css:
--------------------------------------------------------------------------------
1 | iframe.qunit-subsuite{
2 | position: fixed;
3 | bottom: 0;
4 | left: 0;
5 |
6 | margin: 0;
7 | padding: 0;
8 | border-width: 1px 0 0;
9 | height: 45%;
10 | width: 100%;
11 |
12 | background: #fff;
13 | }
--------------------------------------------------------------------------------
/tests/qunit/addons/composite/qunit-composite.js:
--------------------------------------------------------------------------------
1 | (function( QUnit ) {
2 |
3 | var subsuiteFrame;
4 |
5 | QUnit.extend( QUnit, {
6 | testSuites: function( suites ) {
7 | for ( var i = 0; i < suites.length; i++ ) {
8 | (function( suite ) {
9 | asyncTest( suite, function() {
10 | QUnit.runSuite( suite );
11 | });
12 | }( suites[i] ) );
13 | }
14 | QUnit.done = function() {
15 | subsuiteFrame.style.display = "none";
16 | };
17 | },
18 |
19 | testStart: function( data ) {
20 | // update the test status to show which test suite is running
21 | QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "... ";
22 | },
23 |
24 | testDone: function() {
25 | var current = QUnit.id( this.config.current.id ),
26 | children = current.children;
27 |
28 | // undo the auto-expansion of failed tests
29 | for ( var i = 0; i < children.length; i++ ) {
30 | if ( children[i].nodeName === "OL" ) {
31 | children[i].style.display = "none";
32 | }
33 | }
34 | },
35 |
36 | runSuite: function( suite ) {
37 | var body = document.getElementsByTagName( "body" )[0],
38 | iframe = subsuiteFrame = document.createElement( "iframe" ),
39 | iframeWin;
40 |
41 | iframe.className = "qunit-subsuite";
42 | body.appendChild( iframe );
43 |
44 | function onIframeLoad() {
45 | var module, test,
46 | count = 0;
47 |
48 | QUnit.extend( iframeWin.QUnit, {
49 | moduleStart: function( data ) {
50 | // capture module name for messages
51 | module = data.name;
52 | },
53 |
54 | testStart: function( data ) {
55 | // capture test name for messages
56 | test = data.name;
57 | },
58 |
59 | log: function( data ) {
60 | // pass all test details through to the main page
61 | var message = module + ": " + test + ": " + data.message;
62 | expect( ++count );
63 | QUnit.push( data.result, data.actual, data.expected, message );
64 | },
65 |
66 | done: function() {
67 | // start the wrapper test from the main page
68 | start();
69 | }
70 | });
71 | }
72 | QUnit.addEvent( iframe, "load", onIframeLoad );
73 |
74 | iframeWin = iframe.contentWindow;
75 | iframe.setAttribute( "src", suite );
76 |
77 | this.runSuite = function( suite ) {
78 | iframe.setAttribute( "src", suite );
79 | };
80 | }
81 | });
82 | }( QUnit ) );
83 |
--------------------------------------------------------------------------------
/tests/qunit/addons/step/README.md:
--------------------------------------------------------------------------------
1 | QUnit.step() - A QUnit Addon For Testing execution in order
2 | ============================================================
3 |
4 | This addon for QUnit adds a step method that allows you to assert
5 | the proper sequence in which the code should execute.
6 |
7 | Example:
8 |
9 | test("example test", function () {
10 | function x() {
11 | QUnit.step(2, "function y should be called first");
12 | }
13 | function y() {
14 | QUnit.step(1);
15 | }
16 | y();
17 | x();
18 | });
--------------------------------------------------------------------------------
/tests/qunit/addons/step/qunit-step.js:
--------------------------------------------------------------------------------
1 | QUnit.extend( QUnit, {
2 |
3 | /**
4 | * Check the sequence/order
5 | *
6 | * @example step(1); setTimeout(function () { step(3); }, 100); step(2);
7 | * @param Number expected The excepted step within the test()
8 | * @param String message (optional)
9 | */
10 | step: function (expected, message) {
11 | this.config.current.step++; // increment internal step counter.
12 | if (typeof message == "undefined") {
13 | message = "step " + expected;
14 | }
15 | var actual = this.config.current.step;
16 | QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
17 | }
18 | });
19 |
20 | /**
21 | * Reset the step counter for every test()
22 | */
23 | QUnit.testStart(function () {
24 | this.config.current.step = 0;
25 | });
26 |
--------------------------------------------------------------------------------
/tests/qunit/addons/step/step-test.js:
--------------------------------------------------------------------------------
1 | module('Step Addon');
2 | test("step", 3, function () {
3 | QUnit.step(1, "step starts at 1");
4 | setTimeout(function () {
5 | start();
6 | QUnit.step(3);
7 | }, 100);
8 | QUnit.step(2, "before the setTimeout callback is run");
9 | stop();
10 | });
11 | test("step counter", 1, function () {
12 | QUnit.step(1, "each test has its own step counter");
13 | });
--------------------------------------------------------------------------------
/tests/qunit/addons/step/step.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Test Suite - Step Addon
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/qunit/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "qunit",
3 | "author": "The jQuery Project",
4 | "contributors": [
5 | {
6 | "name": "John Resig",
7 | "email": "jeresig@gmail.com",
8 | "url": "http://ejohn.org/"
9 | },
10 | {
11 | "name": "Jörn Zaefferer",
12 | "email": "joern.zaefferer@googlemail.com",
13 | "url": "http://bassistance.de/"
14 | }],
15 | "url": "http://docs.jquery.com/QUnit",
16 | "repositories" : [{
17 | "type": "git",
18 | "url": "https://github.com/jquery/qunit.git"
19 | }],
20 | "license": {
21 | "name": "MIT",
22 | "url": "http://www.opensource.org/licenses/mit-license.php"
23 | },
24 | "description": "An easy-to-use JavaScript Unit Testing framework.",
25 | "keywords": [ "testing", "unit", "jquery" ],
26 | "main": "qunit/qunit.js"
27 | }
28 |
--------------------------------------------------------------------------------
/tests/qunit/qunit/qunit.css:
--------------------------------------------------------------------------------
1 | /**
2 | * QUnit - A JavaScript Unit Testing Framework
3 | *
4 | * http://docs.jquery.com/QUnit
5 | *
6 | * Copyright (c) 2011 John Resig, Jörn Zaefferer
7 | * Dual licensed under the MIT (MIT-LICENSE.txt)
8 | * or GPL (GPL-LICENSE.txt) licenses.
9 | */
10 |
11 | /** Font Family and Sizes */
12 |
13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
15 | }
16 |
17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
18 | #qunit-tests { font-size: smaller; }
19 |
20 |
21 | /** Resets */
22 |
23 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
24 | margin: 0;
25 | padding: 0;
26 | }
27 |
28 |
29 | /** Header */
30 |
31 | #qunit-header {
32 | padding: 0.5em 0 0.5em 1em;
33 |
34 | color: #8699a4;
35 | background-color: #0d3349;
36 |
37 | font-size: 1.5em;
38 | line-height: 1em;
39 | font-weight: normal;
40 |
41 | border-radius: 15px 15px 0 0;
42 | -moz-border-radius: 15px 15px 0 0;
43 | -webkit-border-top-right-radius: 15px;
44 | -webkit-border-top-left-radius: 15px;
45 | }
46 |
47 | #qunit-header a {
48 | text-decoration: none;
49 | color: #c2ccd1;
50 | }
51 |
52 | #qunit-header a:hover,
53 | #qunit-header a:focus {
54 | color: #fff;
55 | }
56 |
57 | #qunit-banner {
58 | height: 5px;
59 | }
60 |
61 | #qunit-testrunner-toolbar {
62 | padding: 0.5em 0 0.5em 2em;
63 | color: #5E740B;
64 | background-color: #eee;
65 | }
66 |
67 | #qunit-userAgent {
68 | padding: 0.5em 0 0.5em 2.5em;
69 | background-color: #2b81af;
70 | color: #fff;
71 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
72 | }
73 |
74 |
75 | /** Tests: Pass/Fail */
76 |
77 | #qunit-tests {
78 | list-style-position: inside;
79 | }
80 |
81 | #qunit-tests li {
82 | padding: 0.4em 0.5em 0.4em 2.5em;
83 | border-bottom: 1px solid #fff;
84 | list-style-position: inside;
85 | }
86 |
87 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
88 | display: none;
89 | }
90 |
91 | #qunit-tests li strong {
92 | cursor: pointer;
93 | }
94 |
95 | #qunit-tests li a {
96 | padding: 0.5em;
97 | color: #c2ccd1;
98 | text-decoration: none;
99 | }
100 | #qunit-tests li a:hover,
101 | #qunit-tests li a:focus {
102 | color: #000;
103 | }
104 |
105 | #qunit-tests ol {
106 | margin-top: 0.5em;
107 | padding: 0.5em;
108 |
109 | background-color: #fff;
110 |
111 | border-radius: 15px;
112 | -moz-border-radius: 15px;
113 | -webkit-border-radius: 15px;
114 |
115 | box-shadow: inset 0px 2px 13px #999;
116 | -moz-box-shadow: inset 0px 2px 13px #999;
117 | -webkit-box-shadow: inset 0px 2px 13px #999;
118 | }
119 |
120 | #qunit-tests table {
121 | border-collapse: collapse;
122 | margin-top: .2em;
123 | }
124 |
125 | #qunit-tests th {
126 | text-align: right;
127 | vertical-align: top;
128 | padding: 0 .5em 0 0;
129 | }
130 |
131 | #qunit-tests td {
132 | vertical-align: top;
133 | }
134 |
135 | #qunit-tests pre {
136 | margin: 0;
137 | white-space: pre-wrap;
138 | word-wrap: break-word;
139 | }
140 |
141 | #qunit-tests del {
142 | background-color: #e0f2be;
143 | color: #374e0c;
144 | text-decoration: none;
145 | }
146 |
147 | #qunit-tests ins {
148 | background-color: #ffcaca;
149 | color: #500;
150 | text-decoration: none;
151 | }
152 |
153 | /*** Test Counts */
154 |
155 | #qunit-tests b.counts { color: black; }
156 | #qunit-tests b.passed { color: #5E740B; }
157 | #qunit-tests b.failed { color: #710909; }
158 |
159 | #qunit-tests li li {
160 | margin: 0.5em;
161 | padding: 0.4em 0.5em 0.4em 0.5em;
162 | background-color: #fff;
163 | border-bottom: none;
164 | list-style-position: inside;
165 | }
166 |
167 | /*** Passing Styles */
168 |
169 | #qunit-tests li li.pass {
170 | color: #5E740B;
171 | background-color: #fff;
172 | border-left: 26px solid #C6E746;
173 | }
174 |
175 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
176 | #qunit-tests .pass .test-name { color: #366097; }
177 |
178 | #qunit-tests .pass .test-actual,
179 | #qunit-tests .pass .test-expected { color: #999999; }
180 |
181 | #qunit-banner.qunit-pass { background-color: #C6E746; }
182 |
183 | /*** Failing Styles */
184 |
185 | #qunit-tests li li.fail {
186 | color: #710909;
187 | background-color: #fff;
188 | border-left: 26px solid #EE5757;
189 | white-space: pre;
190 | }
191 |
192 | #qunit-tests > li:last-child {
193 | border-radius: 0 0 15px 15px;
194 | -moz-border-radius: 0 0 15px 15px;
195 | -webkit-border-bottom-right-radius: 15px;
196 | -webkit-border-bottom-left-radius: 15px;
197 | }
198 |
199 | #qunit-tests .fail { color: #000000; background-color: #EE5757; }
200 | #qunit-tests .fail .test-name,
201 | #qunit-tests .fail .module-name { color: #000000; }
202 |
203 | #qunit-tests .fail .test-actual { color: #EE5757; }
204 | #qunit-tests .fail .test-expected { color: green; }
205 |
206 | #qunit-banner.qunit-fail { background-color: #EE5757; }
207 |
208 |
209 | /** Result */
210 |
211 | #qunit-testresult {
212 | padding: 0.5em 0.5em 0.5em 2.5em;
213 |
214 | color: #2b81af;
215 | background-color: #D2E0E6;
216 |
217 | border-bottom: 1px solid white;
218 | }
219 |
220 | /** Fixture */
221 |
222 | #qunit-fixture {
223 | position: absolute;
224 | top: -10000px;
225 | left: -10000px;
226 | }
227 |
--------------------------------------------------------------------------------
/tests/qunit/test/headless.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QUnit Test Suite
5 |
6 |
7 |
8 |
9 |
20 |
21 |
22 | test markup
23 |
24 |
25 |
--------------------------------------------------------------------------------
/tests/qunit/test/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | test markup
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/qunit/test/logs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QUnit Test Suite
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | test markup
16 |
17 |
18 |
--------------------------------------------------------------------------------
/tests/qunit/test/logs.js:
--------------------------------------------------------------------------------
1 | // TODO disable reordering for this suite!
2 |
3 |
4 | var begin = 0,
5 | moduleStart = 0,
6 | moduleDone = 0,
7 | testStart = 0,
8 | testDone = 0,
9 | log = 0,
10 | moduleContext,
11 | moduleDoneContext,
12 | testContext,
13 | testDoneContext,
14 | logContext;
15 |
16 | QUnit.begin(function() {
17 | begin++;
18 | });
19 | QUnit.done(function() {
20 | });
21 | QUnit.moduleStart(function(context) {
22 | moduleStart++;
23 | moduleContext = context;
24 | });
25 | QUnit.moduleDone(function(context) {
26 | moduleDone++;
27 | moduleDoneContext = context;
28 | });
29 | QUnit.testStart(function(context) {
30 | testStart++;
31 | testContext = context;
32 | });
33 | QUnit.testDone(function(context) {
34 | testDone++;
35 | testDoneContext = context;
36 | });
37 | QUnit.log(function(context) {
38 | log++;
39 | logContext = context;
40 | });
41 |
42 | var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"];
43 | for (var i = 0; i < logs.length; i++) {
44 | (function() {
45 | var log = logs[i];
46 | QUnit[log](function() {
47 | console.log(log, arguments);
48 | });
49 | })();
50 | }
51 |
52 | module("logs1");
53 |
54 | test("test1", 13, function() {
55 | equal(begin, 1);
56 | equal(moduleStart, 1);
57 | equal(testStart, 1);
58 | equal(testDone, 0);
59 | equal(moduleDone, 0);
60 |
61 | deepEqual(logContext, {
62 | result: true,
63 | message: undefined,
64 | actual: 0,
65 | expected: 0
66 | });
67 | equal("foo", "foo", "msg");
68 | deepEqual(logContext, {
69 | result: true,
70 | message: "msg",
71 | actual: "foo",
72 | expected: "foo"
73 | });
74 | strictEqual(testDoneContext, undefined);
75 | deepEqual(testContext, {
76 | module: "logs1",
77 | name: "test1"
78 | });
79 | strictEqual(moduleDoneContext, undefined);
80 | deepEqual(moduleContext, {
81 | name: "logs1"
82 | });
83 |
84 | equal(log, 12);
85 | });
86 | test("test2", 10, function() {
87 | equal(begin, 1);
88 | equal(moduleStart, 1);
89 | equal(testStart, 2);
90 | equal(testDone, 1);
91 | equal(moduleDone, 0);
92 |
93 | deepEqual(testDoneContext, {
94 | module: "logs1",
95 | name: "test1",
96 | failed: 0,
97 | passed: 13,
98 | total: 13
99 | });
100 | deepEqual(testContext, {
101 | module: "logs1",
102 | name: "test2"
103 | });
104 | strictEqual(moduleDoneContext, undefined);
105 | deepEqual(moduleContext, {
106 | name: "logs1"
107 | });
108 |
109 | equal(log, 22);
110 | });
111 |
112 | module("logs2");
113 |
114 | test("test1", 9, function() {
115 | equal(begin, 1);
116 | equal(moduleStart, 2);
117 | equal(testStart, 3);
118 | equal(testDone, 2);
119 | equal(moduleDone, 1);
120 |
121 | deepEqual(testContext, {
122 | module: "logs2",
123 | name: "test1"
124 | });
125 | deepEqual(moduleDoneContext, {
126 | name: "logs1",
127 | failed: 0,
128 | passed: 23,
129 | total: 23
130 | });
131 | deepEqual(moduleContext, {
132 | name: "logs2"
133 | });
134 |
135 | equal(log, 31);
136 | });
137 | test("test2", 8, function() {
138 | equal(begin, 1);
139 | equal(moduleStart, 2);
140 | equal(testStart, 4);
141 | equal(testDone, 3);
142 | equal(moduleDone, 1);
143 |
144 | deepEqual(testContext, {
145 | module: "logs2",
146 | name: "test2"
147 | });
148 | deepEqual(moduleContext, {
149 | name: "logs2"
150 | });
151 |
152 | equal(log, 39);
153 | });
154 |
--------------------------------------------------------------------------------
/tests/qunit/test/test.js:
--------------------------------------------------------------------------------
1 | test("module without setup/teardown (default)", function() {
2 | expect(1);
3 | ok(true);
4 | });
5 |
6 | test("expect in test", 3, function() {
7 | ok(true);
8 | ok(true);
9 | ok(true);
10 | });
11 |
12 | test("expect in test", 1, function() {
13 | ok(true);
14 | });
15 |
16 | module("setup test", {
17 | setup: function() {
18 | ok(true);
19 | }
20 | });
21 |
22 | test("module with setup", function() {
23 | expect(2);
24 | ok(true);
25 | });
26 |
27 | test("module with setup, expect in test call", 2, function() {
28 | ok(true);
29 | });
30 |
31 | var state;
32 |
33 | module("setup/teardown test", {
34 | setup: function() {
35 | state = true;
36 | ok(true);
37 | },
38 | teardown: function() {
39 | ok(true);
40 | }
41 | });
42 |
43 | test("module with setup/teardown", function() {
44 | expect(3);
45 | ok(true);
46 | });
47 |
48 | module("setup/teardown test 2");
49 |
50 | test("module without setup/teardown", function() {
51 | expect(1);
52 | ok(true);
53 | });
54 |
55 | if (typeof setTimeout !== 'undefined') {
56 | state = 'fail';
57 |
58 | module("teardown and stop", {
59 | teardown: function() {
60 | equal(state, "done", "Test teardown.");
61 | }
62 | });
63 |
64 | test("teardown must be called after test ended", function() {
65 | expect(1);
66 | stop();
67 | setTimeout(function() {
68 | state = "done";
69 | start();
70 | }, 13);
71 | });
72 |
73 | test("parameter passed to stop increments semaphore n times", function() {
74 | expect(1);
75 | stop(3);
76 | setTimeout(function() {
77 | state = "not enough starts";
78 | start(), start();
79 | }, 13);
80 | setTimeout(function() {
81 | state = "done";
82 | start();
83 | }, 15);
84 | });
85 |
86 | test("parameter passed to start decrements semaphore n times", function() {
87 | expect(1);
88 | stop(), stop(), stop();
89 | setTimeout(function() {
90 | state = "done";
91 | start(3);
92 | }, 18);
93 | });
94 |
95 | module("async setup test", {
96 | setup: function() {
97 | stop();
98 | setTimeout(function(){
99 | ok(true);
100 | start();
101 | }, 500);
102 | }
103 | });
104 |
105 | asyncTest("module with async setup", function() {
106 | expect(2);
107 | ok(true);
108 | start();
109 | });
110 |
111 | module("async teardown test", {
112 | teardown: function() {
113 | stop();
114 | setTimeout(function(){
115 | ok(true);
116 | start();
117 | }, 500);
118 | }
119 | });
120 |
121 | asyncTest("module with async teardown", function() {
122 | expect(2);
123 | ok(true);
124 | start();
125 | });
126 |
127 | module("asyncTest");
128 |
129 | asyncTest("asyncTest", function() {
130 | expect(2);
131 | ok(true);
132 | setTimeout(function() {
133 | state = "done";
134 | ok(true);
135 | start();
136 | }, 13);
137 | });
138 |
139 | asyncTest("asyncTest", 2, function() {
140 | ok(true);
141 | setTimeout(function() {
142 | state = "done";
143 | ok(true);
144 | start();
145 | }, 13);
146 | });
147 |
148 | test("sync", 2, function() {
149 | stop();
150 | setTimeout(function() {
151 | ok(true);
152 | start();
153 | }, 13);
154 | stop();
155 | setTimeout(function() {
156 | ok(true);
157 | start();
158 | }, 125);
159 | });
160 |
161 | test("test synchronous calls to stop", 2, function() {
162 | stop();
163 | setTimeout(function(){
164 | ok(true, 'first');
165 | start();
166 | stop();
167 | setTimeout(function(){
168 | ok(true, 'second');
169 | start();
170 | }, 150);
171 | }, 150);
172 | });
173 | }
174 |
175 | module("save scope", {
176 | setup: function() {
177 | this.foo = "bar";
178 | },
179 | teardown: function() {
180 | deepEqual(this.foo, "bar");
181 | }
182 | });
183 | test("scope check", function() {
184 | expect(2);
185 | deepEqual(this.foo, "bar");
186 | });
187 |
188 | module("simple testEnvironment setup", {
189 | foo: "bar",
190 | bugid: "#5311" // example of meta-data
191 | });
192 | test("scope check", function() {
193 | deepEqual(this.foo, "bar");
194 | });
195 | test("modify testEnvironment",function() {
196 | this.foo="hamster";
197 | });
198 | test("testEnvironment reset for next test",function() {
199 | deepEqual(this.foo, "bar");
200 | });
201 |
202 | module("testEnvironment with object", {
203 | options:{
204 | recipe:"soup",
205 | ingredients:["hamster","onions"]
206 | }
207 | });
208 | test("scope check", function() {
209 | deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
210 | });
211 | test("modify testEnvironment",function() {
212 | // since we do a shallow copy, the testEnvironment can be modified
213 | this.options.ingredients.push("carrots");
214 | });
215 | test("testEnvironment reset for next test",function() {
216 | deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
217 | });
218 |
219 |
220 | module("testEnvironment tests");
221 |
222 | function makeurl() {
223 | var testEnv = QUnit.current_testEnvironment;
224 | var url = testEnv.url || 'http://example.com/search';
225 | var q = testEnv.q || 'a search test';
226 | return url + '?q='+encodeURIComponent(q);
227 | }
228 |
229 | test("makeurl working",function() {
230 | equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
231 | equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
232 | });
233 |
234 | module("testEnvironment with makeurl settings", {
235 | url: 'http://google.com/',
236 | q: 'another_search_test'
237 | });
238 | test("makeurl working with settings from testEnvironment", function() {
239 | equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
240 | });
241 | test("each test can extend the module testEnvironment", {
242 | q:'hamstersoup'
243 | }, function() {
244 | equal( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
245 | });
246 |
247 | module("jsDump");
248 | test("jsDump output", function() {
249 | equals( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" );
250 | equals( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"top\": 5,\n \"left\": 0\n}" );
251 | if (typeof document !== 'undefined' && document.getElementById("qunit-header")) {
252 | equals( QUnit.jsDump.parse(document.getElementById("qunit-header")), "" );
253 | equals( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n \n]" );
254 | }
255 | });
256 |
257 | module("assertions");
258 | test("raises",function() {
259 | function CustomError( message ) {
260 | this.message = message;
261 | }
262 |
263 | CustomError.prototype.toString = function() {
264 | return this.message;
265 | };
266 |
267 | raises(
268 | function() {
269 | throw "error"
270 | }
271 | );
272 |
273 | raises(
274 | function() {
275 | throw "error"
276 | },
277 | 'raises with just a message, no expected'
278 | );
279 |
280 | raises(
281 | function() {
282 | throw new CustomError();
283 | },
284 | CustomError,
285 | 'raised error is an instance of CustomError'
286 | );
287 |
288 | raises(
289 | function() {
290 | throw new CustomError("some error description");
291 | },
292 | /description/,
293 | "raised error message contains 'description'"
294 | );
295 |
296 | raises(
297 | function() {
298 | throw new CustomError("some error description");
299 | },
300 | function( err ) {
301 | if ( (err instanceof CustomError) && /description/.test(err) ) {
302 | return true;
303 | }
304 | },
305 | "custom validation function"
306 | );
307 |
308 | });
309 |
310 | if (typeof document !== "undefined") {
311 |
312 | module("fixture");
313 | test("setup", function() {
314 | document.getElementById("qunit-fixture").innerHTML = "foobar";
315 | });
316 | test("basics", function() {
317 | equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" );
318 | });
319 |
320 | }
321 |
322 | module("custom assertions");
323 | (function() {
324 | function mod2(value, expected, message) {
325 | var actual = value % 2;
326 | QUnit.push(actual == expected, actual, expected, message);
327 | }
328 | test("mod2", function() {
329 | mod2(2, 0, "2 % 2 == 0");
330 | mod2(3, 1, "3 % 2 == 1");
331 | })
332 | })();
333 |
334 |
335 | module("recursions");
336 |
337 | function Wrap(x) {
338 | this.wrap = x;
339 | if (x == undefined) this.first = true;
340 | }
341 |
342 | function chainwrap(depth, first, prev) {
343 | depth = depth || 0;
344 | var last = prev || new Wrap();
345 | first = first || last;
346 |
347 | if (depth == 1) {
348 | first.wrap = last;
349 | }
350 | if (depth > 1) {
351 | last = chainwrap(depth-1, first, new Wrap(last));
352 | }
353 |
354 | return last;
355 | }
356 |
357 | test("check jsDump recursion", function() {
358 | expect(4);
359 |
360 | var noref = chainwrap(0);
361 | var nodump = QUnit.jsDump.parse(noref);
362 | equal(nodump, '{\n "wrap": undefined,\n "first": true\n}');
363 |
364 | var selfref = chainwrap(1);
365 | var selfdump = QUnit.jsDump.parse(selfref);
366 | equal(selfdump, '{\n "wrap": recursion(-1),\n "first": true\n}');
367 |
368 | var parentref = chainwrap(2);
369 | var parentdump = QUnit.jsDump.parse(parentref);
370 | equal(parentdump, '{\n "wrap": {\n "wrap": recursion(-2),\n "first": true\n }\n}');
371 |
372 | var circref = chainwrap(10);
373 | var circdump = QUnit.jsDump.parse(circref);
374 | ok(new RegExp("recursion\\(-10\\)").test(circdump), "(" +circdump + ") should show -10 recursion level");
375 | });
376 |
377 | test("check (deep-)equal recursion", function() {
378 | var noRecursion = chainwrap(0);
379 | equal(noRecursion, noRecursion, "I should be equal to me.");
380 | deepEqual(noRecursion, noRecursion, "... and so in depth.");
381 |
382 | var selfref = chainwrap(1);
383 | equal(selfref, selfref, "Even so if I nest myself.");
384 | deepEqual(selfref, selfref, "... into the depth.");
385 |
386 | var circref = chainwrap(10);
387 | equal(circref, circref, "Or hide that through some levels of indirection.");
388 | deepEqual(circref, circref, "... and checked on all levels!");
389 | });
390 |
391 |
392 | test('Circular reference with arrays', function() {
393 |
394 | // pure array self-ref
395 | var arr = [];
396 | arr.push(arr);
397 |
398 | var arrdump = QUnit.jsDump.parse(arr);
399 |
400 | equal(arrdump, '[\n recursion(-1)\n]');
401 | equal(arr, arr[0], 'no endless stack when trying to dump arrays with circular ref');
402 |
403 |
404 | // mix obj-arr circular ref
405 | var obj = {};
406 | var childarr = [obj];
407 | obj.childarr = childarr;
408 |
409 | var objdump = QUnit.jsDump.parse(obj);
410 | var childarrdump = QUnit.jsDump.parse(childarr);
411 |
412 | equal(objdump, '{\n "childarr": [\n recursion(-2)\n ]\n}');
413 | equal(childarrdump, '[\n {\n "childarr": recursion(-2)\n }\n]');
414 |
415 | equal(obj.childarr, childarr, 'no endless stack when trying to dump array/object mix with circular ref');
416 | equal(childarr[0], obj, 'no endless stack when trying to dump array/object mix with circular ref');
417 |
418 | });
419 |
420 |
421 | test('Circular reference - test reported by soniciq in #105', function() {
422 | var MyObject = function() {};
423 | MyObject.prototype.parent = function(obj) {
424 | if (obj === undefined) { return this._parent; }
425 | this._parent = obj;
426 | };
427 | MyObject.prototype.children = function(obj) {
428 | if (obj === undefined) { return this._children; }
429 | this._children = obj;
430 | };
431 |
432 | var a = new MyObject(),
433 | b = new MyObject();
434 |
435 | var barr = [b];
436 | a.children(barr);
437 | b.parent(a);
438 |
439 | equal(a.children(), barr);
440 | deepEqual(a.children(), [b]);
441 | });
442 |
443 |
444 |
445 |
446 | (function() {
447 | var reset = QUnit.reset;
448 | function afterTest() {
449 | ok( false, "reset should not modify test status" );
450 | }
451 | module("reset");
452 | test("reset runs assertions", function() {
453 | QUnit.reset = function() {
454 | afterTest();
455 | reset.apply( this, arguments );
456 | };
457 | });
458 | test("reset runs assertions2", function() {
459 | QUnit.reset = reset;
460 | });
461 | })();
462 |
463 | module("noglobals", {
464 | teardown: function() {
465 | delete window.badGlobalVariableIntroducedInTest;
466 | }
467 | });
468 | test("let teardown clean up globals", function() {
469 | // this test will always pass if run without ?noglobals=true
470 | window.badGlobalVariableIntroducedInTest = true;
471 | });
472 |
--------------------------------------------------------------------------------
/tests/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit Test Suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | test markup
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/tests/test.js:
--------------------------------------------------------------------------------
1 | var uid = 0;
2 |
3 | function createSWF(e){
4 |
5 | var flashvars = {
6 | readyFunction: "onSWFReady",
7 | eventProxyFunction: "onSWFEvent",
8 | errorEventProxyFunction: "onSWFErrorEvent",
9 | src: "http://vjs.zencdn.net/v/oceans.mp4",
10 | autoplay: false,
11 | preload: 'auto',
12 | poster: "http://vjs.zencdn.net/v/oceans.png"
13 | };
14 |
15 | var params = {
16 | allowScriptAccess: "always",
17 | bgcolor: "#000000"
18 | };
19 |
20 | var attributes = {
21 | id: "videoPlayer"+uid,
22 | name: "videoPlayer"+uid
23 | };
24 |
25 | swfobject.embedSWF("../dist/video-js.swf", "videoPlayer"+uid, "100%", "100%", "10.3", "", flashvars, params, attributes);
26 | }
27 |
28 | function swfSetup(){
29 | stop();
30 |
31 | window.onSWFReady = $.proxy(function(swfID){
32 | // console.log("onSWFReady", swfID);
33 | this.box = document.getElementById(swfID+"_box");
34 | this.swf = document.getElementById(swfID);
35 | start();
36 | }, this);
37 |
38 | window.onSWFEvent = function(swfID, eventName){
39 | console.log("onSWFEvent", swfID, eventName);
40 |
41 | // Triggering on outer div because triggering in object wasn't working for some reason.
42 | $("#"+swfID+"_box").trigger(eventName);
43 | };
44 |
45 | // Bind events to outer box.
46 | this.on = function(eventName, fn){
47 | $(this.box).bind(eventName, $.proxy(fn, this));
48 | }
49 |
50 | // Custom methods for failing a test after a certain amount of time
51 | this.failIn = function(ms){ this.failOutID = setTimeout(function(){ start(); }, ms); };
52 | this.cancelFail = function(){ clearTimeout(this.failOutID); };
53 |
54 | // Embed new box and placeholder for swf
55 | uid++;
56 | var id = "videoPlayer"+uid;
57 | $("#custom-fixture").append("")
58 |
59 | createSWF();
60 | }
61 |
62 | function swfTeardown(){
63 | swfobject.removeSWF(this.swf.id);
64 | delete this.swf;
65 | $("#custom-fixture").html("");
66 | }
67 |
68 |
69 | module("SWF Tests", {
70 | setup: swfSetup,
71 | teardown: swfTeardown
72 | });
73 |
74 | test("SWF Set Up & Ready", 2, function() {
75 | ok(this.swf, "Player has been set up and is ready.");
76 | ok(typeof this.swf.vjs_play == 'function', "API Methods are available on ready.");
77 | });
78 |
79 | // Pause after playing event
80 | test("Pause After 'playing' Event", 1, function() {
81 | stop();
82 |
83 | // Wait for playing even then call pause()
84 | this.on("playing", function(){
85 | this.swf.vjs_pause();
86 | });
87 |
88 | this.on("pause", function(){
89 | ok(true, "Player pauses.");
90 |
91 | this.cancelFail();
92 | start();
93 | });
94 |
95 | // Fail after 5 seconds if it doesn't work
96 | this.failIn(3000);
97 |
98 | this.swf.vjs_play();
99 | });
100 |
101 |
102 | // Play Method
103 | test("Play", 1, function() {
104 | stop();
105 |
106 | this.on("playing", function(){
107 | ok(true, "Player plays.");
108 | start();
109 | });
110 |
111 | this.swf.vjs_play();
112 | });
113 |
114 | // 'seeked' event
115 | // Commented-out as this only works intermittently. Sometimes the "seeked"
116 | // event doesn't happen
117 | /*test("Seeked event fires after time change", 1, function() {
118 | stop();
119 | this.on("loadeddata", function(){
120 | this.swf.vjs_pause();
121 | this.ct = this.swf.vjs_getProperty("currentTime");
122 |
123 | this.on("seeked", function(){
124 |
125 | ok(this.ct != this.swf.vjs_getProperty("currentTime"), "currentTime changed");
126 | start();
127 | });
128 |
129 | this.swf.vjs_setProperty("currentTime", 30);
130 | });
131 |
132 | this.swf.vjs_play();
133 | });
134 | */
135 |
136 | // Commented out for unknown reasons...
137 |
138 | // /* Methods
139 | // ================================================================================ */
140 | // module("API Methods", {
141 | // setup: playerSetup,
142 | // teardown: playerTeardown
143 | // });
144 | //
145 | // function failOnEnded() {
146 | // this.player.one("ended", _V_.proxy(this, function(){
147 | // start();
148 | // }));
149 | // }
150 | //
151 | // // Play Method
152 | // test("play()", 1, function() {
153 | // stop();
154 | //
155 | // this.player.one("playing", _V_.proxy(this, function(){
156 | // ok(true);
157 | // start();
158 | // }));
159 | //
160 | // this.player.play();
161 | //
162 | // failOnEnded.call(this);
163 | // });
164 | //
165 | // // Pause Method
166 | // test("pause()", 1, function() {
167 | // stop();
168 | //
169 | // // Flash doesn't currently like calling pause immediately after 'playing'.
170 | // this.player.one("timeupdate", _V_.proxy(this, function(){
171 | //
172 | // this.player.pause();
173 | //
174 | // }));
175 | //
176 | // this.player.addEvent("pause", _V_.proxy(this, function(){
177 | // ok(true);
178 | // start();
179 | // }));
180 | //
181 | // this.player.play();
182 | // });
183 | //
184 | // // Paused Method
185 | // test("paused()", 2, function() {
186 | // stop();
187 | //
188 | // this.player.one("timeupdate", _V_.proxy(this, function(){
189 | // equal(this.player.paused(), false);
190 | // this.player.pause();
191 | // }));
192 | //
193 | // this.player.addEvent("pause", _V_.proxy(this, function(){
194 | // equal(this.player.paused(), true);
195 | // start();
196 | // }));
197 | //
198 | // this.player.play();
199 | // });
200 | //
201 | // test("currentTime()", 1, function() {
202 | // stop();
203 | //
204 | // // Try for 3 time updates, sometimes it updates at 0 seconds.
205 | // // var tries = 0;
206 | //
207 | // // Can't rely on just time update because it's faked for Flash.
208 | // this.player.one("loadeddata", _V_.proxy(this, function(){
209 | //
210 | // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
211 | //
212 | // if (this.player.currentTime() > 0) {
213 | // ok(true, "Time is greater than 0.");
214 | // start();
215 | // } else {
216 | // // tries++;
217 | // }
218 | //
219 | // // if (tries >= 3) {
220 | // // start();
221 | // // }
222 | // }));
223 | //
224 | // }));
225 | //
226 | // this.player.play();
227 | // });
228 | //
229 | //
230 | // test("currentTime(seconds)", 2, function() {
231 | // stop();
232 | //
233 | // // var afterPlayback = _V_.proxy(this, function(){
234 | // // this.player.currentTime(this.player.duration() / 2);
235 | // //
236 | // // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
237 | // // ok(this.player.currentTime() > 0, "Time is greater than 0.");
238 | // //
239 | // // this.player.pause();
240 | // //
241 | // // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
242 | // // ok(this.player.currentTime() == 0, "Time is 0.");
243 | // // start();
244 | // // }));
245 | // //
246 | // // this.player.currentTime(0);
247 | // // }));
248 | // // });
249 | //
250 | // // Wait for Source to be ready.
251 | // this.player.one("loadeddata", _V_.proxy(this, function(){
252 | //
253 | // _V_.log("loadeddata", this.player);
254 | // this.player.currentTime(this.player.duration() - 1);
255 | //
256 | // }));
257 | //
258 | // this.player.one("seeked", _V_.proxy(this, function(){
259 | //
260 | // _V_.log("seeked", this.player.currentTime())
261 | // ok(this.player.currentTime() > 1, "Time is greater than 1.");
262 | //
263 | // this.player.one("seeked", _V_.proxy(this, function(){
264 | //
265 | // _V_.log("seeked2", this.player.currentTime())
266 | //
267 | // ok(this.player.currentTime() <= 1, "Time is less than 1.");
268 | // start();
269 | //
270 | // }));
271 | //
272 | // this.player.currentTime(0);
273 | //
274 | // }));
275 | //
276 | //
277 | // this.player.play();
278 | //
279 | // // this.player.one("timeupdate", _V_.proxy(this, function(){
280 | // //
281 | // // this.player.currentTime(this.player.duration() / 2);
282 | // //
283 | // // this.player.one("timeupdate", _V_.proxy(this, function(){
284 | // // ok(this.player.currentTime() > 0, "Time is greater than 0.");
285 | // //
286 | // // this.player.pause();
287 | // // this.player.currentTime(0);
288 | // //
289 | // // this.player.one("timeupdate", _V_.proxy(this, function(){
290 | // //
291 | // // ok(this.player.currentTime() == 0, "Time is 0.");
292 | // // start();
293 | // //
294 | // // }));
295 | // //
296 | // // }));
297 | // //
298 | // //
299 | // // }));
300 | //
301 | // });
302 | //
303 | // /* Events
304 | // ================================================================================ */
305 | // module("API Events", {
306 | // setup: playerSetup,
307 | // teardown: playerTeardown
308 | // });
309 | //
310 | // var playEventList = []
311 | //
312 | // // Test all playback events
313 | // test("Initial Events", 11, function() {
314 | // stop(); // Give 30 seconds to run then fail.
315 | //
316 | // var events = [
317 | // // "loadstart" // Called during setup
318 | // "play",
319 | // "playing",
320 | //
321 | // "durationchange",
322 | // "loadedmetadata",
323 | // "loadeddata",
324 | //
325 | // "progress",
326 | // "timeupdate",
327 | //
328 | // "canplay",
329 | // "canplaythrough",
330 | //
331 | // "pause",
332 | // "ended"
333 | // ];
334 | //
335 | // // Add an event listener for each event type.
336 | // for (var i=0, l=events.length; i