incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/3] spec commit: Added test for setting headers on FileTransfer uploads.
Date Sat, 28 Jul 2012 00:47:03 GMT
Added test for setting headers on FileTransfer uploads.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/e19bc127
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/e19bc127
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/e19bc127

Branch: refs/heads/master
Commit: e19bc127d75324ab6bfadc689d2e78b99eab2551
Parents: a8a95ea
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jul 12 16:49:32 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jul 27 20:42:54 2012 -0400

----------------------------------------------------------------------
 autotest/tests/filetransfer.tests.js |   51 +++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/e19bc127/autotest/tests/filetransfer.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/filetransfer.tests.js b/autotest/tests/filetransfer.tests.js
index 0779116..5f8304d 100644
--- a/autotest/tests/filetransfer.tests.js
+++ b/autotest/tests/filetransfer.tests.js
@@ -402,6 +402,57 @@ describe('FileTransfer', function() {
             });
 
         });
+        it("should be able to set custom headers", function() {
+            var remoteFile = "http://whatheaders.com";
+            var localFileName = "upload.txt";
+
+            var fileFail = function() {};
+            var uploadFail = function() {
+                expect(false).toBe(true, "Ensure " + remoteFile + " is in the white list");
+            };
+
+            var uploadWin = jasmine.createSpy().andCallFake(function(uploadResult) {
+                expect(uploadResult.bytesSent).toBeGreaterThan(0);
+                expect(uploadResult.responseCode).toBe(200);
+                expect(uploadResult.response).toBeDefined();
+                deleteEntry(localFileName);
+                var responseHtml = decodeURIComponent(uploadResult.response);
+                expect(responseHtml).toMatch(/CustomHeader1[\s\S]*CustomValue1/i);
+                expect(responseHtml).toMatch(/CustomHeader2[\s\S]*CustomValue2[\s\S]*CustomValue3/i,
"Should allow array values");
+                expect(responseHtml).not.toMatch(/X-Requested-With/i, "Should hot have sent
User-Agent header");
+            });
+
+            var fileWin = function(fileEntry) {
+                ft = new FileTransfer();
+
+                var options = new FileUploadOptions();
+                options.fileKey = "file";
+                options.fileName = localFileName;
+                options.mimeType = "text/plain";
 
+                var params = new Object();
+                params.value1 = "test";
+                params.value2 = "param";
+                options.params = params;
+                options.headers = {
+                    "CustomHeader1": "CustomValue1",
+                    "CustomHeader2": ["CustomValue2", "CustomValue3"],
+                    "X-Requested-With": null  // Removes the header.
+                };
+
+                // removing options cause Android to timeout
+                ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, options);
+            };
+
+            runs(function() {
+                writeFile(localFileName, "this file should upload", fileWin, fileFail);
+            });
+
+            waitsFor(function() { return uploadWin.wasCalled; }, "uploadWin", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(uploadWin).toHaveBeenCalled();
+            });
+        });
     });
 });


Mime
View raw message