提交 d417b8bf 编写于 作者: Z zhangfuzhi

http测试用例整改

Signed-off-by: Nzhangfuzhi <zhangfuzhi1@huawei.com>
上级 a3a2b737
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import { Hypium } from 'hypium/index' import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test' import testsuite from '../test/List.test';
export default { export default {
onCreate() { onCreate() {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import {describe, it, expect} from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import connection from "@ohos.net.connection"; import connection from "@ohos.net.connection";
...@@ -83,7 +83,7 @@ export default function httpJsunit() { ...@@ -83,7 +83,7 @@ export default function httpJsunit() {
expect(data).assertEqual(true); expect(data).assertEqual(true);
done(); done();
}).catch((error) => { }).catch((error) => {
console.log(`${caseName} isDefaultNetMetered error`); console.log(JSON.stringify(error));
expect().assertFail(); expect().assertFail();
done(); done();
}) })
......
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,9 +13,8 @@ ...@@ -13,9 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import { describe, expect, it } from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import utils from './Utils'
export default function httpRequestJsunit() { export default function httpRequestJsunit() {
describe("HttpRequestJsunitTest", function () { describe("HttpRequestJsunitTest", function () {
...@@ -32,23 +31,19 @@ export default function httpRequestJsunit() { ...@@ -32,23 +31,19 @@ export default function httpRequestJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequest_request Test end-----------------------"); console.log("-----------------------HttpRequest_request Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_request_0100 : error = " + error); console.log("Telephony_http_HttpRequest_request_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -63,19 +58,15 @@ export default function httpRequestJsunit() { ...@@ -63,19 +58,15 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_request_01 Test is starting-----------------------"); console.log("-----------------------HttpRequest_request_01 Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", (err, data) => { httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequest_request_01 Test end-----------------------"); console.log("-----------------------HttpRequest_request_01 Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_request_0200 : error = " + error); console.log("Telephony_http_HttpRequest_request_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -93,26 +84,23 @@ export default function httpRequestJsunit() { ...@@ -93,26 +84,23 @@ export default function httpRequestJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
}; };
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequest_request_02 Test end-----------------------"); console.log("-----------------------HttpRequest_request_02 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info('HttpRequest_request_0300 asyncCallback error : ' + JSON.stringify(error)); console.info('HttpRequest_request_0300 asyncCallback error : ' + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_request_0300 : error = " + error); console.log("Telephony_http_HttpRequest_request_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -130,29 +118,25 @@ export default function httpRequestJsunit() { ...@@ -130,29 +118,25 @@ export default function httpRequestJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
try{ try {
httpRequest.destroy(); httpRequest.destroy();
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequest_destroy Test end-----------------------"); console.log("-----------------------HttpRequest_destroy Test end-----------------------");
done(); done();
}catch(error){ } catch (error) {
expect(false).assertFail(); expect(false).assertFail();
done(); done();
} }
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_destroy_0100 : error = " + error); console.log("Telephony_http_HttpRequest_destroy_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -167,20 +151,18 @@ export default function httpRequestJsunit() { ...@@ -167,20 +151,18 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_on_headerReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_on_headerReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) { httpRequest.on('headerReceive', (data) => {
expect(true).assertTrue();
done();
return;
}
httpRequest.on('headerReceive',(data) => {
console.log(casename + " data: " + JSON.stringify(data)); console.log(casename + " data: " + JSON.stringify(data));
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequest_on_headerReceive Test end-----------------------"); console.log("-----------------------HttpRequest_on_headerReceive Test end-----------------------");
done(); done();
}); });
httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + " data: " + JSON.stringify(data.responseCode) + " err: " + JSON.stringify(err));
});
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_on_headerReceive_0100 : error = " + error); console.log("Telephony_http_HttpRequest_on_headerReceive_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -195,21 +177,19 @@ export default function httpRequestJsunit() { ...@@ -195,21 +177,19 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_off_headerReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_off_headerReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) { httpRequest.off('headerReceive', (data) => {
expect(true).assertTrue();
done();
return;
}
//httpRequest.off_headerReceive((data) => {
httpRequest.off('headerReceive',(data) => {
console.log(casename + " data: " + JSON.stringify(data)); console.log(casename + " data: " + JSON.stringify(data));
expect(true).assertTrue(); expect(false).assertTrue();
console.log("-----------------------HttpRequest_off_headerReceive Test end-----------------------"); console.log("-----------------------HttpRequest_off_headerReceive Test end-----------------------");
done(); done();
}); });
httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + " data: " + JSON.stringify(data.responseCode) + " err: " + JSON.stringify(err));
done();
});
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_off_headerReceive_0100 : error = " + error); console.log("Telephony_http_HttpRequest_off_headerReceive_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -226,20 +206,18 @@ export default function httpRequestJsunit() { ...@@ -226,20 +206,18 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_on_headersReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_on_headersReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.on("headersReceive", (data) => { httpRequest.on("headersReceive", (data) => {
console.log(casename + " data: " + JSON.stringify(data)); console.log(casename + " data: " + JSON.stringify(data));
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequest_on_headersReceive Test end-----------------------"); console.log("-----------------------HttpRequest_on_headersReceive Test end-----------------------");
done(); done();
}); });
httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + " data: " + JSON.stringify(data.responseCode) + " err: " + JSON.stringify(err));
});
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_on_headersReceive_0100 : error = " + error); console.log("Telephony_http_HttpRequest_on_headersReceive_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -254,20 +232,19 @@ export default function httpRequestJsunit() { ...@@ -254,20 +232,19 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_off_headersReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_off_headersReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.off("headersReceive", (data) => { httpRequest.off("headersReceive", (data) => {
console.log(casename + " data: " + JSON.stringify(data)); console.log(casename + " data: " + JSON.stringify(data));
expect(true).assertTrue(); expect(false).assertTrue();
console.log("-----------------------HttpRequest_off_headersReceive Test end-----------------------"); console.log("-----------------------HttpRequest_off_headersReceive Test end-----------------------");
done(); done();
}); });
httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + " data: " + JSON.stringify(data.responseCode) + " err: " + JSON.stringify(err));
done();
});
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_off_headersReceive_0100 : error = " + error); console.log("Telephony_http_HttpRequest_off_headersReceive_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -278,21 +255,16 @@ export default function httpRequestJsunit() { ...@@ -278,21 +255,16 @@ export default function httpRequestJsunit() {
* @tc.desc Test Test httprequest property. * @tc.desc Test Test httprequest property.
*/ */
it("Telephony_http_HttpRequest_off_headersReceive_0200", 0, function (done) { it("Telephony_http_HttpRequest_off_headersReceive_0200", 0, function (done) {
var casename = "Telephony_http_HttpRequest_off_headersReceive_0200"
console.log("-----------------------HttpRequest_off_headersReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_off_headersReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.off('headersReceive'); httpRequest.off('headersReceive');
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequest_off_headersReceive_0200 Test end-----------------------"); console.log("-----------------------HttpRequest_off_headersReceive_0200 Test end-----------------------");
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_off_headersReceive_0200 : error = " + error); console.log("Telephony_http_HttpRequest_off_headersReceive_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -307,25 +279,21 @@ export default function httpRequestJsunit() { ...@@ -307,25 +279,21 @@ export default function httpRequestJsunit() {
console.log("-----------------------HttpRequest_once_headersReceive Test is starting-----------------------"); console.log("-----------------------HttpRequest_once_headersReceive Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.once('headersReceive', (data) => { httpRequest.once('headersReceive', (data) => {
console.log(casename + " data: " + JSON.stringify(data)); console.log(casename + " data: " + JSON.stringify(data));
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequest_on_headersReceive Test end-----------------------"); console.log("-----------------------HttpRequest_on_headersReceive Test end-----------------------");
done(); done();
}); });
httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + " data: " + JSON.stringify(data.responseCode) + " err: " + JSON.stringify(err));
});
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequest_once_headersReceive_010 : error = " + error); console.log("Telephony_http_HttpRequest_once_headersReceive_010 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
}) })
}; };
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,9 +12,8 @@ ...@@ -12,9 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import {describe, it, expect} from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import utils from './Utils'
export default function HttpRequestOptionsJsunit() { export default function HttpRequestOptionsJsunit() {
...@@ -34,23 +33,19 @@ export default function HttpRequestOptionsJsunit() { ...@@ -34,23 +33,19 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestOptions_method Test end-----------------------"); console.log("-----------------------HttpRequestOptions_method Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_method_0100 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_method_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -68,26 +63,23 @@ export default function HttpRequestOptionsJsunit() { ...@@ -68,26 +63,23 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestOptions_method_01 Test end-----------------------"); console.log("-----------------------HttpRequestOptions_method_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestOptions_method_0200 : error = " + error); console.log("Telephony_http_HttpRequestOptions_method_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -113,23 +105,19 @@ export default function HttpRequestOptionsJsunit() { ...@@ -113,23 +105,19 @@ export default function HttpRequestOptionsJsunit() {
rn: "30" rn: "30"
}, },
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions, (err, data) => { httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestOptions_extraData Test end-----------------------"); console.log("-----------------------HttpRequestOptions_extraData Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_extraData_0100 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_extraData_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -155,26 +143,23 @@ export default function HttpRequestOptionsJsunit() { ...@@ -155,26 +143,23 @@ export default function HttpRequestOptionsJsunit() {
rn: "30" rn: "30"
}, },
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions).then(data => { httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestOptions_extraData_01 Test end-----------------------"); console.log("-----------------------HttpRequestOptions_extraData_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_extraData_0200 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_extraData_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -192,19 +177,13 @@ export default function HttpRequestOptionsJsunit() { ...@@ -192,19 +177,13 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
try { try {
var entity = JSON.parse(data.result.toString());
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequestOptions_header Test end-----------------------"); console.log("-----------------------HttpRequestOptions_header Test end-----------------------");
done(); done();
...@@ -216,6 +195,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -216,6 +195,7 @@ export default function HttpRequestOptionsJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_header_0100 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_header_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -233,19 +213,13 @@ export default function HttpRequestOptionsJsunit() { ...@@ -233,19 +213,13 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
try { try {
var entity = JSON.parse(data.result.toString());
expect(true).assertTrue(); expect(true).assertTrue();
console.log("-----------------------HttpRequestOptions_header_01 Test end-----------------------"); console.log("-----------------------HttpRequestOptions_header_01 Test end-----------------------");
done(); done();
...@@ -254,13 +228,14 @@ export default function HttpRequestOptionsJsunit() { ...@@ -254,13 +228,14 @@ export default function HttpRequestOptionsJsunit() {
expect().assertFail(); expect().assertFail();
done(); done();
} }
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_header_0200 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_header_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -281,15 +256,10 @@ export default function HttpRequestOptionsJsunit() { ...@@ -281,15 +256,10 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/xml", header: "content-type': 'application/xml",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
try { try {
...@@ -304,6 +274,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -304,6 +274,7 @@ export default function HttpRequestOptionsJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_header_0300 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_header_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -321,21 +292,14 @@ export default function HttpRequestOptionsJsunit() { ...@@ -321,21 +292,14 @@ export default function HttpRequestOptionsJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/xml", header: "content-type': 'application/xml",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
try { try {
var result = '<?xml version="1.0" encoding="utf-8"?>'; expect(data.result.valueOf() != "").assertTrue();
//expect(data.getResult().contains(result)).assertTrue();
expect(data.result.valueOf() == result).assertTrue();
console.log("-----------------------HttpRequestOptions_header_03 Test end-----------------------"); console.log("-----------------------HttpRequestOptions_header_03 Test end-----------------------");
done(); done();
} catch (error) { } catch (error) {
...@@ -343,13 +307,14 @@ export default function HttpRequestOptionsJsunit() { ...@@ -343,13 +307,14 @@ export default function HttpRequestOptionsJsunit() {
expect().assertFail(); expect().assertFail();
done(); done();
} }
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_header_0400 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_header_0400 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -359,7 +324,6 @@ export default function HttpRequestOptionsJsunit() { ...@@ -359,7 +324,6 @@ export default function HttpRequestOptionsJsunit() {
* @tc.name HttpRequestOptions::readTimeout * @tc.name HttpRequestOptions::readTimeout
* @tc.desc Test Test HttpRequestOptions property. * @tc.desc Test Test HttpRequestOptions property.
*/ */
it("Telephony_Http_HttpRequestOptions_readTimeout_0100", 0, async function (done) { it("Telephony_Http_HttpRequestOptions_readTimeout_0100", 0, async function (done) {
var casename = 'Telephony_Http_HttpRequestOptions_0400'; var casename = 'Telephony_Http_HttpRequestOptions_0400';
console.log("-----------------------HttpRequestOptions_readTimeout Test is starting-----------------------"); console.log("-----------------------HttpRequestOptions_readTimeout Test is starting-----------------------");
...@@ -372,8 +336,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -372,8 +336,7 @@ export default function HttpRequestOptionsJsunit() {
connectTimeout: 60 connectTimeout: 60
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) { if (httpRequestOptions.connectTimeout < 60000) {
expect(true).assertTrue();
done(); done();
return; return;
} }
...@@ -385,6 +348,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -385,6 +348,7 @@ export default function HttpRequestOptionsJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_readTimeout_0100 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_readTimeout_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -406,8 +370,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -406,8 +370,7 @@ export default function HttpRequestOptionsJsunit() {
connectTimeout: 60 connectTimeout: 60
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) { if (httpRequestOptions.connectTimeout < 60000) {
expect(true).assertTrue();
done(); done();
return; return;
} }
...@@ -418,10 +381,12 @@ export default function HttpRequestOptionsJsunit() { ...@@ -418,10 +381,12 @@ export default function HttpRequestOptionsJsunit() {
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_readTimeout_0200 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_readTimeout_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -442,12 +407,11 @@ export default function HttpRequestOptionsJsunit() { ...@@ -442,12 +407,11 @@ export default function HttpRequestOptionsJsunit() {
readTimeout: 60, readTimeout: 60,
connectTimeout: 0.1 connectTimeout: 0.1
} }
var httpRequest = http.createHttp(); if (httpRequestOptions.connectTimeout < 60000) {
if (utils.notCheck) {
expect(true).assertTrue();
done(); done();
return; return;
} }
var httpRequest = http.createHttp();
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode == 504).assertTrue(); expect(data.responseCode == 504).assertTrue();
...@@ -456,6 +420,7 @@ export default function HttpRequestOptionsJsunit() { ...@@ -456,6 +420,7 @@ export default function HttpRequestOptionsJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_connectTimeout_0100 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_connectTimeout_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -477,12 +442,11 @@ export default function HttpRequestOptionsJsunit() { ...@@ -477,12 +442,11 @@ export default function HttpRequestOptionsJsunit() {
readTimeout: 60, readTimeout: 60,
connectTimeout: 0.1 connectTimeout: 0.1
} }
var httpRequest = http.createHttp(); if (httpRequestOptions.connectTimeout < 60000) {
if (utils.notCheck) {
expect(true).assertTrue();
done(); done();
return; return;
} }
var httpRequest = http.createHttp();
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode == 504).assertTrue(); expect(data.responseCode == 504).assertTrue();
...@@ -490,10 +454,12 @@ export default function HttpRequestOptionsJsunit() { ...@@ -490,10 +454,12 @@ export default function HttpRequestOptionsJsunit() {
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestOptions_connectTimeout_0200 : error = " + error); console.log("Telephony_Http_HttpRequestOptions_connectTimeout_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
......
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,9 +12,8 @@ ...@@ -12,9 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import {describe,it, expect} from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import utils from './Utils'
export default function httpResponseJsunit() { export default function httpResponseJsunit() {
describe("HttpResponseJsunitTest", function () { describe("HttpResponseJsunitTest", function () {
...@@ -33,15 +32,10 @@ export default function httpResponseJsunit() { ...@@ -33,15 +32,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.result != null).assertTrue(); expect(data.result != null).assertTrue();
...@@ -50,6 +44,7 @@ export default function httpResponseJsunit() { ...@@ -50,6 +44,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_result_0100 : error = " + error); console.log("Telephony_Http_HttpResponse_result_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -66,11 +61,6 @@ export default function httpResponseJsunit() { ...@@ -66,11 +61,6 @@ export default function httpResponseJsunit() {
console.log("-----------------------HttpResponse result_01 Test is starting-----------------------"); console.log("-----------------------HttpResponse result_01 Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", (err, data) => { httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.result != null).assertTrue(); expect(data.result != null).assertTrue();
...@@ -79,6 +69,7 @@ export default function httpResponseJsunit() { ...@@ -79,6 +69,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_result_0200 : error = " + error); console.log("Telephony_Http_HttpResponse_result_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -98,15 +89,10 @@ export default function httpResponseJsunit() { ...@@ -98,15 +89,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.result != null).assertTrue(); expect(data.result != null).assertTrue();
...@@ -114,10 +100,12 @@ export default function httpResponseJsunit() { ...@@ -114,10 +100,12 @@ export default function httpResponseJsunit() {
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_result_0300 : error = " + error); console.log("Telephony_Http_HttpResponse_result_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -137,15 +125,10 @@ export default function httpResponseJsunit() { ...@@ -137,15 +125,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode != 0).assertTrue(); expect(data.responseCode != 0).assertTrue();
...@@ -154,6 +137,7 @@ export default function httpResponseJsunit() { ...@@ -154,6 +137,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_responseCode_0100 : error = " + error); console.log("Telephony_Http_HttpResponse_responseCode_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -170,11 +154,6 @@ export default function httpResponseJsunit() { ...@@ -170,11 +154,6 @@ export default function httpResponseJsunit() {
console.log("-----------------------HttpResponse responseCode_01 Test is starting-----------------------"); console.log("-----------------------HttpResponse responseCode_01 Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", (err, data) => { httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode != 0).assertTrue(); expect(data.responseCode != 0).assertTrue();
...@@ -183,6 +162,7 @@ export default function httpResponseJsunit() { ...@@ -183,6 +162,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_responseCode_0200 : error = " + error); console.log("Telephony_Http_HttpResponse_responseCode_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -203,15 +183,10 @@ export default function httpResponseJsunit() { ...@@ -203,15 +183,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode != 0).assertTrue(); expect(data.responseCode != 0).assertTrue();
...@@ -219,10 +194,12 @@ export default function httpResponseJsunit() { ...@@ -219,10 +194,12 @@ export default function httpResponseJsunit() {
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_responseCode_0300 : error = " + error); console.log("Telephony_Http_HttpResponse_responseCode_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -241,15 +218,10 @@ export default function httpResponseJsunit() { ...@@ -241,15 +218,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.header != null).assertTrue(); expect(data.header != null).assertTrue();
...@@ -258,6 +230,7 @@ export default function httpResponseJsunit() { ...@@ -258,6 +230,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_header_0100 : error = " + error); console.log("Telephony_Http_HttpResponse_header_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -274,11 +247,6 @@ export default function httpResponseJsunit() { ...@@ -274,11 +247,6 @@ export default function httpResponseJsunit() {
console.log("-----------------------HttpResponse header_01 Test is starting-----------------------"); console.log("-----------------------HttpResponse header_01 Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", (err, data) => { httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.header != null).assertTrue(); expect(data.header != null).assertTrue();
...@@ -287,6 +255,7 @@ export default function httpResponseJsunit() { ...@@ -287,6 +255,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_header_0200 : error = " + error); console.log("Telephony_Http_HttpResponse_header_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -307,15 +276,10 @@ export default function httpResponseJsunit() { ...@@ -307,15 +276,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.header != null).assertTrue(); expect(data.header != null).assertTrue();
...@@ -327,6 +291,7 @@ export default function httpResponseJsunit() { ...@@ -327,6 +291,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_header_0300 : error = " + error); console.log("Telephony_Http_HttpResponse_header_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -345,15 +310,10 @@ export default function httpResponseJsunit() { ...@@ -345,15 +310,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.cookies != null).assertTrue(); expect(data.cookies != null).assertTrue();
...@@ -362,6 +322,7 @@ export default function httpResponseJsunit() { ...@@ -362,6 +322,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_cookies_0100 : error = " + error); console.log("Telephony_Http_HttpResponse_cookies_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -379,11 +340,6 @@ export default function httpResponseJsunit() { ...@@ -379,11 +340,6 @@ export default function httpResponseJsunit() {
console.log("-----------------------HttpResponse cookies_01 Test is starting-----------------------"); console.log("-----------------------HttpResponse cookies_01 Test is starting-----------------------");
try { try {
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", (err, data) => { httpRequest.request("https://www.baidu.com/", (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.cookies != null).assertTrue(); expect(data.cookies != null).assertTrue();
...@@ -392,6 +348,7 @@ export default function httpResponseJsunit() { ...@@ -392,6 +348,7 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_cookies_0200 : error = " + error); console.log("Telephony_Http_HttpResponse_cookies_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -411,15 +368,10 @@ export default function httpResponseJsunit() { ...@@ -411,15 +368,10 @@ export default function httpResponseJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.cookies != null).assertTrue(); expect(data.cookies != null).assertTrue();
...@@ -431,11 +383,10 @@ export default function httpResponseJsunit() { ...@@ -431,11 +383,10 @@ export default function httpResponseJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpResponse_cookies_0300 : error = " + error); console.log("Telephony_Http_HttpResponse_cookies_0300 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
}) })
}; };
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
//other import import httpJsunit from './HttpJsunit.test';
import httpJsunit from './HttpJsunit.test'
import responseCodeJsunit from './ResponseCodeJsunit.test'; import responseCodeJsunit from './ResponseCodeJsunit.test';
import requestMethodJsunit from './RequestMethodJsunit.test'; import requestMethodJsunit from './RequestMethodJsunit.test';
import httpResponseJsunit from './HttpResponseJsunit.test'; import httpResponseJsunit from './HttpResponseJsunit.test';
...@@ -22,7 +21,6 @@ import HttpRequestOptionsJsunit from './HttpRequestOptionsJsunit.test'; ...@@ -22,7 +21,6 @@ import HttpRequestOptionsJsunit from './HttpRequestOptionsJsunit.test';
import httpRequestJsunit from './HttpRequestJsunit.test'; import httpRequestJsunit from './HttpRequestJsunit.test';
export default function testsuite() { export default function testsuite() {
//other
httpJsunit(); httpJsunit();
responseCodeJsunit(); responseCodeJsunit();
requestMethodJsunit(); requestMethodJsunit();
......
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,9 +12,8 @@ ...@@ -12,9 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import {describe, it, expect} from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import utils from './Utils'
export default function requestMethodJsunit() { export default function requestMethodJsunit() {
describe("requestMethodJsunit", function () { describe("requestMethodJsunit", function () {
...@@ -33,23 +32,19 @@ export default function requestMethodJsunit() { ...@@ -33,23 +32,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.OPTIONS, method: http.RequestMethod.OPTIONS,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_options Test end-----------------------"); console.log("-----------------------HttpRequestMethod_options Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_options_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_options_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -70,26 +65,23 @@ export default function requestMethodJsunit() { ...@@ -70,26 +65,23 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.OPTIONS, method: http.RequestMethod.OPTIONS,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_options_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_options_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_options_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_options_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -110,23 +102,19 @@ export default function requestMethodJsunit() { ...@@ -110,23 +102,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_GET Test end-----------------------"); console.log("-----------------------HttpRequestMethod_GET Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_GET_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_GET_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -147,18 +135,13 @@ export default function requestMethodJsunit() { ...@@ -147,18 +135,13 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_GET_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_GET_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
...@@ -167,6 +150,7 @@ export default function requestMethodJsunit() { ...@@ -167,6 +150,7 @@ export default function requestMethodJsunit() {
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_GET_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_GET_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -193,23 +177,19 @@ export default function requestMethodJsunit() { ...@@ -193,23 +177,19 @@ export default function requestMethodJsunit() {
rn: "30" rn: "30"
}, },
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions, (err, data) => { httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_POST Test end-----------------------"); console.log("-----------------------HttpRequestMethod_POST Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_POST_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_POST_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -238,26 +218,23 @@ export default function requestMethodJsunit() { ...@@ -238,26 +218,23 @@ export default function requestMethodJsunit() {
rn: "30" rn: "30"
}, },
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions).then(data => { httpRequest.request("https://image.baidu.com/search/albumsdetail/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_POST_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_POST_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_POST_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_POST_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -278,23 +255,19 @@ export default function requestMethodJsunit() { ...@@ -278,23 +255,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.TRACE, method: http.RequestMethod.TRACE,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_TRACE Test end-----------------------"); console.log("-----------------------HttpRequestMethod_TRACE Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_TRACE_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_TRACE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -314,26 +287,23 @@ export default function requestMethodJsunit() { ...@@ -314,26 +287,23 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.TRACE, method: http.RequestMethod.TRACE,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_TRACE_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_TRACE_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_TRACE_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_TRACE_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -356,23 +326,23 @@ export default function requestMethodJsunit() { ...@@ -356,23 +326,23 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.PUT, method: http.RequestMethod.PUT,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); if (httpRequestOptions.method == http.RequestMethod.PUT) {
if (utils.notCheck) {
expect(true).assertTrue();
done(); done();
return; return;
} }
var httpRequest = http.createHttp();
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_PUT Test end-----------------------"); console.log("-----------------------HttpRequestMethod_PUT Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_PUT_0100 : error = " + error); console.log("Telephony_http_HttpRequestMethod_PUT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -393,26 +363,27 @@ export default function requestMethodJsunit() { ...@@ -393,26 +363,27 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.PUT, method: http.RequestMethod.PUT,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); if (httpRequestOptions.method == http.RequestMethod.PUT) {
if (utils.notCheck) {
expect(true).assertTrue();
done(); done();
return; return;
} }
var httpRequest = http.createHttp();
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_PUT_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_PUT_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_PUT_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_PUT_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -431,23 +402,19 @@ export default function requestMethodJsunit() { ...@@ -431,23 +402,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.HEAD, method: http.RequestMethod.HEAD,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_head Test end-----------------------"); console.log("-----------------------HttpRequestMethod_head Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_head_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_head_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -465,26 +432,23 @@ export default function requestMethodJsunit() { ...@@ -465,26 +432,23 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.HEAD, method: http.RequestMethod.HEAD,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_HEAD_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_HEAD_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_HEAD_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_HEAD_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -503,23 +467,19 @@ export default function requestMethodJsunit() { ...@@ -503,23 +467,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.DELETE, method: http.RequestMethod.DELETE,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_DELETE Test end-----------------------"); console.log("-----------------------HttpRequestMethod_DELETE Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_DELETE_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_DELETE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -537,26 +497,23 @@ export default function requestMethodJsunit() { ...@@ -537,26 +497,23 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.DELETE, method: http.RequestMethod.DELETE,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_DELETE_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_DELETE_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_DELETE_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_DELETE_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -575,23 +532,19 @@ export default function requestMethodJsunit() { ...@@ -575,23 +532,19 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.CONNECT, method: http.RequestMethod.CONNECT,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => { httpRequest.request("https://www.baidu.com/", httpRequestOptions, (err, data) => {
console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data)); console.log(casename + JSON.stringify(err) + " data: " + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_CONNECT Test end-----------------------"); console.log("-----------------------HttpRequestMethod_CONNECT Test end-----------------------");
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_Http_HttpRequestMethod_CONNECT_0100 : error = " + error); console.log("Telephony_Http_HttpRequestMethod_CONNECT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -609,31 +562,26 @@ export default function requestMethodJsunit() { ...@@ -609,31 +562,26 @@ export default function requestMethodJsunit() {
method: http.RequestMethod.CONNECT, method: http.RequestMethod.CONNECT,
extraData: null, extraData: null,
header: "content-type': 'application/json", header: "content-type': 'application/json",
readTimeout: 60, readTimeout: 60000,
connectTimeout: 60 connectTimeout: 60000
} }
var httpRequest = http.createHttp(); var httpRequest = http.createHttp();
if (utils.notCheck) {
expect(true).assertTrue();
done();
return;
}
httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => { httpRequest.request("https://www.baidu.com/", httpRequestOptions).then(data => {
console.log(casename + JSON.stringify(data)); console.log(casename + JSON.stringify(data));
expect(data.responseCode = 200).assertTrue(); expect(data.responseCode == 200).assertTrue();
console.log("-----------------------HttpRequestMethod_CONNECT_01 Test end-----------------------"); console.log("-----------------------HttpRequestMethod_CONNECT_01 Test end-----------------------");
done(); done();
}).catch(error => { }).catch(error => {
console.info(casename+"errocode" + JSON.stringify(error)); console.info(casename+"errocode" + JSON.stringify(error));
expect(false).assertTrue();
done(); done();
}); });
} catch (error) { } catch (error) {
console.log("Telephony_http_HttpRequestMethod_CONNECT_0200 : error = " + error); console.log("Telephony_http_HttpRequestMethod_CONNECT_0200 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
}) })
}; };
/* /*
* Copyright (C) 2021 Huawei Device Co., Ltd. * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License') * Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, afterAll, it, expect, afterEach} from 'hypium/index'; import {describe,it, expect} from '@ohos/hypium';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
export default function responseCodeJsunit() { export default function responseCodeJsunit() {
...@@ -50,6 +50,7 @@ export default function responseCodeJsunit() { ...@@ -50,6 +50,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_ACCEPTED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_ACCEPTED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -68,6 +69,7 @@ export default function responseCodeJsunit() { ...@@ -68,6 +69,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NOT_AUTHORITATIVE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NOT_AUTHORITATIVE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -86,6 +88,7 @@ export default function responseCodeJsunit() { ...@@ -86,6 +88,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NO_CONTENT_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NO_CONTENT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -103,6 +106,7 @@ export default function responseCodeJsunit() { ...@@ -103,6 +106,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_MULT_CHOICE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_MULT_CHOICE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -121,6 +125,7 @@ export default function responseCodeJsunit() { ...@@ -121,6 +125,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_MOVED_PERM_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_MOVED_PERM_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -139,6 +144,7 @@ export default function responseCodeJsunit() { ...@@ -139,6 +144,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_SEE_OTHER_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_SEE_OTHER_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -157,6 +163,7 @@ export default function responseCodeJsunit() { ...@@ -157,6 +163,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NOT_MODIFIED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NOT_MODIFIED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -174,6 +181,7 @@ export default function responseCodeJsunit() { ...@@ -174,6 +181,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_USE_PROXY_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_USE_PROXY_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -192,6 +200,7 @@ export default function responseCodeJsunit() { ...@@ -192,6 +200,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_BAD_REQUEST_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_BAD_REQUEST_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -210,6 +219,7 @@ export default function responseCodeJsunit() { ...@@ -210,6 +219,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_UNAUTHORIZED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_UNAUTHORIZED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -228,6 +238,7 @@ export default function responseCodeJsunit() { ...@@ -228,6 +238,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_PAYMENT_REQUIRED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_PAYMENT_REQUIRED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -246,6 +257,7 @@ export default function responseCodeJsunit() { ...@@ -246,6 +257,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_BAD_METHOD_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_BAD_METHOD_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -264,6 +276,7 @@ export default function responseCodeJsunit() { ...@@ -264,6 +276,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NOT_ACCEPTABLED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NOT_ACCEPTABLED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -282,6 +295,7 @@ export default function responseCodeJsunit() { ...@@ -282,6 +295,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_PROXY_AUTH_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_PROXY_AUTH_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -300,6 +314,7 @@ export default function responseCodeJsunit() { ...@@ -300,6 +314,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_CLIENT_TIMEOUT_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_CLIENT_TIMEOUT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -318,6 +333,7 @@ export default function responseCodeJsunit() { ...@@ -318,6 +333,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_LENGTH_REQUIRED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_LENGTH_REQUIRED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -336,6 +352,7 @@ export default function responseCodeJsunit() { ...@@ -336,6 +352,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_PRECON_FAILED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_PRECON_FAILED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -354,6 +371,7 @@ export default function responseCodeJsunit() { ...@@ -354,6 +371,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_ENTITY_TOO_LARGE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_ENTITY_TOO_LARGE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -373,6 +391,7 @@ export default function responseCodeJsunit() { ...@@ -373,6 +391,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_REQ_TOO_LONG_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_REQ_TOO_LONG_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -392,6 +411,7 @@ export default function responseCodeJsunit() { ...@@ -392,6 +411,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_UNSUPPORTED_TYPE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_UNSUPPORTED_TYPE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -409,6 +429,7 @@ export default function responseCodeJsunit() { ...@@ -409,6 +429,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_INTERNAL_ERROR_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_INTERNAL_ERROR_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -427,6 +448,7 @@ export default function responseCodeJsunit() { ...@@ -427,6 +448,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NOT_IMPLEMENTED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NOT_IMPLEMENTED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -445,6 +467,7 @@ export default function responseCodeJsunit() { ...@@ -445,6 +467,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_BAD_GATEWAY_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_BAD_GATEWAY_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -463,6 +486,7 @@ export default function responseCodeJsunit() { ...@@ -463,6 +486,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_GATEWAY_TIMEOUT_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_GATEWAY_TIMEOUT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -481,6 +505,7 @@ export default function responseCodeJsunit() { ...@@ -481,6 +505,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_VERSION_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_VERSION_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -499,6 +524,7 @@ export default function responseCodeJsunit() { ...@@ -499,6 +524,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_CREATED_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_CREATED_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -516,6 +542,7 @@ export default function responseCodeJsunit() { ...@@ -516,6 +542,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_RESET_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_RESET_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -534,6 +561,7 @@ export default function responseCodeJsunit() { ...@@ -534,6 +561,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_PARTIAL_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_PARTIAL_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -553,6 +581,7 @@ export default function responseCodeJsunit() { ...@@ -553,6 +581,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_MOVED_TEMP_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_MOVED_TEMP_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -571,6 +600,7 @@ export default function responseCodeJsunit() { ...@@ -571,6 +600,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_FORBIDDEN_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_FORBIDDEN_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -589,6 +619,7 @@ export default function responseCodeJsunit() { ...@@ -589,6 +619,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_NOT_FOUND_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_NOT_FOUND_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -608,6 +639,7 @@ export default function responseCodeJsunit() { ...@@ -608,6 +639,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_CONFLICT_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_CONFLICT_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -627,6 +659,7 @@ export default function responseCodeJsunit() { ...@@ -627,6 +659,7 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_GONE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_GONE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
...@@ -646,12 +679,10 @@ export default function responseCodeJsunit() { ...@@ -646,12 +679,10 @@ export default function responseCodeJsunit() {
done(); done();
} catch (error) { } catch (error) {
console.log("Telephony_Http_ResponseCode_UNAVAILABLE_0100 : error = " + error); console.log("Telephony_Http_ResponseCode_UNAVAILABLE_0100 : error = " + error);
expect(false).assertTrue();
done(); done();
} }
}); });
}) })
}; };
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static notCheck = true;
static sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info(`sleep ${time} over...`)
})
}
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
static async swipe(downX, downY, upX, upY, steps) {
console.info('start to swipe')
this.drags(downX, downY, upX, upY, steps, false)
}
static async drag(downX, downY, upX, upY, steps) {
console.info('start to drag')
this.drags(downX, downY, upX, upY, steps, true)
}
static async drags(downX, downY, upX, upY, steps, drag) {
var xStep;
var yStep;
var swipeSteps;
var ret;
xStep = 0;
yStep = 0;
ret = false;
swipeSteps = steps;
if (swipeSteps == 0) {
swipeSteps = 1;
}
xStep = (upX - downX) / swipeSteps;
yStep = (upY - downY) / swipeSteps;
console.info('move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep)
var downPonit: TouchObject = {
id: 1,
x: downX,
y: downY,
type: TouchType.Down,
}
console.info('down touch started: ' + JSON.stringify(downPonit))
sendTouchEvent(downPonit);
console.info('start to move')
if (drag) {
await this.sleep(500)
}
for (var i = 1;i <= swipeSteps; i++) {
var movePoint: TouchObject = {
id: 1,
x: downX + (xStep * i),
y: downY + (yStep * i),
type: TouchType.Move
}
console.info('move touch started: ' + JSON.stringify(movePoint))
ret = sendTouchEvent(movePoint)
if (ret == false) {
break;
}
await this.sleep(5)
}
console.info('start to up')
if (drag) {
await this.sleep(100)
}
var upPoint: TouchObject = {
id: 1,
x: upX,
y: upY,
type: TouchType.Up,
}
console.info('up touch started: ' + JSON.stringify(upPoint))
sendTouchEvent(upPoint)
await this.sleep(500)
}
}
/**
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// sim slot id
export const DEFAULT_SLOTID = 0;
export const SLOTID3 = 3;
export const SLOTID2 = 2;
export const SLOTID_MINUS1 = -1;
// sim correct password
export const CORRECT_PIN = '1234';
export const CORRECT_PIN2 = '18099014';
// sim incorrect password
export const INCORRECT_PIN = '134679';
export const INCORRECT_PIN_LEN3 = '123';
export const INCORRECT_PUK = '134679';
export const INCORRECT_PIN2 = '134679';
export const INCORRECT_PIN2_LEN3 = '123';
export const INCORRECT_PIN2_LEN9 = '123456789';
export const INCORRECT_PUK2 = '134679';
// lock status response
export const LOCK_RESULT = { SUCCESS: 0, FAILURE: -1, EXCEPTION: -2 };
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册