diff --git a/communication/BUILD.gn b/communication/BUILD.gn
index 7676dd882d511ccb6eaa48aa8bf99354620e6891..a585b4a86db9a9b009b1ba7f5c1c20eab05cb0b2 100755
--- a/communication/BUILD.gn
+++ b/communication/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Copyright (C) 2022 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
@@ -15,8 +15,17 @@ import("//build/ohos_var.gni")
group("communication") {
testonly = true
if (is_standard_system) {
- deps = [ "wifi_standard:wifi_standard_test" ]
+ deps = [
+ # "bluetooth_ble:ActsBluetoothBleJsTest",
+ # "bluetooth_on:ActsBluetoothOnJsTest",
+ # "bluetooth_standard:ActsBluetoothJsTest",
+ # "dsoftbus/rpc:ActsRpcJsTest",
+ "wifi_hotspot:ActsHotSpotJSTest",
+ "wifi_p2p:ActsP2PJSTest",
+ "wifi_standard:ActsWifiJSTest",
+ ]
} else {
- deps = [ "wifi_standard:wifi_standard_test" ]
+ deps = [ "wifi_standard:ActsWifiJSTest" ]
}
}
+
diff --git a/communication/wifi_hotspot/BUILD.gn b/communication/wifi_hotspot/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..1780dd41559468fcad561a86118db6142142ddd1
--- /dev/null
+++ b/communication/wifi_hotspot/BUILD.gn
@@ -0,0 +1,31 @@
+# Copyright (C) 2022 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.
+
+import("//test/xts/tools/build/suite.gni")
+
+ohos_js_hap_suite("ActsHotSpotJSTest") {
+ hap_profile = "./src/main/config.json"
+ deps = [
+ ":wifi_js_assets",
+ ":wifi_resources",
+ ]
+ certificate_profile = "./signature/openharmony_sx.p7b"
+ hap_name = "ActsHotSpotJSApiTest"
+}
+ohos_js_assets("wifi_js_assets") {
+ source_dir = "./src/main/js/default"
+}
+ohos_resources("wifi_resources") {
+ sources = [ "./src/main/resources" ]
+ hap_profile = "./src/main/config.json"
+}
diff --git a/communication/wifi_hotspot/Test.json b/communication/wifi_hotspot/Test.json
new file mode 100755
index 0000000000000000000000000000000000000000..857d50b5eab01f0bc6a250f22d4a6ab7141edf40
--- /dev/null
+++ b/communication/wifi_hotspot/Test.json
@@ -0,0 +1,18 @@
+{
+ "description": "Configuration for wifi js api Tests",
+ "driver": {
+ "type": "JSUnitTest",
+ "test-timeout": "600000",
+ "package": "ohos.acts.communication.wifi.wifidevice",
+ "shell-timeout": "600000"
+ },
+ "kits": [
+ {
+ "test-file-name": [
+ "ActsHotSpotJSApiTest.hap"
+ ],
+ "type": "AppInstallKit",
+ "cleanup-apps": true
+ }
+ ]
+}
diff --git a/communication/wifi_hotspot/signature/openharmony_sx.p7b b/communication/wifi_hotspot/signature/openharmony_sx.p7b
new file mode 100755
index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858
Binary files /dev/null and b/communication/wifi_hotspot/signature/openharmony_sx.p7b differ
diff --git a/communication/wifi_hotspot/src/main/config.json b/communication/wifi_hotspot/src/main/config.json
new file mode 100755
index 0000000000000000000000000000000000000000..01796c829e3e2036ccc09f6c3003d71c70822871
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/config.json
@@ -0,0 +1,99 @@
+{
+ "app": {
+ "bundleName": "ohos.acts.communication.wifi.wifidevice",
+ "vendor": "acts",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ },
+ "apiVersion": {
+ "compatible": 4,
+ "target": 5
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "ohos.acts.communication.wifi.wifidevice",
+ "name": ".MyApplication",
+ "mainAbility": "ohos.acts.communication.wifi.wifidevice.MainAbility",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "wifi_standard",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "visible": true,
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "name": "ohos.acts.communication.wifi.wifidevice.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:app_name",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
+ }
+ ],
+ "reqPermissions": [
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO",
+ "reason" : "use ohos.permission.GET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_INFO",
+ "reason" : "use ohos.permission.SET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_CONNECTION",
+ "reason" : "use ohos.permission.MANAGE_WIFI_CONNECTION"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.SET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.GET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
+ "reason" : "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_LOCAL_MAC",
+ "reason" : "use ohos.permission.GET_WIFI_LOCAL_MAC"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_HOTSPOT",
+ "reason" : "use ohos.permission.MANAGE_WIFI_HOTSPOT"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO_INTERNAL",
+ "reason" : "use ohos.permission.GET_WIFI_INFO_INTERNAL"
+ }
+ ]
+ }
+}
diff --git a/communication/wifi_hotspot/src/main/js/default/app.js b/communication/wifi_hotspot/src/main/js/default/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..8fe0b77dcef1db4bb1706399fd481541de8166cd
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/app.js
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 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 {
+ onCreate() {
+ console.info('AceApplication onCreate');
+ },
+ onDestroy() {
+ console.info('AceApplication onDestroy');
+ }
+};
diff --git a/communication/wifi_hotspot/src/main/js/default/i18n/en-US.json b/communication/wifi_hotspot/src/main/js/default/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/i18n/en-US.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "Hello",
+ "world": "World"
+ }
+}
\ No newline at end of file
diff --git a/communication/wifi_hotspot/src/main/js/default/i18n/zh-CN.json b/communication/wifi_hotspot/src/main/js/default/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/i18n/zh-CN.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "您好",
+ "world": "世界"
+ }
+}
\ No newline at end of file
diff --git a/communication/wifi_hotspot/src/main/js/default/pages/index/index.css b/communication/wifi_hotspot/src/main/js/default/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..3a8326a076cdb9ecabf543df9dba84240f5b52a4
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/pages/index/index.css
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.title {
+ font-size: 100px;
+}
diff --git a/communication/wifi_hotspot/src/main/js/default/pages/index/index.hml b/communication/wifi_hotspot/src/main/js/default/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..0053057b5ff7362e00db48887ee1663cffa35988
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/pages/index/index.hml
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+
+
+ {{ $t('strings.hello') }} {{ title }}
+
+
diff --git a/communication/wifi_hotspot/src/main/js/default/pages/index/index.js b/communication/wifi_hotspot/src/main/js/default/pages/index/index.js
new file mode 100755
index 0000000000000000000000000000000000000000..696aad4cf934ca8ca2e2b636169bb736427a4ea0
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/pages/index/index.js
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+
+import {Core, ExpectExtend} from 'deccjsunit/index'
+
+export default {
+ data: {
+ title: '',
+ myTimeout: 15000
+ },
+ onInit() {
+ this.title = this.$t('strings.world');
+ },
+ onShow() {
+ console.info('onShow finish')
+ },
+ onReady() {
+ console.info('onReady finish')
+ const core = Core.getInstance()
+ const expectExtend = new ExpectExtend({
+ 'id': 'extend'
+ })
+ core.addService('expect', expectExtend)
+ core.init()
+
+ const configService = core.getDefaultService('config')
+ this.timeout = this.myTimeout
+ configService.setConfig(this)
+
+ require('../../test/List.test')
+ core.execute()
+
+ },
+}
+
diff --git a/communication/wifi_hotspot/src/main/js/default/test/List.test.js b/communication/wifi_hotspot/src/main/js/default/test/List.test.js
new file mode 100755
index 0000000000000000000000000000000000000000..c82020cebf53f6db3e4f23a35e7577c0576ed456
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/test/List.test.js
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+require('./WifiSoftAP.test.js')
+
+
+
diff --git a/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js b/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js
new file mode 100755
index 0000000000000000000000000000000000000000..4014472fa2ba66d3fce575a00ea47a2d2b6253b9
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/js/default/test/WifiSoftAP.test.js
@@ -0,0 +1,702 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+import wifi from '@ohos.wifi'
+
+function sleep(delay) {
+ return new Promise(resovle => setTimeout(resovle, delay))
+}
+
+async function tryToDisableWifi(){
+ if(wifi.isWifiActive()){
+ console.info("wifi_test/disable wifi:" + wifi.disableWifi());
+ await sleep(5000);
+ }
+ console.info("wifi_test/wifi status:" + wifi.isWifiActive());
+}
+
+var WifiSecurityType = {
+ WIFI_SEC_TYPE_INVALID : 0,
+ WIFI_SEC_TYPE_OPEN : 1,
+ WIFI_SEC_TYPE_WEP : 2,
+ WIFI_SEC_TYPE_PSK : 3,
+ WIFI_SEC_TYPE_SAE : 4,
+}
+
+var HotspotConfig = {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+}
+
+describe('ACTS_WifiTest', function() {
+ beforeEach(function () {
+ })
+
+ afterEach(function () {
+ })
+
+ /**
+ * @tc.number OPEN_0002
+ * @tc.name SUB_Communication_WiFi_Hotspot_Open_0002
+ * @tc.desc Test wifi.enableHotspot and wifi.disableHotspot API functionality1.
+ * @tc.level Level 0
+ */
+ it('SUB_Communication_WiFi_Hotspot_Open_0002', 0, async function (done) {
+ if (wifi.isWifiActive()) {
+ var disable = wifi.disableWifi();
+ await sleep(5000);
+ expect(disable).assertTrue();
+ }
+ var close =wifi.isWifiActive();
+ console.info("[wifi_test] wifi status result: " + close);
+ expect(close).assertFalse();
+ if (!wifi.isHotspotActive()) {
+ var on = wifi.enableHotspot();
+ await sleep(5000);
+ expect(on).assertTrue();
+ }
+ console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive());
+ expect(wifi.isHotspotActive()).assertTrue();
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0001
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0001
+ * @tc.desc Test set a valid 2.4G hotspot config
+ * @tc.level Level 0
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0001', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(3000);
+ expect(off).assertTrue();
+ }
+ console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive());
+ expect(wifi.isHotspotActive()).assertFalse();
+ var isSuccess = wifi.setHotspotConfig(HotspotConfig);
+ expect(isSuccess).assertTrue();
+
+ var hotspotConfig = wifi.getHotspotConfig();
+ console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig));
+ expect(hotspotConfig.band).assertEqual(1);
+ done()
+ })
+
+ /**
+ * @tc.number CONFIG_0002
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0002
+ * @tc.desc Test set a valid 5G hotspot config
+ * @tc.level Level 1
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0002', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(3000);
+ expect(off).assertTrue();
+ }
+ console.info("[wifi_test] Hotspot status result -> " + wifi.isHotspotActive());
+ var HotspotConfig5G = {
+ "ssid": "testWgr",
+ "band": 2,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess5 = wifi.setHotspotConfig(HotspotConfig5G);
+ expect(isSuccess5).assertFalse();
+
+ var hotspotConfig5 = wifi.getHotspotConfig();
+ console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfig5));
+ expect(hotspotConfig5.band).assertEqual(1);
+ done()
+ })
+
+ /**
+ * @tc.number CONFIG_0003
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0003
+ * @tc.desc Test set a invalid band hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0003', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(3000);
+ console.info("[wifi_test] disableHotspot result -> " + off);
+ expect(off).assertTrue();
+ }
+ var HotspotConfig1= {
+ "ssid": "testWgr",
+ "band": 21,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfig1);
+ console.log("[wifi_test] set invalid band hotspot config result1:" + isSuccess1);
+ expect(isSuccess1).assertFalse();
+ done();
+
+ })
+
+
+ /**
+ * @tc.number CONFIG_0004
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0004
+ * @tc.desc Test set a max preSharedKey is hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0004', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+ }
+ var HotspotConfigM= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "123456789123456789123456789123456789123456789123456789123456789",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM);
+ console.log("[wifi_test] set max preSharedKey valid hotspot config result: " + isSuccess1);
+ expect(isSuccess1).assertTrue();
+
+ var HotspotConfigM1= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "1234567891234567891234567891234567891234567891234567891234567891",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigM1);
+ expect(isSuccess1).assertFalse();
+ var hotspotConfigS= wifi.getHotspotConfig();
+ console.log("[wifi_test] getHotspotConfig result: " + JSON.stringify(hotspotConfigS));
+ expect(hotspotConfigS.preSharedKey.length).assertEqual(63);
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0005
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0005
+ * @tc.desc Test set a min preSharedKey is hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0005', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+ }
+
+ var HotspotConfigI= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI);
+ expect(isSuccess1).assertTrue();
+
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ console.info("preSharedKey: " + config.preSharedKey);
+ expect(config.preSharedKey.length).assertEqual(8);
+
+ var HotspotConfigI2= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "1234567",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2);
+ expect(isSuccess1).assertFalse();
+
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.preSharedKey.length).assertEqual(8);
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0006
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0006
+ * @tc.desc Test set a max ssid for hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0006', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+ }
+ var isHotspotActive = wifi.isHotspotActive();
+ console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
+ expect(isHotspotActive).assertFalse();
+
+ var HotspotConfigS= {
+ "ssid": "testWgr123testWgr123testWgr12356",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS);
+ expect(isSuccess1).assertTrue();
+
+ var HotspotConfigS1= {
+ "ssid": "testWgr123testWgr123testWgr123567",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigS1);
+ console.log("[wifi_test] set 33bit ssid invalid hotspot config result: " + isSuccess1);
+ expect(isSuccess1).assertFalse();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.ssid.length).assertEqual(32);
+ done();
+
+ })
+
+ /**
+ * @tc.number CONFIG_0007
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0007
+ * @tc.desc Test set a null ssid invalid hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0007', 0, async function(done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(2000);
+ expect(off).assertTrue();
+ }
+ var HotspotConfigN= {
+ "ssid": "",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigN);
+ console.log("[wifi_test] set a null ssid invalid hotspot config result1:" + isSuccess1);
+ expect(isSuccess1).assertFalse();
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0008
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0008
+ * @tc.desc Test set a contains Chinese.special.digits valid hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0008', 0, async function(done) {
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(3000);
+ expect(off).assertTrue();
+ }
+ var HotspotConfigC= {
+ "ssid": "测试123!@#¥%……&*( ",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigC);
+ expect(isSuccess1).assertTrue();
+
+ var isHotspotActive = wifi.isHotspotActive();
+ console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
+ expect(isHotspotActive).assertFalse();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(true).assertEqual(config.ssid==HotspotConfigC.ssid);
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0009
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0009
+ * @tc.desc Test set a invalid preSharedKey hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0009', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(3000);
+ expect(off).assertTrue();
+
+ }
+ var HotspotConfigWep= {
+ "ssid": "test123",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType":WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigWep);
+ console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess1);
+ expect(isSuccess1).assertFalse();
+
+ var HotspotConfigSAE= {
+ "ssid": "test123",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType":WifiSecurityType.WIFI_SEC_TYPE_SAE,
+ "maxConn": 8
+ };
+ var isSuccess2 = wifi.setHotspotConfig(HotspotConfigSAE);
+ console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess2);
+ expect(isSuccess2).assertFalse();
+
+ var HotspotConfigC= {
+ "ssid": "test123",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType":12,
+ "maxConn": 8
+ };
+ var isSuccess3 = wifi.setHotspotConfig(HotspotConfigC);
+ console.log("[wifi_test] set a invalid preSharedKey hotspot config result1: " + isSuccess3);
+ expect(isSuccess3).assertFalse();
+ done();
+
+ })
+
+ /**
+ * @tc.number CONFIG_0010
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0010
+ * @tc.desc Test set a valid PSK preSharedKey hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0010', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+ }
+
+ var HotspotConfigPSK= {
+ "ssid": "test123",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType":WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ }
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigPSK);
+ expect(isSuccess1).assertTrue();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.securityType).assertEqual(3);
+ console.log("[wifi_test] check the state of Hotspot" );
+ var isHotspotActive = wifi.isHotspotActive();
+ console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
+ expect(isHotspotActive).assertFalse();
+ done();
+
+ })
+
+ /**
+ * @tc.number CONFIG_0011
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0011
+ * @tc.desc Test set a valid OPEN preSharedKey hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0011', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+ }
+
+ var HotspotConfigO= {
+ "ssid": "test123",
+ "band": 1,
+ "preSharedKey": "",
+ "securityType":WifiSecurityType.WIFI_SEC_TYPE_OPEN,
+ "maxConn": 8
+ }
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigO);
+ console.log("[wifi_test] set a open preSharedKey hotspot config result1: " + isSuccess1);
+ expect(isSuccess1).assertTrue();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.securityType).assertEqual(1);
+ done();
+
+ })
+
+ /**
+ * @tc.number CONN_0001
+ * @tc.name SUB_Communication_WiFi_Hotspot_Conn_0001
+ * @tc.desc Test set a maxConn and more maxConn hotspot config
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Conn_0001', 0, async function (done) {
+ await tryToDisableWifi();
+ if (wifi.isHotspotActive()) {
+ var off = wifi.disableHotspot();
+ await sleep(5000);
+ expect(off).assertTrue();
+
+ }
+ var HotspotConfigI= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "12345678",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI);
+ console.log("[wifi_test] set maxConn valid hotspot config result: " + isSuccess1);
+ expect(isSuccess1).assertTrue();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.maxConn).assertEqual(8);
+
+ var HotspotConfigI2= {
+ "ssid": "testWgr",
+ "band": 1,
+ "preSharedKey": "1234567",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 9
+ };
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigI2);
+ console.log("[wifi_test] set more maxConn invalid hotspot config result: " + isSuccess1);
+ expect(isSuccess1).assertFalse();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.maxConn).assertEqual(8);
+ done();
+ })
+
+ /**
+ * @tc.number CONFIG_0012
+ * @tc.name SUB_Communication_WiFi_Hotspot_Config_0012
+ * @tc.desc Test set a valid hotspot config after open Hotspot
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Config_0012', 0, async function (done) {
+ await tryToDisableWifi();
+ if (!wifi.isHotspotActive()) {
+ var on = wifi.enableHotspot();
+ await sleep(5000);
+ expect(on).assertTrue();
+ }
+ var isHotspotActive = wifi.isHotspotActive();
+ console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
+ expect(isHotspotActive).assertTrue();
+ var HotspotConfigWO= {
+ "ssid": "WIFITEST",
+ "band": 1,
+ "preSharedKey": "123456789",
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "maxConn": 8
+ }
+ var isSuccess1 = wifi.setHotspotConfig(HotspotConfigWO);
+ console.log("[wifi_test] set a psk preSharedKey hotspot config result1: " + isSuccess1);
+ expect(isSuccess1).assertTrue();
+ var config = wifi.getHotspotConfig();
+ console.info("[wifi_test] getHotspotConfig result -> " + JSON.stringify(config));
+ expect(config.ssid).assertEqual('WIFITEST');
+ done();
+
+ })
+
+
+ /**
+ * @tc.number CONN_0002
+ * @tc.name SUB_Communication_WiFi_Hotspot_Conn_0002
+ * @tc.desc Test Obtains the list of clients that are connected to a Wi-Fi hotspot.
+ * @tc.level Level 2
+ */
+ it('SUB_Communication_WiFi_Hotspot_Conn_0002', 0, async function (done) {
+ await tryToDisableWifi();
+ if (!wifi.isHotspotActive()) {
+ var on = wifi.enableHotspot();
+ await sleep(5000);
+ expect(on).assertTrue();
+ }
+ var isHotspotActive = wifi.isHotspotActive();
+ console.info("[wifi_test] isHotspotActive -> " + isHotspotActive);
+ expect(isHotspotActive).assertTrue();
+ var stationInfo = wifi.getStations();
+ console.info("[wifi_test] getStations result ->" + JSON.stringify(stationInfo));
+ console.info("ssid: " + stationInfo.name +
+ "macAddress: " + stationInfo.macAddress +
+ "ipAddress: " + stationInfo.ipAddress);
+ expect(stationInfo.length).assertEqual(0);
+ done();
+
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_ON_0001
+ * @tc.name testhotspotStateChangeOn
+ * @tc.desc Test hotspotStateChangeOn api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Hotspot_ON_0001', 0, async function (done) {
+ console.info("[wifi_test]hotspotStateChange On test");
+ try {
+ await wifi.on('hotspotStateChange', (data) => {
+ console.info("[wifi_test] hotspotStateChange On ->" + data);
+ expect(true).assertEqual(data != null);
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_Off_0002
+ * @tc.name testhotspotStateChangeOff
+ * @tc.desc Test hotspotStateChange api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_Off_0002', 0, async function (done) {
+ try {
+ await wifi.off('hotspotStateChange', (data) => {
+ console.info("[wifi_test] hotspotStateChange Off ->" + data);
+ expect(true).assertEqual(data != null);
+ console.info("[wifi_test] wifiRssiChange unregister end");
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_ON_0003
+ * @tc.name testhotspotStaJoinOn
+ * @tc.desc Test hotspotStaJoinOn api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Hotspot_ON_0003', 0, async function (done) {
+ console.info("[wifi_test]hotspotStaJoin On test");
+ try {
+ await wifi.on('hotspotStaJoin', (data) => {
+ console.info("[wifi_test] hotspotStaJoin On ->" + data);
+ expect(true).assertEqual(data != null);
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_Off_0004
+ * @tc.name testhotspotStaJoinOff
+ * @tc.desc Test hotspotStaJoin api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_Off_0004', 0, async function (done) {
+ try {
+ await wifi.off('hotspotStaJoin', (data) => {
+ console.info("[wifi_test] hotspotStaJoin Off ->" + data);
+ expect(true).assertEqual(data != null);
+ console.info("[wifi_test] wifiRssiChange unregister end");
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_ON_0005
+ * @tc.name testhotspotStaLeaveOn
+ * @tc.desc Test hotspotStaLeaveOn api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Hotspot_ON_0005', 0, async function (done) {
+ console.info("[wifi_test]hotspotStaLeave On test");
+ try {
+ await wifi.on('hotspotStaLeave', (data) => {
+ console.info("[wifi_test] hotspotStaLeave On ->" + data);
+ expect(true).assertEqual(data != null);
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Hotspot_Off_0006
+ * @tc.name testhotspotStaLeaveOff
+ * @tc.desc Test hotspotStaLeave api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Hotspot_Off_0006', 0, async function (done) {
+ try {
+ await wifi.off('hotspotStaLeave', (data) => {
+ console.info("[wifi_test] hotspotStaLeave Off ->" + data);
+ expect(true).assertEqual(data != null);
+ console.info("[wifi_test] hotspotStaLeave unregister end");
+ });
+
+ }catch(e) {
+ expect(null).assertFail();
+ }
+ done();
+ })
+
+ console.log("*************[wifi_test] start wifi js unit test end*************");
+})
+
+
diff --git a/communication/wifi_hotspot/src/main/resources/base/element/string.json b/communication/wifi_hotspot/src/main/resources/base/element/string.json
new file mode 100755
index 0000000000000000000000000000000000000000..14f9c3a9210f78b12caf3b945dc2b2c0f63f7d3d
--- /dev/null
+++ b/communication/wifi_hotspot/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "OsAccountTest"
+ },
+ {
+ "name": "mainability_description",
+ "value": "JS_Phone_Empty Feature Ability"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/communication/wifi_hotspot/src/main/resources/base/media/icon.png b/communication/wifi_hotspot/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/communication/wifi_hotspot/src/main/resources/base/media/icon.png differ
diff --git a/communication/wifi_p2p/BUILD.gn b/communication/wifi_p2p/BUILD.gn
new file mode 100755
index 0000000000000000000000000000000000000000..76ec0a7400196640447387c30d9568807fbd0ddb
--- /dev/null
+++ b/communication/wifi_p2p/BUILD.gn
@@ -0,0 +1,31 @@
+# Copyright (C) 2022 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.
+
+import("//test/xts/tools/build/suite.gni")
+
+ohos_js_hap_suite("ActsP2PJSTest") {
+ hap_profile = "./src/main/config.json"
+ deps = [
+ ":wifi_js_assets",
+ ":wifi_resources",
+ ]
+ certificate_profile = "./signature/openharmony_sx.p7b"
+ hap_name = "ActsP2PJSApiTest"
+}
+ohos_js_assets("wifi_js_assets") {
+ source_dir = "./src/main/js/default"
+}
+ohos_resources("wifi_resources") {
+ sources = [ "./src/main/resources" ]
+ hap_profile = "./src/main/config.json"
+}
diff --git a/communication/wifi_p2p/Test.json b/communication/wifi_p2p/Test.json
new file mode 100755
index 0000000000000000000000000000000000000000..458986061c34b55cab97e728672c39ab3b974868
--- /dev/null
+++ b/communication/wifi_p2p/Test.json
@@ -0,0 +1,18 @@
+{
+ "description": "Configuration for wifi js api Tests",
+ "driver": {
+ "type": "JSUnitTest",
+ "test-timeout": "600000",
+ "package": "ohos.acts.communication.wifi.wifidevice",
+ "shell-timeout": "600000"
+ },
+ "kits": [
+ {
+ "test-file-name": [
+ "ActsP2PJSApiTest.hap"
+ ],
+ "type": "AppInstallKit",
+ "cleanup-apps": true
+ }
+ ]
+}
diff --git a/communication/wifi_p2p/signature/openharmony_sx.p7b b/communication/wifi_p2p/signature/openharmony_sx.p7b
new file mode 100755
index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858
Binary files /dev/null and b/communication/wifi_p2p/signature/openharmony_sx.p7b differ
diff --git a/communication/wifi_p2p/src/main/config.json b/communication/wifi_p2p/src/main/config.json
new file mode 100755
index 0000000000000000000000000000000000000000..01796c829e3e2036ccc09f6c3003d71c70822871
--- /dev/null
+++ b/communication/wifi_p2p/src/main/config.json
@@ -0,0 +1,99 @@
+{
+ "app": {
+ "bundleName": "ohos.acts.communication.wifi.wifidevice",
+ "vendor": "acts",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ },
+ "apiVersion": {
+ "compatible": 4,
+ "target": 5
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "ohos.acts.communication.wifi.wifidevice",
+ "name": ".MyApplication",
+ "mainAbility": "ohos.acts.communication.wifi.wifidevice.MainAbility",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "wifi_standard",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "visible": true,
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "name": "ohos.acts.communication.wifi.wifidevice.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:app_name",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
+ }
+ ],
+ "reqPermissions": [
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO",
+ "reason" : "use ohos.permission.GET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_INFO",
+ "reason" : "use ohos.permission.SET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_CONNECTION",
+ "reason" : "use ohos.permission.MANAGE_WIFI_CONNECTION"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.SET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.GET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
+ "reason" : "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_LOCAL_MAC",
+ "reason" : "use ohos.permission.GET_WIFI_LOCAL_MAC"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_HOTSPOT",
+ "reason" : "use ohos.permission.MANAGE_WIFI_HOTSPOT"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO_INTERNAL",
+ "reason" : "use ohos.permission.GET_WIFI_INFO_INTERNAL"
+ }
+ ]
+ }
+}
diff --git a/communication/wifi_p2p/src/main/js/default/app.js b/communication/wifi_p2p/src/main/js/default/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..8fe0b77dcef1db4bb1706399fd481541de8166cd
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/app.js
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 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 {
+ onCreate() {
+ console.info('AceApplication onCreate');
+ },
+ onDestroy() {
+ console.info('AceApplication onDestroy');
+ }
+};
diff --git a/communication/wifi_p2p/src/main/js/default/i18n/en-US.json b/communication/wifi_p2p/src/main/js/default/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/i18n/en-US.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "Hello",
+ "world": "World"
+ }
+}
\ No newline at end of file
diff --git a/communication/wifi_p2p/src/main/js/default/i18n/zh-CN.json b/communication/wifi_p2p/src/main/js/default/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/i18n/zh-CN.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "您好",
+ "world": "世界"
+ }
+}
\ No newline at end of file
diff --git a/communication/wifi_p2p/src/main/js/default/pages/index/index.css b/communication/wifi_p2p/src/main/js/default/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..3a8326a076cdb9ecabf543df9dba84240f5b52a4
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/pages/index/index.css
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.title {
+ font-size: 100px;
+}
diff --git a/communication/wifi_p2p/src/main/js/default/pages/index/index.hml b/communication/wifi_p2p/src/main/js/default/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..0053057b5ff7362e00db48887ee1663cffa35988
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/pages/index/index.hml
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+
+
+ {{ $t('strings.hello') }} {{ title }}
+
+
diff --git a/communication/wifi_p2p/src/main/js/default/pages/index/index.js b/communication/wifi_p2p/src/main/js/default/pages/index/index.js
new file mode 100755
index 0000000000000000000000000000000000000000..a756c422e6c842edbb3d5a877a8ad90cd3fd29b1
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/pages/index/index.js
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
+
+import {Core, ExpectExtend} from 'deccjsunit/index'
+
+export default {
+ data: {
+ title: '',
+ myTimeout: 15000
+ },
+ onInit() {
+ this.title = this.$t('strings.world');
+ },
+ onShow() {
+ console.info('onShow finish')
+ },
+ onReady() {
+ console.info('onReady finish')
+ const core = Core.getInstance()
+ const expectExtend = new ExpectExtend({
+ 'id': 'extend'
+ })
+ core.addService('expect', expectExtend)
+ core.init()
+
+ const configService = core.getDefaultService('config')
+
+ this.timeout = this.myTimeout
+ configService.setConfig(this)
+
+ require('../../test/List.test')
+ core.execute()
+
+ },
+}
+
diff --git a/communication/wifi_p2p/src/main/js/default/test/List.test.js b/communication/wifi_p2p/src/main/js/default/test/List.test.js
new file mode 100755
index 0000000000000000000000000000000000000000..4be23311c4230cf78a7b7149d5fd597780d4c23a
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/test/List.test.js
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+//require('./WifiSta.test.js')
+//require('./WifiSoftAP.test.js')
+require('./WifiP2P.test.js')
+
+
diff --git a/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js b/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..c216faa0dec4f3cee043fd6644014c3402dc6fbd
--- /dev/null
+++ b/communication/wifi_p2p/src/main/js/default/test/WifiP2P.test.js
@@ -0,0 +1,565 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+import wifi from '@ohos.wifi'
+
+function sleep(delay) {
+ return new Promise(resovle => setTimeout(resovle, delay))
+}
+
+async function tryToEnableWifi(){
+ if(!wifi.isWifiActive()){
+ console.info("wifi_test/enable wifi:" + wifi.enableWifi());
+ await sleep(3000);
+ }
+ console.info("wifi_test/wifi status:" + wifi.isWifiActive());
+}
+
+var GroupOwnerBand = {
+ GO_BAND_AUTO : 0,
+ GO_BAND_2GHZ : 1,
+ GO_BAND_5GHZ : 2,
+}
+
+describe('ACTS_WifiTest', function () {
+ beforeEach(function () {
+ })
+
+ afterEach(function () {
+ })
+
+ /**
+ * @tc.number Setting_0001
+ * @tc.name SUB_Communication_WiFi_P2P_Setting_0001
+ * @tc.desc Test setDeviceName infos
+ */
+ it('SUB_Communication_WiFi_P2P_Setting_0001', 0, async function(done) {
+ await tryToEnableWifi();
+ console.info("[wifi_test] test setDeviceName start.");
+ var devName = wifi.setDeviceName("P2PTest");
+ console.info("[wifi_test] test start setDeviceName->" + devName);
+ expect(devName).assertTrue();
+ done();
+ })
+
+ /**
+ * @tc.number config_0001
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0001
+ * @tc.desc Test createGroup and getCurrentGroup promise infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0001', 0, async function(done) {
+ await tryToEnableWifi();
+ var WifiP2PConfig = {
+ deviceAddress : "00:00:00:00:00:00",
+ netId : -1,
+ passphrase : "12345678",
+ groupName : "AAAZZZ",
+ goBand : 0
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var addConfig = wifi.createGroup(WifiP2PConfig);
+ await sleep(2000);
+ expect(addConfig).assertTrue();
+ await wifi.getCurrentGroup()
+ .then((data) => {
+ var resultLength = Object.keys(data).length;
+ console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data));
+ expect(true).assertEqual(resultLength!=0);
+ }).catch((error) => {
+ console.info("[wifi_js]getCurrentGroup promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ done();
+
+ })
+
+ /**
+ * @tc.number config_0002
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0002
+ * @tc.desc Test getCurrentGroup callback infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0002', 0, async function(done) {
+ await tryToEnableWifi();
+ var WifiP2PConfig = {
+ deviceAddress : "00:00:00:00:00:00",
+ netId : -1,
+ passphrase : "12345678",
+ groupName : "AAAZZZ",
+ goBand : 0
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var addConfig = wifi.createGroup(WifiP2PConfig);
+ await sleep(2000);
+ expect(addConfig).assertTrue();
+
+ await wifi.getCurrentGroup(
+ (err, result) => {
+ if (err) {
+ console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err));
+ return;
+ }
+ console.info("[wifi_test] getCurrentGroup [callback] -> " + JSON.stringify(result));
+ console.info("isP2pGo: " + result.isP2pGo +
+ "deviceName: " + result.ownerInfo.deviceName +
+ "deviceAddress: " + result.ownerInfo.deviceAddress +
+ "primaryDeviceType: " + result.ownerInfo.primaryDeviceType +
+ "deviceStatus: " + result.ownerInfo.deviceStatus +
+ "groupCapabilitys: " + result.ownerInfo.groupCapabilitys +
+ "passphrase: " + result.passphrase + "interface: "+ result.interface
+ + "groupName: " + result.groupName +
+ "clientDevices: " + result.clientDevices +"networkId: " + result.networkId
+ + "frequency: " + result.frequency + "goIpAddress: " + result.goIpAddress);
+ var removeConfig = wifi.removeGroup();
+ expect(removeConfig).assertTrue();
+ done();
+ });
+ })
+
+ /**
+ * @tc.number config_0003
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0003
+ * @tc.desc Test createGroup 2.4G band and getCurrentGroup infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0003', 0, async function(done) {
+ await tryToEnableWifi();
+ var WifiP2PConfig2 = {
+ deviceAddress : "00:00:00:00:00:00",
+ netId : -1,
+ passphrase : "12345678",
+ groupName : "AAAZZZ",
+ goBand : 1
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var addConfig = wifi.createGroup(WifiP2PConfig2);
+ await sleep(2000);
+ expect(addConfig).assertTrue();
+ await wifi.getCurrentGroup()
+ .then((data) => {
+ var resultLength = Object.keys(data).length;
+ console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data));
+ expect(true).assertEqual(resultLength!=0);
+ }).catch((error) => {
+ console.info("[wifi_test]getCurrentGroup promise then error." + JSON.stringify(error));
+ expect(error).assertFail();
+ });
+ var removeConfig = wifi.removeGroup();
+ expect(removeConfig).assertTrue();
+ done();
+ })
+
+ /**
+ * @tc.number config_0004
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0004
+ * @tc.desc Test createGroup and deletePersistentGroup infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0004', 0, async function(done) {
+ await tryToEnableWifi();
+ var WifiP2PConfig = {
+ deviceAddress : "00:00:00:00:00:00",
+ netId : -2,
+ passphrase : "12345678",
+ groupName : "AAAZZZ",
+ goBand : 0
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var addConfig = wifi.createGroup(WifiP2PConfig);
+ await sleep(2000);
+ expect(addConfig).assertTrue();
+ await wifi.getCurrentGroup()
+ .then((data) => {
+ var resultLength = Object.keys(data).length;
+ console.info("[wifi_test] getCurrentGroup [promise] result -> " + JSON.stringify(data));
+ expect(true).assertEqual(resultLength!=0);
+
+ var removePConfig = wifi.deletePersistentGroup(data.networkId);
+ expect(removePConfig).assertTrue();
+
+ var removeConfig = wifi.removeGroup();
+ expect(removeConfig).assertTrue();
+ });
+ done();
+ })
+
+ /**
+ * @tc.number config_0005
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0005
+ * @tc.desc Test p2pConnect infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0005', 0, async function(done) {
+ await tryToEnableWifi();
+ var WifiP2PConfig3 = {
+ deviceAddress : "00:00:00:00:00:00",
+ netId : -2,
+ passphrase : "12345678",
+ groupName : "AAAZZZ",
+ goBand : 0
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var scanConfig = wifi.startDiscoverDevices();
+ await sleep(2000);
+ expect(scanConfig).assertTrue();
+
+ var connConfig = wifi.p2pConnect(WifiP2PConfig3);
+ console.info("[wifi_test] test p2pConnect result." + connConfig);
+ expect(connConfig).assertTrue();
+ var stopScan = wifi.stopDiscoverDevices();
+ console.info("[wifi_test] test stopDiscoverDevices result." + stopScan);
+ done()
+ })
+
+ /**
+ * @tc.number config_0006
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0006
+ * @tc.desc Test getP2pLinkedInfo promise infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0006', 0, async function(done) {
+ await tryToEnableWifi();
+ var P2pConnectState = {
+ DISCONNECTED :0,
+ CONNECTED : 1,
+ };
+ await wifi.getP2pLinkedInfo()
+ .then((data) => {
+ var resultLength = Object.keys(data).length;
+ console.info("[wifi_test] getP2pLinkedInfo [promise] result -> " + JSON.stringify(data));
+ expect(true).assertEqual(resultLength!=0);
+ }).catch((error) => {
+ console.info("[wifi_test]getP2pLinkedInfo promise then error." + JSON.stringify(error));
+ expect(error).assertFail();
+ });
+
+ done();
+ })
+
+/**
+ * @tc.number config_0007
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0007
+ * @tc.desc Test getP2pLinkedInfo callback infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0007', 0, async function(done) {
+ await tryToEnableWifi();
+ var P2pConnectState = {
+ DISCONNECTED :0,
+ CONNECTED : 1,
+ };
+
+ await wifi.getP2pLinkedInfo((err, result) => {
+ if (err) {
+ console.error('failed to getP2pLinkedInfo callback ' + JSON.stringify(err));
+ return;
+ }
+ console.info("[wifi_test] getP2pLinkedInfo [callback] -> " + JSON.stringify(result));
+ console.info("connectState: " + result.connectState +
+ "isGroupOwner: " + result.isGroupOwner +
+ "groupOwnerAddr: " + result.groupOwnerAddr);
+ expect(false).assertEqual(result.connectState ==P2pConnectState.CONNECTED);
+ });
+ done();
+ })
+
+ /**
+ * @tc.number config_0008
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0008
+ * @tc.desc Test p2pCancelConnect infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0008', 0, async function(done) {
+ await tryToEnableWifi();
+ var disConn = wifi.p2pCancelConnect();
+ await sleep(2000);
+ console.info("[wifi_test] test p2pCancelConnect result." + disConn);
+ expect(disConn).assertTrue();
+ var removeConfig = wifi.removeGroup();
+ console.info("[wifi_test] test start removeGroup" + removeConfig);
+ expect(removeConfig).assertTrue();
+ done();
+ })
+
+ /**
+ * @tc.number config_0009
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0009
+ * @tc.desc Test getP2pPeerDevices infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0009', 0, async function(done){
+ await tryToEnableWifi();
+ var P2pDeviceStatus = {
+ CONNECTED : 0,
+ INVITED : 1,
+ FAILED : 2,
+ AVAILABLE : 3,
+ UNAVAILABLE : 4,
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var scanConfig = wifi.startDiscoverDevices();
+ await sleep(2000);
+ expect(scanConfig).assertTrue();
+ await wifi.getP2pPeerDevices()
+ .then((data) => {
+ var resultLength = Object.keys(data).length;
+ console.info("[wifi_test] getP2pPeerDevices [promise] result -> " + JSON.stringify(data));
+ expect(true).assertEqual(resultLength >= 0);
+ }).catch((error) => {
+ console.info("[wifi_test]getP2pPeerDevices promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ done();
+
+ })
+
+ /**
+ * @tc.number config_0010
+ * @tc.name SUB_Communication_WiFi_P2P_Config_0010
+ * @tc.desc Test getP2pPeerDevices infos
+ */
+ it('SUB_Communication_WiFi_P2P_Config_0010', 0, async function(done){
+ await tryToEnableWifi();
+ var P2pDeviceStatus = {
+ CONNECTED : 0,
+ INVITED : 1,
+ FAILED : 2,
+ AVAILABLE : 3,
+ UNAVAILABLE : 4,
+ };
+
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ expect(wifi.isWifiActive()).assertTrue();
+ var scanConfig = wifi.startDiscoverDevices();
+ await sleep(2000);
+ expect(scanConfig).assertTrue();
+
+ await wifi.getP2pPeerDevices((err, result) => {
+ if (err) {
+ console.error('failed to getP2pPeerDevices infos callback because ' + JSON.stringify(err));
+ return;
+ }
+ console.info("[wifi_test] getP2pPeerDevices [callback] -> " + JSON.stringify(result));
+ var len = Object.keys(result).length;
+ for (var j = 0; j < len; ++j) {
+ console.info("deviceName: " + result[j].deviceName +
+ "deviceAddress: " + result[j].deviceAddress +
+ "primaryDeviceType: " + result[j].primaryDeviceType +
+ "deviceStatus: " + result[j].deviceStatus +
+ "groupCapabilitys: " + result[j].groupCapabilitys );
+ if(result[j].deviceStatus ==P2pDeviceStatus.UNAVAILABLE){
+ console.info("deviceStatus: " + result[j].deviceStatus);
+ }
+ if(result[j].deviceStatus ==P2pDeviceStatus.CONNECTED){
+ console.info("deviceStatus: " + result[j].deviceStatus);
+ }
+ if(result[j].deviceStatus ==P2pDeviceStatus.INVITED){
+ console.info("deviceStatus: " + result[j].deviceStatus);
+ }
+ if(result[j].deviceStatus ==P2pDeviceStatus.FAILED){
+ console.info("deviceStatus: " + result[j].deviceStatus);
+ }
+ if(result[j].deviceStatus ==P2pDeviceStatus.AVAILABLE){
+ console.info("deviceStatus: " + result[j].deviceStatus);
+ }
+ }
+ var stopScan = wifi.stopDiscoverDevices();
+ expect(stopScan).assertTrue();
+ done();
+ });
+ })
+
+ /**
+ * @tc.number p2pStateChange_0001
+ * @tc.name SUB_Communication_WiFi_P2P_P2pStateChange_0001
+ * @tc.desc Test p2pStateChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_P2pStateChange_0001', 0, async function (done) {
+ await tryToEnableWifi();
+ await wifi.on('p2pStateChange', result => {
+ console.info("onP2pStateChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ done();
+ });
+ setTimeout(function() {
+
+ wifi.off('p2pStateChange', result => {
+ console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ /**
+ * @tc.number p2pConnectionChange_0002
+ * @tc.name SUB_Communication_WiFi_P2P_p2pConnectionChange_0002
+ * @tc.desc Test p2pConnectionChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_p2pConnectionChange_0002', 0, async function (done) {
+ await tryToEnableWifi();
+ await wifi.on('p2pConnectionChange', recvP2pConnectionChangeFunc => {
+ console.info("[wifi_test] p2pConnectionChange result -> " + recvP2pConnectionChangeFunc);
+ expect(true).assertEqual(recvP2pConnectionChangeFunc !=null);
+ done();
+ });
+ setTimeout(function() {
+ console.info('[wifi_test] offP2pStateChange test start ...');
+ wifi.off('p2pConnectionChange', recvP2pConnectionChangeFunc => {
+ console.info("p2pConnectionChange callback" + JSON.stringify(recvP2pConnectionChangeFunc));
+ expect(true).assertEqual(recvP2pConnectionChangeFunc !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ /**
+ * @tc.number p2pDeviceChange_0003
+ * @tc.name SUB_Communication_WiFi_P2P_p2pDeviceChange_0003
+ * @tc.desc Test p2pDeviceChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_p2pDeviceChange_0003', 0, async function (done) {
+ console.info('[wifi_test] Onp2pDeviceChange test start ...');
+ await wifi.on('p2pDeviceChange', result => {
+ console.info("onP2pDeviceChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ done();
+ });
+ setTimeout(function() {
+ console.info('[wifi_test] offP2pDeviceChange test start ...');
+ wifi.off('p2pDeviceChange', result => {
+ console.info("offP2pStateChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ /**
+ * @tc.number p2pPeerDeviceChange_0004
+ * @tc.name SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004
+ * @tc.desc Test p2pPeerDeviceChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_p2pPeerDeviceChange_0004', 0, async function (done) {
+ await tryToEnableWifi();
+ var recvP2pPeerDeviceChangeFunc = result => {
+ console.info("wifi_test / p2p peer device change receive event: " + JSON.stringify(result));
+ wifi.getP2pDevices((err, data) => {
+ if (err) {
+ console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err));
+ return;
+ }
+ console.info("wifi_test / getP2pDevices [callback] -> " + JSON.stringify(data));
+ var len = Object.keys(data).length;
+ console.log("getP2pDevices number: " + len);
+ for (var i = 0; i < len; ++i) {
+ if (data[i].deviceName === "GRE") {
+ console.info("wifi_test / p2pConnect: -> " + data[i].deviceAddress);
+ var config = {
+ "deviceAddress":data[i].deviceAddress,
+ "netId":-1,
+ "passphrase":"",
+ "groupName":"",
+ "goBand":0,
+ }
+ wifi.p2pConnect(config);
+ }
+ }
+ });
+ }
+ await wifi.on('p2pPeerDeviceChange', result => {
+ console.info("onP2pPeerDeviceChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ done();
+ });
+ setTimeout(function() {
+ wifi.off('p2pPeerDeviceChange', result => {
+ console.info("offP2pPeerDeviceChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ /**
+ * @tc.number p2pPersistentGroupChange_0005
+ * @tc.name SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005
+ * @tc.desc Test p2pPersistentGroupChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_p2pPersistentGroupChange_0005', 0, async function (done) {
+ await tryToEnableWifi();
+ var recvP2pPersistentGroupChangeFunc = result => {
+ console.info("wifi_test / p2p persistent group change receive event" + JSON.stringify(result));
+ var config = {
+ "deviceAddress" : "02:11:65:f2:0d:6e",
+ "netId":-2,
+ "passphrase":"",
+ "groupName":"",
+ "goBand":0,
+ };
+ var addConfig = wifi.createGroup(config);
+ expect(addConfig).assertTrue();
+ wifi.getCurrentGroup((err, data) => {
+ if (err) {
+ console.error('wifi_test / failed to get getCurrentGroup: ' + JSON.stringify(err));
+ return;
+ }
+ console.info("wifi_test / get getCurrentGroup [callback] -> " + JSON.stringify(data));
+ });
+ };
+ await wifi.on('p2pPersistentGroupChange', result => {
+ console.info("p2pPersistentGroupChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ done();
+ });
+ setTimeout(function() {
+ wifi.off('p2pPersistentGroupChange', result => {
+ console.info("offP2pPersistentGroupChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ /**
+ * @tc.number p2pDiscoveryChange_0006
+ * @tc.name SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006
+ * @tc.desc Test p2pDiscoveryChange callback
+ */
+ it('SUB_Communication_WiFi_P2P_p2pDiscoveryChange_0006', 0, async function (done) {
+ await tryToEnableWifi();
+ await wifi.on('p2pDiscoveryChange', result => {
+ console.info("onp2pDiscoveryChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ done();
+ });
+ setTimeout(function() {
+ wifi.off('p2pDiscoveryChange', result => {
+ console.info("offp2pDiscoveryChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ });
+ }, 1 * 1000);
+ done();
+ })
+
+ console.log("*************[wifi_test] start wifi js unit test end*************");
+})
+
diff --git a/communication/wifi_p2p/src/main/resources/base/element/string.json b/communication/wifi_p2p/src/main/resources/base/element/string.json
new file mode 100755
index 0000000000000000000000000000000000000000..14f9c3a9210f78b12caf3b945dc2b2c0f63f7d3d
--- /dev/null
+++ b/communication/wifi_p2p/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "OsAccountTest"
+ },
+ {
+ "name": "mainability_description",
+ "value": "JS_Phone_Empty Feature Ability"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/communication/wifi_p2p/src/main/resources/base/media/icon.png b/communication/wifi_p2p/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/communication/wifi_p2p/src/main/resources/base/media/icon.png differ
diff --git a/communication/wifi_standard/BUILD.gn b/communication/wifi_standard/BUILD.gn
index ec29255d480cd0b2e958bba53dfd86fe8538d5b9..6cde1a2f39cd108c70ab908e0a374eb3af1b781b 100755
--- a/communication/wifi_standard/BUILD.gn
+++ b/communication/wifi_standard/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Copyright (C) 2022 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
@@ -13,7 +13,7 @@
import("//test/xts/tools/build/suite.gni")
-ohos_js_hap_suite("wifi_standard_test") {
+ohos_js_hap_suite("ActsWifiJSTest") {
hap_profile = "./src/main/config.json"
deps = [
":wifi_js_assets",
diff --git a/communication/wifi_standard/signature/openharmony_sx.p7b b/communication/wifi_standard/signature/openharmony_sx.p7b
index 9be1e98fa4c0c28ca997ed660112fa16b194f0f5..66b4457a8a81fb8d3356cf46d67226c850944858 100755
Binary files a/communication/wifi_standard/signature/openharmony_sx.p7b and b/communication/wifi_standard/signature/openharmony_sx.p7b differ
diff --git a/communication/wifi_standard/src/main/config.json b/communication/wifi_standard/src/main/config.json
index da83908d60d69a76dd08d78b600677474fe93388..01796c829e3e2036ccc09f6c3003d71c70822871 100755
--- a/communication/wifi_standard/src/main/config.json
+++ b/communication/wifi_standard/src/main/config.json
@@ -15,12 +15,13 @@
"module": {
"package": "ohos.acts.communication.wifi.wifidevice",
"name": ".MyApplication",
+ "mainAbility": "ohos.acts.communication.wifi.wifidevice.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
- "moduleName": "entry",
+ "moduleName": "wifi_standard",
"moduleType": "entry"
},
"abilities": [
@@ -55,6 +56,44 @@
"autoDesignWidth": false
}
}
+ ],
+ "reqPermissions": [
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO",
+ "reason" : "use ohos.permission.GET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_INFO",
+ "reason" : "use ohos.permission.SET_WIFI_INFO"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_CONNECTION",
+ "reason" : "use ohos.permission.MANAGE_WIFI_CONNECTION"
+ },
+ {
+ "name" : "ohos.permission.SET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.SET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_CONFIG",
+ "reason" : "use ohos.permission.GET_WIFI_CONFIG"
+ },
+ {
+ "name" : "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
+ "reason" : "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_LOCAL_MAC",
+ "reason" : "use ohos.permission.GET_WIFI_LOCAL_MAC"
+ },
+ {
+ "name" : "ohos.permission.MANAGE_WIFI_HOTSPOT",
+ "reason" : "use ohos.permission.MANAGE_WIFI_HOTSPOT"
+ },
+ {
+ "name" : "ohos.permission.GET_WIFI_INFO_INTERNAL",
+ "reason" : "use ohos.permission.GET_WIFI_INFO_INTERNAL"
+ }
]
}
}
diff --git a/communication/wifi_standard/src/main/js/default/app.js b/communication/wifi_standard/src/main/js/default/app.js
old mode 100755
new mode 100644
index 363f2555b1badec9fec342a93141db084083fcb8..8fe0b77dcef1db4bb1706399fd481541de8166cd
--- a/communication/wifi_standard/src/main/js/default/app.js
+++ b/communication/wifi_standard/src/main/js/default/app.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Copyright (C) 2022 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
diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.css b/communication/wifi_standard/src/main/js/default/pages/index/index.css
index 6fda792753f2e15f22b529c7b90a82185b2770bf..72baaffcaa675bfe9f3d3d1974690ae7d05c1a4b 100644
--- a/communication/wifi_standard/src/main/js/default/pages/index/index.css
+++ b/communication/wifi_standard/src/main/js/default/pages/index/index.css
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
.container {
flex-direction: column;
justify-content: center;
diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.hml b/communication/wifi_standard/src/main/js/default/pages/index/index.hml
index f64b040a5ae394dbaa5e185e1ecd4f4556b92184..0053057b5ff7362e00db48887ee1663cffa35988 100644
--- a/communication/wifi_standard/src/main/js/default/pages/index/index.hml
+++ b/communication/wifi_standard/src/main/js/default/pages/index/index.hml
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+
{{ $t('strings.hello') }} {{ title }}
diff --git a/communication/wifi_standard/src/main/js/default/pages/index/index.js b/communication/wifi_standard/src/main/js/default/pages/index/index.js
index 96b91894f4a078fc01062de48f02882b5f68f0f2..6e05db1fe0023ba6cd04a32307429c903b5b4d11 100755
--- a/communication/wifi_standard/src/main/js/default/pages/index/index.js
+++ b/communication/wifi_standard/src/main/js/default/pages/index/index.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Copyright (C) 2022 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
@@ -13,36 +13,35 @@
* limitations under the License.
*/
-import app from '@system.app'
-
import {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
- title: ""
+ title: '',
+ myTimeout: 15000
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
+ },
+ onReady() {
+ console.info('onReady finish')
const core = Core.getInstance()
-
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
- // core.addService('report', instrumentLog)
core.init()
-
const configService = core.getDefaultService('config')
-
- this.timeout = 600000
+ this.timeout = this.myTimeout
configService.setConfig(this)
+
require('../../test/List.test')
core.execute()
- },
- onReady() {
+
},
}
+
diff --git a/communication/wifi_standard/src/main/js/default/test/List.test.js b/communication/wifi_standard/src/main/js/default/test/List.test.js
index 7613fbe929826dd0fd4ca25c1d0a6f6aa2923ca8..00a5ef997024685e21e4399f5a6014eeb237be02 100755
--- a/communication/wifi_standard/src/main/js/default/test/List.test.js
+++ b/communication/wifi_standard/src/main/js/default/test/List.test.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Copyright (C) 2022 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
@@ -12,5 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
require('./WifiSta.test.js')
+//require('./WifiSoftAP.test.js')
+//require('./WifiP2P.test.js')
+
+
diff --git a/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js b/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js
index 2d757b3704a670404660be1c4f990bf3c2b8f279..5f6b2cac99d4c1aac03a18bbaccd9c18e12db2b5 100755
--- a/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js
+++ b/communication/wifi_standard/src/main/js/default/test/WifiSta.test.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Copyright (C) 2022 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
@@ -17,12 +17,16 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import wifi from '@ohos.wifi'
-// delay x ms
function sleep(delay) {
- var start = (new Date()).getTime();
- while ((new Date()).getTime() - start < delay) {
- console.log("sleep ms:"+ delay);
+ return new Promise(resovle => setTimeout(resovle, delay))
+}
+
+async function tryToEnableWifi(){
+ if(!wifi.isWifiActive()){
+ console.info("wifi_test/enable wifi:" + wifi.enableWifi());
+ await sleep(3000);
}
+ console.info("wifi_test/wifi status:" + wifi.isWifiActive());
}
var WifiSecurityType = {
@@ -33,12 +37,30 @@ var WifiSecurityType = {
WIFI_SEC_TYPE_SAE: 4,
}
-var wifiDeviceConfig = {
- "ssid": "TEST",
- "bssid": "A1:B1:C1:D1:E1:F1",
- "preSharedKey": "12345678",
- "isHiddenSsid": false,
- "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+var SuppState = {
+ DISCONNECTED: 0,
+ INTERFACE_DISABLED: 1,
+ INACTIVE : 2,
+ SCANNING: 3,
+ AUTHENTICATING: 4,
+ ASSOCIATING: 5,
+ ASSOCIATED: 6,
+ FOUR_WAY_HANDSHAKE: 7,
+ GROUP_HANDSHAKE: 8,
+ COMPLETED: 9,
+ UNINITIALIZED: 10,
+ INVALID: 11,
+}
+
+var ConnState = {
+ SCANNING: 0,
+ CONNECTING: 1,
+ AUTHENTICATING: 2,
+ OBTAINING_IPADDR: 3,
+ CONNECTED: 4,
+ DISCONNECTING: 5,
+ DISCONNECTED: 6,
+ UNKNOWN: 7,
}
var ipConfig = {
@@ -48,6 +70,12 @@ var ipConfig = {
"domains": ["aaa"],
}
+var IpType = {
+ STATIC : 0,
+ DHCP : 1,
+ UNKNOWN: 2
+}
+
describe('ACTS_WifiTest', function() {
beforeEach(function() {})
@@ -58,23 +86,23 @@ describe('ACTS_WifiTest', function() {
* @tc.name SUB_Communication_WiFi_Sta_Open_0001
* @tc.desc Test wifi.isWifiEnable API functionality.
*/
- it('SUB_Communication_WiFi_Sta_Open_0001', 0, function() {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Open_0001]");
+ it('SUB_Communication_WiFi_Sta_Open_0001', 0, async function(done) {
console.info("[wifi_test] check the state of wifi, if it's close, open it.");
var active = wifi.isWifiActive();
if (!active) {
var enable = wifi.enableWifi();
- sleep(3000);
+ await sleep(5000);
console.log("[wifi_test] wifi open result: " + enable);
expect(enable).assertTrue();
}
- console.info("[wifi_test] close wifi test start.");
var disable = wifi.disableWifi();
- sleep(3000);
+ await sleep(5000);
console.log("[wifi_test] wifi close result: " + disable);
expect(disable).assertTrue();
+
console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
expect(wifi.isWifiActive()).assertFalse();
+ done();
})
/**
@@ -83,34 +111,26 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test get ScanInfos callback API functionality.
*/
it('SUB_Communication_WiFi_Sta_Scan_0001', 0, async function(done) {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Scan_0001]");
- if (!wifi.isWifiActive()) {
- var enable = wifi.enableWifi();
- sleep(3000);
- console.log("[wifi_test] wifi open result: " + enable);
- expect(enable).assertTrue();
- }
-
+ await tryToEnableWifi();
var scan = wifi.scan();
- sleep(3000);
+ await sleep(3000);
console.log("[wifi_test] open wifi scan result: " + scan);
expect(scan).assertTrue();
- console.info("[wifi_test] Wifi getScanInfos promise test[1].");
await wifi.getScanInfos()
.then(result => {
var clen = Object.keys(result).length;
- console.log("[wifi_test] wifi getScanInfos promise result length: " + clen);
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos promise result " + JSON.stringify(result));
});
- console.info("[wifi_test] Wifi getScanInfos callback test[2].");
wifi.getScanInfos(
- (result) => {
+ (err,result) => {
+ if(err) {
+ console.log("[wifi_test] wifi getScanInfos failed " + err);
+ }
var clen = Object.keys(result).length;
- console.log("[wifi_test] wifi getScanInfos callback result length: " + clen);
- if (!(clen == 0 && i < 3)) {
+ if (!(clen == 0)) {
expect(clen).assertLarger(0);
console.info("[wifi_test] getScanInfos callback result: " + JSON.stringify(result));
for (var j = 0; j < clen; ++j) {
@@ -127,7 +147,6 @@ describe('ACTS_WifiTest', function() {
}
done()
});
-
})
/**
@@ -135,8 +154,8 @@ describe('ACTS_WifiTest', function() {
* @tc.name SUB_Communication_WiFi_Sta_Scan_0004
* @tc.desc Test wifi.getSignalLevel API functionality.
*/
- it('SUB_Communication_WiFi_Sta_Scan_0004', 0, function() {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Scan_0004]");
+ it('SUB_Communication_WiFi_Sta_Scan_0004', 0, async function(done) {
+ await tryToEnableWifi();
console.info("[wifi_test] check the 2.4G rssi assgined to level test.");
expect(wifi.getSignalLevel(-65, 1)).assertEqual(4);
@@ -166,6 +185,7 @@ describe('ACTS_WifiTest', function() {
expect(wifi.getSignalLevel(-86, 2)).assertEqual(0);
expect(wifi.getSignalLevel(-127, 2)).assertEqual(0);
+ done();
})
/**
@@ -174,21 +194,28 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test create a OPEN SecurityType wifi device config
*/
it('SUB_Communication_WiFi_Sta_Config_0001', 0, async function(done) {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0001]");
- console.info("[wifi_test] create a OPEN SecurityType wifi device config start.");
+ await tryToEnableWifi();
+ wifi.removeAllNetwork();
var wifiDeviceConfig1 = {
"ssid": "TEST_OPEN",
"bssid": "",
"preSharedKey": "",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_OPEN,
+ "netId": -1,
+ "ipType": IpType.DHCP,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": ipConfig,
};
await wifi.addDeviceConfig(wifiDeviceConfig1)
.then(netWorkId => {
console.info("[wifi_test]add OPEN Deviceconfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType);
@@ -197,22 +224,23 @@ describe('ACTS_WifiTest', function() {
});
wifi.addDeviceConfig(wifiDeviceConfig1,
- (netWorkId) => {
+ (err, netWorkId) => {
+ if(err) {
+ console.info("[wifi_test]add OPEN callback failed : " + JSON.stringify(err));
+ return;
+ }
console.info("[wifi_test]add OPEN Deviceconfig callback : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result2 : " + JSON.stringify(configs));
expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType);
expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig1.isHiddenSsid);
expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid);
- console.info("[wifi_test] remove config");
var isRemoved = wifi.removeAllNetwork();
- console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
expect(isRemoved).assertTrue();
var configs = wifi.getDeviceConfigs();
- console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length == 0);
done()
});
@@ -224,21 +252,28 @@ describe('ACTS_WifiTest', function() {
* @tc.desc Test create a PSK SecurityType wifi device config
*/
it('SUB_Communication_WiFi_Sta_Config_0002', 0, async function(done) {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0002]");
- console.info("[wifi_test] create a PSK SecurityType wifi device config start.");
+ await tryToEnableWifi();
+
var wifiDeviceConfig1 = {
"ssid": "TEST_PSK",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
};
await wifi.addDeviceConfig(wifiDeviceConfig1)
.then(netWorkId => {
console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType);
@@ -246,9 +281,7 @@ describe('ACTS_WifiTest', function() {
expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfig1.preSharedKey);
expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid);
- console.info("[wifi_test] remove config");
var isRemoved = wifi.removeDevice(netWorkId);
- console.info("[wifi_test] check remove config successfully,result:" + isRemoved);
expect(isRemoved).assertTrue();
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test]remove config,current getConfig: " + JSON.stringify(configs));
@@ -256,20 +289,64 @@ describe('ACTS_WifiTest', function() {
});
done()
})
+
+ /**
+ * @tc.number Config_0003
+ * @tc.name SUB_Communication_WiFi_Sta_Config_0003
+ * @tc.desc Test create a WEP SecurityType wifi device config
+ */
+ it('SUB_Communication_WiFi_Sta_Config_0003', 0, async function(done) {
+ await tryToEnableWifi();
+
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST_WEP",
+ "bssid": "",
+ "preSharedKey": "ABCDEF1234",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+
+ await wifi.addDeviceConfig(wifiDeviceConfig1)
+ .then(netWorkId => {
+ console.info("[wifi_test]add WEP Deviceconfig promise : " + JSON.stringify(netWorkId));
+ expect(true).assertEqual(netWorkId != -1);
+
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId));
+ expect(wifi.connectToNetwork(netWorkId)).assertTrue();
+ console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].securityType == wifiDeviceConfig1.securityType);
+ expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfig1.isHiddenSsid);
+ expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfig1.preSharedKey);
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfig1.ssid);
+
+ var isRemoved = wifi.removeDevice(netWorkId);
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
/**
- * @tc.number Config_0005
- * @tc.name SUB_Communication_WiFi_Sta_Config_0005
+ * @tc.number Config_0004
+ * @tc.name SUB_Communication_WiFi_Sta_Config_0004
* @tc.desc Test remove all wifi device config
*/
- it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0005]");
- console.info("[wifi_test] create multiple valid wifi device config and add it.");
+ it('SUB_Communication_WiFi_Sta_Config_0004', 0, async function(done) {
+ await tryToEnableWifi();
var wifiDeviceConfig1 = {
"ssid": "TESTWgr1",
"bssid": "",
- "preSharedKey": "12345678",
- "isHiddenSsid": "false",
+ "preSharedKey": "123456789",
+ "isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
};
var wifiDeviceConfig2 = {
@@ -281,32 +358,37 @@ describe('ACTS_WifiTest', function() {
};
let promiseOne = new Promise((resolve, reject) => {
wifi.addDeviceConfig(wifiDeviceConfig1,
- (netWorkId1) => {
+ (err,netWorkId1) => {
+ if(err) {
+ console.info("[wifi_test]add callback failed : " + JSON.stringify(err));
+ return;
+ }
console.info("[wifi_test] wifi addDeviceconfig1 callback:" + JSON.stringify(netWorkId1));
expect(true).assertEqual(netWorkId1 != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length >= 1);
resolve()
});
})
-
let promiseTwo = new Promise((resolve, reject) => {
wifi.addDeviceConfig(wifiDeviceConfig2,
- (netWorkId2) => {
+ (err,netWorkId2) => {
+ if(err) {
+ console.info("[wifi_test]add callback failed : " + JSON.stringify(err));
+ return;
+ }
console.info("[wifi_test] wifi addDeviceconfig2 callback : " + JSON.stringify(netWorkId2));
expect(true).assertEqual(netWorkId2 != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length >= 1);
- console.info("[wifi_test] remove all configs");
+
var isRemoved = wifi.removeAllNetwork();
- console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
expect(isRemoved).assertTrue();
var configs = wifi.getDeviceConfigs();
- console.info("[wifi_test]remove configs,current get Configs : " + JSON.stringify(configs));
expect(true).assertEqual(configs.length == 0);
resolve()
});
@@ -315,42 +397,129 @@ describe('ACTS_WifiTest', function() {
})
/**
- * @tc.number Config_0007
- * @tc.name SUB_Communication_WiFi_Sta_Config_0007
+ * @tc.number Config_0005
+ * @tc.name SUB_Communication_WiFi_Sta_Config_0005
+ * @tc.desc Test disableNetwork device config
+ */
+ it('SUB_Communication_WiFi_Sta_Config_0005', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigD = {
+ "ssid": "TESTD",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ await wifi.addDeviceConfig(wifiDeviceConfigD)
+ .then(netWorkId => {
+ console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId));
+ expect(true).assertEqual(netWorkId != -1);
+ expect(wifi.connectToNetwork(netWorkId)).assertTrue();
+ var disconNet = wifi.disableNetwork(netWorkId);
+ expect(disconNet).assertTrue();
+
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test] wifi device config result : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigD.ssid);
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
+
+ /**
+ * @tc.number Config_0006
+ * @tc.name SUB_Communication_WiFi_Sta_Config_0006
* @tc.desc Test update wifi device config
*/
- it('SUB_Communication_WiFi_Sta_Config_0007', 0, async function(done) {
- console.info("[wifi_test][SUB_Communication_WiFi_Sta_Config_0007]");
- console.info("[wifi_test] create a valid wifi device config start.");
- var wifiDeviceConfig1 = {
+ it('SUB_Communication_WiFi_Sta_Config_0006', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigU = {
"ssid": "TEST",
"bssid": "",
"preSharedKey": "12345678",
"isHiddenSsid": false,
"securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
};
-
- await wifi.addDeviceConfig(wifiDeviceConfig1)
+ await wifi.addDeviceConfig(wifiDeviceConfigU)
.then(netWorkId => {
console.info("[wifi_test]add PSK Deviceconfig promise : " + JSON.stringify(netWorkId));
expect(true).assertEqual(netWorkId != -1);
- console.info("[wifi_test] check add device configs successfully ");
+
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
- wifiDeviceConfig1.ssid = "UPDATE";
- wifiDeviceConfig1.preSharedKey = "1234567890";
- console.info("[wifi_test] wifi new wifiDeviceConfig1:" + wifi.updateNetwork(wifiDeviceConfig1));
-
- console.info("[wifi_test] check update device configs successfully ");
+ wifiDeviceConfigU.ssid = "UPDATE";
+ wifiDeviceConfigU.preSharedKey = "1234567890";
+ expect(true).assertEqual(wifi.updateNetwork(wifiDeviceConfigU) >= 0);
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test] updated wifi device config result : " + JSON.stringify(configs));
- expect(true).assertEqual(configs[1].ssid == wifiDeviceConfig1.ssid);
- expect(true).assertEqual(configs[1].preSharedKey == wifiDeviceConfig1.preSharedKey);
+ expect(true).assertEqual(configs[1].ssid == wifiDeviceConfigU.ssid);
+ expect(true).assertEqual(configs[1].preSharedKey == wifiDeviceConfigU.preSharedKey);
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
+
+ /**
+ * @tc.number Config_SSID_0001
+ * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0001
+ * @tc.desc Test SSID wifi device config
+ */
+ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0001', 0, async function(done) {
+ await tryToEnableWifi();
+
+ var wifiDeviceConfigZ = {
+ "ssid": "中文测试SSID",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ await wifi.addDeviceConfig(wifiDeviceConfigZ)
+ .then(netWorkId => {
+ console.info("[wifi_test]add contains chinese Deviceconfig promise : " + JSON.stringify(netWorkId));
+ expect(true).assertEqual(netWorkId != -1);
+
+ expect(wifi.connectToNetwork(netWorkId)).assertTrue();
+
+ var disconNet = wifi.disableNetwork(netWorkId);
+ expect(disconNet).assertTrue();
+
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigZ.ssid);
+ expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigZ.preSharedKey);
- console.info("[wifi_test] remove config");
var isRemoved = wifi.removeAllNetwork();
- console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
expect(isRemoved).assertTrue();
var configs = wifi.getDeviceConfigs();
console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
@@ -359,23 +528,726 @@ describe('ACTS_WifiTest', function() {
done()
})
+
/**
- * @tc.number Info_0002
- * @tc.name SUB_Communication_WiFi_Sta_Info_0002
- * @tc.desc Test get CountryCode
+ * @tc.number Config_SSID_0002
+ * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0002
+ * @tc.desc Test SSID wifi device config
*/
- it('SUB_Communication_WiFi_Sta_Info_0002', 0, function() {
- if (!wifi.isWifiActive()) {
- var enable = wifi.enableWifi();
- sleep(3000);
- expect(enable).assertTrue();
- }
+ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0002', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigK = {
+ "ssid": "test text",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+
+ await wifi.addDeviceConfig(wifiDeviceConfigK)
+ .then(netWorkId => {
+ console.info("[wifi_test]add kongge SSID Deviceconfig promise : " + JSON.stringify(netWorkId));
+ expect(true).assertEqual(netWorkId != -1);
+
+ expect(wifi.connectToNetwork(netWorkId)).assertTrue();
+
+ var disconNet = wifi.disableNetwork(netWorkId);
+ expect(disconNet).assertTrue();
+
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigK.ssid);
+ expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigK.preSharedKey);
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
+
+ /**
+ * @tc.number Config_SSID_0003
+ * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0003
+ * @tc.desc Test contains chinese SSID device config
+ */
+ it('SSUB_Communication_WiFi_Sta_Conn_SSID_0003', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigT = {
+ "ssid": "!@#¥%&*/",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+
+ await wifi.addDeviceConfig(wifiDeviceConfigT)
+ .then(netWorkId => {
+
+ expect(true).assertEqual(netWorkId != -1);
+ console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId));
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigT.ssid);
+ expect(true).assertEqual(configs[0].preSharedKey == wifiDeviceConfigT.preSharedKey);
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
+
+ /**
+ * @tc.number Config_SSID_0007
+ * @tc.name SSUB_Communication_WiFi_Sta_Conn_SSID_0007
+ * @tc.desc Test hidden SSID wifi device config
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_SSID_0007', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigT = {
+ "ssid": "test",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": true,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+
+ await wifi.addDeviceConfig(wifiDeviceConfigT)
+ .then(netWorkId => {
+
+ expect(true).assertEqual(netWorkId != -1);
+ console.info("[wifi_test]connectdevice result: " + wifi.connectToNetwork(netWorkId));
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test] wifi getDeviceConfigs result1 : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs[0].ssid == wifiDeviceConfigT.ssid);
+ expect(true).assertEqual(configs[0].isHiddenSsid == wifiDeviceConfigT.isHiddenSsid);
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs.length == 0);
+ });
+ done()
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Sta_info_0001
+ * @tc.name testgetMacAddress
+ * @tc.desc Test getMacAddress api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_info_0001', 0, async function (done) {
+ await tryToEnableWifi();
+ expect(wifi.isWifiActive()).assertTrue();
+ console.info('[wifi_test] getDeviceMacAddress test start ...');
+ var result = wifi.getDeviceMacAddress();
+ console.info("[wifi_test] getDeviceMacAddress -> " + JSON.stringify(result));
+ expect(true).assertEqual(result.length >= 1)
+ done();
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Sta_info_0002
+ * @tc.name testgetCountryCode
+ * @tc.desc Test getCountryCode api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_Info_0002', 0, async function(done) {
+ await tryToEnableWifi();
expect(wifi.isWifiActive()).assertTrue();
console.info(" [wifi_test] getCountryCode start ... ");
var countryCode = wifi.getCountryCode();
console.info("[wifi_test] getCountryCode -> " + JSON.stringify(countryCode));
expect(JSON.stringify(countryCode)).assertEqual('"CN"');
+ done()
+ })
+
+ /**
+ * @tc.number SUB_Communication_WiFi_Sta_info_0004
+ * @tc.name testFeatureSupported
+ * @tc.desc Test FeatureSupported api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_info_0004', 0, async function (done) {
+ await tryToEnableWifi();
+ expect(wifi.isWifiActive()).assertTrue();
+ var result = wifi.getSupportedFeatures();
+ console.info("[wifi_test] getFeatureSupported -> " + JSON.stringify(result));
+ console.info("[wifi_test] isFeatureSupported: " + result +"->" + wifi.isFeatureSupported(result));
+ expect(wifi.isFeatureSupported(result)).assertTrue();
+ done();
})
+ /**
+ * @tc.number SUB_Communication_WiFi_Sta_info_0005
+ * @tc.name testHotspotDualBandSupported
+ * @tc.desc Test HotspotDualBandSupported api.
+ * @tc.size MEDIUM
+ * @tc.type Function
+ * @tc.level Level 3
+ */
+ it('SUB_Communication_WiFi_Sta_Info_0005', 0, async function(done) {
+ console.info(" [wifi_test] isHotspotDualBandSupported start ... ");
+ await tryToEnableWifi();
+ expect(wifi.isWifiActive()).assertTrue();
+ var DualBand = wifi.isHotspotDualBandSupported();
+ console.info("[wifi_test] isHotspotDualBandSupported -> " + JSON.stringify(DualBand));
+ expect(DualBand).assertFalse();
+ done();
+
+ })
+
+ /**
+ * @tc.number Conn_Info_0001
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0001
+ * @tc.desc Test reconnect wifi
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Info_0001', 0, async function (done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigConn = {
+ "ssid": "TESTCONN",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ expect(wifi.isWifiActive()).assertTrue();
+ var result1 = wifi.connectToDevice(wifiDeviceConfigConn);
+ expect(result1).assertTrue();
+ console.info("[wifi_test]isConnected : " + wifi.isConnected());
+ expect(wifi.isConnected()).assertFalse();
+ expect(wifi.reconnect()).assertTrue();
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs.length == 0);
+ done()
+
+ })
+
+ /**
+ * @tc.number conn_Config_0002
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0002
+ * @tc.desc Test getLinkedInfo information
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Info_0002', 0, async function(done) {
+ await tryToEnableWifi();
+ await wifi.getLinkedInfo()
+ .then((result) => {
+ console.info("[wifi_test] get wifi link [promise] -> " + JSON.stringify(result));
+ expect(JSON.stringify(result)).assertContain('band');
+ done();
+ }).catch((error) => {
+ console.info("[wifi_test] promise then error." + JSON.stringify(error));
+ expect().assertFail();
+ });
+ })
+
+ /**
+ * @tc.number conn_Config_0003
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003
+ * @tc.desc Test getLinkedInfo callback information
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function(done) {
+ await tryToEnableWifi();
+ await wifi.getLinkedInfo(
+ (err,result) => {
+ if(err) {
+ console.log("[wifi_test] wifi getLinkedInfo failed " + err);
+ }
+ var clen = Object.keys(result).length;
+ expect(clen).assertLarger(0);
+ console.info("[wifi_test] getLinkedInfo callback result: " + JSON.stringify(result));
+ console.info("ssid: " + result.ssid + "bssid:"+ result.bssid +"band: " + result.band+
+ "isHidden: " + result.isHidden + "isRestricted: " + result.isRestricted +
+ "chload: " + result.chload + "rssi " + result.rssi + "netWorkId: " + result.netWorkId+
+ "linkSpeed: " + result.linkSpeed + "frequency:"
+ + result.frequency +"snr:" + result.snr+
+ "macAddress: " + result.macAddress + "ipAddress: " + result.ipAddress +
+ "suppState: " + result.suppState + "connState: " + result.connState);
+ done();
+ });
+ })
+
+ /**
+ * @tc.number Conn_Security_0001
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0001
+ * @tc.desc Test connectToDevice 10 bits WEP Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0001', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST10",
+ "bssid": "",
+ "preSharedKey": "ABCDEF1234",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0002
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0002
+ * @tc.desc Test disconnect Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0002', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TESTDIS",
+ "bssid": "",
+ "preSharedKey": "12345678",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+
+ expect(wifi.disconnect()).assertTrue();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0003
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0003
+ * @tc.desc Test connectToDevice 26 bits WEP Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0003', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST26",
+ "bssid": "",
+ "preSharedKey": "12345678901234567890123456",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0005
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0005
+ * @tc.desc Test connectToDevice 5bits ASCLL WEP Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0005', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST5",
+ "bssid": "",
+ "preSharedKey": "aB1@g",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0007
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0007
+ * @tc.desc Test connectToDevice 13bits ASCLL WEP Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0007', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST7",
+ "bssid": "",
+ "preSharedKey": "1234aA@fFgGzZ",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_WEP,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+ console.info("[wifi_test] check isconnected wifi");
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0013
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0013
+ * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0013', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST13",
+ "bssid": "",
+ "preSharedKey": "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH1234567",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0014
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0014
+ * @tc.desc Test connectToDevice 8bits ASCLL PSK Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0014', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST13",
+ "bssid": "",
+ "preSharedKey": "ABCDEFGH",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Security_0015
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Security_0015
+ * @tc.desc Test connectToDevice 63bits ASCLL PSK Deviceconfig
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Security_0015', 0, async function(done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfig1 = {
+ "ssid": "TEST13",
+ "bssid": "",
+ "preSharedKey": "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH1234567",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfig1);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+ console.info("[wifi_test] check isconnected wifi");
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+ var isRemoved = wifi.removeAllNetwork();
+ console.info("[wifi_test] check remove configs successfully,result:" + isRemoved);
+ expect(isRemoved).assertTrue();
+ done()
+ })
+
+ /**
+ * @tc.number Conn_Info_0003
+ * @tc.name SUB_Communication_WiFi_Sta_Conn_Info_0003
+ * @tc.desc Test get IpInfo information
+ */
+ it('SUB_Communication_WiFi_Sta_Conn_Info_0003', 0, async function (done) {
+ await tryToEnableWifi();
+ var wifiDeviceConfigIp = {
+ "ssid": "TEST1",
+ "bssid": "",
+ "preSharedKey": "123456789",
+ "isHiddenSsid": false,
+ "securityType": WifiSecurityType.WIFI_SEC_TYPE_PSK,
+ "netId": -1,
+ "ipType": 1,
+ "creatorUid": 7,
+ "disableReason": 0,
+ "randomMacType": 0,
+ "randomMacAddr": "11:22:33:44:55:66",
+ "staticIp": {"ipAddress": 1284752956,"gateway": 1284752936},
+ };
+ var result1 = wifi.connectToDevice(wifiDeviceConfigIp);
+ console.log("[wifi_test] wifi connectToDevice result: " + result1);
+ expect(result1).assertTrue();
+
+ var isConnected= wifi.isConnected();
+ expect(isConnected).assertFalse();
+
+ var reass= wifi.reassociate();
+ expect(reass).assertTrue();
+
+ var ipInfo = wifi.getIpInfo();
+ expect(JSON.stringify(ipInfo)).assertContain("gateway");
+ console.info("gateway: " + ipInfo.gateway + "ipAddress: " + ipInfo.ipAddress
+ + "leaseDuration: " + ipInfo.leaseDuration +
+ "leaseDuration: " + ipInfo.leaseDuration +
+ "netmask: " + ipInfo.netmask + "primaryDns:" + ipInfo.primaryDns +
+ "secondDns: " + ipInfo.secondDns + "serverIp: " + ipInfo.serverIp );
+
+ var isRemoved = wifi.removeAllNetwork();
+ expect(isRemoved).assertTrue();
+ var configs = wifi.getDeviceConfigs();
+ console.info("[wifi_test]remove config,current get Config : " + JSON.stringify(configs));
+ expect(true).assertEqual(configs.length == 0);
+ done()
+ })
+
+ /**
+ * @tc.number wifiStateChange_0001
+ * @tc.name SUB_Communication_WiFi_Sta_wifiStateChange_0001
+ * @tc.desc Test wifiStateChange callback
+ */
+ it('SUB_Communication_WiFi_Sta_wifiStateChange_0001', 0, async function (done) {
+ await tryToEnableWifi();
+ wifi.on('wifiStateChange', async result => {
+ console.info("wifiStateChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ let promise = new Promise((resolve) => {
+ wifi.off('wifiStateChange', result => {
+ console.info("offwifiStateChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ resolve()
+ });
+ })
+ await promise.then(done)
+ });
+ var disable = wifi.disableWifi()
+ await sleep(5000);
+ var enable = wifi.enableWifi();
+ await sleep(5000);
+ console.log("[wifi_test] check the state of wifi: " + wifi.isWifiActive());
+ done();
+
+ })
+
+ /**
+ * @tc.number wifiConnectionChange_0002
+ * @tc.name SUB_Communication_WiFi_Sta_wifiConnectionChange_0002
+ * @tc.desc Test wifiStateChange callback
+ */
+ it('SUB_Communication_WiFi_Sta_wifiConnectionChange_0002', 0, async function (done) {
+ await tryToEnableWifi();
+ wifi.on('wifiConnectionChange', async result => {
+ console.info("wifiConnectionChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ let promise = new Promise((resolve) => {
+ console.info('[wifi_test] offwifiConnectionChange test start ...');
+ wifi.off('wifiConnectionChange', result => {
+ console.info("offwifiConnectionChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ resolve()
+ });
+ })
+ await promise.then(done)
+ });
+ done();
+
+ })
+
+ /**
+ * @tc.number wifiScanStateChange_0003
+ * @tc.name SUB_Communication_WiFi_Sta_wifiScanStateChange_0003
+ * @tc.desc Test wifiScanStateChange callback
+ */
+ it('SUB_Communication_WiFi_Sta_wifiScanStateChange_0003', 0, async function (done) {
+ await tryToEnableWifi();
+ wifi.on('wifiScanStateChange', async result => {
+ console.info("wifiScanStateChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ let promise = new Promise((resolve) => {
+ console.info('[wifi_test] offwifiScanStateChange test start ...');
+ wifi.off('wifiScanStateChange', result => {
+ console.info("offwifiScanStateChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ resolve()
+ });
+ })
+ await promise.then(done)
+ });
+ var scan = wifi.scan();
+ await sleep(3000);
+ done();
+
+ })
+
+ /**
+ * @tc.number wifiRssiChange_0004
+ * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0004
+ * @tc.desc Test wifiRssiChange callback
+ */
+ it('SUB_Communication_WiFi_Sta_wifiRssiChange_0004', 0, async function (done) {
+ await tryToEnableWifi();
+ wifi.on('wifiRssiChange', async result => {
+ console.info("wifiRssiChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ let promise = new Promise((resolve) => {
+ console.info('[wifi_test] offwifiRssiChange test start ...');
+ wifi.off('wifiRssiChange', result => {
+ console.info("offwifiRssiChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ resolve()
+ });
+ })
+ await promise.then(done)
+ });
+ done();
+
+ })
+
+ /**
+ * @tc.number streamChange_0005
+ * @tc.name SUB_Communication_WiFi_Sta_wifiRssiChange_0005
+ * @tc.desc Test streamChange callback
+ */
+ it('SUB_Communication_WiFi_Sta_streamChange_0005', 0, async function (done) {
+ await tryToEnableWifi();
+
+ wifi.on('streamChange', async result => {
+ console.info("streamChange callback, result:" + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ let promise = new Promise((resolve) => {
+ console.info('[wifi_test] offstreamChange test start ...');
+ wifi.off('streamChange', result => {
+ console.info("offstreamChange callback, result: " + JSON.stringify(result));
+ expect(true).assertEqual(result !=null);
+ resolve()
+ });
+ })
+ await promise.then(done)
+ });
+ done();
+
+ })
console.log("*************[wifi_test] start wifi js unit test end*************");
})
+