From 321ce652134f69c965faa6bc320db1fc42f69656 Mon Sep 17 00:00:00 2001 From: yangpeng85 Date: Sat, 25 Dec 2021 16:03:36 +0800 Subject: [PATCH 1/3] add mock for settings api --- runtime/main/extend/systemplugin/index.js | 2 - .../main/extend/systemplugin/napi/index.js | 3 + .../main/extend/systemplugin/napi/settings.js | 22 ++++++ runtime/main/extend/systemplugin/settings.js | 69 ------------------- 4 files changed, 25 insertions(+), 71 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/settings.js delete mode 100644 runtime/main/extend/systemplugin/settings.js diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index cc0ac27c..861352af 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -74,7 +74,6 @@ import { mockDeviceManager } from './deviceManager' import { mockScreenshot } from './screenshot' import {mockContact} from './contact' import {mockScreenLock} from "./screenLock" -import {mockSettings} from "./settings" import { mockAppAccount} from './ohos/appAccount' import { mockOsAccount} from './ohos/osAccount' import { mockOhosGeolocation } from './ohos/geolocation' @@ -162,7 +161,6 @@ export function mockSystemPlugin() { mockStorageInfoManager() mockContact() mockScreenLock() - mockSettings() mockAppAbilityManager() mockAppAccount() mockOsAccount() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 3d3223df..20b2235c 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -29,6 +29,7 @@ import { mockRdb } from './rdb' import { mockInputDevice } from './inputDevice' import { mockVibrator } from './vibrator' import { mockSensor } from './sensor' +import { mockSettings } from './settings' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -95,6 +96,8 @@ export function mockRequireNapiFun() { return mockVibrator(); case "sensor": return mockSensor(); + case "settings": + return mockSettings(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/settings.js new file mode 100644 index 00000000..8c00c530 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/settings.js @@ -0,0 +1,22 @@ +import { paramMock } from "../utils" + +export function mockSettings() { + const settingsMock = { + getUri: function (...args) { + console.warn("settings.getUri interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + getValue: function (...args) { + console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + setValue: function (...args) { + console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramBooleanMock; + }, + }; + return settingsMock; +} diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js deleted file mode 100644 index a1e008d1..00000000 --- a/runtime/main/extend/systemplugin/settings.js +++ /dev/null @@ -1,69 +0,0 @@ -import { paramMock } from "./utils" - -export function mockSettings () { - const mockInfo = { - URI : "[PC Preview] unknow string" - } - global.systemplugin.settings = { - getURI: function (...args) { - console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, mockInfo) - } else { - return new Promise((resolve) => { - resolve(mockInfo); - }) - } - }, - getValue: function (...args) { - console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setValue: function (...args) { - console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - enableAirplaneMode: function (...args) { - console.warn("settings.enableAirplaneMode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - canShowFloating: function (...args) { - console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - } -} \ No newline at end of file -- Gitee From e68d2d9ccc6674f15e1cf1bb83f960136756e63a Mon Sep 17 00:00:00 2001 From: yangpeng85 Date: Sat, 25 Dec 2021 16:13:18 +0800 Subject: [PATCH 2/3] Revert "add mock for settings api" This reverts commit 321ce652134f69c965faa6bc320db1fc42f69656. --- runtime/main/extend/systemplugin/index.js | 2 + .../main/extend/systemplugin/napi/index.js | 3 - .../main/extend/systemplugin/napi/settings.js | 22 ------ runtime/main/extend/systemplugin/settings.js | 69 +++++++++++++++++++ 4 files changed, 71 insertions(+), 25 deletions(-) delete mode 100644 runtime/main/extend/systemplugin/napi/settings.js create mode 100644 runtime/main/extend/systemplugin/settings.js diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index 861352af..cc0ac27c 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -74,6 +74,7 @@ import { mockDeviceManager } from './deviceManager' import { mockScreenshot } from './screenshot' import {mockContact} from './contact' import {mockScreenLock} from "./screenLock" +import {mockSettings} from "./settings" import { mockAppAccount} from './ohos/appAccount' import { mockOsAccount} from './ohos/osAccount' import { mockOhosGeolocation } from './ohos/geolocation' @@ -161,6 +162,7 @@ export function mockSystemPlugin() { mockStorageInfoManager() mockContact() mockScreenLock() + mockSettings() mockAppAbilityManager() mockAppAccount() mockOsAccount() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 20b2235c..3d3223df 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -29,7 +29,6 @@ import { mockRdb } from './rdb' import { mockInputDevice } from './inputDevice' import { mockVibrator } from './vibrator' import { mockSensor } from './sensor' -import { mockSettings } from './settings' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -96,8 +95,6 @@ export function mockRequireNapiFun() { return mockVibrator(); case "sensor": return mockSensor(); - case "settings": - return mockSettings(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/settings.js deleted file mode 100644 index 8c00c530..00000000 --- a/runtime/main/extend/systemplugin/napi/settings.js +++ /dev/null @@ -1,22 +0,0 @@ -import { paramMock } from "../utils" - -export function mockSettings() { - const settingsMock = { - getUri: function (...args) { - console.warn("settings.getUri interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); - return paramMock.paramStringMock; - }, - getValue: function (...args) { - console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); - return paramMock.paramStringMock; - }, - setValue: function (...args) { - console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device."); - return paramMock.paramBooleanMock; - }, - }; - return settingsMock; -} diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js new file mode 100644 index 00000000..a1e008d1 --- /dev/null +++ b/runtime/main/extend/systemplugin/settings.js @@ -0,0 +1,69 @@ +import { paramMock } from "./utils" + +export function mockSettings () { + const mockInfo = { + URI : "[PC Preview] unknow string" + } + global.systemplugin.settings = { + getURI: function (...args) { + console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, mockInfo) + } else { + return new Promise((resolve) => { + resolve(mockInfo); + }) + } + }, + getValue: function (...args) { + console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramStringMock); + }) + } + }, + setValue: function (...args) { + console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve(); + }) + } + }, + enableAirplaneMode: function (...args) { + console.warn("settings.enableAirplaneMode interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock) + } else { + return new Promise((resolve) => { + resolve(); + }) + } + }, + canShowFloating: function (...args) { + console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) + } else { + return new Promise((resolve) => { + resolve(paramMock.paramBooleanMock); + }) + } + }, + } +} \ No newline at end of file -- Gitee From ab2dcacaa708fefc737dc68a60bfecdd47bb4da3 Mon Sep 17 00:00:00 2001 From: yangpeng85 Date: Sat, 25 Dec 2021 16:14:02 +0800 Subject: [PATCH 3/3] add mock for settings api Signed-off-by: yangpeng85 --- runtime/main/extend/systemplugin/index.js | 2 - .../main/extend/systemplugin/napi/index.js | 3 + .../main/extend/systemplugin/napi/settings.js | 22 ++++++ runtime/main/extend/systemplugin/settings.js | 69 ------------------- 4 files changed, 25 insertions(+), 71 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/settings.js delete mode 100644 runtime/main/extend/systemplugin/settings.js diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index cc0ac27c..861352af 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -74,7 +74,6 @@ import { mockDeviceManager } from './deviceManager' import { mockScreenshot } from './screenshot' import {mockContact} from './contact' import {mockScreenLock} from "./screenLock" -import {mockSettings} from "./settings" import { mockAppAccount} from './ohos/appAccount' import { mockOsAccount} from './ohos/osAccount' import { mockOhosGeolocation } from './ohos/geolocation' @@ -162,7 +161,6 @@ export function mockSystemPlugin() { mockStorageInfoManager() mockContact() mockScreenLock() - mockSettings() mockAppAbilityManager() mockAppAccount() mockOsAccount() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 3d3223df..20b2235c 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -29,6 +29,7 @@ import { mockRdb } from './rdb' import { mockInputDevice } from './inputDevice' import { mockVibrator } from './vibrator' import { mockSensor } from './sensor' +import { mockSettings } from './settings' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -95,6 +96,8 @@ export function mockRequireNapiFun() { return mockVibrator(); case "sensor": return mockSensor(); + case "settings": + return mockSettings(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/settings.js new file mode 100644 index 00000000..8c00c530 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/settings.js @@ -0,0 +1,22 @@ +import { paramMock } from "../utils" + +export function mockSettings() { + const settingsMock = { + getUri: function (...args) { + console.warn("settings.getUri interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + getValue: function (...args) { + console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + setValue: function (...args) { + console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramBooleanMock; + }, + }; + return settingsMock; +} diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js deleted file mode 100644 index a1e008d1..00000000 --- a/runtime/main/extend/systemplugin/settings.js +++ /dev/null @@ -1,69 +0,0 @@ -import { paramMock } from "./utils" - -export function mockSettings () { - const mockInfo = { - URI : "[PC Preview] unknow string" - } - global.systemplugin.settings = { - getURI: function (...args) { - console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, mockInfo) - } else { - return new Promise((resolve) => { - resolve(mockInfo); - }) - } - }, - getValue: function (...args) { - console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setValue: function (...args) { - console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - enableAirplaneMode: function (...args) { - console.warn("settings.enableAirplaneMode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - canShowFloating: function (...args) { - console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - } -} \ No newline at end of file -- Gitee