未验证 提交 c28b3957 编写于 作者: 高曦 提交者: Gitee

update Http.fetch.test.js.

Signed-off-by: N高曦 <gaoxi785@huawei.com>
上级 9e765698
......@@ -14,6 +14,7 @@
*/
import fetch from '@system.fetch';
import http from '@ohos.net.http';
import { describe, expect, it } from '@ohos/hypium'
export default function Telephony_NetStack_HttpFetchTest() {
......@@ -26,31 +27,34 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchBasicGet_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/anything",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/anything",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -59,34 +63,37 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchUserAgent_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/user-agent",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["user-agent"] == "libcurl-agent/1.0").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/user-agent",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["user-agent"] == "libcurl-agent/1.0").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack fetch complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack fetch complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -95,35 +102,38 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchUserAgent_0200", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/user-agent",
responseType: "json",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["user-agent"] == "libcurl-agent/1.0").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/user-agent",
responseType: "json",
success: function (data) {
console.info("NetStack fetch success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["user-agent"] == "libcurl-agent/1.0").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack fetch complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack fetch complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -132,34 +142,37 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchHeader_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/headers",
success: function (data) {
console.info("NetStack Fetch Success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["headers"]["Content-Type"] === "application/json").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/headers",
success: function (data) {
console.info("NetStack Fetch Success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["headers"]["Content-Type"] === "application/json").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -168,35 +181,38 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchHeader_0200", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/headers",
responseType: "json",
success: function (data) {
console.info("NetStack Fetch Success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["headers"]["Content-Type"] === "application/json").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/headers",
responseType: "json",
success: function (data) {
console.info("NetStack Fetch Success " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["headers"]["Content-Type"] === "application/json").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -205,36 +221,39 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchPost_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/post",
method: "POST",
data: "MineMine",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["data"] === "MineMine").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/post",
method: "POST",
data: "MineMine",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["data"] === "MineMine").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done()
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done()
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -243,37 +262,40 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchPost_0200", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/post",
method: "POST",
data: "MineMine",
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["data"] === "MineMine").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/post",
method: "POST",
data: "MineMine",
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["data"] === "MineMine").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -282,36 +304,39 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchPut_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/put",
method: "PUT",
data: "MineMine",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["data"] === "MineMine").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/put",
method: "PUT",
data: "MineMine",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["data"] === "MineMine").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -320,37 +345,40 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchPut_0200", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/put",
method: "PUT",
data: "MineMine",
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
if (data.code === 200) {
expect(data.code === 200 || data.code > 500).assertTrue();
expect(data.data["data"] === "MineMine").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/put",
method: "PUT",
data: "MineMine",
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
if (data.code === 200) {
expect(data.code === 200 || data.code > 500).assertTrue();
expect(data.data["data"] === "MineMine").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -359,41 +387,44 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchUrlEncode_0100", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/response-headers?key1=val1&key2=val2",
data: {
"name1": "mine1",
"name2": "mine2",
},
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["key1"] === "val1").assertTrue();
expect(JSON.parse(data.data.toString())["key2"] === "val2").assertTrue();
expect(JSON.parse(data.data.toString())["name1"] === "mine1").assertTrue();
expect(JSON.parse(data.data.toString())["name2"] === "mine2").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/response-headers?key1=val1&key2=val2",
data: {
"name1": "mine1",
"name2": "mine2",
},
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(JSON.parse(data.data.toString())["key1"] === "val1").assertTrue();
expect(JSON.parse(data.data.toString())["key2"] === "val2").assertTrue();
expect(JSON.parse(data.data.toString())["name1"] === "mine1").assertTrue();
expect(JSON.parse(data.data.toString())["name2"] === "mine2").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
/**
......@@ -402,42 +433,45 @@ export default function Telephony_NetStack_HttpFetchTest() {
* @tc.desc function test
*/
it("Telephony_NetStack_HttpTestFetchUrlEncode_0200", 0, function (done) {
fetchTest();
var objectTimeOut = setTimeout(function timeout() {
fetchTest();
}, 30000);
function fetchTest() {
fetch.fetch({
url: "https://httpbin.org/response-headers?key1=val1&key2=val2",
data: {
"name1": "mine1",
"name2": "mine2",
},
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["key1"] === "val1").assertTrue();
expect(data.data["key2"] === "val2").assertTrue();
expect(data.data["name1"] === "mine1").assertTrue();
expect(data.data["name2"] === "mine2").assertTrue();
let httpRequest = http.createHttp();
httpRequest.request("https://httpbin.org", {
readTimeout: 10000,
connectTimeout: 10000
}, (err, data) => {
if (!err) {
fetch.fetch({
url: "https://httpbin.org/response-headers?key1=val1&key2=val2",
data: {
"name1": "mine1",
"name2": "mine2",
},
responseType: "json",
success: function (data) {
console.info("NetStack " + JSON.stringify(data));
expect(data.code === 200 || data.code > 500).assertTrue();
if (data.code === 200) {
expect(data.data["key1"] === "val1").assertTrue();
expect(data.data["key2"] === "val2").assertTrue();
expect(data.data["name1"] === "mine1").assertTrue();
expect(data.data["name2"] === "mine2").assertTrue();
}
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
clearTimeout(objectTimeOut);
done();
},
fail: function () {
console.info("NetStack Fetch Failed");
expect().assertFail();
clearTimeout(objectTimeOut);
done();
},
complete: function () {
console.info("NetStack Fetch Complete");
}
})
}
})
} else {
console.info('error:' + JSON.stringify(err));
done();
}
httpRequest.destroy();
});
});
});
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册