Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added tests for sendAsBinary

  • Loading branch information...
commit d5f1cdc6a01229fd53fff2783e0c9165fb3480d0 1 parent 0d39e6c
authored October 01, 2009

Showing 1 changed file with 28 additions and 4 deletions. Show diff stats Hide diff stats

  1. 32  test/xhr-tests.js
32  test/xhr-tests.js
... ...
@@ -1,11 +1,15 @@
1 1
 var assert = require("test/assert");
2 2
 
3 3
 var XHR = require("browser/xhr").XMLHttpRequest,
4  
-    File = require("file");
  4
+    File = require("file"),
  5
+    ByteString = require("binary").ByteString;
5 6
 
6 7
 var testFileMissing = "foobarbaz-missing",
7 8
     testFilePresent = "foobarbaz-present",
8  
-    contents = "hello world\n";
  9
+    contents = "hello world\n",
  10
+    binaryContents = new ByteString(contents);
  11
+
  12
+var sendAsBinary = function(req) { return req.sendAsBinary(binaryContents); };
9 13
 
10 14
 exports.setup = function() {
11 15
     try { File.remove(testFileMissing); } catch (e) {}
@@ -40,9 +44,29 @@ exports.testSynchronouseLocalDELETE = function() {
40 44
     assert.isTrue(!File.exists(testFilePresent), "File should be deleted");
41 45
 }
42 46
 
43  
-function xhrSynchronousTest(method, url, expectedStatus, expectedText) {
  47
+exports.testSynchronouseLocalBinaryGET = function() {
  48
+    xhrSynchronousTest("GET", testFilePresent, 200, contents, sendAsBinary);
  49
+}
  50
+
  51
+exports.testSynchronouseLocalBinaryGETMissing = function() {
  52
+    xhrSynchronousTest("GET", testFileMissing, 404, "", sendAsBinary);
  53
+}
  54
+
  55
+exports.testSynchronouseLocalBinaryPUT = function() {
  56
+    xhrSynchronousTest("PUT", testFileMissing, 201, "", sendAsBinary);
  57
+    assert.isEqual(binaryContents.decodeToString(64), File.read(testFileMissing, "rb").decodeToString(64));
  58
+}
  59
+
  60
+exports.testSynchronouseLocalBinaryDELETE = function() {
  61
+    xhrSynchronousTest("DELETE", testFilePresent, 200, "", sendAsBinary);
  62
+    assert.isTrue(!File.exists(testFilePresent), "File should be deleted");
  63
+}
  64
+
  65
+function xhrSynchronousTest(method, url, expectedStatus, expectedText, send) {
44 66
     var req = new XHR(),
45 67
         lastState = req.readyState;
  68
+
  69
+    send = send || function(req) { req.send(contents); };
46 70
         
47 71
     assert.isEqual(0, lastState);
48 72
     req.onreadystatechange = function() {
@@ -54,7 +78,7 @@ function xhrSynchronousTest(method, url, expectedStatus, expectedText) {
54 78
     
55 79
     assert.isEqual(1, req.readyState);
56 80
     
57  
-    req.send(contents);
  81
+    send(req);
58 82
     
59 83
     assert.isEqual(4, req.readyState);
60 84
     assert.isEqual(4, lastState);

0 notes on commit d5f1cdc

Please sign in to comment.
Something went wrong with that request. Please try again.