diff --git a/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html b/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html new file mode 100644 index 0000000000..26325b45e1 --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html @@ -0,0 +1,171 @@ +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
diff --git a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js index 9f3ab5916a..3444f5389f 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js @@ -186,6 +186,46 @@ }); }); + describe('multiple YT on page', function () { + var state1, state2, state3; + + beforeEach(function () { + loadFixtures('video_yt_multiple.html'); + + spyOn($, 'ajaxWithPrefix'); + + $.ajax.calls.length = 0; + $.ajaxWithPrefix.calls.length = 0; + + // Because several other tests have run, the variable + // that stores the value of the first ajax request must be + // cleared so that we test a pristine state of the video + // module. + Video.clearYoutubeXhr(); + + state1 = new Video('#example1'); + state2 = new Video('#example2'); + state3 = new Video('#example3'); + }); + + it('check for YT availability is performed only once', function () { + var numAjaxCalls = 0; + + // Total ajax calls made. + numAjaxCalls = $.ajax.calls.length; + + // Subtract ajax calls to get captions. + numAjaxCalls -= $.ajaxWithPrefix.calls.length; + + // Subtract ajax calls to get metadata for each video. + numAjaxCalls -= 3; + + // This should leave just one call. It was made to check + // for YT availability. + expect(numAjaxCalls).toBe(1); + }); + }); + describe('setSpeed', function () { describe('YT', function () { beforeEach(function () {