-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-upload.js
More file actions
89 lines (70 loc) · 2.61 KB
/
test-upload.js
File metadata and controls
89 lines (70 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// preamble from addon-sdk/test/sdk/test-reqest.jst
const { Request } = require("sdk/request");
const { pathFor } = require("sdk/system");
const file = require("sdk/io/file");
const { Loader } = require("sdk/test/loader");
const options = require("@test/options");
const loader = Loader(module);
const httpd = loader.require("sdk/test/httpd");
if (options.parseable || options.verbose)
loader.sandbox("sdk/test/httpd").DEBUG = true;
const { startServerAsync } = httpd;
const { Cc, Ci, Cu } = require("chrome");
const { Services } = Cu.import("resource://gre/modules/Services.jsm");
// Use the profile directory for the temporary files as that will be deleted
// when tests are complete
const basePath = pathFor("ProfD")
const port = 8099;
function prepareFile(basename, content) {
let filePath = file.join(basePath, basename);
let fileStream = file.open(filePath, 'w');
fileStream.write(content);
fileStream.close();
}
// micropilot stuff, from here on out.
const { defer, promised, resolve } = require('api-utils/promise');
let { Micropilot,Fuse,EventStore,snoop, killaddon } = require('micropilot');
const { good, bad, jsondump, uu } = require("./utils");
exports['test upload'] = function(assert,done){
// server setup.
let id = uu();
let srv = startServerAsync(port, basePath);
let content = id;
let basename = "upload"
prepareFile(basename, content);
let uploadurl = "http://localhost:" + port + "/" + basename;
let mtp = Micropilot(id)
let group = promised(Array);
group(mtp.record({abc:1}), mtp.record({abc:2})).then(function(){
mtp.upload(uploadurl).then(function(response){
assert.ok(response.text == id);
srv.stop(done);
})
})
};
exports['test ezupload succssful'] = function(assert,done){
// server setup.
let id = uu();
let port = 8901;
let srv = startServerAsync(port, basePath);
let content = id;
let basename = "upload"
prepareFile(basename, content);
let uploadurl = "http://localhost:" + port + "/" + basename;
let mtp = Micropilot(id)
let group = promised(Array);
group(mtp.record({abc:1}), mtp.record({abc:2})).then(function(){
mtp.ezupload({url:uploadurl}).then(function(cleanup){
assert.ok(mtp._config.completed == true, "ezupload success, completed true")
mtp.data().then(function(data){
assert.equal(data.length,0,"ezupload succuss, data is clear");
srv.stop(done);
})
})
})
};
require("test").run(exports);