diff --git a/telephony/telephonyjstest/netmanager_base/network_nowifi/src/main/js/test/Http.nowifi.test.js b/telephony/telephonyjstest/netmanager_base/network_nowifi/src/main/js/test/Http.nowifi.test.js index 1ccf814f4663b7891a0d8d8a21af5aaa6276429f..b1c26d025e295d7b533f53160044bd5041fa858c 100644 --- a/telephony/telephonyjstest/netmanager_base/network_nowifi/src/main/js/test/Http.nowifi.test.js +++ b/telephony/telephonyjstest/netmanager_base/network_nowifi/src/main/js/test/Http.nowifi.test.js @@ -14,53 +14,42 @@ */ import network from '@system.network'; -import { describe, it, expect } from '@ohos/hypium'; +import { describe, expect, it } from '@ohos/hypium'; import connection from '@ohos.net.connection'; export default function Telephony_NetManager_NetWorkTest() { describe("Telephony_NetManager_NetWorkTest", function () { - let networkAvailable = () => { - connection.getDefaultNet(function (error, netHandle) { - if (error || netHandle.netId >= 100) { - console.info("Network available or Network error:" + error); - return true; - } - return false; - }) - } - /** * @tc.number Telephony_NetManager_NetWorkTest_GetType_None_0100 * @tc.name Whether the GetType method is called successfully without WiFi * @tc.desc Function test */ it("Telephony_NetManager_NetWorkTest_GetType_None_0100", 0, function (done) { - if (networkAvailable) { - console.warn("No network environment required"); - done(); - return; - } - network.getType({ - success: function (data) { - console.info("NetManager getType " + JSON.stringify(data)); - expect(data.type === "none").assertTrue(); - expect(data.metered === false).assertTrue(); - network.unsubscribe(); - done(); - }, - fail: function (data, code) { - console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); - expect().assertFail(); - done(); - }, - complete: function () { - expect().assertTrue(); + connection.getDefaultNet(function (error, netHandle) { + if (error || netHandle.netId >= 100) { + console.info("Network available or Network error:" + error); done(); + return; } + network.getType({ + success: function (data) { + console.info("NetManager getType " + JSON.stringify(data)); + expect(data.type == "none").assertTrue(); + expect(data.metered == false).assertTrue(); + network.unsubscribe(); + done(); + }, + fail: function (data, code) { + console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); + expect().assertFail(); + done(); + }, + complete: function () { + } + }) }) - done(); }); /** @@ -69,31 +58,30 @@ export default function Telephony_NetManager_NetWorkTest() { * @tc.desc Function test */ it("Telephony_NetManager_NetWorkTest_GetType_None_0200", 0, function (done) { - if (networkAvailable) { - console.warn("No network environment required"); - done(); - return; - } - network.getType({ - success: function (data) { - console.info("NetManager getType 1 " + JSON.stringify(data)); - expect(data.type === "none").assertTrue(); - expect(data.metered === false).assertTrue(); - network.unsubscribe(); - done(); - console.info("NetManager Telephony_NetManager_NetWorkTest_GetType_none_1 end"); - }, - fail: function (data, code) { - console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); - expect().assertFail(); - done(); - }, - complete: function () { - expect().assertTrue(); + connection.getDefaultNet(function (error, netHandle) { + if (error || netHandle.netId >= 100) { + console.info("Network available or Network error:" + error); done(); + return; } + network.getType({ + success: function (data) { + console.info("NetManager getType 1 " + JSON.stringify(data)); + expect(data.type == "none").assertTrue(); + expect(data.metered == false).assertTrue(); + network.unsubscribe(); + done(); + console.info("NetManager Telephony_NetManager_NetWorkTest_GetType_none_1 end"); + }, + fail: function (data, code) { + console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); + expect().assertFail(); + done(); + }, + complete: function () { + } + }) }) - done(); }); /** @@ -102,26 +90,27 @@ export default function Telephony_NetManager_NetWorkTest() { * @tc.desc Function test */ it("Telephony_NetManager_NetWorkTest_Subscribe_None_0100", 0, function (done) { - if (networkAvailable) { - console.warn("No network environment required"); - done(); - return; - } - network.subscribe({ - success: function (data) { - console.info("NetManager subscribe " + JSON.stringify(data)); - expect(data.type === "none").assertTrue(); - expect(data.metered === false).assertTrue(); - network.unsubscribe(); - done(); - }, - fail: function (data, code) { - console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); - expect().assertFail(); + connection.getDefaultNet(function (error, netHandle) { + if (error || netHandle.netId >= 100) { + console.info("Network available or Network error:" + error); done(); + return; } + network.subscribe({ + success: function (data) { + console.info("NetManager subscribe " + JSON.stringify(data)); + expect(data.type == "none").assertTrue(); + expect(data.metered == false).assertTrue(); + network.unsubscribe(); + done(); + }, + fail: function (data, code) { + console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); + expect().assertFail(); + done(); + } + }) }) - done(); }); /** @@ -130,27 +119,27 @@ export default function Telephony_NetManager_NetWorkTest() { * @tc.desc Function test */ it("Telephony_NetManager_NetWorkTest_Subscribe_None_0200", 0, function (done) { - if (networkAvailable) { - console.warn("No network environment required"); - done(); - return; - } - network.subscribe({ - success: function (data) { - console.info("NetManager subscribe " + JSON.stringify(data)); - expect(data.type === "none").assertTrue(); - expect(data.metered === false).assertTrue(); - network.unsubscribe(); - done(); - }, - fail: function (data, code) { - console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); - expect().assertFail(); + connection.getDefaultNet(function (error, netHandle) { + if (error || netHandle.netId >= 100) { + console.info("Network available or Network error:" + error); done(); + return; } + network.subscribe({ + success: function (data) { + console.info("NetManager subscribe " + JSON.stringify(data)); + expect(data.type == "none").assertTrue(); + expect(data.metered == false).assertTrue(); + network.unsubscribe(); + done(); + }, + fail: function (data, code) { + console.log("data:" + JSON.stringify(data) + " code:" + JSON.stringify(code)); + expect().assertFail(); + done(); + } + }) }) - done(); }); - }); } \ No newline at end of file