]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Fixed assertion collision issues
authorSolly Ross <sross@redhat.com>
Fri, 19 Sep 2014 16:16:06 +0000 (12:16 -0400)
committerSolly Ross <sross@redhat.com>
Fri, 19 Sep 2014 16:16:06 +0000 (12:16 -0400)
When run via karma, all the tests are loaded into the same page.
This was causing a collision in the 'displayed' assertion dealing
with using viewportLoc.

The assertions are now in their own file, pulled in by tests that
need them.  Additionally, several tests which only set fb_width
and fb_height were correct to set viewportLoc as well.

Closes #392

Also-Authored-By: Martin André (github: mandre)
karma.conf.js
tests/assertions.js [new file with mode: 0644]
tests/test.display.js
tests/test.rfb.js

index fca5970deb9a66e00ff8079ddfe361c9cfdfe038..40e21c81231d309795bf9fb483c2b43097139036 100644 (file)
@@ -109,6 +109,7 @@ module.exports = function(config) {
     // list of files / patterns to load in the browser (loaded in order)
     files: [
       'tests/fake.*.js',
+      'tests/assertions.js',
       'include/util.js',  // load first to avoid issues, since methods are called immediately
       //'../include/*.js',
       'include/base64.js',
diff --git a/tests/assertions.js b/tests/assertions.js
new file mode 100644 (file)
index 0000000..92b11d1
--- /dev/null
@@ -0,0 +1,24 @@
+// some useful assertions for noVNC
+chai.use(function (_chai, utils) {
+    _chai.Assertion.addMethod('displayed', function (target_data) {
+        var obj = this._obj;
+        var data_cl = obj._drawCtx.getImageData(0, 0, obj._viewportLoc.w, obj._viewportLoc.h).data;
+        // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
+        var data = new Uint8Array(data_cl);
+        this.assert(utils.eql(data, target_data),
+            "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
+            "expected #{this} not to have displayed the image #{act}",
+            target_data,
+            data);
+    });
+
+    _chai.Assertion.addMethod('sent', function (target_data) {
+        var obj = this._obj;
+        var data = obj._websocket._get_sent_data();
+        this.assert(utils.eql(data, target_data),
+            "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
+            "expected #{this} not to have sent the data #{act}",
+            target_data,
+            data);
+    });
+});
index c4535a038f96d1c95238019627b4630e9e44004b..832970d5361f27d36cec3a4b37dcd6ab6ded76ed 100644 (file)
@@ -1,21 +1,8 @@
 // requires local modules: util, base64, display
+// requires test modules: assertions
 /* jshint expr: true */
 var expect = chai.expect;
 
-chai.use(function (_chai, utils) {
-    _chai.Assertion.addMethod('displayed', function (target_data) {
-        var obj = this._obj;
-        var data_cl = obj._drawCtx.getImageData(0, 0, obj._viewportLoc.w, obj._viewportLoc.h).data;
-        // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
-        var data = new Uint8Array(data_cl);
-        this.assert(utils.eql(data, target_data),
-            "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
-            "expected #{this} not to have displayed the image #{act}",
-            target_data,
-            data);
-    });
-});
-
 describe('Display/Canvas Helper', function () {
     var checked_data = [
         0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
index 595548e10a9613fa9a2920f3b2bc8c1d36984b4e..56ec2562e611ccf7b41f249cdbd4136f601cb0d4 100644 (file)
@@ -1,5 +1,5 @@
 // requires local modules: util, base64, websock, rfb, keyboard, keysym, keysymdef, input, jsunzip, des, display
-// requires test modules: fake.websocket
+// requires test modules: fake.websocket, assertions
 /* jshint expr: true */
 var assert = chai.assert;
 var expect = chai.expect;
@@ -13,31 +13,6 @@ function make_rfb (extra_opts) {
     return new RFB(extra_opts);
 }
 
-// some useful assertions for noVNC
-chai.use(function (_chai, utils) {
-    _chai.Assertion.addMethod('displayed', function (target_data) {
-        var obj = this._obj;
-        var data_cl = obj._drawCtx.getImageData(0, 0, obj._fb_width, obj._fb_height).data;
-        // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
-        var data = new Uint8Array(data_cl);
-        this.assert(utils.eql(data, target_data),
-            "expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
-            "expected #{this} not to have displayed the image #{act}",
-            target_data,
-            data);
-    });
-
-    _chai.Assertion.addMethod('sent', function (target_data) {
-        var obj = this._obj;
-        var data = obj._websocket._get_sent_data();
-        this.assert(utils.eql(data, target_data),
-            "expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
-            "expected #{this} not to have sent the data #{act}",
-            target_data,
-            data);
-    });
-});
-
 describe('Remote Frame Buffer Protocol Client', function() {
     "use strict";
     before(FakeWebSocket.replace);
@@ -1211,6 +1186,8 @@ describe('Remote Frame Buffer Protocol Client', function() {
                     client._fb_height = 4;
                     client._display._fb_width = 4;
                     client._display._fb_height = 4;
+                    client._display._viewportLoc.w = 4;
+                    client._display._viewportLoc.h = 4;
                     client._fb_Bpp = 4;
                 });
 
@@ -1286,6 +1263,8 @@ describe('Remote Frame Buffer Protocol Client', function() {
                         client._fb_height = 4;
                         client._display._fb_width = 4;
                         client._display._fb_height = 4;
+                        client._display._viewportLoc.w = 4;
+                        client._display._viewportLoc.h = 4;
                         client._fb_Bpp = 4;
                     });