未验证 提交 9ec40333 编写于 作者: O openharmony_ci 提交者: Gitee

!9686 request2接口变更为requestInStream

Merge pull request !9686 from 高曦/master
...@@ -35,32 +35,32 @@ function dataEnd_on_callback() { ...@@ -35,32 +35,32 @@ function dataEnd_on_callback() {
console.log("dataEnd_on_callback callback function"); console.log("dataEnd_on_callback callback function");
} }
function dataProgress_on_callback(data) { function dataReceiveProgress_on_callback(data) {
console.log("dataProgress_on_callback receive datProgress:" + JSON.stringify(data)); console.log("dataReceiveProgress_on_callback receive datProgress:" + JSON.stringify(data));
} }
export default function HttpRequest2JsunitTest() { export default function HttprequestInStreamJsunitTest() {
describe("HttpRequest2JsunitTest", function () { describe("HttprequestInStreamJsunitTest", function () {
/** /**
* @tc.number Telephony_http_HttpRequest_request2_0100 * @tc.number Telephony_http_HttpRequest_requestInStream_0100
* @tc.name httprequest2::request2 * @tc.name httprequestInStream::requestInStream
* @tc.desc Test request2(url: string, callback: AsyncCallback<void>): void. * @tc.desc Test requestInStream(url: string, callback: AsyncCallback<void>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_Async_0100", 0, async function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_Async_0100", 0, async function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_Async_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_Async_0100";
let Address_Img = "https://img1.baidu.com/it/u=3010094603,1247181326&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"; let Address_Img = "https://img1.baidu.com/it/u=3010094603,1247181326&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500";
let httpRequest = http.createHttp(); let httpRequest = http.createHttp();
try { try {
httpRequest.on("dataReceive", dataReceive_on_callback); httpRequest.on("dataReceive", dataReceive_on_callback);
httpRequest.on("dataProgress", dataProgress_on_callback); httpRequest.on("dataReceiveProgress", dataReceiveProgress_on_callback);
httpRequest.on("dataEnd", dataEnd_on_callback); httpRequest.on("dataEnd", dataEnd_on_callback);
httpRequest.request2(Address_Img, httpRequestOptions, (err, data) => { httpRequest.requestInStream(Address_Img, httpRequestOptions, (err, data) => {
console.info(CaseName + " responseCode data : " + data); console.info(CaseName + " responseCode data : " + data);
console.log(CaseName + "NETSTACK request2 OK!"); console.log(CaseName + "NETSTACK requestInStream OK!");
httpRequest.off("dataReceive"); httpRequest.off("dataReceive");
console.log("NETSTACK off dataReceive success!"); console.log("NETSTACK off dataReceive success!");
httpRequest.off("dataProgress"); httpRequest.off("dataReceiveProgress");
console.log("NETSTACK off dataProgress success!"); console.log("NETSTACK off dataReceiveProgress success!");
httpRequest.off("dataEnd"); httpRequest.off("dataEnd");
console.log("NETSTACK off dataEnd success!"); console.log("NETSTACK off dataEnd success!");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
...@@ -68,7 +68,7 @@ export default function HttpRequest2JsunitTest() { ...@@ -68,7 +68,7 @@ export default function HttpRequest2JsunitTest() {
done(); done();
}) })
} catch (error) { } catch (error) {
console.log(CaseName + " request2 catch : error = " + JSON.stringify(error)); console.log(CaseName + " requestInStream catch : error = " + JSON.stringify(error));
expect(error).assertFalse(); expect(error).assertFalse();
done(); done();
} }
...@@ -76,35 +76,35 @@ export default function HttpRequest2JsunitTest() { ...@@ -76,35 +76,35 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number Telephony_http_HttpRequest_request2_0200 * @tc.number Telephony_http_HttpRequest_requestInStream_0200
* @tc.name httprequest2::request2 * @tc.name httprequestInStream::requestInStream
* @tc.desc Test request2(url: string, options: HttpRequestOptions, callback: AsyncCallback<void>): void. * @tc.desc Test requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallback<void>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_Async_0200", 0, async function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_Async_0200", 0, async function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_Async_0200" let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_Async_0200"
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.request2(Address_Baidu, (err, data) => { httpRequest.requestInStream(Address_Baidu, (err, data) => {
if (err) { if (err) {
console.log(CaseName + " request2 ERROR" + JSON.stringify(err)); console.log(CaseName + " requestInStream ERROR" + JSON.stringify(err));
expect().assertFail(); expect().assertFail();
done(); done();
} }
httpRequest.destroy(); httpRequest.destroy();
console.log(CaseName + " request2 Finish responseCode " + data); console.log(CaseName + " requestInStream Finish responseCode " + data);
done(); done();
}); });
}); });
/** /**
* @tc.number Telephony_http_HttpRequest_request2_0100 * @tc.number Telephony_http_HttpRequest_requestInStream_0100
* @tc.name httprequest2::request2 * @tc.name httprequestInStream::requestInStream
* @tc.desc Test request2(url: string, options: HttpRequestOptions): Promise<void>. * @tc.desc Test requestInStream(url: string, options: HttpRequestOptions): Promise<void>.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_Promise_0100", 0, async function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_Promise_0100", 0, async function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_Promise_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_Promise_0100";
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.request2(Address_Baidu, httpRequestOptions).then(function (data) { httpRequest.requestInStream(Address_Baidu, httpRequestOptions).then(function (data) {
console.log(CaseName + " request2 Finish responseCode " + data); console.log(CaseName + " requestInStream Finish responseCode " + data);
httpRequest.destroy(); httpRequest.destroy();
done(); done();
}).catch(function (err) { }).catch(function (err) {
...@@ -115,15 +115,15 @@ export default function HttpRequest2JsunitTest() { ...@@ -115,15 +115,15 @@ export default function HttpRequest2JsunitTest() {
}); });
/** /**
* @tc.number Telephony_http_HttpRequest_request2_0100 * @tc.number Telephony_http_HttpRequest_requestInStream_0100
* @tc.name httprequest2::request2 * @tc.name httprequestInStream::requestInStream
* @tc.desc Test request2(url: string): Promise<void>. * @tc.desc Test requestInStream(url: string): Promise<void>.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_Promise_0200", 0, async function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_Promise_0200", 0, async function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_Promise_0200"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_Promise_0200";
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
console.log(CaseName + " request2 Finish responseCode " + data); console.log(CaseName + " requestInStream Finish responseCode " + data);
httpRequest.destroy(); httpRequest.destroy();
done(); done();
}).catch(function (err) { }).catch(function (err) {
...@@ -135,16 +135,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -135,16 +135,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_on_dataReceive_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_on_dataReceive_0100
* @tc.name httprequest2::on_dataReceive * @tc.name httprequestInStream::on_dataReceive
* @tc.desc Test on(type: "dataReceive", callback: Callback<ArrayBuffer>): void. * @tc.desc Test on(type: "dataReceive", callback: Callback<ArrayBuffer>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_on_dataReceive_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_on_dataReceive_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_on_dataReceive_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_on_dataReceive_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataReceive", dataReceive_on_callback); httpRequest.on("dataReceive", dataReceive_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
console.log(CaseName + " on dataReceive Finish "); console.log(CaseName + " on dataReceive Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
httpRequest.destroy(); httpRequest.destroy();
...@@ -163,16 +163,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -163,16 +163,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0100
* @tc.name httprequest2::off_dataReceive * @tc.name httprequestInStream::off_dataReceive
* @tc.desc Test off(type: "dataReceive", callback: Callback<ArrayBuffer>): void. * @tc.desc Test off(type: "dataReceive", callback: Callback<ArrayBuffer>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataReceive", dataReceive_on_callback); httpRequest.on("dataReceive", dataReceive_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataReceive", dataReceive_on_callback); httpRequest.off("dataReceive", dataReceive_on_callback);
console.log(CaseName + " off dataReceive Finish "); console.log(CaseName + " off dataReceive Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
...@@ -192,16 +192,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -192,16 +192,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0200 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0200
* @tc.name httprequest2::off_dataReceive * @tc.name httprequestInStream::off_dataReceive
* @tc.desc Test off(type: "dataReceive"): void. * @tc.desc Test off(type: "dataReceive"): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0200", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0200", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataReceive_0200"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataReceive_0200";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataReceive", dataReceive_on_callback); httpRequest.on("dataReceive", dataReceive_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataReceive"); httpRequest.off("dataReceive");
console.log(CaseName + " off dataReceive Finish "); console.log(CaseName + " off dataReceive Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
...@@ -220,17 +220,17 @@ export default function HttpRequest2JsunitTest() { ...@@ -220,17 +220,17 @@ export default function HttpRequest2JsunitTest() {
}); });
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_on_dataProgress_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_on_dataReceiveProgress_0100
* @tc.name httprequest2::on_dataProgress * @tc.name httprequestInStream::on_dataReceiveProgress
* @tc.desc Test on(type: "dataProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void. * @tc.desc Test on(type: "dataReceiveProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_on_dataProgress_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_on_dataReceiveProgress_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_on_dataProgress_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_on_dataReceiveProgress_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataProgress", dataProgress_on_callback); httpRequest.on("dataReceiveProgress", dataReceiveProgress_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
console.log(CaseName + " on dataProgress Finish "); console.log(CaseName + " on dataReceiveProgress Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
httpRequest.destroy(); httpRequest.destroy();
done(); done();
...@@ -247,18 +247,18 @@ export default function HttpRequest2JsunitTest() { ...@@ -247,18 +247,18 @@ export default function HttpRequest2JsunitTest() {
}); });
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0100
* @tc.name httprequest2::off_dataProgress * @tc.name httprequestInStream::off_dataReceiveProgress
* @tc.desc Test off(type: "dataProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void. * @tc.desc Test off(type: "dataReceiveProgress", callback: Callback<{ receiveSize: number, totalSize: number }>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataProgress", dataProgress_on_callback); httpRequest.on("dataReceiveProgress", dataReceiveProgress_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataProgress", dataProgress_on_callback); httpRequest.off("dataReceiveProgress", dataReceiveProgress_on_callback);
console.log(CaseName + " off dataProgress Finish "); console.log(CaseName + " off dataReceiveProgress Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
httpRequest.destroy(); httpRequest.destroy();
done(); done();
...@@ -276,18 +276,18 @@ export default function HttpRequest2JsunitTest() { ...@@ -276,18 +276,18 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0200 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0200
* @tc.name httprequest2::off_dataProgress * @tc.name httprequestInStream::off_dataReceiveProgress
* @tc.desc Test off(type: "dataProgress"): void. * @tc.desc Test off(type: "dataReceiveProgress"): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0200", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0200", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataProgress_0200"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataReceiveProgress_0200";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataProgress", dataProgress_on_callback); httpRequest.on("dataReceiveProgress", dataReceiveProgress_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataProgress"); httpRequest.off("dataReceiveProgress");
console.log(CaseName + " off dataProgress Finish "); console.log(CaseName + " off dataReceiveProgress Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
httpRequest.destroy(); httpRequest.destroy();
done(); done();
...@@ -305,16 +305,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -305,16 +305,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_on_dataEnd_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_on_dataEnd_0100
* @tc.name httprequest2::on_dataEnd * @tc.name httprequestInStream::on_dataEnd
* @tc.desc Test on(type: "dataEnd", callback: Callback<void>): void. * @tc.desc Test on(type: "dataEnd", callback: Callback<void>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_on_dataEnd_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_on_dataEnd_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_on_dataEnd_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_on_dataEnd_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataEnd", dataEnd_on_callback); httpRequest.on("dataEnd", dataEnd_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
console.log(CaseName + " on dataEnd Finish "); console.log(CaseName + " on dataEnd Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
httpRequest.destroy(); httpRequest.destroy();
...@@ -333,16 +333,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -333,16 +333,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0100 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0100
* @tc.name httprequest2::off_dataEnd * @tc.name httprequestInStream::off_dataEnd
* @tc.desc Test off(type: "dataEnd", callback?: Callback<void>): void. * @tc.desc Test off(type: "dataEnd", callback?: Callback<void>): void.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0100", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0100", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0100"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0100";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataEnd", dataEnd_on_callback); httpRequest.on("dataEnd", dataEnd_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataEnd", dataEnd_on_callback); httpRequest.off("dataEnd", dataEnd_on_callback);
console.log(CaseName + " off dataEnd Finish "); console.log(CaseName + " off dataEnd Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
...@@ -362,16 +362,16 @@ export default function HttpRequest2JsunitTest() { ...@@ -362,16 +362,16 @@ export default function HttpRequest2JsunitTest() {
/** /**
* @tc.number SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0200 * @tc.number SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0200
* @tc.name httprequest2::off_dataEnd * @tc.name httprequestInStream::off_dataEnd
* @tc.desc Test off(type: "dataEnd"): void;. * @tc.desc Test off(type: "dataEnd"): void;.
*/ */
it("SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0200", 0, function (done) { it("SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0200", 0, function (done) {
let CaseName = "SUB_Telephony_NetStack_HttpRequest2_off_dataEnd_0200"; let CaseName = "SUB_Telephony_NetStack_HttprequestInStream_off_dataEnd_0200";
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
httpRequest.on("dataEnd", dataEnd_on_callback); httpRequest.on("dataEnd", dataEnd_on_callback);
httpRequest.request2(Address_Baidu).then(function (data) { httpRequest.requestInStream(Address_Baidu).then(function (data) {
httpRequest.off("dataEnd"); httpRequest.off("dataEnd");
console.log(CaseName + " off dataEnd Finish "); console.log(CaseName + " off dataEnd Finish ");
expect(data == 200).assertTrue(); expect(data == 200).assertTrue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册