cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [19/25] js commit: Make base64 tests work in browser as well as Node (cherry picked from commit ee2c1d20c3cc4e5ff9d0aa9e6fa0368a6b6956f6)
Date Tue, 22 Oct 2013 15:45:29 GMT
Make base64 tests work in browser as well as Node
(cherry picked from commit ee2c1d20c3cc4e5ff9d0aa9e6fa0368a6b6956f6)


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/afb4f946
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/afb4f946
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/afb4f946

Branch: refs/heads/2.9.x
Commit: afb4f94683eb5b87bb94370f4aa5f9f059391233
Parents: df8d3e1
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Jul 29 15:24:07 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Oct 22 11:37:48 2013 -0400

----------------------------------------------------------------------
 test/test.base64.js | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/afb4f946/test/test.base64.js
----------------------------------------------------------------------
diff --git a/test/test.base64.js b/test/test.base64.js
index f9b1912..563cff3 100644
--- a/test/test.base64.js
+++ b/test/test.base64.js
@@ -49,15 +49,15 @@ describe("base64", function () {
     });
 
     it("can base64 encode an text string in an ArrayBuffer", function () {
-      var buffer = new Buffer('Some Awesome Test This Is!', 'binary')
-        , base64string = buffer.toString('base64')
-        , arrayBuffer = new ArrayBuffer(buffer.length)
-        , view = new Uint8Array(arrayBuffer);
+        var orig = 'Some Awesome Test This Is!'
+            , base64string = typeof btoa != 'undefined' ? btoa(orig) : new Buffer('Some Awesome
Test This Is!', 'binary').toString('base64')
+            , arrayBuffer = new ArrayBuffer(orig.length)
+            , view = new Uint8Array(arrayBuffer);
 
-      for (var i = 0; i < buffer.length; i++) {
-        view[i] = buffer[i];
-      }
+        for (var i = 0; i < orig.length; i++) {
+            view[i] = orig.charCodeAt(i);
+        }
 
-      expect(base64.fromArrayBuffer(arrayBuffer)).toBe(base64string);
+        expect(base64.fromArrayBuffer(arrayBuffer)).toBe(base64string);
     });
 });


Mime
View raw message