update jsfw code for wgr

Signed-off-by: liwenzhen <liwenzhen3@huawei.com>
Change-Id: I0725e78ce0de746715f070f5cfa02ef90371afe7
This commit is contained in:
liwenzhen 2021-12-22 16:14:28 +08:00
parent 06f4ec894f
commit 620668403c
56 changed files with 6612 additions and 3682 deletions

16
.gitattributes vendored
View File

@ -1,15 +1 @@
*.tgz filter=lfs diff=lfs merge=lfs -text
*.trp filter=lfs diff=lfs merge=lfs -text
*.apk filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.asm filter=lfs diff=lfs merge=lfs -text
*.8svn filter=lfs diff=lfs merge=lfs -text
*.9svn filter=lfs diff=lfs merge=lfs -text
*.dylib filter=lfs diff=lfs merge=lfs -text
*.exe filter=lfs diff=lfs merge=lfs -text
*.a filter=lfs diff=lfs merge=lfs -text
*.so filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text

View File

@ -38,8 +38,15 @@ action("gen_snapshot") {
if (is_standard_system) {
node_modules = "//prebuilts/build-tools/common/js-framework/node_modules"
if (use_mac) {
nodejs_path =
"//prebuilts/build-tools/common/nodejs/node-v12.18.4-darwin-x64"
is_mac = "true"
} else {
nodejs_path =
"//prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64"
is_mac = "false"
}
} else {
node_modules = "//prebuilts/ace-toolkit/js-framework/node_modules"
if (use_mac) {

33
OAT.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filepath" name="node_modules/.*" desc="dependencies"/>
<filteritem type="filepath" name="runtime/.*" desc="based on third party software"/>
<filteritem type="filepath" name="test/.*" desc="for test"/>
<filteritem type="filepath" name="NOTICE" desc="third party software notice"/>
<filteritem type="filepath" name=".eslintrc" desc="eslint settings"/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>

View File

@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"test:lint": "eslint -c .eslintrc --fix test/**/*.ts",
"test:unit": "mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts",
"test:unit": "mocha --timeout 5000 -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts",
"build": "node build.js"
},
"keywords": [

View File

@ -171,7 +171,7 @@ class I18n {
return '';
});
} else if (Object.prototype.toString.call(params) === '[object Number]') {
value = value.replace(/\{count\}/g, params);
value = value.replace(/\{count\}/g, params.toLocaleString(this.locale.replace('_', '-')));
} else {
return value;
}

View File

@ -287,9 +287,9 @@ export function mockAbilityFeatureAbility() {
want: WantMock
}
const ContinuationStateMock = {
LOCAL_RUNNING : '0',
REMOTE_RUNNING : '1',
REPLICA_RUNNING : '2'
LOCAL_RUNNING: '0',
REMOTE_RUNNING: '1',
REPLICA_RUNNING: '2'
}
const PermissionRequestResultMock = {
requestCode: "[PC Preview] unknow requestCode",
@ -320,7 +320,7 @@ export function mockAbilityFeatureAbility() {
permissions: ["[PC Preview] unknow permission", "[PC Preview] unknow permission"],
moduleInfo: [ModuleInfoMock],
entryDir: "[PC Preview] unknow entryDir",
customizeData:new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]])
customizeData: new Map([["[PC Preview] unknow customizeDataKey", CustomizeDataMock]])
}
const AbilityInfoMock = {
bundleName: "[PC Preview] unknow bundleName",
@ -956,12 +956,12 @@ export function mockAbilityParticleAbility() {
}
},
connectAbility: function (...args) {
console.warn("ability.featureAbility.connectAbility interface mocked in the Previewer. How this interface works" +
console.warn("ability.particleAbility.connectAbility interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return paramMock.paramNumberMock;
},
disconnectAbility: function (...args) {
console.warn("ability.featureAbility.disconnectAbility interface mocked in the Previewer. How this interface works" +
console.warn("ability.particleAbility.disconnectAbility 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') {
@ -1049,9 +1049,9 @@ export function mockAbilityFormManager() {
entities: "[PC Preview] unknow entities"
}
const FormStateMock = {
UNKNOWN : '-1',
DEFAULT : '0',
READY : '1'
UNKNOWN: '-1',
DEFAULT: '0',
READY: '1'
}
const FormInfoArrayMock = [
FormInfoMock

View File

@ -1,244 +1,199 @@
import { paramMock } from "./utils"
import {paramMock} from './utils';
export function mockAccessibility() {
const AbilitySubTypeMock = {
UNSPECIFIED: 0,
CA: 1,
}
CA: 1
};
const DisplayOrientationMock = {
UNSPECIFIED: 1,
LANDSCAPE: 2,
PORTRAIT: 3,
FOLLOWRECENT: 4,
}
FOLLOWRECENT: 4
};
const LaunchModeMock = {
SINGLETON: 0,
STANDARD: 1,
}
STANDARD: 1
};
const ApplicationInfoMock = {
name: "[PC Preview] unknow name",
description: "[PC Preview] unknow description",
descriptionId: "[PC Preview] unknow descriptionId",
systemApp: "[PC Preview] unknow systemApp",
enabled: "[PC Preview] unknow enabled",
label: "[PC Preview] unknow label",
labelId: "[PC Preview] unknow labelId",
icon: "[PC Preview] unknow icon",
iconId: "[PC Preview] unknow iconId",
process: "[PC Preview] unknow process",
supportedModes: "[PC Preview] unknow supportedModes",
moduleSourceDirs: "[PC Preview] unknow moduleSourceDirs",
permissions: "[PC Preview] unknow permissions",
permissions: "[PC Preview] unknow permissions",
flags: "[PC Preview] unknow flags",
entryDir: "[PC Preview] unknow entryDir",
}
name: '[PC Preview] unknow name',
description: '[PC Preview] unknow description',
descriptionId: '[PC Preview] unknow descriptionId',
systemApp: '[PC Preview] unknow systemApp',
enabled: '[PC Preview] unknow enabled',
label: '[PC Preview] unknow label',
labelId: '[PC Preview] unknow labelId',
icon: '[PC Preview] unknow icon',
iconId: '[PC Preview] unknow iconId',
process: '[PC Preview] unknow process',
supportedModes: '[PC Preview] unknow supportedModes',
moduleSourceDirs: '[PC Preview] unknow moduleSourceDirs',
permissions: '[PC Preview] unknow permissions',
permissions: '[PC Preview] unknow permissions',
flags: '[PC Preview] unknow flags',
entryDir: '[PC Preview] unknow entryDir'
};
const AbilityInfoMock = {
bundleName: "[PC Preview] unknow bundleName",
name: "[PC Preview] unknow name",
label: "[PC Preview] unknow label",
description: "[PC Preview] unknow description",
icon: "[PC Preview] unknow icon",
labelId: "[PC Preview] unknow labelId",
descriptionId: "[PC Preview] unknow descriptionId",
moduleName: "[PC Preview] unknow moduleName",
iconId: "[PC Preview] unknow iconId",
process: "[PC Preview] unknow process",
targetAbility: "[PC Preview] unknow targetAbility",
backgroundModes: "[PC Preview] unknow backgroundModes",
isVisible: "[PC Preview] unknow isVisible",
formEnabled: "[PC Preview] unknow formEnabled",
bundleName: '[PC Preview] unknow bundleName',
name: '[PC Preview] unknow name',
label: '[PC Preview] unknow label',
description: '[PC Preview] unknow description',
icon: '[PC Preview] unknow icon',
labelId: '[PC Preview] unknow labelId',
descriptionId: '[PC Preview] unknow descriptionId',
moduleName: '[PC Preview] unknow moduleName',
iconId: '[PC Preview] unknow iconId',
process: '[PC Preview] unknow process',
targetAbility: '[PC Preview] unknow targetAbility',
backgroundModes: '[PC Preview] unknow backgroundModes',
isVisible: '[PC Preview] unknow isVisible',
formEnabled: '[PC Preview] unknow formEnabled',
type: AbilityTypeMock,
subType: AbilitySubTypeMock,
orientation: DisplayOrientationMock,
launchMode: LaunchModeMock,
permissions: "[PC Preview] unknow permissions",
deviceTypes: "[PC Preview] unknow deviceTypes",
deviceCapabilities: "[PC Preview] unknow deviceCapabilities",
readPermission: "[PC Preview] unknow readPermission",
writePermission: "[PC Preview] unknow writePermission",
permissions: '[PC Preview] unknow permissions',
deviceTypes: '[PC Preview] unknow deviceTypes',
deviceCapabilities: '[PC Preview] unknow deviceCapabilities',
readPermission: '[PC Preview] unknow readPermission',
writePermission: '[PC Preview] unknow writePermission',
applicationInfo: ApplicationInfoMock,
formEntity: "[PC Preview] unknow formEntity",
minFormHeight: "[PC Preview] unknow minFormHeight",
defaultFormHeight: "[PC Preview] unknow defaultFormHeight",
minFormWidth: "[PC Preview] unknow minFormWidth",
defaultFormWidth: "[PC Preview] unknow defaultFormWidth",
uri: "[PC Preview] unknow uri",
}
formEntity: '[PC Preview] unknow formEntity',
minFormHeight: '[PC Preview] unknow minFormHeight',
defaultFormHeight: '[PC Preview] unknow defaultFormHeight',
minFormWidth: '[PC Preview] unknow minFormWidth',
defaultFormWidth: '[PC Preview] unknow defaultFormWidth',
uri: '[PC Preview] unknow uri'
};
const AbilityTypeMock = {
audible: 'audible',
generic: 'generic',
haptic: 'haptic',
spoken: 'spoken',
visual: 'visual',
}
visual: 'visual'
};
const CapabilityMock = {
retrieve: 'retrieve',
touchGuide: 'touchGuide',
keyEventObserver: 'keyEventObserver',
zoom: 'zoom',
gesture: 'gesture',
}
gesture: 'gesture'
};
const EventTypeMock = {
accessibilityFocus: 'accessibilityFocus',
accessibilityFocusClear: 'accessibilityFocusClear',
click: 'click',
longClick: 'longClick',
focus: 'focus',
select: 'select',
hoverEnter: 'hoverEnter',
hoverExit: 'hoverExit',
textUpdate: 'textUpdate',
textSelectionUpdate: 'textSelectionUpdate',
scroll: 'scroll',
}
const EventTypeMock = '[PC Preview] unknow EventType';
const AccessibilityAbilityInfoMock = {
id: "[PC Preview] unknow id",
name: "[PC Preview] unknow name",
bundleName: "[PC Preview] unknow bundleName",
id: '[PC Preview] unknow id',
name: '[PC Preview] unknow name',
bundleName: '[PC Preview] unknow bundleName',
abilityInfo: AbilityInfoMock,
abilityTypes: [AbilityTypeMock],
capabilities: [CapabilityMock],
description: "[PC Preview] unknow description",
eventTypes: [EventTypeMock],
}
description: '[PC Preview] unknow description',
eventTypes: [EventTypeMock]
};
const WindowUpdateTypeMock = {
add: 'add',
remove: 'remove',
title: 'title',
bounds: 'bounds',
layer: 'layer',
active: 'active',
focus: 'focus',
accessibilityFocus: 'accessibilityFocus',
parent: 'parent',
children: 'children',
pip: 'pip',
}
const WindowUpdateTypeMock = '[PC Preview] unknow WindowUpdateType';
const ActionMock = {
accessibilityFocus: 'accessibilityFocus',
clearAccessibilityFocus: 'clearAccessibilityFocus',
focus: 'focus',
clearFocus: 'clearFocus',
clearSelection: 'clearSelection',
click: 'click',
longClick: 'longClick',
cut: 'cut',
copy: 'copy',
paste: 'paste',
select: 'select',
setText: 'setText',
delete: 'delete',
scrollForward: 'scrollForward',
scrollBackward: 'scrollBackward',
setSelection: 'setSelection',
}
const ActionMock = '[PC Preview] unknow Action';
const TextMoveUnitMock = {
char: 'char',
word: 'word',
line: 'line',
page: 'page',
paragraph: 'paragraph'
}
const EventInfoMock = {
type: EventTypeMock,
windowUpdateType: WindowUpdateTypeMock,
bundleName: "[PC Preview] unknow bundleName",
componentType: "[PC Preview] unknow componentType",
pageId: "[PC Preview] unknow pageId",
description: "[PC Preview] unknow description",
triggerAction: ActionMock,
textMoveUnit: TextMoveUnitMock,
contents: "[PC Preview] unknow contents",
lastContent: "[PC Preview] unknow lastContent",
beginIndex: "[PC Preview] unknow beginIndex",
currentIndex: "[PC Preview] unknow currentIndex",
endIndex: "[PC Preview] unknow endIndex",
itemCount: "[PC Preview] unknow itemCount",
const TextMoveUnitMock = '[PC Preview] unknow TextMoveUnit';
const EventInfoClass = class EventInfo {
constructor(jsonObject) {
console.warn('accessibility.EventInfoClass.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.type = EventTypeMock;
this.windowUpdateType = WindowUpdateTypeMock;
this.bundleName = '[PC Preview] unknow bundleName';
this.componentType = '[PC Preview] unknow componentType';
this.pageId = '[PC Preview] unknow pageId';
this.description = '[PC Preview] unknow description';
this.triggerAction = ActionMock;
this.textMoveUnit = TextMoveUnitMock;
this.contents = '[PC Preview] unknow contents';
this.lastContent = '[PC Preview] unknow lastContent';
this.beginIndex = '[PC Preview] unknow beginIndex';
this.currentIndex = '[PC Preview] unknow currentIndex';
this.endIndex = '[PC Preview] unknow endIndex';
this.itemCount = '[PC Preview] unknow itemCount';
}
};
const StateEventMock = {
eventType: '[PC Preview] unknow eventType',
state: '[PC Preview] unknow state',
description: '[PC Preview] unknow description'
};
global.systemplugin.accessibility = {
isOpenAccessibility: function (...args) {
console.warn("accessibility.isOpenAccessibility 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
EventInfo: EventInfoClass,
isOpenAccessibility: function(...args) {
console.warn('accessibility.isOpenAccessibility 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)
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramBooleanMock);
})
});
}
},
isOpenTouchGuide: function (...args) {
console.warn("accessibility.isOpenTouchGuide 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
isOpenTouchGuide: function(...args) {
console.warn('accessibility.isOpenTouchGuide 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)
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
} else {
return new Promise((resolve) => {
resolve(paramMock.paramBooleanMock);
})
});
}
},
on: function (...args) {
console.warn("accessibility.on 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
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
on: function(...args) {
console.warn('accessibility.on 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;
args[len - 1].call(this, paramMock.businessErrorMock, StateEventMock);
},
off: function (...args) {
console.warn("accessibility.off 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 (len === 0) {
return
}
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
off: function(...args) {
console.warn('accessibility.off 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, StateEventMock);
} else {
return
return;
}
},
getAbilityLists: function (...args) {
console.warn("accessibility.getAbilityLists 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
getAbilityLists: function(...args) {
console.warn('accessibility.getAbilityLists 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, [AccessibilityAbilityInfoMock])
args[len - 1].call(this, paramMock.businessErrorMock, [AccessibilityAbilityInfoMock]);
} else {
return new Promise((resolve, reject) => {
resolve([AccessibilityAbilityInfoMock]);
})
});
}
},
sendEvent: function (...args) {
console.warn("accessibility.sendEvent 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 (len === 1 && args[0].className === 'EventInfo') {
return
} else if (len === 2 && args[0].className === 'EventInfo' && typeof args[1] === 'function') {
args[1].call(this, paramMock.businessErrorMock, EventInfoMock)
} else if (len === 2 && typeof args[0] === 'string' && typeof args[1] === 'function') {
args[1].call(this, paramMock.businessErrorMock)
sendEvent: function(...args) {
console.warn('accessibility.sendEvent 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, reject) => {
resolve();
})
});
}
},
}
};
}

View File

@ -1,166 +1,379 @@
import {paramMock} from "./utils"
import {paramMock} from './utils';
export function mockCalendar() {
const arr = ["accId", "availableStatus", "syncId", "description", "duration",
"endTimezone", "eventColour", "eventColourIndex", "eventEndTime", "eventPosition", "eventStartTime", "eventStatus",
"initialId", "recurDate", "recurRule", "startTimezone", "title", "hasAlarm", "hasAttendeeInfo", "isWholeDay"]
const infoMock = {
isDeleted: "[PC preview] unknown isDeleted",
isUpdated: "[PC preview] unknown isUpdated",
isInsert: "[PC preview] unknown isInsert",
number: "[PC preview] unknown number",
const CalendarEntityClass = class CalendarEntity {
constructor() {
console.warn('calendar.CalendarEntity.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.id = '[PC preview] unknown id';
}
const event1 = {
accId: "[PC preview] unknown accId",
availableStatus: "[PC preview] unknown availableStatus",
syncId: "[PC preview] unknown syncId",
description: "[PC preview] unknown description",
duration: "[PC preview] unknown duration",
endTimezone: "[PC preview] unknown endTimezone",
eventColour: "[PC preview] unknown eventColour",
eventColourIndex: "[PC preview] unknown eventColourIndex",
eventEndTime: "[PC preview] unknown eventEndTime",
eventPosition: "[PC preview] unknown eventPosition",
eventStartTime: "[PC preview] unknown eventStartTime",
eventStatus: "[PC preview] unknown eventStatus",
initialId: "[PC preview] unknown initialId",
recurDate: "[PC preview] unknown recurDate",
recurRule: "[PC preview] unknown recurRule",
startTimezone: "[PC preview] unknown startTimezone",
title: "[PC preview] unknown title",
hasAlarm: "[PC preview] unknown hasAlarm",
hasAttendeeInfo: "[PC preview] unknown hasAttendeeInfo",
isWholeDay: "[PC preview] unknown isWholeDay",
};
CalendarEntityClass.ACC_TYPE_LOCAL = 'LOCAL';
CalendarEntityClass.IS_SYNC_ADAPTER = 'caller_is_syncadapter';
const AccountsClass = class Accounts extends CalendarEntityClass {
constructor() {
super();
console.warn('calendar.Accounts.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.name = '[PC preview] unknown name';
this.accName = '[PC preview] unknown accName';
this.accType = '[PC preview] unknown accType';
this.accColour = '[PC preview] unknown accColour';
this.accDisplayName = '[PC preview] unknown accDisplayName';
this.visible = '[PC preview] unknown visible';
this.accTimezone = '[PC preview] unknown accTimezone';
this.isSyncEvents = '[PC preview] unknown isSyncEvents';
this.remindersType = '[PC preview] unknown remindersType';
this.attendeeTypes = '[PC preview] unknown attendeeTypes';
}
const helper = {
queryEntityName: "[PC preview] unknown queryEntityName",
};
AccountsClass.NAME = 'name';
const EventsClass = class Events extends CalendarEntityClass {
constructor() {
super();
console.warn('calendar.Events.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.accId = '[PC preview] unknown accId';
this.title = '[PC preview] unknown title';
this.description = '[PC preview] unknown description';
this.eventPosition = '[PC preview] unknown eventPosition';
this.eventStatus = '[PC preview] unknown eventStatus';
this.eventStartTime = '[PC preview] unknown eventStartTime';
this.eventEndTime = '[PC preview] unknown eventEndTime';
this.duration = '[PC preview] unknown duration';
this.isWholeDay = '[PC preview] unknown isWholeDay';
this.availableStatus = '[PC preview] unknown availableStatus';
this.hasAlarm = '[PC preview] unknown hasAlarm';
this.recurRule = '[PC preview] unknown recurRule';
this.recurDate = '[PC preview] unknown recurDate';
this.initialId = '[PC preview] unknown initialId';
this.hasAttendeeInfo = '[PC preview] unknown hasAttendeeInfo';
}
const CalendarCollectionMock = {
handler: "[PC preview] unknown handler",
count: function (...args) {
console.warn("calendar.CalendarCollection.count interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
};
const InstancesClass = class Instances extends CalendarEntityClass {
constructor() {
super();
console.warn('calendar.Instances.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.instanceBegin = '[PC preview] unknown instanceBegin';
this.instanceEnd = '[PC preview] unknown instanceEnd';
this.eventId = '[PC preview] unknown eventId';
this.instanceStartDay = '[PC preview] unknown instanceStartDay';
this.instanceEndDay = '[PC preview] unknown instanceEndDay';
this.instanceStartMinute = '[PC preview] unknown instanceStartMinute';
this.instanceEndMinute = '[PC preview] unknown instanceEndMinute';
}
};
const ParticipantsClass = class Participants extends CalendarEntityClass {
constructor() {
super();
console.warn('calendar.Participants.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.eventId = '[PC preview] unknown eventId';
this.participantName = '[PC preview] unknown participantName';
this.participantEmail = '[PC preview] unknown participantEmail';
this.participantRoleType = '[PC preview] unknown participantRoleType';
this.participantType = '[PC preview] unknown participantType';
this.participantStatus = '[PC preview] unknown participantStatus';
}
};
const RemindersClass = class Reminders extends CalendarEntityClass {
constructor() {
super();
console.warn('calendar.Reminders.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.eventId = '[PC preview] unknown eventId';
this.remindMinutes = '[PC preview] unknown remindMinutes';
this.remindType = '[PC preview] unknown remindType';
this.syncId = '[PC preview] unknown syncId';
}
};
const AppletEntityClass = class AppletEntity {
constructor() {
console.warn('calendar.AppletEntity.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.title = '[PC preview] unknown title';
this.startTime = '[PC preview] unknown startTime';
this.allDay = '[PC preview] unknown allDay';
this.description = '[PC preview] unknown description';
this.location = '[PC preview] unknown location';
this.endTime = '[PC preview] unknown endTime';
this.alarm = '[PC preview] unknown alarm';
this.alarmOffset = '[PC preview] unknown alarmOffset';
this.repeatInterval = '[PC preview] unknown repeatInterval';
this.repeatEndTime = '[PC preview] unknown repeatEndTime';
}
};
const AppletRepeatEntityClass = class AppletRepeatEntity extends AppletEntityClass {
constructor() {
super();
console.warn('calendar.AppletRepeatEntity.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.repeatInterval = '[PC preview] unknown repeatInterval';
this.repeatEndTime = '[PC preview] unknown repeatEndTime';
}
};
const CalendarCollectionClass = class CalendarCollection {
constructor() {
this.handler = '[PC preview] unknown handler';
this.close = function (...args) {
console.warn('calendar.CalendarCollection.close interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
};
this.count = function (...args) {
console.warn('calendar.CalendarCollection.count interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return paramMock.paramNumberMock;
},
next: function (...args) {
console.warn("calendar.CalendarCollection.next interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return infoMock.event1;
},
close: function (...args) {
console.warn("calendar.CalendarCollection.close interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
},
hasNext: function (...args) {
console.warn("calendar.CalendarCollection.hasNext interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
};
this.next = function (...args) {
console.warn('calendar.CalendarCollection.next interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new CalendarEntityClass();
};
this.hasNext = function (...args) {
console.warn('calendar.CalendarCollection.hasNext interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return paramMock.paramBooleanMock;
};
}
}
global.systemplugin.calendar = {
addPhoneCalendar: function (...args) {
console.warn("calendar.addPhoneCalendar 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
};
const CalendarDataHelperClass = class CalendarDataHelper {
constructor() {
this.name = '[PC preview] unknown queryEntityName';
this.query = function (...args) {
console.warn('calendar.CalendarDataHelper.query 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)
args[len - 1].call(this, paramMock.businessErrorMock, new CalendarCollectionClass());
} else {
return new Promise((resolve) => {
resolve()
resolve(new CalendarCollectionClass());
});
}
};
this.insert = function (...args) {
console.warn('calendar.CalendarDataHelper.insert 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);
});
}
};
this.update = function (...args) {
console.warn('calendar.CalendarDataHelper.update 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();
});
}
};
this.delete = function (...args) {
console.warn('calendar.CalendarDataHelper.delete 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') {
if (typeof args[0] === 'number') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else if (args[0] instanceof CalendarEntityClass) {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
}
} else {
if (typeof args[0] === 'number') {
return new Promise((resolve) => {
resolve();
});
} else if (args[0] instanceof CalendarEntityClass) {
return new Promise((resolve) => {
resolve();
});
} else {
return new Promise((resolve) => {
resolve(paramMock.paramNumberMock);
});
}
}
};
}
};
CalendarDataHelperClass.creator = function (...args) {
console.warn('calendar.CalendarDataHelper.creator interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new CalendarDataHelperClass();
};
global.systemplugin.calendar = {
BaseColumns: {
COUNT: "_count",
ID: "_id"
},
AccountColumns: {
ACC_COLOR: "calendar_color",
ACC_COLOR_INDEX: "calendar_color_index",
ACC_DISPLAY_NAME: "calendar_displayName",
VISIBLE: "visible",
ACC_TIME_ZONE: "calendar_timezone",
IS_SYNC_EVENTS: "sync_events",
REMINDERS_TYPE: "allowedReminders",
AVAILABILITY_STATUS: "allowedAvailability",
ATTENDEE_TYPES: "allowedAttendeeTypes",
IS_PRIMARY: "isPrimary"
},
AccountSyncColumns: {
ACC_SYNC1: "cal_sync1",
ACC_SYNC2: "cal_sync2",
ACC_SYNC3: "cal_sync3",
ACC_SYNC4: "cal_sync4",
ACC_SYNC5: "cal_sync5",
ACC_SYNC6: "cal_sync6",
ACC_SYNC7: "cal_sync7",
ACC_SYNC8: "cal_sync8",
ACC_SYNC9: "cal_sync9",
ACC_SYNC10: "cal_sync10"
},
EventsColumns: {
ACC_ID: "calendar_id",
TITLE: "title",
DESCRIPTION: "description",
EVENT_POSITION: "eventLocation",
EVENT_STATUS: "eventStatus",
EVENT_STATUS_TENTATIVE: 0,
EVENT_STATUS_CONFIRMED: 1,
EVENT_STATUS_CANCELED: 2,
OWNER_ATTENDEE_STATUS: "selfAttendeeStatus",
EXTEND_DATA1: "sync_data1",
EXTEND_DATA2: "sync_data2",
EXTEND_DATA3: "sync_data3",
EXTEND_DATA4: "sync_data4",
EXTEND_DATA5: "sync_data5",
EXTEND_DATA6: "sync_data6",
D_DATA7: "sync_data7",
EXTEND_DATA8: "sync_data8",
EXTEND_DATA9: "sync_data9",
EXTEND_DATA10: "sync_data10",
EVENT_START_TIME: "dtstart",
EVENT_END_TIME: "dtend",
DURATION: "duration",
START_TIMEZONE: "eventTimezone",
END_TIMEZONE: "eventEndTimezone",
IS_WHOLE_DAY: "allDay",
PERMISSION_LEVEL: "accessLevel",
PERMISSION_DEFAULT: 0,
PERMISSION_CONFIDENTIAL: 1,
PERMISSION_PRIVATE: 2,
PERMISSION_PUBLIC: 3,
AVAILABLE_STATUS: "availability",
STATUS_BUSY: 0,
STATUS_FREE: 1,
STATUS_TENTATIVE: 2,
HAS_ALARM: "hasAlarm",
HAS_EXTENDED_ATTRIBUTES: "hasExtendedProperties",
RECUR_RULE: "rrule",
RECUR_DATE: "rdate",
INITIAL_ID: "original_id",
INITIAL_SYNC_ID: "original_sync_id",
HAS_ATTENDEE_INFO: "hasAttendeeData",
ORGANIZER_EMAIL: "organizer"
},
InstancesColumns: {
EVENT_ID: "event_id",
INSTANCE_START: "begin",
INSTANCE_END: "end",
INSTANCE_START_DAY: "startDay",
INSTANCE_END_DAY: "endDay",
INSTANCE_START_MINUTE: "startMinute",
INSTANCE_END_MINUTE: "endMinute"
},
ParticipantsColumns: {
EVENT_ID: "event_id",
PARTICIPANT_NAME: "attendeeName",
PARTICIPANT_EMAIL: "attendeeEmail",
PARTICIPANT_ROLE_TYPE: "attendeeRelationship",
ROLE_NONE: 0,
ROLE_ATTENDEE: 1,
ROLE_ORGANIZER: 2,
ROLE_PERFORMER: 3,
ROLE_SPEAKER: 4,
PARTICIPANT_TYPE: "attendeeType",
TYPE_NONE: 0,
TYPE_REQUIRED: 1,
TYPE_OPTIONAL: 2,
TYPE_RESOURCE: 3,
PARTICIPANT_STATUS: "attendeeStatus",
PARTICIPANT_STATUS_NONE: 0,
PARTICIPANT_STATUS_ACCEPTED: 1,
PARTICIPANT_STATUS_DECLINED: 2,
PARTICIPANT_STATUS_INVITED: 3,
PARTICIPANT_STATUS_TENTATIVE: 4
},
RemindersColumns: {
EVENT_ID: "event_id",
REMIND_MINUTES: "minutes",
REMIND_MINUTES_DEFAULT: -1,
REMIND_TYPE: "method",
TYPE_DEFAULT: 0,
TYPE_ALERT: 1,
TYPE_EMAIL: 2,
TYPE_SMS: 3,
TYPE_ALARM: 4
},
SyncColumns: {
ACC_NAME: "account_name",
ACC_TYPE: "account_type",
SYNC_ID: "_sync_id",
DIRTY: "dirty",
CALLING_BUNDLE_NAME: "mutators",
DELETED: "deleted"
},
queryEntityName: {
EVENTS: "EVENTS",
ACCOUNTS: "ACCOUNTS",
INSTANCES: "INSTANCES",
PARTICIPANTS: "PARTICIPANTS",
REMINDERS: "REMINDERS"
},
CalendarEntity: CalendarEntityClass,
Accounts: AccountsClass,
Events: EventsClass,
Instances: InstancesClass,
Participants: ParticipantsClass,
Reminders: RemindersClass,
AppletEntity: AppletEntityClass,
AppletRepeatEntity: AppletRepeatEntityClass,
CalendarCollection: CalendarCollectionClass,
CalendarDataHelper: CalendarDataHelperClass,
addPhoneCalendar: function (...args) {
console.warn('calendar.addPhoneCalendar 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();
});
}
},
addPhoneRepeatCalendar: function (...args) {
console.warn("calendar.addPhoneRepeatCalendar 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()
});
}
},
CalendarDataHelper: {
name: '[PC preview] unknown queryEntityName',
creator: function (...args) {
console.warn("calendar.CalendarDataHelper.creator interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return global.systemplugin.calendar.CalendarDataHelper;
},
query: function (...args) {
console.warn("calendar.CalendarDataHelper.query 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, CalendarCollectionMock)
} else {
return new Promise((resolve) => {
resolve(CalendarCollectionMock)
});
}
},
delete: function (...args) {
console.warn("calendar.CalendarDataHelper.delete interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
console.warn('calendar.addPhoneRepeatCalendar 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 (!Array.prototype.subsetTo) {
Array.prototype.subsetTo = function (arr) {
return this.every(v => arr.includes(v));
}
}
if (typeof args[len - 1] === 'function') {
if (typeof args[len - 2] === 'number') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else if (Object.getOwnPropertyNames(args[len - 2]).subsetTo(arr)) {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
args[len - 1].call(this, paramMock.businessErrorMock, infoMock.number);
}
} else {
if (typeof args(len - 1) === 'number') {
return new Promise((resolve) => {
resolve()
});
} else if (Object.getOwnPropertyNames(args[len - 1]).subsetTo(arr)) {
return new Promise((resolve) => {
resolve()
});
} else {
return new Promise((resolve) => {
resolve(infoMock.number)
resolve();
});
}
}
},
update: function (...args) {
console.warn("calendar.CalendarDataHelper.update 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, infoMock.isUpdated)
} else {
return new Promise((resolve) => {
resolve(infoMock.isUpdated)
});
}
},
insert: function (...args) {
console.warn("calendar.CalendarDataHelper.insert 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, infoMock.isInsert)
} else {
return new Promise((resolve) => {
resolve(infoMock.isInsert)
});
}
},
}
}
};
}

View File

@ -1,35 +1,259 @@
import { paramMock } from "./utils"
import {paramMock} from "./utils"
export function mockContact () {
const contactMock = {
contactAttributes:"[PC Preview] unknow contactAttributes",
id:"[PC Preview] unknow id",
key:"[PC Preview] unknow key",
emails:"[PC Preview] unknow emails",
events:"[PC Preview] unknow events",
groups:"[PC Preview] unknow groups",
imAddresses:"[PC Preview] unknow imAddresses",
phoneNumbers:"[PC Preview] unknow phoneNumbers",
portrait:"[PC Preview] unknow portrait",
postalAddresses:"[PC Preview] unknow postalAddresses",
relations:"[PC Preview] unknow relations",
sipAddresses:"[PC Preview] unknow sipAddresses",
websites:"[PC Preview] unknow websites",
name:"[PC Preview] unknow name",
nickName:"[PC Preview] unknow nickName",
note:"[PC Preview] unknow note",
organization:"[PC Preview] unknow organization",
export function mockContact() {
const ContactClass = class Contact {
constructor() {
console.warn('contact.Contact.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.id = "[PC Preview] unknow id";
this.key = "[PC Preview] unknow key";
this.contactAttributes = "[PC Preview] unknow contactAttributes";
this.emails = "[PC Preview] unknow emails";
this.events = "[PC Preview] unknow events";
this.groups = "[PC Preview] unknow groups";
this.imAddresses = "[PC Preview] unknow imAddresses";
this.phoneNumbers = "[PC Preview] unknow phoneNumbers";
this.portrait = "[PC Preview] unknow portrait";
this.postalAddresses = "[PC Preview] unknow postalAddresses";
this.relations = "[PC Preview] unknow relations";
this.sipAddresses = "[PC Preview] unknow sipAddresses";
this.websites = "[PC Preview] unknow websites";
this.name = "[PC Preview] unknow name";
this.nickName = "[PC Preview] unknow nickName";
this.note = "[PC Preview] unknow note";
this.organization = "[PC Preview] unknow organization";
}
const holderMock = {
holderId:"[PC Preview] unknow holderId",
bundleName:"[PC Preview] unknow bundleName",
displayName:"[PC Preview] unknow displayName",
}
const groupMock = {
groupId:"[PC Preview] unknow groupId",
title:"[PC Preview] unknow title"
const ContactAttributesClass = class ContactAttributes {
constructor() {
console.warn('contact.ContactAttributes.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.attributes = ["[PC Preview] unknow Attribute"]
}
}
const EmailClass = class Email {
constructor() {
console.warn('contact.Email.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.EMAIL_HOME = 1;
this.EMAIL_WORK = 2;
this.EMAIL_OTHER = 3;
this.INVALID_LABEL_ID = -1;
this.email = "[PC Preview] unknow email";
this.labelName = "[PC Preview] unknow labelName";
this.displayName = "[PC Preview] unknow displayName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const EventClass = class Event {
constructor() {
console.warn('contact.Event.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.EVENT_ANNIVERSARY = 1;
this.EVENT_OTHER = 2;
this.EVENT_BIRTHDAY = 3;
this.INVALID_LABEL_ID = -1;
this.eventDate = "[PC Preview] unknow eventDate";
this.labelName = "[PC Preview] unknow labelName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const GroupClass = class Group {
constructor() {
console.warn('contact.Group.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.groupId = "[PC Preview] unknow groupId";
this.title = "[PC Preview] unknow title";
}
}
const HolderClass = class Holder {
constructor() {
console.warn('contact.Holder.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.bundleName = "[PC Preview] unknow bundleName";
this.displayName = "[PC Preview] unknow displayName";
this.holderId = "[PC Preview] unknow holderId";
}
}
const ImAddressClass = class ImAddress {
constructor() {
console.warn('contact.ImAddress.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = -1;
this.IM_AIM = 0;
this.IM_MSN = 1;
this.IM_YAHOO = 2;
this.IM_SKYPE = 3;
this.IM_QQ = 4;
this.IM_ICQ = 6;
this.IM_JABBER = 7;
this.INVALID_LABEL_ID = -2;
this.imAddress = "[PC Preview] unknow imAddress";
this.labelName = "[PC Preview] unknow labelName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const NameClass = class Name {
constructor() {
console.warn('contact.Name.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.familyName = "[PC Preview] unknow familyName";
this.familyNamePhonetic = "[PC Preview] unknow familyNamePhonetic";
this.fullName = "[PC Preview] unknow fullName";
this.givenName = "[PC Preview] unknow givenName";
this.givenNamePhonetic = "[PC Preview] unknow givenNamePhonetic";
this.middleNamePhonetic = "[PC Preview] unknow middleNamePhonetic";
this.namePrefix = "[PC Preview] unknow namePrefix";
this.nameSuffix = "[PC Preview] unknow nameSuffix";
}
}
const NickNameClass = class NickName {
constructor() {
console.warn('contact.NickName.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.nickName = "[PC Preview] unknow nickName";
}
}
const NoteClass = class Note {
constructor() {
console.warn('contact.Note.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.noteContent = "[PC Preview] unknow noteContent";
}
}
const OrganizationClass = class Organization {
constructor() {
console.warn('contact.Organization.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.name = "[PC Preview] unknow name";
this.title = "[PC Preview] unknow title";
}
}
const PhoneNumberClass = class PhoneNumber {
constructor() {
console.warn('contact.PhoneNumber.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.NUM_HOME = 1;
this.NUM_MOBILE = 2;
this.NUM_WORK = 3;
this.NUM_FAX_WORK = 4;
this.NUM_FAX_HOME = 5;
this.NUM_PAGER = 6;
this.NUM_OTHER = 7;
this.NUM_CALLBACK = 8;
this.NUM_CAR = 9;
this.NUM_COMPANY_MAIN = 10;
this.NUM_ISDN = 11;
this.NUM_MAIN = 12;
this.NUM_OTHER_FAX = 13;
this.NUM_RADIO = 14;
this.NUM_TELEX = 15;
this.NUM_TTY_TDD = 16;
this.NUM_WORK_MOBILE = 17;
this.NUM_WORK_PAGER = 18;
this.NUM_ASSISTANT = 19;
this.NUM_MMS = 20;
this.INVALID_LABEL_ID = -1;
this.phoneNumber = "[PC Preview] unknow phoneNumber";
this.labelName = "[PC Preview] unknow labelName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const PortraitClass = class Portrait {
constructor() {
console.warn('contact.Portrait.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.uri = "[PC Preview] unknow uri";
}
}
const PostalAddressClass = class PostalAddress {
constructor() {
console.warn('contact.PostalAddress.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.ADDR_HOME = 1;
this.ADDR_WORK = 2;
this.ADDR_OTHER = 3;
this.INVALID_LABEL_ID = -1;
this.city = "[PC Preview] unknow city";
this.country = "[PC Preview] unknow country";
this.labelName = "[PC Preview] unknow labelName";
this.neighborhood = "[PC Preview] unknow neighborhood";
this.pobox = "[PC Preview] unknow pobox";
this.postalAddress = "[PC Preview] unknow postalAddress";
this.postcode = "[PC Preview] unknow postcode";
this.region = "[PC Preview] unknow region";
this.street = "[PC Preview] unknow street";
this.labelId = "[PC Preview] unknow labelId";
}
}
const RelationClass = class Relation {
constructor() {
console.warn('contact.Relation.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.RELATION_ASSISTANT = 1;
this.RELATION_BROTHER = 2;
this.RELATION_CHILD = 3;
this.RELATION_DOMESTIC_PARTNER = 4;
this.RELATION_FATHER = 5;
this.RELATION_FRIEND = 6;
this.RELATION_MANAGER = 7;
this.RELATION_MOTHER = 8;
this.RELATION_PARENT = 9;
this.RELATION_PARTNER = 10;
this.RELATION_REFERRED_BY = 11;
this.RELATION_RELATIVE = 12;
this.RELATION_SISTER = 13;
this.RELATION_SPOUSE = 14;
this.INVALID_LABEL_ID = -1;
this.relationName = "[PC Preview] unknow relationName";
this.labelName = "[PC Preview] unknow labelName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const SipAddressClass = class SipAddress {
constructor() {
console.warn('contact.SipAddress.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.CUSTOM_LABEL = 0;
this.SIP_HOME = 1;
this.SIP_WORK = 2;
this.SIP_OTHER = 3;
this.INVALID_LABEL_ID = -1;
this.sipAddress = "[PC Preview] unknow sipAddress";
this.labelName = "[PC Preview] unknow labelName";
this.labelId = "[PC Preview] unknow labelId";
}
}
const WebsiteClass = class Website {
constructor() {
console.warn('contact.Website.constructor interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
this.website = "[PC Preview] unknow website";
}
}
global.systemplugin.contact = {
Contact: ContactClass,
ContactAttributes: ContactAttributesClass,
Email: EmailClass,
Event: EventClass,
Group: GroupClass,
Holder: HolderClass,
ImAddress: ImAddressClass,
Name: NameClass,
NickName: NickNameClass,
Note: NoteClass,
Organization: OrganizationClass,
PhoneNumber: PhoneNumberClass,
Portrait: PortraitClass,
PostalAddress: PostalAddressClass,
Relation: RelationClass,
SipAddress: SipAddressClass,
Website: WebsiteClass,
addContact: function (...args) {
console.warn("contact.addContact interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
@ -46,7 +270,7 @@ export function mockContact () {
console.warn("contact.selectContact interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(contactMock);
array.push(new ContactClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -73,10 +297,10 @@ export function mockContact () {
" 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, contactMock)
args[len - 1].call(this, paramMock.businessErrorMock, new ContactClass())
} else {
return new Promise((resolve) => {
resolve(contactMock)
resolve(new ContactClass())
});
}
},
@ -84,7 +308,7 @@ export function mockContact () {
console.warn("contact.queryContacts interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(contactMock);
array.push(new ContactClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -98,7 +322,7 @@ export function mockContact () {
console.warn("contact.queryContactsByEmail interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(contactMock);
array.push(new ContactClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -112,7 +336,7 @@ export function mockContact () {
console.warn("contact.queryContactsByPhoneNumber interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(contactMock);
array.push(new ContactClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -126,7 +350,7 @@ export function mockContact () {
console.warn("contact.queryGroups interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(groupMock);
array.push(new GroupClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -140,7 +364,7 @@ export function mockContact () {
console.warn("contact.queryHolders interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(holderMock);
array.push(new HolderClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)
@ -166,7 +390,7 @@ export function mockContact () {
console.warn("contact.queryMyCard interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var array = new Array();
array.push(contactMock);
array.push(new ContactClass());
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, array)

View File

@ -62,7 +62,7 @@ import { mockSystemPackage } from './systemPackage'
import { mockUserauth } from './userIAM'
import { mockVibrator } from './vibrator'
import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics } from './net'
import { mockWebSocket, mockHttp, mockMdns, mockSocket, mockHotspot, mockStatistics, mockConnection } from './net'
import { mockWifi } from './ohos/wifi'
import { mockWindow } from './window'
import { mockWorkScheduler } from './ohos/workScheduler'
@ -139,6 +139,7 @@ export function mockSystemPlugin() {
mockSocket()
mockHotspot()
mockStatistics()
mockConnection()
mockDeviceInfo()
mockWifi()
mockResourceManager()

View File

@ -444,6 +444,127 @@ export function mockMultimediaMedia() {
}
}
}
const MimeTypeMock = '[PC Preview] unknow mimeType'
const CodecDescriptionMock = {
name: "[PC Preview] unknow name",
mimeTypes: new Array(MimeTypeMock),
isAudio: "[PC Preview] unknow isAudio",
isEncoder: "[PC Preview] unknow isEncoder",
isSoftware: "[PC Preview] unknow isSoftware",
}
const codecDescriptionHelperMock = {
findDecoder: function (...args) {
console.warn("CodecDescriptionHelper.findDecoder 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, CodecDescriptionMock);
} else {
return new Promise((resolve, reject) => {
resolve(CodecDescriptionMock);
})
}
},
findEncoder: function (...args) {
console.warn("CodecDescriptionHelper.findEncoder 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, CodecDescriptionMock);
} else {
return new Promise((resolve, reject) => {
resolve(CodecDescriptionMock);
})
}
},
getSupportedDecoders: function (...args) {
console.warn("CodecDescriptionHelper.getSupportedDecoders 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
var CodecDescriptionArray = new Array(CodecDescriptionMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray);
} else {
return new Promise((resolve, reject) => {
resolve(CodecDescriptionArray);
})
}
},
getSupportedEncoders: function (...args) {
console.warn("CodecDescriptionHelper.getSupportedEncoders 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
var CodecDescriptionArray = new Array(CodecDescriptionMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray);
} else {
return new Promise((resolve, reject) => {
resolve(CodecDescriptionArray);
})
}
},
getSupportedMimes: function (...args) {
console.warn("CodecDescriptionHelper.getSupportedMimes 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
var MimeTypeArray = new Array(MimeTypeMock)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, MimeTypeArray);
} else {
return new Promise((resolve, reject) => {
resolve(MimeTypeArray);
})
}
},
isDecoderSupportedByFormat: function (...args) {
console.warn("CodecDescriptionHelper.isDecoderSupportedByFormat 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, reject) => {
resolve(paramMock.paramBooleanMock);
})
}
},
isDecoderSupportedByMime: function (...args) {
console.warn("CodecDescriptionHelper.isDecoderSupportedByMime 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, reject) => {
resolve(paramMock.paramBooleanMock);
})
}
},
isEncoderSupportedByFormat: function (...args) {
console.warn("CodecDescriptionHelper.isEncoderSupportedByFormat 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, reject) => {
resolve(paramMock.paramBooleanMock);
})
}
},
isEncoderSupportedByMime: function (...args) {
console.warn("CodecDescriptionHelper.findDisEncoderSupportedByMime 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, reject) => {
resolve(paramMock.paramBooleanMock);
})
}
}
}
global.systemplugin.multimedia.media = {
MediaType: {
VIDEO: 0,
@ -468,6 +589,11 @@ export function mockMultimediaMedia() {
console.warn("multimedia.media.createMediaDecoder interface mocked in the Previewer. How this interface works" +
" on the Previewer may be different from that on a real device.")
return mediaDecoderMock;
},
getCodecDescriptionHelper: function () {
console.warn("multimedia.media.getCodecDescriptionHelper interface mocked in the Previewer. How this" +
" interface works on the Previewer may be different from that on a real device.")
return codecDescriptionHelperMock;
}
}
}
@ -915,7 +1041,7 @@ export function mockMultimediaAudio() {
}
},
setMicrophoneMute: function (...args) {
console.warn("AudioManager.isMicrophoneMute interface mocked in the Previewer. How this interface works on the" +
console.warn("AudioManager.setMicrophoneMute 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') {

View File

@ -0,0 +1,317 @@
import {paramMock} from "../../utils"
const ModuleInfoMock = {
moduleName: '[PC preview] unknow moduleName',
moduleSourceDir: '[PC preview] unknow moduleSourceDir',
}
export const AbilityInfoMock = {
bundleName: '[PC preview] unknow bundleName',
name: '[PC preview] unknow name',
label: '[PC preview] unknow label',
description: '[PC preview] unknow description',
icon: '[PC preview] unknow icon',
labelId: '[PC preview] unknow labelId',
descriptionId: '[PC preview] unknow descriptionId',
iconId: '[PC preview] unknow iconId',
moduleName: '[PC preview] unknow moduleName',
process: '[PC preview] unknow process',
targetAbility: '[PC preview] unknow targetAbility',
backgroundModes: '[PC preview] unknow backgroundModes',
isVisible: '[PC preview] unknow isVisible',
abilityTypeMock: '[PC preview] unknow abilityTypeMock',
AbilitySubTypeMock: '[PC preview] unknow AbilitySubTypeMock',
DisplayOrientationMock: '[PC preview] unknow DisplayOrientationMock',
launchModeMock: '[PC preview] unknow launchModeMock',
formEnabled: '[PC preview] unknow formEnabled',
permissions: [paramMock.paramStringMock],
deviceTypes: [paramMock.paramStringMock],
deviceCapabilities: [paramMock.paramStringMock],
readPermission: '[PC preview] unknow readPermission',
writePermission: '[PC preview] unknow writePermission',
applicationInfo: applicationInfoMock,
formEntity: '[PC preview] unknow formEntity',
minFormHeight: '[PC preview] unknow minFormHeight',
defaultFormHeight: '[PC preview] unknow defaultFormHeight',
minFormWidth: '[PC preview] unknow minFormWidth',
defaultFormWidth: '[PC preview] unknow defaultFormWidth',
uri: '[PC preview] unknow uri',
customizeData: new Map([["[PC Preview] unknow customizeDataKey", "[PC Preview] unknow customizeDataValue"]])
}
const applicationInfoMock = {
name: '[PC preview] unknow name',
description: '[PC preview] unknow description',
descriptionId: '[PC preview] unknow descriptionId',
systemApp: '[PC preview] unknow systemApp',
enabled: '[PC preview] unknow enabled',
label: '[PC preview] unknow label',
labelId: '[PC preview] unknow labelId',
icon: '[PC preview] unknow icon',
iconId: '[PC preview] unknow iconId',
process: '[PC preview] unknow process',
supportedModes: '[PC preview] unknow supportedModes',
moduleSourceDirs: [paramMock.paramStringMock],
permissions: [paramMock.paramStringMock],
moduleInfo: [ModuleInfoMock],
entryDir: '[PC preview] unknow entryDir',
codepath: '[PC preview] unknow codepath',
removable: '[PC preview] unknow removable',
customizeData: new Map([["[PC Preview] unknow customizeDataKey", "[PC Preview] unknow customizeDataValue"]])
}
const HapModuleInfoMock = {
name: '[PC preview] unknow name',
description: '[PC preview] unknow description',
descriptionId: '[PC preview] unknow descriptionId',
icon: '[PC preview] unknow icon',
label: '[PC preview] unknow label',
labelId: '[PC preview] unknow labelId',
iconId: '[PC preview] unknow iconId',
backgroundImg: '[PC preview] unknow backgroundImg',
supportedModes: '[PC preview] unknow supportedModes',
reqCapabilities: [paramMock.paramStringMock],
deviceTypes: [paramMock.paramStringMock],
abilityInfo: AbilityInfoMock,
moduleName: '[PC preview] unknow moduleName',
mainAbilityName: '[PC preview] unknow mainAbilityName',
installationFree: '[PC preview] unknow installationFree',
}
const screenDensityMock = {
SCREEN_SDPI: '[PC preview] unknow SCREEN_SDPI',
SCREEN_MDPI: '[PC preview] unknow SCREEN_MDPI',
SCREEN_LDPI: '[PC preview] unknow SCREEN_LDPI',
SCREEN_XLDPI: '[PC preview] unknow SCREEN_XLDPI',
SCREEN_XXLDPI: '[PC preview] unknow SCREEN_XXLDPI',
SCREEN_XXXLDPI: '[PC preview] unknow SCREEN_XXXLDPI'
}
const deviceTypeMock = {
DEVICE_TYPE_PHONE: '[PC preview] unknow DEVICE_TYPE_PHONE',
DEVICE_TYPE_TABLET: '[PC preview] unknow DEVICE_TYPE_TABLET',
DEVICE_TYPE_CAR: '[PC preview] unknow DEVICE_TYPE_CAR',
DEVICE_TYPE_PC: '[PC preview] unknow DEVICE_TYPE_PC',
DEVICE_TYPE_TV: '[PC preview] unknow DEVICE_TYPE_TV',
DEVICE_TYPE_WEARABLE: '[PC preview] unknow DEVICE_TYPE_WEARABLE'
}
const DeviceCapabilityClass = class DeviceCapability {
constructor() {
console.warn('DeviceCapability.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
screenDensity = screenDensityMock,
deviceType = deviceTypeMock
}
}
const configurationClass = class configuration{
constructor() {
console.warn('configuration.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
directionMock = '[PC preview] unknow directionMock',
locale = '[PC preview] unknow locale'
}
}
const resourceManagerMock = {
getString: function (...args) {
console.warn("ResourceManager.getString 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramStringMock);
})
}
},
getStringArray: function (...args) {
console.warn("ResourceManager.getStringArray 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramStringMock]);
} else {
return new Promise((resolve, reject) => {
resolve([paramMock.paramStringMock]);
})
}
},
getMedia: function (...args) {
console.warn("ResourceManager.getMedia 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, new Uint8Array());
} else {
return new Promise((resolve, reject) => {
resolve(new Uint8Array());
})
}
},
getMediaBase64: function (...args) {
console.warn("ResourceManager.getMediaBase64 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramStringMock);
})
}
},
getDeviceCapability: function (...args) {
console.warn("ResourceManager.getDeviceCapability 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, new DeviceCapabilityClass());
} else {
return new Promise((resolve, reject) => {
resolve(new DeviceCapabilityClass());
})
}
},
getConfiguration: function (...args) {
console.warn("ResourceManager.getConfiguration 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, new configurationClass());
} else {
return new Promise((resolve, reject) => {
resolve(new configurationClass());
})
}
},
getPluralString: function (...args) {
console.warn("ResourceManager.getPluralString 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramStringMock);
})
}
},
getRawFile: function (...args) {
console.warn("ResourceManager.getRawFile 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, new Uint8Array());
} else {
return new Promise((resolve, reject) => {
resolve(new Uint8Array());
})
}
},
}
export const contextClass = class context{
constructor() {
console.warn('context.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.resourceManager = resourceManagerMock;
this.applicationInfo = applicationInfoMock;
this.HapModuleInfo = HapModuleInfoMock;
this.cacheDir = '[PC preview] unknow cacheDir';
this.tempDir = '[PC preview] unknow tempDir';
this.filesDir = '[PC preview] unknow filesDir';
this.databaseDir = '[PC preview] unknow databaseDir';
this.storageDir = '[PC preview] unknow storageDir';
this.bundleCodeDir = '[PC preview] unknow bundleCodeDir';
this.distributedFilesDir = '[PC preview] unknow distributedFilesDir';
}
};
export const abilityStageContextClass = class abilityStageContext extends contextClass{
constructor() {
super();
console.warn('Context.abilityStageContext.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.currentHapModuleInfo = HapModuleInfoMock;
}
}
export const ExtensionContextClass = class ExtensionContext extends contextClass {
constructor() {
super();
console.warn('Context.ExtensionContext.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
}
};
export const AbilityResultMock = {
resultCode: "[PC Preview] unknow resultCode",
}
export const AbilityContextClass = class AbilityContext extends contextClass {
constructor() {
super();
console.warn('Ability.AbilityContext.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.abilityInfo = AbilityInfoMock;
this.currentHapModuleInfo = HapModuleInfoMock;
this.startAbility = function (...args) {
console.warn("Ability.AbilityContext.startAbility 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
this.startAbilityForResult = function (...args) {
console.warn("Ability.AbilityContext.startAbilityForResult 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, AbilityResultMock);
} else {
return new Promise((resolve, reject) => {
resolve(AbilityResultMock);
})
}
};
this.terminateSelf = function (...args) {
console.warn("Ability.AbilityContext.terminateSelf 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
this.terminateSelfWithResult = function (...args) {
console.warn("Ability.AbilityContext.terminateSelfWithResult 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
this.connectAbility = function (...args) {
console.warn("Ability.AbilityContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
};
this.disconnectAbility = function (...args) {
console.warn("Ability.AbilityContext.disconnectAbility 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
}
}
export function mockAbilityContext() {
return new AbilityContextClass();
}

View File

@ -0,0 +1,54 @@
import { paramMock } from "../utils"
import { AbilityContextClass } from "./application/abilityContext"
const WantClass = class Want {
constructor() {
console.warn('Ability.Want.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.deviceId = "[PC Preview] unknow deviceId";
this.bundleName = "[PC Preview] unknow bundleName";
this.abilityName = "[PC Preview] unknow abilityName";
this.uri = "[PC Preview] unknow uri";
this.type = "[PC Preview] unknow type";
this.flag = "[PC Preview] unknow flag";
this.action = "[PC Preview] unknow action";
this.parameters = {};
this.entities = [paramMock.paramStringMock];
}
}
export function mockAbility() {
const AbilityClass = class Ability {
constructor() {
console.warn('application.Ability.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.context = new AbilityContextClass();
this.launchWant = new WantClass();
this.lastRequestWant = new WantClass();
this.onCreate = function (...args) {
console.warn("application.Ability.onCreate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.onWindowStageCreate = function (...args) {
console.warn("application.Ability.onWindowStageCreate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.onWindowStageDestroy = function () {
console.warn("application.Ability.onWindowStageDestroy interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.onDestroy = function () {
console.warn("application.Ability.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.onForeground = function () {
console.warn("application.Ability.onForeground interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.onBackground = function () {
console.warn("application.Ability.onBackground interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
}
}
return new AbilityClass();
}

View File

@ -0,0 +1,16 @@
import { abilityStageContextClass } from "./application/abilityContext"
export function mockAbilityStage(){
const AbilityStageClass = class AbilityStage{
constructor() {
console.warn('application.AbilityStage.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.context = new abilityStageContextClass();
this.onCreate = function () {
console.warn("application.AbilityStage.onCreate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
}
}
}
return new AbilityStageClass();
}

View File

@ -0,0 +1,60 @@
import { paramMock } from "../utils"
import { ExtensionContextClass } from "./application/abilityContext"
export function mockFormExtension(){
const formBindingDataMock = {
data: paramMock.paramObjectMock
}
const formExtensionContextClass = class formExtensionContext extends ExtensionContextClass {
constructor() {
super();
console.warn('formExtension.formExtensionContext.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.updateForm = function (...args) {
console.warn("formExtension.formExtensionContext.updateForm 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
}
}
}
const formExtensionClass = class formExtension {
constructor() {
console.warn('application.formExtension.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.context = new formExtensionContextClass();
this.onCreate = function (...args) {
console.warn("application.formExtension.onCreate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return formBindingDataMock
};
this.onCastToNormal = function (...args) {
console.warn("application.formExtension.onCastToNormal interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onUpdate = function (...args) {
console.warn("application.formExtension.onUpdate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onVisibilityChange = function (...args) {
console.warn("application.formExtension.onVisibilityChange interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onEvent = function (...args) {
console.warn("application.formExtension.onEvent interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onDestroy = function (...args) {
console.warn("application.formExtension.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
}
}
}
return new formExtensionClass();
}

View File

@ -0,0 +1,201 @@
import { paramMock } from "../utils"
import { ExtensionContextClass } from "./application/abilityContext"
export function mockServiceExtension(){
const IRemoteBrokerMock = {
asObject: function () {
console.warn("IRemoteBroker.asObject interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return IRemoteObjectMock;
},
}
const IRemoteObjectMock = {
queryLocalInterface: function () {
console.warn("IRemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return IRemoteBrokerMock;
},
sendRequest: function (...args) {
console.warn("IRemoteObject.sendRequest interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
return new Promise((resolve, reject) => {
resolve();
})
},
addDeathRecipient: function () {
console.warn("IRemoteObject.addDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
removeDeathRecipient: function () {
console.warn("IRemoteObject.removeDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
getInterfaceDescriptor: function () {
console.warn("IRemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock;
},
isObjectDead: function () {
console.warn("IRemoteObject.isObjectDead interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
}
}
const RemoteObjectClass = class RemoteObject {
constructor() {
console.warn('RemoteObject.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.queryLocalInterface = function () {
console.warn("RemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return IRemoteBrokerMock;
},
this.sendRequest = function (...args) {
console.warn("RemoteObject.sendRequest interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
return new Promise((resolve, reject) => {
resolve();
})
},
this.addDeathRecipient = function () {
console.warn("RemoteObject.addDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
this.removeDeathRecipient = function () {
console.warn("RemoteObject.removeDeathRecipient interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
},
this.getInterfaceDescriptor = function () {
console.warn("RemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock;
},
this.isObjectDead = function () {
console.warn("RemoteObject.isObjectDead interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock;
}
this.queryLocalInterface = function (...args) {
console.warn("RemoteObject.queryLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return IRemoteObjectMock
},
this.getInterfaceDescriptor = function () {
console.warn("RemoteObject.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock
},
this.onRemoteRequest = function (...args) {
console.warn("RemoteObject.onRemoteRequest interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramBooleanMock
},
this.sendRequest = function (...args) {
console.warn("RemoteObject.sendRequest interface mocked in the Previewer." +
" How this interface works on the Previewer may be different from that on a real device.")
return new Promise((resolve, reject) => {
resolve();
})
};
this.getCallingPid = function () {
console.warn("RemoteObject.getCallingPid interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
};
this.getCallingUid = function () {
console.warn("RemoteObject.getCallingUid interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
};
this.attachLocalInterface = function (...args) {
console.warn("RemoteObject.attachLocalInterface interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
}
}
const serviceExtensionContextClass = class serviceExtensionContext extends ExtensionContextClass{
constructor() {
super();
console.warn('ServiceExtension.serviceExtensionContext.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.startAbility = function (...args) {
console.warn("ServiceExtension.serviceExtensionContext.startAbility 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
this.terminateSelf = function (...args) {
console.warn("ServiceExtension.serviceExtensionContext.terminateSelf 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
};
this.connectAbility = function (...args) {
console.warn("ServiceExtension.serviceExtensionContext.connectAbility interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramNumberMock
};
this.disconnectAbility = function (...args) {
console.warn("ServiceExtension.serviceExtensionContext.disconnectAbility 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 (len > 0 && typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock);
} else {
return new Promise((resolve, reject) => {
resolve();
})
}
}
}
}
const ServiceExtensionClass = class ServiceExtension {
constructor() {
console.warn('application.ServiceExtension.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.context = new serviceExtensionContextClass();
this.onCreate = function (...args) {
console.warn("application.ServiceExtension.onCreate interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onDestroy = function () {
console.warn("application.ServiceExtension.onDestroy interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onRequest = function (...args) {
console.warn("application.ServiceExtension.onRequest interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onConnect = function (...args) {
console.warn("application.ServiceExtension.onConnect interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return new RemoteObjectClass();
},
this.onDisconnect = function (...args) {
console.warn("application.ServiceExtension.onDisconnect interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
this.onReconnect = function (...args) {
console.warn("application.ServiceExtension.onReconnect interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
}
}
}
return new ServiceExtensionClass();
}

View File

@ -1,296 +1,160 @@
import { paramMock } from "../utils"
import {paramMock} from '../utils';
import {RdbPredicatesClass} from './rdb'
export function mockDataAbility() {
const DataAbilityPredicatesClass = class DataAbilityPredicates {
constructor() {
console.warn('DataAbility.DataAbilityPredicates.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
this.equalTo = function (...args) {
console.warn('DataAbilityPredicates.equalTo interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.notEqualTo = function (...args) {
console.warn('DataAbilityPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.beginWrap = function (...args) {
console.warn('DataAbilityPredicates.beginWrap interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.endWrap = function (...args) {
console.warn('DataAbilityPredicates.endWrap interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.or = function (...args) {
console.warn('DataAbilityPredicates.or interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.and = function (...args) {
console.warn('DataAbilityPredicates.and interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.contains = function (...args) {
console.warn('DataAbilityPredicates.contains interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.beginsWith = function (...args) {
console.warn('DataAbilityPredicates.beginsWith interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.endsWith = function (...args) {
console.warn('DataAbilityPredicates.endsWith interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.isNull = function (...args) {
console.warn('DataAbilityPredicates.isNull interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.isNotNull = function (...args) {
console.warn('DataAbilityPredicates.isNotNull interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.like = function (...args) {
console.warn('DataAbilityPredicates.like interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.glob = function (...args) {
console.warn('DataAbilityPredicates.glob interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.between = function (...args) {
console.warn('DataAbilityPredicates.between interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.notBetween = function (...args) {
console.warn('DataAbilityPredicates.notBetween interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.greaterThan = function (...args) {
console.warn('DataAbilityPredicates.greaterThan interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.lessThan = function (...args) {
console.warn('DataAbilityPredicates.lessThan interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.greaterThanOrEqualTo = function (...args) {
console.warn('DataAbilityPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.lessThanOrEqualTo = function (...args) {
console.warn('DataAbilityPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.orderByAsc = function (...args) {
console.warn('DataAbilityPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.orderByDesc = function (...args) {
console.warn('DataAbilityPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.distinct = function (...args) {
console.warn('DataAbilityPredicates.distinct interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.limitAs = function (...args) {
console.warn('DataAbilityPredicates.limitAs interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.offsetAs = function (...args) {
console.warn('DataAbilityPredicates.offsetAs interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.groupBy = function (...args) {
console.warn('DataAbilityPredicates.groupBy interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.indexedBy = function (...args) {
console.warn('DataAbilityPredicates.indexedBy interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.in = function (...args) {
console.warn('DataAbilityPredicates.in interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
this.notIn = function (...args) {
console.warn('DataAbilityPredicates.notIn interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
return new DataAbilityPredicatesClass();
};
}
};
const dataAbilityMock = {
createRdbPredicates: function (...args) {
console.warn("DataAbility.createRdbPredicates interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
console.warn('DataAbility.createRdbPredicates.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer may be different from that on a real device.');
return new RdbPredicatesClass();
},
DataAbilityPredicates: DataAbilityPredicatesClass
};
const rdbPredicates = {
equalTo: function (...args) {
console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notEqualTo: function (...args) {
console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
beginWrap: function (...args) {
console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
endWrap: function (...args) {
console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
or: function (...args) {
console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
and: function (...args) {
console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
contains: function (...args) {
console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
beginsWith: function (...args) {
console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
endsWith: function (...args) {
console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
isNull: function (...args) {
console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
isNotNull: function (...args) {
console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
like: function (...args) {
console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
glob: function (...args) {
console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
between: function (...args) {
console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notBetween: function (...args) {
console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
greaterThan: function (...args) {
console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
lessThan: function (...args) {
console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
greaterThanOrEqualTo: function (...args) {
console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
lessThanOrEqualTo: function (...args) {
console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
orderByAsc: function (...args) {
console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
orderByDesc: function (...args) {
console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
distinct: function (...args) {
console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
limitAs: function (...args) {
console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
offsetAs: function (...args) {
console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
groupBy: function (...args) {
console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
indexedBy: function (...args) {
console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
in: function (...args) {
console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notIn: function (...args) {
console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
};
const dataAbilityPredicates = {
equalTo: function (...args) {
console.warn("DataAbilityPredicates.equalTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
notEqualTo: function (...args) {
console.warn("DataAbilityPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
beginWrap: function (...args) {
console.warn("DataAbilityPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
endWrap: function (...args) {
console.warn("DataAbilityPredicates.endWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
or: function (...args) {
console.warn("DataAbilityPredicates.or interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
and: function (...args) {
console.warn("DataAbilityPredicates.and interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
contains: function (...args) {
console.warn("DataAbilityPredicates.contains interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
beginsWith: function (...args) {
console.warn("DataAbilityPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
endsWith: function (...args) {
console.warn("DataAbilityPredicates.endsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
isNull: function (...args) {
console.warn("DataAbilityPredicates.isNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
isNotNull: function (...args) {
console.warn("DataAbilityPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
like: function (...args) {
console.warn("DataAbilityPredicates.like interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
glob: function (...args) {
console.warn("DataAbilityPredicates.glob interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
between: function (...args) {
console.warn("DataAbilityPredicates.between interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
notBetween: function (...args) {
console.warn("DataAbilityPredicates.notBetween interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
greaterThan: function (...args) {
console.warn("DataAbilityPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
lessThan: function (...args) {
console.warn("DataAbilityPredicates.lessThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
greaterThanOrEqualTo: function (...args) {
console.warn("DataAbilityPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
lessThanOrEqualTo: function (...args) {
console.warn("DataAbilityPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
orderByAsc: function (...args) {
console.warn("DataAbilityPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
orderByDesc: function (...args) {
console.warn("DataAbilityPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
distinct: function (...args) {
console.warn("DataAbilityPredicates.distinct interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
limitAs: function (...args) {
console.warn("DataAbilityPredicates.limitAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
offsetAs: function (...args) {
console.warn("DataAbilityPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
groupBy: function (...args) {
console.warn("DataAbilityPredicates.groupBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
indexedBy: function (...args) {
console.warn("DataAbilityPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
in: function (...args) {
console.warn("DataAbilityPredicates.in interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
notIn: function (...args) {
console.warn("DataAbilityPredicates.notIn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return dataAbilityPredicates;
},
}
return dataAbilityMock;
}

View File

@ -1,7 +1,14 @@
import { paramMock } from "../utils"
import {paramMock} from "../utils"
export function mockHilog() {
const hilog = {
LogLevel: {
DEBUG: 3,
INFO: 4,
WARN: 5,
ERROR: 6,
FATAL: 7
},
debug: function (...args) {
console.warn("hilog.debug interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
@ -26,7 +33,7 @@ export function mockHilog() {
console.warn("hilog.isLoggable 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 hilog;
}

View File

@ -1,4 +1,8 @@
import { mockSystemParameter } from './systemParameter'
import { mockAbility } from './applicationAbility'
import { mockFormExtension } from './applicationFormExtension'
import { mockServiceExtension } from './applicationServiceExtension'
import { mockAbilityStage } from './applicationAbilityStage'
import { mockFileio } from './fileio'
import { mockWorker } from './worker'
import { mockUtil } from './util'
@ -11,7 +15,6 @@ import { mockwebgl } from './webgl'
import { mockwebgl2 } from './webgl2'
import { mockProcess } from './process'
import { mockUrl } from './url'
import { mockMediaQuery } from './mediaquery'
import { mockHiAppEvent } from './hiAppEvent'
import { mockHilog } from './hilog'
import { mockTv } from './tv'
@ -22,12 +25,24 @@ import { mockDistributedData } from './distributedData'
import { mockDataAbility } from './dataAbility'
import { mockStorage } from './storage'
import { mockRdb } from './rdb'
import { mockInputDevice } from './inputDevice'
import { mockLight } from './light'
import { mockVibrator } from './vibrator'
import { mockSensor } from './sensor'
export function mockRequireNapiFun() {
global.requireNapi = function (...args) {
switch (args[0]) {
case "systemParameter":
return mockSystemParameter();
case "application.Ability":
return mockAbility();
case "application.FormExtension":
return mockFormExtension();
case "application.ServiceExtension":
return mockServiceExtension();
case "application.AbilityStage":
return mockAbilityStage();
case "fileio":
return mockFileio();
case "worker" :
@ -52,8 +67,6 @@ export function mockRequireNapiFun() {
return mockBytrace();
case "url":
return mockUrl();
case "mediaquery":
return mockMediaQuery();
case "hiAppEvent":
return mockHiAppEvent();
case "hilog":
@ -74,6 +87,16 @@ export function mockRequireNapiFun() {
return mockStorage();
case "data.dataAbility":
return mockDataAbility();
case "multimodalInput.inputDevice":
return mockInputDevice();
case "light":
return mockLight();
case "vibrator":
return mockVibrator();
case "sensor":
return mockSensor();
default:
return global.requireNapiPreview(...args);
}
}
}

View File

@ -0,0 +1,106 @@
import { paramMock } from "../utils"
export function mockInputDevice() {
const AxisRange = {
source: '[PC preview] unknow source',
axis : '[PC preview] unknow axis',
max : '[PC preview] unknow max',
min: '[PC preview] unknow min'
}
const InputDeviceData = {
id: '[PC preview] unknow id',
name: '[PC preview] unknow name',
sources : ['[PC preview] unknow sources'],
axisRanges : [AxisRange]
}
const EventType = ['add', 'remove', 'update']
const DeviceIds = [-1,0,1,2,3,4,5,6,7]
const inputDevice = {
on: function (...args) {
console.warn("inputDevice.on 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 (len === 2) {
if (EventType.indexOf(args[0]) === -1) {
console.warn("the first parameter must be 'add'|'remove'|'update'")
}
if (typeof args[1] != 'function') {
console.warn("the second parameter type must be 'function'")
}
} else {
console.warn("the number of parameter must be two")
}
},
off: function (...args) {
console.warn("inputDevice.off 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 (len < 1 || len >2) {
console.warn("the number of parameter must be one or two")
} else if (len === 1) {
if (EventType.indexOf(args[0]) === -1) {
console.warn("first parameter must be 'add'|'remove'|'update'")
}
} else {
if (EventType.indexOf(args[0]) === -1) {
console.warn("first parameter must be 'add'|'remove'|'update'")
}
if (typeof args[1] != 'function') {
console.warn("second parameter type must be 'function'")
}
}
},
getDeviceSync: function (...args) {
console.warn("inputDevice.getDeviceSync 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 (len != 1) {
console.warn("the number of parameter must be one")
} else {
if (DeviceIds.indexOf(args[len - 1]) != -1) {
return InputDeviceData;
} else {
console.warn("parameter error")
return paramMock.businessErrorMock;
}
}
},
getDeviceIdsSync: function () {
console.warn("inputDevice.getDeviceIdsSync interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return DeviceIds;
},
getDeviceIds: function (...args) {
console.warn("inputDevice.getDeviceIds 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 (len != 1) {
console.warn("the number of parameter must be one")
}
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, DeviceIds);
} else {
console.warn("parameter type must be 'function")
}
},
getDevice: function (...args) {
console.warn("inputDevice.getDevice 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 (len != 2) {
console.warn("the number of parameter must be two")
}
if (DeviceIds.indexOf(args[0]) === -1) {
console.warn("the first parameter error")
}
if (typeof args[1] === 'function') {
console.warn("asynchronous callback")
args[1].call(this, InputDeviceData);
} else {
console.warn("the second parameter type must be 'function'")
}
}
}
return inputDevice
}

View File

@ -0,0 +1,93 @@
import { paramMock } from "../utils"
export function mockLight() {
const LightId = {
LIGHT_ID_LED: 0,
LIGHT_ID_KEYBOARD: 1,
LIGHT_ID_BUTTONS: 2,
LIGHT_ID_BELT: 3,
UNKNOWN: 4
}
const LightEffectId = {
LIGHT_ID_LED: "0",
LIGHT_ID_KEYBOARD: "1",
LIGHT_ID_BUTTONS: "2",
LIGHT_ID_BELT: "3",
UNKNOWN: "4"
}
const LightBrightness = {
redBrightness: "[PC preview] unknown redBrightness",
greenBrightness: "[PC preview] unknown greenBrightness",
blueBrightness: "[PC preview] unknown blueBrightness"
}
const LightEffect = {
lightBrightness: "[PC preview] unknown lightBrightness",
onDuration: "[PC preview] unknown onDuration",
offDuration: "[PC preview] unknown offDuration"
}
const light = {
turnOn: function (...args) {
console.warn("light.turnOn 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();
})
}
},
turnOff: function (...args) {
console.warn("light.turnOff 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();
})
}
},
getLightIdList: function (...args) {
console.warn("light.getLightIdList interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
var lightIdArray = new Array();
lightIdArray.push(paramMock.paramNumberMock);
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, lightIdArray);
} else {
return new Promise((resolve) => {
resolve(lightIdArray);
})
}
},
isSupport: function (...args) {
console.warn("light.isSupport 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);
})
}
},
isEffectSupport: function (...args) {
console.warn("light.isEffectSupport 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);
})
}
}
}
return light
}

View File

@ -1,4 +1,151 @@
import { paramMock } from "../utils"
import {paramMock} from "../utils"
export const RdbPredicatesClass = class RdbPredicates {
constructor(...args) {
console.warn('data.rdb.RdbPredicates.constructor interface mocked in the Previewer. How this interface works on the' +
' Previewer may be different from that on a real device.');
this.equalTo = function (...args) {
console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.notEqualTo = function (...args) {
console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.beginWrap = function (...args) {
console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.endWrap = function (...args) {
console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.or = function (...args) {
console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.and = function (...args) {
console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.contains = function (...args) {
console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.beginsWith = function (...args) {
console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.endsWith = function (...args) {
console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.isNull = function (...args) {
console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.isNotNull = function (...args) {
console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.like = function (...args) {
console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.glob = function (...args) {
console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.between = function (...args) {
console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.notBetween = function (...args) {
console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.greaterThan = function (...args) {
console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.lessThan = function (...args) {
console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.greaterThanOrEqualTo = function (...args) {
console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.lessThanOrEqualTo = function (...args) {
console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.orderByAsc = function (...args) {
console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.orderByDesc = function (...args) {
console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.distinct = function (...args) {
console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.limitAs = function (...args) {
console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.offsetAs = function (...args) {
console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.groupBy = function (...args) {
console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.indexedBy = function (...args) {
console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.in = function (...args) {
console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
this.notIn = function (...args) {
console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return new RdbPredicatesClass();
};
}
};
export function mockRdb() {
const rdbMock = {
@ -26,6 +173,7 @@ export function mockRdb() {
})
}
},
RdbPredicates: RdbPredicatesClass
};
const resultSetMock = {
columnNames: "[[PC Preview] unknow columnNames]",
@ -105,7 +253,7 @@ export function mockRdb() {
close: function (...args) {
console.warn("ResultSet.close interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
},
}
}
const storeConfig = {
name: "[PC Preview] unknown name"
@ -170,149 +318,8 @@ export function mockRdb() {
resolve();
})
}
},
};
const rdbPredicates = {
equalTo: function (...args) {
console.warn("RdbPredicates.equalTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notEqualTo: function (...args) {
console.warn("RdbPredicates.notEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
beginWrap: function (...args) {
console.warn("RdbPredicates.beginWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
endWrap: function (...args) {
console.warn("RdbPredicates.endWrap interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
or: function (...args) {
console.warn("RdbPredicates.or interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
and: function (...args) {
console.warn("RdbPredicates.and interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
contains: function (...args) {
console.warn("RdbPredicates.contains interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
beginsWith: function (...args) {
console.warn("RdbPredicates.beginsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
endsWith: function (...args) {
console.warn("RdbPredicates.endsWith interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
isNull: function (...args) {
console.warn("RdbPredicates.isNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
isNotNull: function (...args) {
console.warn("RdbPredicates.isNotNull interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
like: function (...args) {
console.warn("RdbPredicates.like interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
glob: function (...args) {
console.warn("RdbPredicates.glob interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
between: function (...args) {
console.warn("RdbPredicates.between interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notBetween: function (...args) {
console.warn("RdbPredicates.notBetween interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
greaterThan: function (...args) {
console.warn("RdbPredicates.greaterThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
lessThan: function (...args) {
console.warn("RdbPredicates.lessThan interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
greaterThanOrEqualTo: function (...args) {
console.warn("RdbPredicates.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
lessThanOrEqualTo: function (...args) {
console.warn("RdbPredicates.lessThanOrEqualTo interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
orderByAsc: function (...args) {
console.warn("RdbPredicates.orderByAsc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
orderByDesc: function (...args) {
console.warn("RdbPredicates.orderByDesc interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
distinct: function (...args) {
console.warn("RdbPredicates.distinct interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
limitAs: function (...args) {
console.warn("RdbPredicates.limitAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
offsetAs: function (...args) {
console.warn("RdbPredicates.offsetAs interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
groupBy: function (...args) {
console.warn("RdbPredicates.groupBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
indexedBy: function (...args) {
console.warn("RdbPredicates.indexedBy interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
in: function (...args) {
console.warn("RdbPredicates.in interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
notIn: function (...args) {
console.warn("RdbPredicates.notIn interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return rdbPredicates;
},
}
};
return rdbMock;
}

View File

@ -1,5 +1,37 @@
import { paramMock } from "../utils"
export const IRemoteObject = {
queryLocalInterface: function (...args) {
console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return IRemoteBroker
},
sendRequest: function (...args) {
console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
addDeathRecipient: function (...args) {
console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
removeDeathRecipient: function (...args) {
console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
getInterfaceDescriptor: function () {
console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramStringMock
},
isObjectDead: function () {
console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
}
}
export function mockRpc() {
const MessageParcel = {
reclaim: function () {
@ -272,38 +304,6 @@ export function mockRpc() {
return paramMock.paramArrayMock;
}
};
const IRemoteObject = {
queryLocalInterface: function (...args) {
console.warn("rpc.queryLocalInterface interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return IRemoteBroker
},
sendRequest: function (...args) {
console.warn("rpc.sendRequest interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
addDeathRecipient: function (...args) {
console.warn("rpc.addDeathRecipient interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
removeDeathRecipient: function (...args) {
console.warn("rpc.removeDeathRecipient interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
getInterfaceDescriptor: function () {
console.warn("rpc.getInterfaceDescriptor interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramStringMock
},
isObjectDead: function () {
console.warn("rpc.isObjectDead interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
}
};
const IRemoteBroker = {
asObject: function () {
console.warn("rpc.asObject interface mocked in the Previewer. How this interface works on the" +

View File

@ -0,0 +1,341 @@
import { paramMock } from "../utils"
export function mockSensor() {
const AccelerometerResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const LinearAccelerometerResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const AccelerometerUncalibratedResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z",
biasX: "[PC preview] unknown biasX",
biasY: "[PC preview] unknown biasY",
biasZ: "[PC preview] unknown biasZ"
}
const GravityResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const OrientationResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const RotationVectorResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const GyroscopeResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const GyroscopeUncalibratedResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z",
biasX: "[PC preview] unknown biasX",
biasY: "[PC preview] unknown biasY",
biasZ: "[PC preview] unknown biasZ"
}
const SignificantMotionResponse = {
scalar: "[PC preview] unknown scalar"
}
const ProximityResponse = {
distance: "[PC preview] unknown distance"
}
const LightResponse = {
intensity: "[PC preview] unknown intensity"
}
const HallResponse = {
status: "[PC preview] unknown status"
}
const MagneticFieldResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z"
}
const MagneticFieldUncalibratedResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z",
biasX: "[PC preview] unknown biasX",
biasY: "[PC preview] unknown biasY",
biasZ: "[PC preview] unknown biasZ"
}
const PedometerResponse = {
steps: "[PC preview] unknown steps"
}
const HumidityResponse = {
humidity: "[PC preview] unknown humidity"
}
const PedometerDetectResponse = {
scalar: "[PC preview] unknown scalar"
}
const AmbientTemperatureResponse = {
temperature: "[PC preview] unknown temperature"
}
const BarometerResponse = {
pressure: "[PC preview] unknown pressure"
}
const HeartRateResponse = {
heartRate: "[PC preview] unknown heartRate"
}
const WearDetectionResponse = {
value: "[PC preview] unknown value"
}
const Options = {
interval: "[PC preview] unknown value"
}
const GeomagneticResponse = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y",
z: "[PC preview] unknown z",
biasX: "[PC preview] unknown biasX",
biasY: "[PC preview] unknown biasY",
biasZ: "[PC preview] unknown biasZ"
}
const LocationOptions = {
latitude: "[PC preview] unknown latitude",
longitude: "[PC preview] unknown longitude",
altitude: "[PC preview] unknown altitude",
}
const CoordinatesOptions = {
x: "[PC preview] unknown x",
y: "[PC preview] unknown y"
}
const SensorType = {
SENSOR_TYPE_ID_ACCELEROMETER: 1,
SENSOR_TYPE_ID_GYROSCOPE: 2,
SENSOR_TYPE_ID_AMBIENT_LIGHT: 5,
SENSOR_TYPE_ID_MAGNETIC_FIELD: 6,
SENSOR_TYPE_ID_BAROMETER: 8,
SENSOR_TYPE_ID_HALL: 10,
SENSOR_TYPE_ID_PROXIMITY: 12,
SENSOR_TYPE_ID_HUMIDITY: 13,
SENSOR_TYPE_ID_ORIENTATION: 256,
SENSOR_TYPE_ID_GRAVITY: 257,
SENSOR_TYPE_ID_LINEAR_ACCELERATION: 258,
SENSOR_TYPE_ID_ROTATION_VECTOR: 259,
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE: 260,
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED: 261,
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED: 263,
SENSOR_TYPE_ID_SIGNIFICANT_MOTION: 264,
SENSOR_TYPE_ID_PEDOMETER_DETECTION: 265,
SENSOR_TYPE_ID_PEDOMETER: 266,
SENSOR_TYPE_ID_HEART_RATE: 278,
SENSOR_TYPE_ID_WEAR_DETECTION: 280,
SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED: 281
}
const sensor = {
on: function (...args) {
console.warn("sensor.on 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;
const callback = typeof args[len - 1] == 'function' ? args[len - 1] : args[len - 2];
if (args[0] == 1) {
callback.call(this, paramMock.businessErrorMock, AccelerometerResponse);
} else if (args[0] == 2) {
callback.call(this, paramMock.businessErrorMock, GyroscopeResponse);
} else if (args[0] == 5) {
callback.call(this, paramMock.businessErrorMock, LightResponse);
} else if (args[0] == 6) {
callback.call(this, paramMock.businessErrorMock, MagneticFieldResponse);
} else if (args[0] == 8) {
callback.call(this, paramMock.businessErrorMock, BarometerResponse);
} else if (args[0] == 10) {
callback.call(this, paramMock.businessErrorMock, HallResponse);
} else if (args[0] == 12) {
callback.call(this, paramMock.businessErrorMock, ProximityResponse);
} else if (args[0] == 13) {
callback.call(this, paramMock.businessErrorMock, HumidityResponse);
} else if (args[0] == 256) {
callback.call(this, paramMock.businessErrorMock, OrientationResponse);
} else if (args[0] == 257) {
callback.call(this, paramMock.businessErrorMock, GravityResponse);
} else if (args[0] == 258) {
callback.call(this, paramMock.businessErrorMock, LinearAccelerometerResponse);
} else if (args[0] == 259) {
callback.call(this, paramMock.businessErrorMock, RotationVectorResponse);
} else if (args[0] == 260) {
callback.call(this, paramMock.businessErrorMock, AmbientTemperatureResponse);
} else if (args[0] == 261) {
callback.call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse);
} else if (args[0] == 263) {
callback.call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse);
} else if (args[0] == 264) {
callback.call(this, paramMock.businessErrorMock, SignificantMotionResponse);
} else if (args[0] == 265) {
callback.call(this, paramMock.businessErrorMock, PedometerDetectResponse);
} else if (args[0] == 266) {
callback.call(this, paramMock.businessErrorMock, PedometerResponse);
} else if (args[0] == 278) {
callback.call(this, paramMock.businessErrorMock, HeartRateResponse);
} else if (args[0] == 280) {
callback.call(this, paramMock.businessErrorMock, WearDetectionResponse);
} else if (args[0] == 281) {
callback.call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse);
}
},
once: function (...args) {
console.warn("sensor.once 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 (args[0] == 1) {
args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerResponse);
} else if (args[0] == 2) {
args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeResponse);
} else if (args[0] == 5) {
args[len - 1].call(this, paramMock.businessErrorMock, LightResponse);
} else if (args[0] == 6) {
args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldResponse);
} else if (args[0] == 8) {
args[len - 1].call(this, paramMock.businessErrorMock, BarometerResponse);
} else if (args[0] == 10) {
args[len - 1].call(this, paramMock.businessErrorMock, HallResponse);
} else if (args[0] == 12) {
args[len - 1].call(this, paramMock.businessErrorMock, ProximityResponse);
} else if (args[0] == 13) {
args[len - 1].call(this, paramMock.businessErrorMock, HumidityResponse);
} else if (args[0] == 256) {
args[len - 1].call(this, paramMock.businessErrorMock, OrientationResponse);
} else if (args[0] == 257) {
args[len - 1].call(this, paramMock.businessErrorMock, GravityResponse);
} else if (args[0] == 258) {
args[len - 1].call(this, paramMock.businessErrorMock, LinearAccelerometerResponse);
} else if (args[0] == 259) {
args[len - 1].call(this, paramMock.businessErrorMock, RotationVectorResponse);
} else if (args[0] == 260) {
args[len - 1].call(this, paramMock.businessErrorMock, AmbientTemperatureResponse);
} else if (args[0] == 261) {
args[len - 1].call(this, paramMock.businessErrorMock, MagneticFieldUncalibratedResponse);
} else if (args[0] == 263) {
args[len - 1].call(this, paramMock.businessErrorMock, GyroscopeUncalibratedResponse);
} else if (args[0] == 264) {
args[len - 1].call(this, paramMock.businessErrorMock, SignificantMotionResponse);
} else if (args[0] == 265) {
args[len - 1].call(this, paramMock.businessErrorMock, PedometerDetectResponse);
} else if (args[0] == 266) {
args[len - 1].call(this, paramMock.businessErrorMock, PedometerResponse);
} else if (args[0] == 278) {
args[len - 1].call(this, paramMock.businessErrorMock, HeartRateResponse);
} else if (args[0] == 280) {
args[len - 1].call(this, paramMock.businessErrorMock, WearDetectionResponse);
} else if (args[0] == 281) {
args[len - 1].call(this, paramMock.businessErrorMock, AccelerometerUncalibratedResponse);
}
},
off: function (...args) {
console.warn("sensor.off 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
args[len - 1].call(this, paramMock.businessErrorMock);
},
getGeomagneticField: function (...args) {
console.warn("sensor.getGeomagneticField 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.businessErrorMoc, GeomagneticResponse);
} else {
return new Promise((resolve, reject) => {
resolve(GeomagneticResponse);
})
}
},
getAltitude: function (...args) {
console.warn("sensor.getAltitude 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.businessErrorMoc, paramMock.paramNumberMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramNumberMock);
})
}
},
getGeomagneticDip: function (...args) {
console.warn("sensor.getGeomagneticDip 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.businessErrorMoc, paramMock.paramNumberMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramNumberMock);
})
}
},
getAngleModifiy: function (...args) {
console.warn("sensor.getAngleModifiy 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.businessErrorMoc, paramMock.paramArrayMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
})
}
},
createRotationMatrix: function (...args) {
console.warn("sensor.createRotationMatrix 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.businessErrorMoc, paramMock.paramArrayMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
})
}
},
transformCoordinateSystem: function (...args) {
console.warn("sensor.transformCoordinateSystem 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.businessErrorMoc, paramMock.paramArrayMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
})
}
},
createQuaternion: function (...args) {
console.warn("sensor.createQuaternion 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.businessErrorMoc, paramMock.paramArrayMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
})
}
},
getDirection: function (...args) {
console.warn("sensor.getDirection 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.businessErrorMoc, paramMock.paramArrayMock);
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramArrayMock);
})
}
}
}
return sensor
}

View File

@ -1,104 +1,136 @@
import { paramMock } from "../utils"
import {paramMock} from '../utils';
export function mockUrl() {
const result = {
URLSearchParams: function(...args) {
console.warn("url.URLSearchParams interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return URLSearchParamsMock;
},
URL: function(...args) {
console.warn("url.URL interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return URLMock;
const URLSearchParamsClass = class URLSearchParams {
constructor(...args) {
console.warn('url.URLSearchParams.constructor interface mocked in the Previewer. How this interface works on' +
' the Previewer' +
' may be different from that on a real device.');
this.append = function(...args) {
console.warn('url.URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
};
this.delete = function(...args) {
console.warn('url.URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
};
this.getAll = function(...args) {
console.warn('url.URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return [paramMock.paramStringMock];
};
this.entries = function(...args) {
console.warn('url.URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
const IteratorTwoStringMock = {
*[Symbol.iterator]() {
yield [paramMock.paramStringMock, paramMock.paramStringMock];
}
}
const URLSearchParamsMock = {
append: function(...args) {
console.warn("URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
delete: function(...args) {
console.warn("URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
getAll: function(...args) {
console.warn("URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
var arrStr = new Array()
return arrStr;
},
entries: function(...args) {
console.warn("URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramObjectMock;
},
forEach: function(...args) {
console.warn("URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
get: function(...args) {
console.warn("URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
return IteratorTwoStringMock;
};
this.forEach = function(...args) {
console.warn('url.URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
};
this.get = function(...args) {
console.warn('url.URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
},
has: function(...args) {
console.warn("URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.has = function(...args) {
console.warn('url.URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramBooleanMock;
},
set: function(...args) {
console.warn("URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
sort: function(...args) {
console.warn("URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
},
keys: function(...args) {
console.warn("URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramObjectMock;
},
values: function(...args) {
console.warn("URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramObjectMock;
},
[Symbol.iterator]: function(...args) {
console.warn("URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramObjectMock;
},
toString: function(...args) {
console.warn("URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
};
this.set = function(...args) {
console.warn('url.URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
};
this.sort = function(...args) {
console.warn('url.URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
};
this.keys = function(...args) {
console.warn('url.URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
const IteratorStringMock = {
*[Symbol.iterator]() {
yield paramMock.paramStringMock;
}
};
return IteratorStringMock;
};
this.values = function(...args) {
console.warn('url.URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
const IteratorStringMock = {
*[Symbol.iterator]() {
yield paramMock.paramStringMock;
}
};
return IteratorStringMock;
};
this.toString = function(...args) {
console.warn('url.URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
};
}
[Symbol.iterator]() {
console.warn('url.URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
let index = 0;
const IteratorTwoStringMock = {
next: () => {
if (index < 1) {
const returnValue = [paramMock.paramStringMock, paramMock.paramStringMock];
index++;
return {
value: returnValue,
done: false
};
} else {
return {
done: true
};
}
}
const URLMock = {
toString: function(...args) {
console.warn("URL.toString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock;
},
toJSON: function(...args) {
console.warn("URL.toJSON interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramStringMock;
},
hash: '[PC preview] unknow hash',
host: '[PC preview] unknow host',
hostname: '[PC preview] unknow hostname',
href: '[PC preview] unknow href',
origin: '[PC preview] unknow origin',
password: '[PC preview] unknow password',
pathname: '[PC preview] unknow pathname',
port: '[PC preview] unknow port',
protocol: '[PC preview] unknow protocol',
search: '[PC preview] unknow search',
searchParams: URLSearchParamsMock,
username: '[PC preview] unknow username',
};
return IteratorTwoStringMock;
}
};
const URLClass = class URL {
constructor(...args) {
console.warn('url.URL.constructor interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
this.toString = function(...args) {
console.warn('URL.toString interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
};
this.toJSON = function(...args) {
console.warn('URL.toJSON interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
};
this.hash = '[PC preview] unknow hash';
this.host = '[PC preview] unknow host';
this.hostname = '[PC preview] unknow hostname';
this.href = '[PC preview] unknow href';
this.origin = '[PC preview] unknow origin';
this.password = '[PC preview] unknow password';
this.pathname = '[PC preview] unknow pathname';
this.port = '[PC preview] unknow port';
this.protocol = '[PC preview] unknow protocol';
this.search = '[PC preview] unknow search';
this.searchParams = new URLSearchParamsClass();
this.username = '[PC preview] unknow username';
}
};
const result = {
URLSearchParams: URLSearchParamsClass,
URL: URLClass
};
return result;
}

View File

@ -1,60 +1,77 @@
import { paramMock } from "../utils"
import {paramMock} from '../utils';
export function mockUtil() {
const result = {
printf: function(...args) {
console.warn("util.printf interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('util.printf interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
},
getErrorString: function(...args) {
console.warn("util.getErrorString interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('util.getErrorString interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
},
callbackWrapper: function(...args) {
console.warn("util.callbackWrapper interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('util.callbackWrapper interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return function(...args) {
console.warn('util.callbackWrapper.return function interface mocked in the Previewer. How this interface' +
' works on the Previewer may be different from that on a real device.');
};
},
promiseWrapper: function(...args) {
console.warn("util.promiseWrapper interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return paramMock.paramObjectMock;
promiseWrapper: function(func) {
console.warn('util.promiseWrapper interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
if (typeof func === 'function') {
return function(...args) {
return new Promise((resolve, reject) => {
const callback = function(err, ...values) {
if (err) {
reject(err);
} else {
resolve(values);
}
};
func.apply(null, [...args, callback]);
});
};
}
},
TextDecoder: function(...args) {
console.warn("util.TextDecoder interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('util.TextDecoder interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return TextDecoderMock;
},
TextEncoder: function(...args) {
console.warn("util.TextEncoder interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('util.TextEncoder interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return TextEncoderMock;
}
}
};
const TextDecoderMock = {
encoding: '[PC preview] unknow encoding',
fatal: '[PC preview] unknow fatal',
ignoreBOM: '[PC preview] unknow ignoreBOM',
decode: function (...args) {
console.warn("TextDecoder.decode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
decode: function(...args) {
console.warn('TextDecoder.decode interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramStringMock;
},
}
};
const TextEncoderMock = {
encoding: '[PC preview] unknow encoding',
encode: function(...args) {
console.warn("TextEncoder.encode interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
const arr = new Uint8Array()
console.warn('TextEncoder.encode interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
const arr = new Uint8Array();
return arr;
},
encodeInto: function(...args) {
console.warn("TextEncoder.encodeInto interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
console.warn('TextEncoder.encodeInto interface mocked in the Previewer. How this interface works on the Previewer' +
' may be different from that on a real device.');
return paramMock.paramObjectMock;
}
}
};
return result;
}

View File

@ -0,0 +1,38 @@
import { paramMock } from "../utils"
export function mockVibrator() {
const EffectId = {
EFFECT_CLOCK_TIMER: "haptic.clock.timer"
}
const VibratorStopMode = {
VIBRATOR_STOP_MODE_TIME: "time",
VIBRATOR_STOP_MODE_PRESET: "preset"
}
const vibrator = {
vibrate: function (...args) {
console.warn("vibrator.vibrate 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();
})
}
},
stop: function (...args) {
console.warn("vibrator.stop 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();
})
}
}
}
return vibrator
}

View File

@ -1,4 +1,4 @@
import {paramMock} from "./utils"
import { paramMock } from "./utils"
export function mockWebSocket() {
global.systemplugin.net = {}
@ -68,7 +68,7 @@ export function mockWebSocket() {
} else if (args[0] === 'message') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
} else if (args[0] === 'close') {
args[len - 1].call(this, paramMock.businessErrorMock,{
args[len - 1].call(this, paramMock.businessErrorMock, {
code: "[PC Preview] unknow code",
reason: "[PC Preview] unknow reason"
});
@ -88,6 +88,49 @@ export function mockWebSocket() {
}
export function mockHttp() {
const HttpResponseCacheOptions = {
filePath: "[PC Preview] unknow filePath",
fileChildPath: "[PC Preview] unknow fileChildPath",
cacheSize: "[PC Preview] unknow cacheSize"
}
const HttpResponseCache = {
close: function (...args) {
console.warn("net.HttpResponseCache.close 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, reject) => {
resolve();
})
}
},
delete: function (...args) {
console.warn("net.HttpResponseCache.delete 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, reject) => {
resolve();
})
}
},
flush: function (...args) {
console.warn("net.HttpResponseCache.flush 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, reject) => {
resolve();
})
}
}
}
const HttpResponseMock = {
result: "[PC Preview] unknow result",
responseCode: "[PC Preview] unknow responseCode",
@ -132,6 +175,30 @@ export function mockHttp() {
console.warn("net.http.createHttp interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return HttpRequestMock;
},
getInstalledHttpResponseCache: function (...args) {
console.warn("net.http.getInstalledHttpResponseCache 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, HttpResponseCache);
} else {
return new Promise((resolve, reject) => {
resolve(HttpResponseCache);
})
}
},
createHttpResponseCache: function (...args) {
console.warn("net.http.createHttpResponseCache 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, HttpResponseCacheOptions);
} else {
return new Promise((resolve, reject) => {
resolve(HttpResponseCache);
})
}
}
}
}
@ -150,23 +217,23 @@ export function mockMdns() {
const len = args.length
if (typeof args[len - 1] === 'function') {
if (args[0] === 'serviceAdd') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceRemove') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceStart') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceStop') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceFound') {
args[len - 1].call(this, localServiceInfoMock);
} else if (args[0] === 'serviceLost') {
args[len - 1].call(this, localServiceInfoMock);
} else if (args[0] === 'serviceResolve') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceLost') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'error') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else {
args[len - 1].call(this);
}
@ -176,27 +243,29 @@ export function mockMdns() {
console.warn("net.mdns.off 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') {
if (args[0] === 'serviceAdd') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceRemove') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceStart') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceStop') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceFound') {
args[len - 1].call(this, localServiceInfoMock);
} else if (args[0] === 'serviceLost') {
args[len - 1].call(this, localServiceInfoMock);
} else if (args[0] === 'serviceResolve') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'serviceLost') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else if (args[0] === 'error') {
args[len - 1].call(this, {serviceInfo : localServiceInfoMock, errorCode: 0});
args[len - 1].call(this, { serviceInfo: localServiceInfoMock, errorCode: 0 });
} else {
args[len - 1].call(this);
}
}
},
addLocalService: function (...args) {
console.warn("net.mdns.addLocalService interface mocked in the Previewer. How this interface works on the Previewer may" +
@ -249,7 +318,7 @@ export function mockMdns() {
}
}
export function mockSocket(){
export function mockSocket() {
const SocketStateBase = {
isBound: "[PC Preview] unknow isBound",
isClose: "[PC Preview] unknow isClose",
@ -267,12 +336,12 @@ export function mockSocket(){
port: "[PC Preview] unknow port "
}
const UDPSocket = {
bind: function (...args){
bind: function (...args) {
console.warn("UDPSocket.bind 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -283,8 +352,8 @@ export function mockSocket(){
console.warn("UDPSocket.send 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -295,8 +364,8 @@ export function mockSocket(){
console.warn("UDPSocket.close 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -307,8 +376,8 @@ export function mockSocket(){
console.warn("UDPSocket.getState 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, SocketStateBase)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase)
} else {
return new Promise((resolve, reject) => {
resolve(SocketStateBase);
@ -319,8 +388,8 @@ export function mockSocket(){
console.warn("UDPSocket.setExtraOptions 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -364,12 +433,12 @@ export function mockSocket(){
}
const TCPSocket = {
bind: function (...args){
bind: function (...args) {
console.warn("TcpSocket.bind 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -380,8 +449,8 @@ export function mockSocket(){
console.warn("TcpSocket.connect 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -392,8 +461,8 @@ export function mockSocket(){
console.warn("TcpSocket.send 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -404,8 +473,8 @@ export function mockSocket(){
console.warn("TcpSocket.close 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -416,8 +485,8 @@ export function mockSocket(){
console.warn("TcpSocket.getRemoteAddress 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, NetAddress)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, NetAddress)
} else {
return new Promise((resolve, reject) => {
resolve(NetAddress);
@ -428,8 +497,8 @@ export function mockSocket(){
console.warn("TcpSocket.getState 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, SocketStateBase)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, SocketStateBase)
} else {
return new Promise((resolve, reject) => {
resolve(SocketStateBase);
@ -440,8 +509,8 @@ export function mockSocket(){
console.warn("TcpSocket.setExtraOptions 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)
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve, reject) => {
resolve();
@ -483,13 +552,13 @@ export function mockSocket(){
}
}
}
global.systemplugin.net.socket ={
constructUDPSocketInstance : function () {
global.systemplugin.net.socket = {
constructUDPSocketInstance: function () {
console.warn("net.socket.constructUDPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return UDPSocket;
},
constructTCPSocketInstance : function () {
constructTCPSocketInstance: function () {
console.warn("net.socket.constructTCPSocketInstance interface mocked in the Previewer. How this interface works on the Previewer" +
" may be different from that on a real device.")
return TCPSocket;
@ -835,12 +904,12 @@ export function mockConnection() {
} else if (args[0] === 'netBlockStatusChange') {
args[len - 1].call(this, paramMock.businessErrorMock, { NetHandle, blocked });
} else if (args[0] === 'netCapabilitiesChange') {
args[len - 1].call(this, { NetHandle, netCap });
args[len - 1].call(this, { NetHandle, NetCap });
} else if (args[0] === 'netConnectionPropertiesChange') {
args[len - 1].call(this, { netHandle, connectionProperties });
args[len - 1].call(this, { NetHandle, ConnectionProperties });
} else if (args[0] === 'netLosing') {
args[len - 1].call(this, {
netHandle,
NetHandle,
maxMsToLive: "[PC Preview] unknow maxMsToLive"
});
} else if (args[0] === 'netLost') {
@ -860,12 +929,12 @@ export function mockConnection() {
} else if (args[0] === 'netBlockStatusChange') {
args[len - 1].call(this, { NetHandle, blocked });
} else if (args[0] === 'netCapabilitiesChange') {
args[len - 1].call(this, { NetHandle, netCap });
args[len - 1].call(this, { NetHandle, NetCap });
} else if (args[0] === 'netConnectionPropertiesChange') {
args[len - 1].call(this, { netHandle, connectionProperties });
args[len - 1].call(this, { NetHandle, ConnectionProperties });
} else if (args[0] === 'netLosing') {
args[len - 1].call(this, {
netHandle,
NetHandle,
maxMsToLive: "[PC Preview] unknow maxMsToLive"
});
} else if (args[0] === 'netLost') {
@ -1067,5 +1136,29 @@ export function mockConnection() {
})
}
},
reportNetConnected: function (...args) {
console.warn("net.connection.reportNetConnected 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, reject) => {
resolve();
})
}
},
reportNetDisconnected: function (...args) {
console.warn("net.connection.reportNetDisconnected 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, reject) => {
resolve();
})
}
},
}
}

View File

@ -111,7 +111,7 @@ export function mockOhosBluetooth() {
"How this interface works on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
on: function(...args) {
on: function (...args) {
console.warn("GattServer.on 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
@ -129,7 +129,7 @@ export function mockOhosBluetooth() {
}
}
},
off: function(...args) {
off: function (...args) {
console.warn("GattServer.off 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
@ -164,7 +164,7 @@ export function mockOhosBluetooth() {
"How this interface works on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
getDeviceName: function(...args) {
getDeviceName: function (...args) {
console.warn("GattClientDevice.getDeviceName 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
@ -176,7 +176,7 @@ export function mockOhosBluetooth() {
})
}
},
getServices: function(...args) {
getServices: function (...args) {
console.warn("GattClientDevice.getServices 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
@ -188,7 +188,7 @@ export function mockOhosBluetooth() {
})
}
},
readCharacteristicValue: function(...args) {
readCharacteristicValue: function (...args) {
console.warn("GattClientDevice.readCharacteristicValue 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
@ -200,7 +200,7 @@ export function mockOhosBluetooth() {
})
}
},
readDescriptorValue: function(...args) {
readDescriptorValue: function (...args) {
console.warn("GattClientDevice.readDescriptorValue 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
@ -222,7 +222,7 @@ export function mockOhosBluetooth() {
"How this interface works on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
getRssiValue: function(...args) {
getRssiValue: function (...args) {
console.warn("GattClientDevice.getRssiValue 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
@ -244,7 +244,7 @@ export function mockOhosBluetooth() {
"How this interface works on the Previewer may be different from that on a real device.")
return paramMock.paramBooleanMock
},
on: function(...args) {
on: function (...args) {
console.warn("GattClientDevice.on 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
@ -256,7 +256,7 @@ export function mockOhosBluetooth() {
}
}
},
off: function(...args) {
off: function (...args) {
console.warn("GattClientDevice.off 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
@ -298,7 +298,7 @@ export function mockOhosBluetooth() {
return GattClientDeviceMock
},
getConnectedBLEDevices: function () {
console.warn("bluetooth.BLE.startBLEScan interface mocked in the Previewer." +
console.warn("bluetooth.BLE.getConnectedBLEDevices interface mocked in the Previewer." +
"How this interface works on the Previewer may be different from that on a real device.")
return connectedBLEDevicesMock
},
@ -310,7 +310,7 @@ export function mockOhosBluetooth() {
console.warn("bluetooth.BLE.stopBLEScan interface mocked in the Previewer." +
"How this interface works on the Previewer may be different from that on a real device.")
},
on: function(...args) {
on: function (...args) {
console.warn("bluetooth.BLE.on 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
@ -320,7 +320,7 @@ export function mockOhosBluetooth() {
}
}
},
off: function(...args) {
off: function (...args) {
console.warn("bluetooth.BLE.off 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

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import {paramMock} from "../utils"
import { paramMock } from "../utils"
export function mockCommonEvent() {
const CommonEventSubscriberMock = {
@ -179,7 +179,7 @@ export function mockCommonEvent() {
}
},
unsubscribe: function (...args) {
console.warn("commonEvent.subscribe interface mocked in the Previewer. How this interface works on the" +
console.warn("commonEvent.unsubscribe 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') {

View File

@ -1,4 +1,4 @@
import {paramMock} from "../utils"
import {paramMock} from '../utils';
export function mockOhosNotification() {
const NotificationSlotMock = {
@ -13,12 +13,12 @@ export function mockOhosNotification() {
lightEnabled: '[PC preview] unknow lightEnabled',
lightColor: '[PC preview] unknow lightColor',
vibrationValues: '[PC preview] unknow vibrationValues'
}
};
const DoNotDisturbDateMock = {
type: '[PC preview] unknow type',
begin: '[PC preview] unknow begin',
end: '[PC preview] unknow end',
}
end: '[PC preview] unknow end'
};
const NotificationRequestMock = {
content: '[PC preview] unknow content',
id: '[PC preview] unknow id',
@ -46,12 +46,33 @@ export function mockOhosNotification() {
classification: '[PC preview] unknow classification',
hashCode: '[PC preview] unknow hashCode',
groupName: '[PC preview] unknow groupName',
template: '[PC preview] unknow template',
}
template: '[PC preview] unknow template'
};
global.ohosplugin.notification = {
publish: function (...args) {
console.warn("notification.publish interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
SlotType: {
UNKNOWN_TYPE: 0,
SOCIAL_COMMUNICATION: 1,
SERVICE_INFORMATION: 2,
CONTENT_INFORMATION: 3,
OTHER_TYPES: 0xFFFF
},
ContentType: {
NOTIFICATION_CONTENT_BASIC_TEXT: 0,
NOTIFICATION_CONTENT_LONG_TEXT: 1,
NOTIFICATION_CONTENT_PICTURE: 2,
NOTIFICATION_CONTENT_CONVERSATION: 3,
NOTIFICATION_CONTENT_MULTILINE: 4
},
SlotLevel: {
LEVEL_NONE: 0,
LEVEL_MIN: 1,
LEVEL_LOW: 2,
LEVEL_DEFAULT: 3,
LEVEL_HIGH: 4
},
publish: function(...args) {
console.warn('notification.publish 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);
@ -61,9 +82,9 @@ export function mockOhosNotification() {
});
}
},
cancel: function (...args) {
console.warn("notification.cancel interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
cancel: function(...args) {
console.warn('notification.cancel 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);
@ -73,9 +94,9 @@ export function mockOhosNotification() {
});
}
},
cancelAll: function (...args) {
console.warn("notification.cancelAll interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
cancelAll: function(...args) {
console.warn('notification.cancelAll 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);
@ -85,9 +106,9 @@ export function mockOhosNotification() {
});
}
},
addSlot: function (...args) {
console.warn("notification.addSlot interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
addSlot: function(...args) {
console.warn('notification.addSlot 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);
@ -97,9 +118,9 @@ export function mockOhosNotification() {
});
}
},
addSlots: function (...args) {
console.warn("notification.addSlots interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
addSlots: function(...args) {
console.warn('notification.addSlots 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);
@ -109,9 +130,9 @@ export function mockOhosNotification() {
});
}
},
getSlot: function (...args) {
console.warn("notification.getSlot interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getSlot: function(...args) {
console.warn('notification.getSlot 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, NotificationSlotMock);
@ -121,9 +142,9 @@ export function mockOhosNotification() {
});
}
},
getSlots: function (...args) {
console.warn("notification.getSlots interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getSlots: function(...args) {
console.warn('notification.getSlots 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, [NotificationSlotMock]);
@ -133,9 +154,9 @@ export function mockOhosNotification() {
});
}
},
removeSlot: function (...args) {
console.warn("notification.removeSlot interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
removeSlot: function(...args) {
console.warn('notification.removeSlot 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);
@ -145,9 +166,9 @@ export function mockOhosNotification() {
});
}
},
removeAllSlots: function (...args) {
console.warn("notification.removeAllSlots interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
removeAllSlots: function(...args) {
console.warn('notification.removeAllSlots 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);
@ -157,9 +178,9 @@ export function mockOhosNotification() {
});
}
},
subscribe: function (...args) {
console.warn("notification.subscribe interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
subscribe: function(...args) {
console.warn('notification.subscribe 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);
@ -169,9 +190,9 @@ export function mockOhosNotification() {
});
}
},
unsubscribe: function (...args) {
console.warn("notification.unsubscribe interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
unsubscribe: function(...args) {
console.warn('notification.unsubscribe 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);
@ -181,9 +202,9 @@ export function mockOhosNotification() {
});
}
},
enableNotification: function (...args) {
console.warn("notification.enableNotification interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
enableNotification: function(...args) {
console.warn('notification.enableNotification 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);
@ -193,9 +214,9 @@ export function mockOhosNotification() {
});
}
},
isNotificationEnabled: function (...args) {
console.warn("notification.isNotificationEnabled interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
isNotificationEnabled: function(...args) {
console.warn('notification.isNotificationEnabled 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);
@ -205,9 +226,9 @@ export function mockOhosNotification() {
});
}
},
displayBadge: function (...args) {
console.warn("notification.displayBadge interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
displayBadge: function(...args) {
console.warn('notification.displayBadge 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);
@ -217,9 +238,9 @@ export function mockOhosNotification() {
});
}
},
isBadgeDisplayed: function (...args) {
console.warn("notification.isBadgeDisplayed interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
isBadgeDisplayed: function(...args) {
console.warn('notification.isBadgeDisplayed 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);
@ -229,9 +250,9 @@ export function mockOhosNotification() {
});
}
},
setSlotByBundle: function (...args) {
console.warn("notification.setSlotByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
setSlotByBundle: function(...args) {
console.warn('notification.setSlotByBundle 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);
@ -241,9 +262,9 @@ export function mockOhosNotification() {
});
}
},
getSlotsByBundle: function (...args) {
console.warn("notification.getSlotsByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getSlotsByBundle: function(...args) {
console.warn('notification.getSlotsByBundle 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, [NotificationSlotMock]);
@ -253,9 +274,9 @@ export function mockOhosNotification() {
});
}
},
getSlotNumByBundle: function (...args) {
console.warn("notification.getSlotNumByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getSlotNumByBundle: function(...args) {
console.warn('notification.getSlotNumByBundle 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.paramNumberMock);
@ -265,9 +286,9 @@ export function mockOhosNotification() {
});
}
},
remove: function (...args) {
console.warn("notification.remove interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
remove: function(...args) {
console.warn('notification.remove 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);
@ -277,9 +298,9 @@ export function mockOhosNotification() {
});
}
},
removeAll: function (...args) {
console.warn("notification.removeAll interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
removeAll: function(...args) {
console.warn('notification.removeAll 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);
@ -289,9 +310,9 @@ export function mockOhosNotification() {
});
}
},
getAllActiveNotifications: function (...args) {
console.warn("notification.getAllActiveNotifications interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getAllActiveNotifications: function(...args) {
console.warn('notification.getAllActiveNotifications 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, [NotificationRequestMock]);
@ -301,9 +322,9 @@ export function mockOhosNotification() {
});
}
},
getActiveNotificationCount: function (...args) {
console.warn("notification.getActiveNotificationCount interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getActiveNotificationCount: function(...args) {
console.warn('notification.getActiveNotificationCount 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.paramNumberMock);
@ -313,9 +334,9 @@ export function mockOhosNotification() {
});
}
},
getActiveNotifications: function (...args) {
console.warn("notification.getActiveNotifications interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getActiveNotifications: function(...args) {
console.warn('notification.getActiveNotifications 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, [NotificationRequestMock]);
@ -325,9 +346,9 @@ export function mockOhosNotification() {
});
}
},
isDistributedEnabled: function (...args) {
console.warn("notification.isDistributedEnabled interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
isDistributedEnabled: function(...args) {
console.warn('notification.isDistributedEnabled 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);
@ -337,9 +358,9 @@ export function mockOhosNotification() {
});
}
},
enableDistributed: function (...args) {
console.warn("notification.enableDistributed interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
enableDistributed: function(...args) {
console.warn('notification.enableDistributed 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);
@ -349,9 +370,9 @@ export function mockOhosNotification() {
});
}
},
enableDistributedSelf: function (...args) {
console.warn("notification.enableDistributedSelf interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
enableDistributedSelf: function(...args) {
console.warn('notification.enableDistributedSelf 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);
@ -361,9 +382,9 @@ export function mockOhosNotification() {
});
}
},
enableDistributedByBundle: function (...args) {
console.warn("notification.enableDistributedByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
enableDistributedByBundle: function(...args) {
console.warn('notification.enableDistributedByBundle 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);
@ -373,9 +394,9 @@ export function mockOhosNotification() {
});
}
},
isDistributedEnabledByBundle: function (...args) {
console.warn("notification.isDistributedEnabledByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
isDistributedEnabledByBundle: function(...args) {
console.warn('notification.isDistributedEnabledByBundle 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);
@ -385,9 +406,9 @@ export function mockOhosNotification() {
});
}
},
cancelGroup: function (...args) {
console.warn("notification.cancelGroup interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
cancelGroup: function(...args) {
console.warn('notification.cancelGroup 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);
@ -397,9 +418,9 @@ export function mockOhosNotification() {
});
}
},
removeGroupByBundle: function (...args) {
console.warn("notification.removeGroupByBundle interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
removeGroupByBundle: function(...args) {
console.warn('notification.removeGroupByBundle 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);
@ -409,9 +430,9 @@ export function mockOhosNotification() {
});
}
},
isSupportDoNotDisturbMode: function (...args) {
console.warn("notification.isSupportDoNotDisturbMode interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
isSupportDoNotDisturbMode: function(...args) {
console.warn('notification.isSupportDoNotDisturbMode 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);
@ -421,9 +442,9 @@ export function mockOhosNotification() {
});
}
},
setDoNotDisturbDate: function (...args) {
console.warn("notification.setDoNotDisturbDate interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
setDoNotDisturbDate: function(...args) {
console.warn('notification.setDoNotDisturbDate 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);
@ -433,9 +454,9 @@ export function mockOhosNotification() {
});
}
},
getDoNotDisturbDate: function (...args) {
console.warn("notification.getDoNotDisturbDate interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
getDoNotDisturbDate: function(...args) {
console.warn('notification.getDoNotDisturbDate 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, DoNotDisturbDateMock);
@ -445,7 +466,22 @@ export function mockOhosNotification() {
});
}
},
DoNotDisturbType: {
TYPE_NONE: 0,
TYPE_ONCE: 1,
TYPE_DAILY: 2,
TYPE_CLEARLY: 3
},
TemplateType: {
TYPE_NONE: 0,
TYPE_PROCESS_BAR: 0x100
},
DoNotDisturbMode: {
ALLOW_UNKNOWN: 0,
ALLOW_ALL: 1,
ALLOW_PRIORITY: 2,
ALLOW_NONE: 3,
ALLOW_ALARMS: 4
}
};
}

View File

@ -1,4 +1,4 @@
import {paramMock} from "../utils"
import { paramMock } from "../utils"
export function mockWantAgent() {
const WantMock = {
@ -21,6 +21,25 @@ export function mockWantAgent() {
}
const WantAgentMock = {}
global.ohosplugin.wantAgent = {
OperationType: {
UNKNOWN_TYPE: 0,
START_ABILITY: 1,
START_ABILITIES: 2,
START_SERVICE: 3,
SEND_COMMON_EVENT: 4
},
WantAgentFlags: {
ONE_TIME_FLAG: 0,
NO_BUILD_FLAG: 1,
CANCEL_PRESENT_FLAG: 2,
UPDATE_PRESENT_FLAG: 3,
CONSTANT_FLAG: 4,
REPLACE_ELEMENT: 5,
REPLACE_ACTION: 6,
REPLACE_URI: 7,
REPLACE_ENTITIES: 8,
REPLACE_BUNDLE: 9
},
getBundleName: function (...args) {
console.warn("wantAgent.getBundleName interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");

View File

@ -1,4 +1,4 @@
import {paramMock} from "./utils"
import { paramMock } from "./utils"
const CallState = "[PC Preview] unknow CallState";
export function mockCall() {
@ -459,7 +459,7 @@ export function mockCall() {
})
}
},
setCallRestriction :function (...args) {
setCallRestriction: function (...args) {
console.warn("telephony.call.setCallRestriction 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
@ -681,17 +681,17 @@ const NetworkState = {
}
const SignalInformation = {
signalType: "[PC Preview] unknow signalType",
signalLevel:"[PC Preview] unknow signalLevel"
signalLevel: "[PC Preview] unknow signalLevel"
}
const DataFlowType = "[PC Preview] unknow DataFlowType"
const DataConnectState = "[PC Preview] unknow DataConnectState"
const CellInformation = {
networkType: "[PC Preview] unknow networkType",
isCamped: "[PC Preview] unknow isCamped",
timeStamp:"[PC Preview] unknow timeStamp",
signalInformation:"[PC Preview] unknow signalInformation",
data:"[PC Preview] unknow unkown data"
}
timeStamp: "[PC Preview] unknow timeStamp",
signalInformation: "[PC Preview] unknow signalInformation",
data: "[PC Preview] unknow unkown data"
}
export function mockRadio() {
const NetworkSearchResult = {
isNetworkSearchSuccess: "[PC Preview] unknow isNetworkSearchSuccess",
@ -703,7 +703,7 @@ export function mockRadio() {
}]
}
const PreferredNetworkMode = "[PC Preview] unknow PreferredNetworkMode"
const NrOptionMode ="[PC Preview] unknow NrOptionMode"
const NrOptionMode = "[PC Preview] unknow NrOptionMode"
const NetworkSelectionMode = "[PC Preview] unknow unkown NetworkSelectionMode"
global.systemplugin.telephony.radio = {
getRadioTech: function (...args) {
@ -956,6 +956,18 @@ export function mockRadio() {
resolve(PreferredNetworkMode);
})
}
},
getIMEISV: function (...args) {
console.warn("telephony.radio.getIMEISV 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, reject) => {
resolve(paramMock.paramStringMock);
})
}
}
}
}
@ -1637,7 +1649,7 @@ export function mockObserver() {
}
global.systemplugin.telephony.observer = {
on: function (...args) {
console.warn("telephony.on interface mocked in the Previewer. How this interface works on the Previewer may " +
console.warn("telephony.observer.on 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') {
@ -1667,7 +1679,7 @@ export function mockObserver() {
}
},
off: function (...args) {
console.warn("telephony.off interface mocked in the Previewer. How this interface works on the Previewer may " +
console.warn("telephony.observer.off 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') {
@ -1697,7 +1709,7 @@ export function mockObserver() {
}
},
once: function (...args) {
console.warn("telephony.once interface mocked in the Previewer. How this interface works on the Previewer may " +
console.warn("telephony.observer.once 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') {

View File

@ -1,8 +1,8 @@
export function hasComplete(...args) {
if (args[0] === undefined) {
return
return;
}
args[0].call(this)
args[0].call(this);
}
export function getRandomArbitrary(min, max) {
@ -11,9 +11,9 @@ export function getRandomArbitrary(min, max) {
export const paramMock = {
businessErrorMock: null,
paramNumberMock: "[PC Preview] unknow number",
paramStringMock: "[PC Preview] unknow string",
paramBooleanMock: "[PC Preview] unknow boolean",
paramObjectMock: "[PC Preview] unknow object",
paramArrayMock: "[PC Preview] unknow Array"
}
paramNumberMock: '[PC Preview] unknow number',
paramStringMock: '[PC Preview] unknow string',
paramBooleanMock: '[PC Preview] unknow boolean',
paramObjectMock: '[PC Preview] unknow object',
paramArrayMock: '[PC Preview] unknow Array'
};

View File

@ -1,8 +1,8 @@
import { paramMock } from "./utils"
export const windowPropertiesMock = {
windowRect:'[PC preview] unknow windowRect',
type:'[PC preview] unknow type',
windowRect: '[PC preview] unknow windowRect',
type: '[PC preview] unknow type',
brightness: '[PC preview] unknow brightness',
isTransparent: '[PC preview] unknow isTransparent',
isFullScreen: '[PC preview] unknow isFullScreen',
@ -295,13 +295,17 @@ export const windowMock = {
console.warn("Window.on 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.paramNumberMock)
}
},
off: function (...args) {
console.warn("Window.off 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.paramNumberMock)
}
},
}
export function mockWindow() {
@ -351,8 +355,8 @@ export function mockWindow() {
})
}
},
getWindowMode: function (...args) {
console.warn("Window.getWindowMode interface mocked in the Previewer. How this interface works on the Previewer" +
getAbilityWindowMode: function (...args) {
console.warn("Window.getAbilityWindowMode 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') {

View File

@ -24,7 +24,8 @@
import {
Log,
typof
typof,
bufferToBase64
} from '../../../utils/index';
import CallbackManager from './CallbackManager';
@ -81,6 +82,58 @@ export class TaskCenter {
return this.callbackManager.isEmpty();
}
/**
* Normalize args.
* @param {*} v - Original args.
* @return {*} - Normalized args.
*/
public normalizePrimitive(v: any): any {
const type = typof(v);
switch (type) {
case 'undefined':
case 'null':
return '';
case 'regexp':
return v.toString();
case 'date':
return v.toISOString();
case 'number':
case 'string':
case 'boolean':
case 'array':
case 'object':
return v;
case 'arraybuffer':
return {
'@type': 'binary',
dataType: type,
base64: bufferToBase64(v)
};
case 'int8array':
case 'uint8array':
case 'uint8clampedarray':
case 'int16array':
case 'uint16array':
case 'int32array':
case 'uint32array':
case 'float32array':
case 'float64array':
return {
'@type': 'binary',
dataType: type,
base64: bufferToBase64(v.buffer)
};
default:
return JSON.stringify(v);
}
}
/**
* Standardizing a value. Specially, if the value is a function, generate a function id.
* @param {*} arg - Any type.
@ -99,7 +152,7 @@ export class TaskCenter {
} else if (type === 'array') {
return arg.map(i => this.standardization(i));
} else {
return arg;
return this.normalizePrimitive(arg);
}
}

View File

@ -36,10 +36,12 @@ import {
setClass,
setIdStyle,
setTagStyle,
setUniversalStyle,
setId,
bindSubVm,
bindSubVmAfterInitialized,
newWatch
newWatch,
bindDir
} from './directive';
import {
createBlock,
@ -80,6 +82,7 @@ export interface AttrInterface {
slot: string;
name: string;
data: () => any | string;
$data: () => any | string;
}
export interface TemplateInterface {
@ -118,15 +121,15 @@ interface ConfigInterface {
}
export function build(vm: Vm) {
const opt: any = vm.vmOptions || {};
const opt: any = vm._vmOptions || {};
const template: any = opt.template || {};
compile(vm, template, vm.parentEl);
Log.debug(`"OnReady" lifecycle in Vm(${vm.type}).`);
compile(vm, template, vm._parentEl);
Log.debug(`"OnReady" lifecycle in Vm(${vm._type}).`);
vm.$emit('hook:onReady');
if (vm.parent) {
if (vm._parent) {
vm.$emit('hook:onAttached');
}
vm.ready = true;
vm._ready = true;
}
/**
@ -137,7 +140,7 @@ export function build(vm: Vm) {
* @param {MetaInterface} [meta] - To transfer data.
*/
function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | Element, meta?: Partial<MetaInterface>): void {
const app: any = vm.app || {};
const app: any = vm._app || {};
if (app.lastSignal === -1) {
return;
}
@ -169,6 +172,10 @@ function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | E
compileCustomComponent(vm, component, target, dest, type, meta);
return;
}
if (type === 'compontent') {
compileDyanmicComponent(vm, target, dest, type, meta);
return;
}
if (targetIsBlock(target)) {
compileBlock(vm, target, dest);
return;
@ -176,6 +183,61 @@ function compile(vm: Vm, target: TemplateInterface, dest: FragBlockInterface | E
compileNativeComponent(vm, target, dest, type);
}
/**
* Compile a dynamic component.
* @param {Vm} vm - Vm object needs to be compiled.
* @param {TemplateInterface} target - Node needs to be compiled. Structure of the label in the template.
* @param {Element | FragBlockInterface} dest - Parent Node's VM of current.
* @param {string} type - Component Type.
* @param {MetaInterface} meta - To transfer data.
*/
export function compileDyanmicComponent(
vm: Vm,
target: TemplateInterface,
dest: Element | FragBlockInterface,
type: string,
meta: Partial<MetaInterface>
): void {
const attr: object = target.attr;
let dynamicType: string;
for (const key in attr) {
const value = attr[key];
if (key === 'name') {
if (typeof value === 'function') {
dynamicType = value.call(vm, vm);
} else if (typeof value === 'string') {
dynamicType = value;
} else {
Log.error('compontent attr name is unkonwn');
return;
}
}
}
const elementDiv = createElement(vm, 'div');
attachTarget(elementDiv, dest);
const element = createElement(vm, type);
element.vm = vm;
element.target = target;
element.destroyHook = function() {
if (element.watchers !== undefined) {
element.watchers.forEach(function(watcher) {
watcher.teardown();
});
element.watchers = [];
}
};
bindDir(vm, element, 'attr', attr);
attachTarget(element, elementDiv);
const component: VmOptions | null = targetIsComposed(vm, dynamicType);
if (component) {
compileCustomComponent(vm, component, target, elementDiv, dynamicType, meta);
return;
}
}
/**
* Check if target type is slot.
*
@ -212,17 +274,18 @@ function targetNeedCheckShown(target: TemplateInterface, meta: Partial<MetaInter
* @param {string} type - Component type.
* @return {VmOptions} Component.
*/
function targetIsComposed(vm: Vm, type: string): VmOptions {
export function targetIsComposed(vm: Vm, type: string): VmOptions {
let component;
if (vm.app && vm.app.customComponentMap) {
component = vm.app.customComponentMap[type];
if (vm._app && vm._app.customComponentMap) {
component = vm._app.customComponentMap[type];
}
if (component) {
if (component.data && typeof component.data === 'object') {
if (!component.initObjectData) {
component.initObjectData = component.data;
}
component.data = Object.assign({}, component.initObjectData);
const str = JSON.stringify(component.initObjectData);
component.data = JSON.parse(str);
}
}
return component;
@ -235,16 +298,16 @@ function targetIsComposed(vm: Vm, type: string): VmOptions {
* @param {dest} dest - Node need to be appended.
*/
function compileSlot(vm: Vm, target: TemplateInterface, dest: Element): Element {
if (!vm.slotContext) {
if (!vm._slotContext) {
// slot in root vm
return;
}
const slotDest = createBlock(vm, dest);
// reslove slot contentext
const namedContents = vm.slotContext.content;
const parentVm = vm.slotContext.parentVm;
// reslove slot content
const namedContents = vm._slotContext.content;
const parentVm = vm._slotContext.parentVm;
const slotItem = { target, dest: slotDest };
const slotName = target.attr.name || 'default';
@ -337,7 +400,7 @@ function compileBlock(vm: Vm, target: TemplateInterface, dest: Element | FragBlo
if (isBlock(dest) && dest.children) {
dest.children.push(block);
}
const app: any = vm.app || {};
const app: any = vm._app || {};
const children = target.children;
if (children && children.length) {
children.every((child) => {
@ -356,7 +419,7 @@ function compileBlock(vm: Vm, target: TemplateInterface, dest: Element | FragBlo
* @param {string} type - Component Type.
* @param {MetaInterface} meta - To transfer data.
*/
function compileCustomComponent(
export function compileCustomComponent(
vm: Vm,
component: VmOptions,
target: TemplateInterface,
@ -384,11 +447,11 @@ function compileCustomComponent(
}
});
}
this.slotContext = { content: namedContents, parentVm: vm };
this.__slotContext = { content: namedContents, parentVm: vm };
setId(vm, null, target.id, this);
// Bind template earlier because of lifecycle issues.
this.externalBinding = {
this.__externalBinding = {
parent: vm,
template: target
};
@ -411,7 +474,7 @@ function resetElementStyle(vm: Vm, element: Element): void {
if (element.children !== undefined) {
len = element.children.length;
}
const css = vm.css || {};
const css = vm._css || {};
const mqArr = css['@MEDIA'];
for (let ii = 0; ii < len; ii++) {
const el = element.children[ii] as Element;
@ -419,6 +482,7 @@ function resetElementStyle(vm: Vm, element: Element): void {
resetElementStyle(vm, el);
}
}
setUniversalStyle(vm, element);
if (element.type) {
setTagStyle(vm, element, element.type);
}
@ -447,28 +511,28 @@ function resetElementStyle(vm: Vm, element: Element): void {
*/
function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragBlockInterface | Element, type: string): void {
function handleViewSizeChanged(e) {
if (!vm.mediaStatus) {
vm.mediaStatus = {};
if (!vm._mediaStatus) {
vm._mediaStatus = {};
}
vm.mediaStatus.orientation = e.orientation;
vm.mediaStatus.width = e.width;
vm.mediaStatus.height = e.height;
vm.mediaStatus.resolution = e.resolution;
vm.mediaStatus['device-type'] = e.deviceType;
vm.mediaStatus['aspect-ratio'] = e.aspectRatio;
vm.mediaStatus['device-width'] = e.deviceWidth;
vm.mediaStatus['device-height'] = e.deviceHeight;
vm.mediaStatus['round-screen'] = e.roundScreen;
vm.mediaStatus['dark-mode'] = e.darkMode;
const css = vm.vmOptions && vm.vmOptions.style || {};
vm._mediaStatus.orientation = e.orientation;
vm._mediaStatus.width = e.width;
vm._mediaStatus.height = e.height;
vm._mediaStatus.resolution = e.resolution;
vm._mediaStatus['device-type'] = e['device-type'];
vm._mediaStatus['aspect-ratio'] = e['aspect-ratio'];
vm._mediaStatus['device-width'] = e['device-width'];
vm._mediaStatus['device-height'] = e['device-height'];
vm._mediaStatus['round-screen'] = e['round-screen'];
vm._mediaStatus['dark-mode'] = e['dark-mode'];
const css = vm._vmOptions && vm._vmOptions.style || {};
const mqArr = css['@MEDIA'];
if (!mqArr) {
return;
}
if (e.isInit && vm.init) {
if (e.isInit && vm._init) {
return;
}
vm.init = true;
vm._init = true;
resetElementStyle(vm, e.currentTarget);
e.currentTarget.addEvent('show');
}
@ -492,11 +556,11 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB
};
}
if (!vm.rootEl) {
vm.rootEl = element;
if (!vm._rootEl) {
vm._rootEl = element;
// Bind event earlier because of lifecycle issues.
const binding: any = vm.externalBinding || {};
const binding: any = vm._externalBinding || {};
const target = binding.template;
const parentVm = binding.parent;
if (target && target.events && parentVm && element) {
@ -511,7 +575,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB
bindPageLifeCycle(vm, element);
element.setCustomFlag();
element.customFlag = true;
vm.init = true;
vm._init = true;
element.addEvent('viewsizechanged', handleViewSizeChanged);
}
@ -529,7 +593,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB
element.attr.append = template.append;
}
let treeMode = template.append === 'tree';
const app: any = vm.app || {};
const app: any = vm._app || {};
// Record the parent node of treeMode, used by class selector.
if (treeMode) {
@ -559,7 +623,7 @@ function compileNativeComponent(vm: Vm, template: TemplateInterface, dest: FragB
* @return {void | boolean} If there is no children, return null. Return true if has node.
*/
function compileChildren(vm: Vm, template: any, dest: Element | FragBlockInterface): void | boolean {
const app: any = vm.app || {};
const app: any = vm._app || {};
const children = template.children;
if (children && children.length) {
children.every((child) => {
@ -614,6 +678,7 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter
// Remove unused element foreach old item.
const reusedList: any[] = [];
const cacheList: any[] = [];
oldData.forEach((item, index) => {
const key = trackBy && item[trackBy] !== undefined ? item[trackBy] : index;
if (hasOwn(trackMap, key)) {
@ -624,7 +689,10 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter
};
reusedList.push(item);
} else {
removeTarget(oldChildren[index]);
cacheList.push({
target: oldChildren[index],
vm: oldVms[index]
});
}
});
@ -650,11 +718,26 @@ function bindRepeat(vm: Vm, target: TemplateInterface, fragBlock: FragBlockInter
reused.vm[keyName] = index;
fragBlock.updateMark = reused.target;
} else {
if (cacheList.length > 0) {
const reusedItem = cacheList[0];
cacheList.shift();
moveTarget(reusedItem.target, fragBlock.updateMark);
children.push(reusedItem.target);
vms.push(reusedItem.vm);
reusedItem.vm[valueName] = item;
reusedItem.vm[keyName] = index;
fragBlock.updateMark = reusedItem.target;
} else {
compileItem(item, index, vm);
}
}
});
delete fragBlock.updateMark;
cacheList.forEach((item) => {
removeTarget(item.target);
});
}
);
if (list && Array.isArray(list)) {
@ -709,7 +792,7 @@ function bindShown(
* @return {*} Init value of calc.
*/
function watchBlock(vm: Vm, fragBlock: FragBlockInterface, calc: Function, type: string, handler: Function): any {
const differ = vm && vm.app && vm.app.differ;
const differ = vm && vm._app && vm._app.differ;
const config: Partial<ConfigInterface> = {};
const newWatcher = newWatch(vm, calc, (value) => {
config.latestValue = value;
@ -735,11 +818,11 @@ function watchBlock(vm: Vm, fragBlock: FragBlockInterface, calc: Function, type:
*/
function mergeContext(context: Vm, mergedData: object): any {
const newContext = Object.create(context);
newContext._data = mergedData;
newContext._shareData = {};
newContext.__data = mergedData;
newContext.__shareData = {};
initData(newContext);
initComputed(newContext);
newContext._realParent = context;
newContext.__realParent = context;
return newContext;
}

View File

@ -53,9 +53,11 @@ const SETTERS = {
attr: 'setAttr',
style: 'setStyle',
data: 'setData',
$data: 'setData',
event: 'addEvent',
idStyle: 'setIdStyle',
tagStyle: 'setTagStyle'
tagStyle: 'setTagStyle',
universalStyle: 'setUniversalStyle'
};
/**
@ -68,7 +70,7 @@ const SETTERS = {
export function bindElement(vm: Vm, el: Element, template: TemplateInterface, parentElement: Element | FragBlockInterface): void {
// Set descendant style.
setDescendantStyle(
vm.selector,
vm._selector,
{
id: template.id,
class: template.classList,
@ -80,7 +82,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa
if (!style) {
return;
}
const css = vm.css || {};
const css = vm._css || {};
setAnimation(style, css);
setFontFace(style, css);
setStyle(vm, el, style);
@ -108,6 +110,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa
setIdStyle(vm, el, template.id);
setClass(vm, el, template.classList);
setTagStyle(vm, el, template.type);
setUniversalStyle(vm, el);
applyStyle(vm, el);
bindEvents(vm, el, template.events);
@ -116,9 +119,9 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa
bindEvents(vm, el, template.catchBubbleEvents, 'catchbubble');
bindEvents(vm, el, template.catchCaptureEvents, 'catchcapture');
if (!vm.isHide && !vm.init) {
if (!vm._isHide && !vm._init) {
el.addEvent('hide');
vm.isHide = true;
vm._isHide = true;
}
}
@ -133,7 +136,7 @@ export function bindElement(vm: Vm, el: Element, template: TemplateInterface, pa
export function bindSubVm(vm: Vm, rawSubVm: Vm, rawTemplate: TemplateInterface, repeatItem: object): void {
const subVm: any = rawSubVm || {};
const template: any = rawTemplate || {};
const options: any = subVm.vmOptions || {};
const options: any = subVm._vmOptions || {};
let props = options.props;
if (isArray(props) || !props) {
@ -209,7 +212,7 @@ function bindSubEvent(vm: Vm, subVm: Vm, template: TemplateInterface): void {
* @return {*} Sub vm object.
*/
function mergePropsObject(key: string, value: any, vm: Vm, subVm: Vm): any {
subVm.props.push(key);
subVm._props.push(key);
if (typeof value === 'function') {
const returnValue = watch(vm, value, function(v) {
subVm[key] = v;
@ -241,7 +244,7 @@ function mergeProps(target: object, props: any, vm: Vm, subVm: Vm): void {
}
for (const key in target) {
if (!props || props[key] || key === 'show') {
subVm.props.push(key);
subVm._props.push(key);
const value = target[key];
if (typeof value === 'function') {
const returnValue = watch(vm, value, function(v) {
@ -271,14 +274,14 @@ function mergeStyle(target: { [key: string]: any }, vm: Vm, subVm: Vm): void {
const value = target[key];
if (typeof value === 'function') {
const returnValue = watch(vm, value, function(v) {
if (subVm.rootEl) {
subVm.rootEl.setStyle(key, v);
if (subVm._rootEl) {
subVm._rootEl.setStyle(key, v);
}
});
subVm.rootEl.setStyle(key, returnValue);
subVm._rootEl.setStyle(key, returnValue);
} else {
if (subVm.rootEl) {
subVm.rootEl.setStyle(key, value);
if (subVm._rootEl) {
subVm._rootEl.setStyle(key, value);
}
}
}
@ -291,8 +294,8 @@ function mergeStyle(target: { [key: string]: any }, vm: Vm, subVm: Vm): void {
* @param {Vm} subVm - Sub vm.
*/
function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void {
const css = vm.css || {};
if (!subVm.rootEl) {
const css = vm._css || {};
if (!subVm._rootEl) {
return;
}
@ -301,7 +304,7 @@ function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void {
* @constant {string}
*/
const CLASS_NAME = '@originalRootEl';
css['.' + CLASS_NAME] = subVm.rootEl.classStyle;
css['.' + CLASS_NAME] = subVm._rootEl.classStyle;
function addClassName(list, name) {
if (typof(list) === 'array') {
@ -312,13 +315,13 @@ function mergeClassStyle(target: Function | string[], vm: Vm, subVm: Vm): void {
if (typeof target === 'function') {
const value = watch(vm, target, v => {
addClassName(v, CLASS_NAME);
setClassStyle(subVm.rootEl, css, v);
setClassStyle(subVm._rootEl, css, v);
});
addClassName(value, CLASS_NAME);
setClassStyle(subVm.rootEl, css, value);
setClassStyle(subVm._rootEl, css, value);
} else if (target !== undefined) {
addClassName(target, CLASS_NAME);
setClassStyle(subVm.rootEl, css, target);
setClassStyle(subVm._rootEl, css, target);
}
}
@ -338,7 +341,7 @@ export function setId(vm: Vm, el: Element, id: Function | string, target: Vm): v
configurable: false
},
el: {
get: () => el || target.rootEl,
get: () => el || target._rootEl,
configurable: false
}
});
@ -347,17 +350,17 @@ export function setId(vm: Vm, el: Element, id: Function | string, target: Vm): v
const newId = handler.call(vm);
if (newId || newId === 0) {
setElementId(el, newId);
vm.ids[newId] = map;
vm._ids[newId] = map;
}
watch(vm, handler, (newId) => {
if (newId) {
setElementId(el, newId);
vm.ids[newId] = map;
vm._ids[newId] = map;
}
});
} else if (id && typeof id === 'string') {
setElementId(el, id);
vm.ids[id] = map;
vm._ids[id] = map;
}
}
@ -378,11 +381,15 @@ function setElementId(el: Element, id: string): void {
* @param {Element} el - Element.
* @param {AttrInterface} attr - Attr to bind.
*/
function setAttr(vm: Vm, el: Element, attr: Partial<AttrInterface>): void {
if (attr && attr.data) {
// address data independently
export function setAttr(vm: Vm, el: Element, attr: Partial<AttrInterface>): void {
if (attr) {
// address $data or data independently
if (attr.$data) {
bindDir(vm, el, '$data', attr.$data);
} else if (attr.data && Object.prototype.toString.call(attr.data) === '[object Object]') {
bindDir(vm, el, 'data', attr.data);
}
}
bindDir(vm, el, 'attr', attr);
}
@ -483,13 +490,13 @@ function selectStyle(css: object, key: string, vm: Vm): any {
if (!vm) {
return style;
}
const mediaStatus = vm.mediaStatus;
const mediaStatus = vm._mediaStatus;
if (!mediaStatus) {
return style;
}
const mqArr = css['@MEDIA'];
if (!mqArr) {
vm.init = true;
vm._init = true;
return style;
}
const classStyle = {};
@ -582,8 +589,10 @@ function setClassStyle(el: Element, css: object, classList: string[], vm?: Vm):
const animationName = classStyle['animationName'];
if (animationName) {
classStyle['animationName'] = keyframes[animationName];
if (classStyle['animationName']) {
classStyle['animationName'].push({'animationName': animationName});
}
}
const transitionEnter = classStyle['transitionEnter'];
if (transitionEnter) {
classStyle['transitionEnter'] = keyframes[transitionEnter];
@ -620,7 +629,7 @@ export function setClass(vm: Vm, el: Element, classList: Function | string[]): v
el.setClassStyle({});
return;
}
const style = vm.css || {};
const style = vm._css || {};
if (typeof classList === 'function') {
const value = watch(vm, classList, v => {
setClassStyle(el, style, v, vm);
@ -639,7 +648,7 @@ export function setClass(vm: Vm, el: Element, classList: Function | string[]): v
*/
export function setIdStyle(vm: Vm, el: Element, id: Function | string): void {
if (id) {
const css = vm.css || {};
const css = vm._css || {};
if (typeof id === 'function') {
const value = watch(vm, id, v => {
doSetStyle(vm, el, selectIdStyle(css, v, vm), css, 'idStyle');
@ -706,12 +715,22 @@ function setAnimation(style: any, css: any): void {
* @param {string} tag - Tag.
*/
export function setTagStyle(vm: Vm, el: Element, tag: string): void {
const css = vm.css || {};
const css = vm._css || {};
if (tag && typeof tag === 'string') {
doSetStyle(vm, el, selectStyle(css, tag, vm), css, 'tagStyle');
}
}
/**
* Set * style.
* @param {Vm} vm - Vm object.
* @param {Element} el - ELement component.
*/
export function setUniversalStyle(vm: Vm, el: Element): void {
const css = vm._css || {};
doSetStyle(vm, el, selectStyle(css, "*", vm), css, 'universalStyle');
}
/**
* Bind style to an element.
* @param {Vm} vm - Vm object.
@ -769,7 +788,7 @@ function bindEvents(vm: Vm, el: Element, events: object, eventType?: string): vo
* @param {string} name - Method name.
* @param {Object} data - Data that needed.
*/
function bindDir(vm: Vm, el: Element, name: string, data: object): void {
export function bindDir(vm: Vm, el: Element, name: string, data: object): void {
if (!data) {
return;
}
@ -781,6 +800,11 @@ function bindDir(vm: Vm, el: Element, name: string, data: object): void {
const methodName = SETTERS[name];
const method = el[methodName];
const isSetStyle = methodName === 'setStyle';
if (methodName === 'setIdStyle') {
for (const id in el.idStyle) {
el.idStyle[id] = '';
}
}
while (i--) {
const key = keys[i];
const value = data[key];
@ -815,7 +839,7 @@ function bindKey(vm: Vm, el: Element, setValue: Function, calc: Function): void
function handler() {
setValue(value);
}
const differ = vm && vm.app && vm.app.differ;
const differ = vm && vm._app && vm._app.differ;
if (differ) {
differ.append('element', el.ref, handler);
} else {
@ -833,7 +857,7 @@ function bindKey(vm: Vm, el: Element, setValue: Function, calc: Function): void
* @return {*} FontFamily Filter.
*/
export function filterFontFamily(vm: Vm, fontFamilyName: string): any[] {
const css = vm.css || {};
const css = vm._css || {};
return _getFontFamily(css, fontFamilyName);
}
@ -877,7 +901,7 @@ export function watch(vm: Vm, calc: Function, callback: Function): any {
* @param {Element} el - Element object.
*/
function applyStyle(vm: Vm, el: Element): void {
const css = vm.css || {};
const css = vm._css || {};
const allStyle = el.style;
setAnimation(allStyle, css);
}

View File

@ -38,7 +38,7 @@ import { emitSubVmLife } from './pageLife';
* @return {Node} Body of Node by type.
*/
export function createBody(vm: Vm, type: string): Node {
const doc = vm.app.doc;
const doc = vm._app.doc;
return doc.createBody(type);
}
@ -49,7 +49,7 @@ export function createBody(vm: Vm, type: string): Node {
* @return {Element} Element of Node by type.
*/
export function createElement(vm: Vm, type: string): Element {
const doc = vm.app.doc;
const doc = vm._app.doc;
return doc.createElement(type);
}
@ -95,7 +95,7 @@ let lastestBlockId = 1;
* @return {Comment} A block starter.
*/
function createBlockStart(vm: Vm): Comment {
const doc = vm.app.doc;
const doc = vm._app.doc;
const anchor = doc.createComment('start');
return anchor;
}
@ -106,7 +106,7 @@ function createBlockStart(vm: Vm): Comment {
* @return {Comment} A block starter.
*/
function createBlockEnd(vm: Vm): Comment {
const doc = vm.app.doc;
const doc = vm._app.doc;
const anchor = doc.createComment('end');
anchor.destroyHook = function() {
if (anchor.watchers !== undefined) {

View File

@ -136,7 +136,7 @@ export const LIFE_CYCLE_TYPES: Array<PageLifecycleHooks | string> = [
* @param {ExternalEvent} externalEvents - External events.
*/
export function initEvents(vm: Vm, externalEvents: ExternalEvent): void {
const options = vm.vmOptions || {};
const options = vm._vmOptions || {};
for (const externalEvent in externalEvents) {
vm.$on(externalEvent, externalEvents[externalEvent]);
}

View File

@ -72,40 +72,40 @@ import {
* VM constructor.
* @param {string} type - Type.
* @param {null | VmOptions} options - Component options.
* @param {Vm} parentVm which contains _app.
* @param {Vm} parentVm which contains __app.
* @param {Element | FragBlockInterface} parentEl - root element or frag block.
* @param {Object} mergedData - External data.
* @param {ExternalEvent} externalEvents - External events.
*/
export default class Vm {
private _parent: Vm;
private _app: Page;
private _computed: ComputedInterface;
private _css: cssType;
private _type: string;
private readonly _descriptor: string;
private _props: Props;
private _vmOptions: VmOptions;
private _selector: object;
private _ids: Record<string, {vm: Vm, el: Element}>;
private _init: boolean;
private _ready: boolean;
private _valid: boolean;
private _vmEvents: object;
private _childrenVms: Vm[];
private _visible: boolean;
private _data: any;
private _shareData: any;
private _realParent: Vm
private _parentEl: Element | FragBlockInterface;
private _rootEl: Element;
private _$refs: Record<string, Element>;
private _externalBinding: ExternalBindingInterface;
private _isHide: boolean;
private _mediaStatus: Partial<MediaStatusInterface<string, boolean>>;
private _methods: Record<string, (...args: unknown[]) => any>;
private _slotContext: { content: Record<string, any>, parentVm: Vm };
private _$app: any;
private __methods: Record<string, (...args: unknown[]) => any>;
private __type: string;
private __css: cssType;
private __vmOptions: VmOptions;
private __parent: Vm;
private __realParent: Vm;
private __computed: ComputedInterface;
private __selector: object;
private __parentEl: Element | FragBlockInterface;
private __app: Page;
private __shareData: any;
private __data: any;
private __props: Props;
private __init: boolean;
private __valid: boolean;
private __visible: boolean;
private __ready: boolean;
private __rootEl: Element;
private __ids: Record<string, {vm: Vm, el: Element}>;
private __vmEvents: object;
private __childrenVms: Vm[];
private __externalBinding: ExternalBindingInterface;
private readonly __descriptor: string;
private __isHide: boolean;
private __mediaStatus: Partial<MediaStatusInterface<string, boolean>>;
private _$refs: Record<string, Element>;
private __slotContext: { content: Record<string, any>, parentVm: Vm };
constructor(
type: string,
@ -116,38 +116,38 @@ export default class Vm {
externalEvents: ExternalEvent
) {
this._$app = global.aceapp;
this._parent = parentVm._realParent ? parentVm._realParent : parentVm;
this._app = parentVm._app;
parentVm._childrenVms && parentVm._childrenVms.push(this);
this.__parent = parentVm.__realParent ? parentVm.__realParent : parentVm;
this.__app = parentVm.__app;
parentVm.__childrenVms && parentVm.__childrenVms.push(this);
if (!options && this._app.customComponentMap) {
options = this._app.customComponentMap[type];
if (!options && this.__app.customComponentMap) {
options = this.__app.customComponentMap[type];
}
const data = options.data || {};
const shareData = options.shareData || {};
this._vmOptions = options;
this._computed = options.computed;
this._css = options.style;
this._selector = selector(this._css);
this._ids = {};
this.__vmOptions = options;
this.__computed = options.computed;
this.__css = options.style;
this.__selector = selector(this.__css);
this.__ids = {};
this._$refs = {};
this._vmEvents = {};
this._childrenVms = [];
this._type = type;
this._valid = true;
this._props = [];
this._methods = {};
this.__vmEvents = {};
this.__childrenVms = [];
this.__type = type;
this.__valid = true;
this.__props = [];
this.__methods = {};
// Bind events and lifecycles.
initEvents(this, externalEvents);
Log.debug(
`'_innerInit' lifecycle in Vm(${this._type}) and mergedData = ${JSON.stringify(mergedData)}.`
`'_innerInit' lifecycle in Vm(${this.__type}) and mergedData = ${JSON.stringify(mergedData)}.`
);
this.$emit('hook:_innerInit');
this._data = (typeof data === 'function' ? data.apply(this) : data) || {};
this._shareData = (typeof shareData === 'function' ? shareData.apply(this) : shareData) || {};
this._descriptor = options._descriptor;
this.__data = (typeof data === 'function' ? data.apply(this) : data) || {};
this.__shareData = (typeof shareData === 'function' ? shareData.apply(this) : shareData) || {};
this.__descriptor = options._descriptor;
if (global.aceapp && global.aceapp.i18n && global.aceapp.i18n.extend) {
global.aceapp.i18n.extend(this);
}
@ -158,10 +158,10 @@ export default class Vm {
// MergedData means extras params.
if (mergedData) {
if (hasOwn(mergedData, 'paramsData') && hasOwn(mergedData, 'dontOverwrite') && mergedData['dontOverwrite'] === false) {
dataAccessControl(this, mergedData['paramsData'], this._app.options && this._app.options.appCreate);
dataAccessControl(this, mergedData['paramsData'], this.__app.options && this.__app.options.appCreate);
extend(this._data, mergedData['paramsData']);
} else {
dataAccessControl(this, mergedData, this._app.options && this._app.options.appCreate);
dataAccessControl(this, mergedData, this.__app.options && this.__app.options.appCreate);
extend(this._data, mergedData);
}
}
@ -169,7 +169,7 @@ export default class Vm {
initPropsToData(this);
initState(this);
initBases(this);
Log.debug(`"onInit" lifecycle in Vm(${this._type})`);
Log.debug(`"onInit" lifecycle in Vm(${this.__type})`);
if (mergedData && hasOwn(mergedData, 'paramsData') && hasOwn(mergedData, 'dontOverwrite')) {
if (mergedData['dontOverwrite'] === false) {
@ -181,23 +181,23 @@ export default class Vm {
this.$emit('hook:onInit');
}
if (!this._app.doc) {
if (!this.__app.doc) {
return;
}
this.mediaStatus = {};
this.mediaStatus.orientation = this._app.options.orientation;
this.mediaStatus.width = this._app.options.width;
this.mediaStatus.height = this._app.options.height;
this.mediaStatus.resolution = this._app.options.resolution;
this.mediaStatus['device-type'] = this._app.options['device-type'];
this.mediaStatus['aspect-ratio'] = this._app.options['aspect-ratio'];
this.mediaStatus['device-width'] = this._app.options['device-width'];
this.mediaStatus['device-height'] = this._app.options['device-height'];
this.mediaStatus['round-screen'] = this._app.options['round-screen'];
this.mediaStatus['dark-mode'] = this._app.options['dark-mode'];
this.__mediaStatus = {};
this.__mediaStatus.orientation = this.__app.options.orientation;
this.__mediaStatus.width = this.__app.options.width;
this.__mediaStatus.height = this.__app.options.height;
this.__mediaStatus.resolution = this.__app.options.resolution;
this.__mediaStatus['device-type'] = this.__app.options['device-type'];
this.__mediaStatus['aspect-ratio'] = this.__app.options['aspect-ratio'];
this.__mediaStatus['device-width'] = this.__app.options['device-width'];
this.__mediaStatus['device-height'] = this.__app.options['device-height'];
this.__mediaStatus['round-screen'] = this.__app.options['round-screen'];
this.__mediaStatus['dark-mode'] = this.__app.options['dark-mode'];
// If there is no parentElement, specify the documentElement.
this._parentEl = parentEl || this._app.doc.documentElement;
this.__parentEl = parentEl || this.__app.doc.documentElement;
build(this);
}
@ -212,12 +212,12 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'id' should be string or number, not ${typeof id}.`);
return;
}
const info: any = this.ids[id];
const info: any = this._ids[id];
if (info) {
return info.el;
}
} else {
return this.rootEl;
return this.__rootEl;
}
}
@ -227,7 +227,7 @@ export default class Vm {
* @return {Vm} Vm object.
*/
public $vm(id: string): Vm {
const info = this.ids[id];
const info = this._ids[id];
if (info) {
return info.vm;
}
@ -237,7 +237,7 @@ export default class Vm {
* Get parent Vm of current.
*/
public $parent(): Vm {
return this.parent;
return this._parent;
}
/**
@ -255,7 +255,7 @@ export default class Vm {
* Get root element of current.
*/
public $rootElement(): Element {
return this.rootEl;
return this.__rootEl;
}
/**
@ -277,7 +277,7 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'type' should be string, not ${typeof type}.`);
return;
}
const events = this._vmEvents;
const events = this.__vmEvents;
const handlerList = events[type];
if (handlerList) {
const results = [];
@ -300,7 +300,7 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'type' should be string, not ${typeof type}.`);
return;
}
const events = this._vmEvents;
const events = this.__vmEvents;
const handlerList = events[type];
if (handlerList) {
const results = [];
@ -323,8 +323,8 @@ export default class Vm {
}
const evt = new Evt(type, detail);
this.$emit(type, evt);
if (!evt.hasStopped() && this._parent && this._parent.$dispatch) {
this._parent.$dispatch(type, evt);
if (!evt.hasStopped() && this.__parent && this.__parent.$dispatch) {
this.__parent.$dispatch(type, evt);
}
}
@ -340,8 +340,8 @@ export default class Vm {
}
const evt = new Evt(type, detail);
this.$emit(type, evt);
if (!evt.hasStopped() && this._childrenVms) {
this._childrenVms.forEach((subVm) => {
if (!evt.hasStopped() && this.__childrenVms) {
this.__childrenVms.forEach((subVm) => {
subVm.$broadcast(type, evt);
});
}
@ -361,11 +361,11 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'handler' should be function, not ${typeof handler}.`);
return;
}
const events = this._vmEvents;
const events = this.__vmEvents;
const handlerList = events[type] || [];
handlerList.push(handler);
events[type] = handlerList;
if (type === 'hook:onReady' && this._ready) {
if (type === 'hook:onReady' && this.__ready) {
this.$emit('hook:onReady');
}
}
@ -384,7 +384,7 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'handler' should be function, not ${typeof handler}.`);
return;
}
const events = this._vmEvents;
const events = this.__vmEvents;
if (!handler) {
delete events[type];
return;
@ -411,7 +411,7 @@ export default class Vm {
Log.warn(`Invalid parameter type: The type of 'id' should be string, not ${typeof id}.`);
return;
}
const info = this.ids[id];
const info = this._ids[id];
if (info) {
const element = info.el;
const evt = new Evt(type, data);
@ -470,33 +470,33 @@ export default class Vm {
* Delete Vm object.
*/
public destroy(): void {
Log.debug(`[JS Framework] "onDestroy" lifecycle in Vm(${this.type})`);
Log.debug(`[JS Framework] "onDestroy" lifecycle in Vm(${this.__type})`);
this.$emit('hook:onDestroy');
this.$emit('hook:onDetached');
fireNodeDetached(this._rootEl);
this._valid = false;
fireNodeDetached(this.__rootEl);
this.__valid = false;
delete this._app;
delete this._computed;
delete this._css;
delete this._data;
delete this._ids;
delete this._vmOptions;
delete this._parent;
delete this._parentEl;
delete this._rootEl;
delete this.__app;
delete this.__computed;
delete this.__css;
delete this.__data;
delete this.__ids;
delete this.__vmOptions;
delete this.__parent;
delete this.__parentEl;
delete this.__rootEl;
delete this._$refs;
// Destroy child vms recursively.
if (this._childrenVms) {
let vmCount: number = this._childrenVms.length;
if (this.__childrenVms) {
let vmCount: number = this.__childrenVms.length;
while (vmCount--) {
this.destroy.call(this._childrenVms[vmCount], this._childrenVms[vmCount]);
this.destroy.call(this.__childrenVms[vmCount], this.__childrenVms[vmCount]);
}
delete this._childrenVms;
delete this.__childrenVms;
}
delete this._type;
delete this._vmEvents;
delete this.__type;
delete this.__vmEvents;
}
/**
@ -539,8 +539,8 @@ export default class Vm {
* @type {Object}
* @readonly
*/
public get methods() {
return this._methods;
public get _methods() {
return this.__methods;
}
/**
@ -548,12 +548,12 @@ export default class Vm {
* @type {string}
* @readonly
*/
public get type() {
return this._type;
public get _type() {
return this.__type;
}
public set type(newType: string) {
this._type = newType;
public set _type(newType: string) {
this.__type = newType;
}
/**
@ -561,20 +561,20 @@ export default class Vm {
* @type {[key: string]: any}
* @readonly
*/
public get css() {
return this._css;
public get _css() {
return this.__css;
}
/**
* Options of this Vm.
* @type {VmOptions}
*/
public get vmOptions() {
return this._vmOptions;
public get _vmOptions() {
return this.__vmOptions;
}
public set vmOptions(newOptions: VmOptions) {
this._vmOptions = newOptions;
public set _vmOptions(newOptions: VmOptions) {
this.__vmOptions = newOptions;
}
/**
@ -582,20 +582,20 @@ export default class Vm {
* @type {Vm}
* @readonly
*/
public get parent() {
return this._parent;
public get _parent() {
return this.__parent;
}
/**
* RealParent of this Vm.
* @type {Vm}
*/
public get realParent() {
return this._realParent;
public get _realParent() {
return this.__realParent;
}
public set realParent(realParent: Vm) {
this._realParent = realParent;
public set _realParent(realParent: Vm) {
this.__realParent = realParent;
}
/**
@ -603,11 +603,11 @@ export default class Vm {
* @type {ComputedInterface}
*/
public get computed() {
return this._computed;
return this.__computed;
}
public set computed(newComputed: ComputedInterface) {
this._computed = newComputed;
this.__computed = newComputed;
}
/**
@ -615,56 +615,56 @@ export default class Vm {
* @type {Object}
* @readonly
*/
public get selector() {
return this._selector;
public get _selector() {
return this.__selector;
}
/**
* ParentEl of this Vm.
* @type {FragBlockInterface | Element}
*/
public get parentEl() {
return this._parentEl;
public get _parentEl() {
return this.__parentEl;
}
public set parentEl(newParentEl: FragBlockInterface | Element) {
this._parentEl = newParentEl;
public set _parentEl(newParentEl: FragBlockInterface | Element) {
this.__parentEl = newParentEl;
}
/**
* App of this Vm.
* @type {Page}
*/
public get app() {
return this._app;
public get _app() {
return this.__app;
}
public set app(newApp: Page) {
this._app = newApp;
public set _app(newApp: Page) {
this.__app = newApp;
}
/**
* ShareData of this Vm.
* @type {*}
*/
public get shareData() {
return this._shareData;
public get _shareData() {
return this.__shareData;
}
public set shareData(newShareData: object) {
this._shareData = newShareData;
public set _shareData(newShareData: object) {
this.__shareData = newShareData;
}
/**
* Data of this Vm.
* @type {*}
*/
public get __data() {
return this._data;
public get _data() {
return this.__data;
}
public set __data(newData: any) {
this._data = newData;
public set _data(newData: any) {
this.__data = newData;
}
/**
@ -672,20 +672,20 @@ export default class Vm {
* @type {Props}
* @readonly
*/
public get props() {
return this._props;
public get _props() {
return this.__props;
}
/**
* Init of this Vm.
* @type {boolean}
*/
public get init() {
return this._init;
public get _init() {
return this.__init;
}
public set init(newInit: boolean) {
this._init = newInit;
public set _init(newInit: boolean) {
this.__init = newInit;
}
/**
@ -693,44 +693,44 @@ export default class Vm {
* @type {boolean}
* @readonly
*/
public get valid() {
return this._valid;
public get _valid() {
return this.__valid;
}
/**
* Visible of this Vm.
* @type {boolean}
*/
public get visible() {
return this._visible;
public get _visible() {
return this.__visible;
}
public set visible(newVisible) {
this._visible = newVisible;
public set _visible(newVisible) {
this.__visible = newVisible;
}
/**
* Ready of this Vm.
* @type {boolean}
*/
public get ready() {
return this._ready;
public get _ready() {
return this.__ready;
}
public set ready(newReady: boolean) {
this._ready = newReady;
public set _ready(newReady: boolean) {
this.__ready = newReady;
}
/**
* RootEl of this Vm.
* @type {Element}
*/
public get rootEl() {
return this._rootEl;
public get _rootEl() {
return this.__rootEl;
}
public set rootEl(newRootEl: Element) {
this._rootEl = newRootEl;
public set _rootEl(newRootEl: Element) {
this.__rootEl = newRootEl;
}
/**
@ -738,8 +738,8 @@ export default class Vm {
* @type {{[key: string]: { vm: Vm, el: Element}}}
* @readonly
*/
public get ids() {
return this._ids;
public get _ids() {
return this.__ids;
}
/**
@ -747,28 +747,28 @@ export default class Vm {
* @type {Object}
* @readonly
*/
public get vmEvents() {
return this._vmEvents;
public get _vmEvents() {
return this.__vmEvents;
}
/**
* children of vm.
* @return {Array} - children of Vm.
*/
public get childrenVms() {
return this._childrenVms;
public get _childrenVms() {
return this.__childrenVms;
}
/**
* ExternalBinding of this Vm.
* @type {ExternalBinding}
*/
public get externalBinding() {
return this._externalBinding;
public get _externalBinding() {
return this.__externalBinding;
}
public set externalBinding(newExternalBinding: ExternalBindingInterface) {
this._externalBinding = newExternalBinding;
public set _externalBinding(newExternalBinding: ExternalBindingInterface) {
this.__externalBinding = newExternalBinding;
}
/**
@ -776,32 +776,32 @@ export default class Vm {
* @type {string}
* @readonly
*/
public get descriptor() {
return this._descriptor;
public get _descriptor() {
return this.__descriptor;
}
/**
* IsHide of this Vm.
* @type {boolean}
*/
public get isHide() {
return this._isHide;
public get _isHide() {
return this.__isHide;
}
public set isHide(newIsHide: boolean) {
this._isHide = newIsHide;
public set _isHide(newIsHide: boolean) {
this.__isHide = newIsHide;
}
/**
* MediaStatus of this Vm.
* @type {MediaStatusInterface<string, boolean>}
*/
public get mediaStatus() {
return this._mediaStatus;
public get _mediaStatus() {
return this.__mediaStatus;
}
public set mediaStatus(newMediaStatus: Partial<MediaStatusInterface<string, boolean>>) {
this._mediaStatus = newMediaStatus;
public set _mediaStatus(newMediaStatus: Partial<MediaStatusInterface<string, boolean>>) {
this.__mediaStatus = newMediaStatus;
}
/**
@ -817,12 +817,12 @@ export default class Vm {
* slotContext of this Vm.
* @type { content: Record<string, any>, parentVm: Vm }
*/
public get slotContext() {
return this._slotContext;
public get _slotContext() {
return this.__slotContext;
}
public set slotContext(newMSoltContext: { content: Record<string, any>, parentVm: Vm }) {
this._slotContext = newMSoltContext;
public set _slotContext(newMSoltContext: { content: Record<string, any>, parentVm: Vm }) {
this.__slotContext = newMSoltContext;
}
}
@ -877,11 +877,11 @@ function dataAccessControl(vm: any, mergedData: object, external: boolean): void
* @return {Vm} Root vm.
*/
function getRoot(vm: any): Vm {
const parent = vm.parent;
const parent = vm._parent;
if (!parent) {
return vm;
}
if (parent._rootVm) {
if (parent.__rootVm) {
return vm;
}
return getRoot(parent);

View File

@ -123,7 +123,7 @@ const PAGE_LIFE_CYCLE_TYPES: Array<PageLifecycleHooks> = [
* @param {Element} element - Element object.
*/
export function bindPageLifeCycle(vm: Vm, element: Element): void {
const options = vm.vmOptions || {};
const options = vm._vmOptions || {};
PAGE_LIFE_CYCLE_TYPES.forEach(type => {
let eventType;
if (type === PageLifecycleHooks.ONSHOW) {
@ -166,10 +166,10 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void {
function eventHandle(event, ...args: any[]): any {
if (type === PageLifecycleHooks.ONSHOW) {
emitSubVmLife(vm, 'onPageShow');
vm.visible = true;
vm._visible = true;
} else if (type === PageLifecycleHooks.ONHIDE) {
emitSubVmLife(vm, 'onPageHide');
vm.visible = false;
vm._visible = false;
} else if (type === PageLifecycleHooks.ONCONFIGURATIONUPDATED) {
return vm.$emitDirect(`hook:${type}`, ...args);
}
@ -203,7 +203,7 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void {
if (!result) {
return false;
}
const shareResult = vm.shareData || {};
const shareResult = vm._shareData || {};
if (shareResult instanceof Object && !(shareResult instanceof Array)) {
allData.shareData = shareResult;
}
@ -219,11 +219,11 @@ export function bindPageLifeCycle(vm: Vm, element: Element): void {
const saveData = restoreData.saveData || {};
const shareData = restoreData.shareData || {};
Object.assign(vm.shareData, shareData);
Object.assign(vm._shareData, shareData);
return vm.$emitDirect(`hook:${type}`, saveData);
}
function handleNewRequest(data: any) {
Object.assign(vm.__data, data);
Object.assign(vm._data, data);
return vm.$emitDirect(`hook:${type}`);
}
});
@ -255,8 +255,8 @@ export function watch(vm: Vm, data: string, callback: ((...args: any) => any) |
if (typeof callback === 'function') {
callback(value, oldValue);
} else {
if (vm.methods[callback] && typeof vm.methods[callback] === 'function') {
vm.methods[callback](value, oldValue);
if (vm._methods[callback] && typeof vm._methods[callback] === 'function') {
vm._methods[callback](value, oldValue);
}
}
}, null);
@ -268,9 +268,9 @@ export function watch(vm: Vm, data: string, callback: ((...args: any) => any) |
* @param {Vm} vm - Vm object.
*/
export function initPropsToData(vm: Vm): void {
vm.props.forEach(prop => {
if (vm.__data) {
vm.__data[prop] = vm[prop];
vm._props.forEach(prop => {
if (vm._data) {
vm._data[prop] = vm[prop];
}
});
}
@ -281,8 +281,8 @@ export function initPropsToData(vm: Vm): void {
* @param {String} type - event type
*/
export function emitSubVmLife(vm: Vm, type:string) {
if (vm.childrenVms) {
vm.childrenVms.forEach((subVm) => {
if (vm._childrenVms) {
vm._childrenVms.forEach((subVm) => {
subVm.$emit(`hook:${type}`);
emitSubVmLife(subVm, type);
});

View File

@ -51,8 +51,10 @@ export class Image {
width: this._width,
height: this._height,
success: data => {
this._width = data.width;
this._height = data.height;
if (this.onload && typeof this.onload === 'function') {
this.onload(data);
this.onload();
}
},
fail: data => {

View File

@ -117,5 +117,5 @@ export function bootstrap(page: Page, name: string, data: any): any {
}
// Create a new Vm and mark rootVm.
page.vm = new Vm(componentName, null, { _app: page, _rootVm: true }, null, data, null);
page.vm = new Vm(componentName, null, { __app: page, __rootVm: true }, null, data, null);
}

View File

@ -104,6 +104,10 @@ export function init(page: Page, code: string | Function, data: object, services
// Support page global and init language.
global.__appProto__ = getPageGlobal(page.packageName);
global.language = page.options.language;
global.$app_define$ = pageDefine;
global.$app_require$ = pageRequireModule;
global.Image = imageObj;
global.OffscreenCanvas = offscreenCanvasObj;
let functionCode: string;
if (typeof code !== 'function') {

View File

@ -18,9 +18,9 @@ export function initState (vm) {
}
export function initData (vm) {
let data = vm._data;
let data = vm.__data;
initDataSegment(vm, data);
let shareData = vm._shareData;
let shareData = vm.__shareData;
initDataSegment(vm, shareData);
}
@ -40,7 +40,7 @@ export function initDataSegment (vm, data) {
}
export function initBases(vm) {
const options = vm.vmOptions
const options = vm.__vmOptions
// mixins exist?
if(hasOwn(options, 'mixins')) {
options['mixins'].forEach(mixin => {
@ -63,7 +63,7 @@ function noop () {
}
export function initComputed (vm) {
const computed = vm._computed;
const computed = vm.__computed;
if (computed) {
for (let key in computed) {
const userDef = computed[key];
@ -105,7 +105,7 @@ function makeComputedGetter (getter, owner) {
}
export function initMethods (vm) {
const options = vm._vmOptions;
const options = vm.__vmOptions;
for (let key in options) {
if (typeof options[key] === 'function' && key !== 'data') {
vm._methods[key] = options[key].bind(vm);
@ -119,10 +119,10 @@ function proxyMethods(vm, key) {
configurable: true,
enumerable: true,
get: function proxyGetter () {
return vm._methods[key];
return vm.__methods[key];
},
set: function proxySetter(newValue) {
vm._methods[key] = typeof newValue === 'function' && key !== 'data' ?
vm.__methods[key] = typeof newValue === 'function' && key !== 'data' ?
newValue.bind(vm) : newValue;
}
})

View File

@ -78,3 +78,19 @@ export function isObject(any) {
export function isPlainObject(any) {
return Object.prototype.toString.call(any) === '[object Object]';
}
/**
* Convert ArrayBuffer to Base64.
* @param {*} buffer - Binary data buffer.
* @return {string} Base64 encoding string.
*/
export function bufferToBase64 (buffer) {
if (typeof btoa !== 'function') {
return '';
}
const string = Array.prototype.map.call(
new Uint8Array(buffer),
code => String.fromCharCode(code)
).join('');
return btoa(string);
}

View File

@ -111,91 +111,92 @@ type components<T> = {
}
const ComponentsInfo: components<string>[] = [
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'clock'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'image'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'label'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item-group'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'progress'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'rating'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'select'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'switch'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tabs'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-bar'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-content'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'text'},
{'methods': ['focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'div'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'clock'},
{'methods': ['show'], 'type': 'colorpicker'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'image'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'label'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'list-item-group'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'progress'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'rating'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'select'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'switch'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tabs'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-bar'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'tab-content'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'text'},
{'methods': ['focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'div'},
{
'methods': ['setProgress', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['setProgress', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'button'
},
{'methods': ['append', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'chart'},
{'methods': ['goto', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'calendar'},
{'methods': ['append', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'chart'},
{'methods': ['goto', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'calendar'},
{
'methods': ['getContext', 'toDataURL', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['getContext', 'toDataURL', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'canvas'
},
{
'methods': ['getXComponentContext', 'createIntersectionObserver'],
'methods': ['getXComponentContext', 'createIntersectionObserver', 'addChild'],
'type': 'xcomponent'
},
{'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'dialog'},
{'methods': ['animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'divider'},
{'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'dialog'},
{'methods': ['animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'divider'},
{
'methods': ['getColumns', 'getColumnWidth', 'getGutterWidth', 'getSizeType', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['getColumns', 'getColumnWidth', 'getGutterWidth', 'getSizeType', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'],
'type': 'grid-container'
},
{
'methods': ['start', 'stop', 'pause', 'resume', 'getState', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['start', 'stop', 'pause', 'resume', 'getState', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'image-animator'
},
{
'methods': ['showError', 'delete', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['showError', 'delete', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'input'
},
{
'methods': ['scrollTo', 'scrollBy', 'focus', 'scrollArrow', 'scrollTop', 'scrollBottom', 'scrollPage', 'collapseGroup', 'expandGroup', 'currentOffset', 'rotation', 'animate', 'chainanimation', 'getBoundingClientRect', 'getScrollOffset', 'createIntersectionObserver'],
'methods': ['scrollTo', 'scrollBy', 'focus', 'addChild', 'scrollArrow', 'scrollTop', 'scrollBottom', 'scrollPage', 'collapseGroup', 'expandGroup', 'currentOffset', 'rotation', 'animate', 'chainanimation', 'getBoundingClientRect', 'getScrollOffset', 'createIntersectionObserver'],
'type': 'list'
},
{
'methods': ['start', 'stop', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['start', 'stop', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'marquee'
},
{'methods': ['show', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'menu'},
{'methods': ['focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'option'},
{'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'panel'},
{'methods': ['show', 'animate', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'picker'},
{'methods': ['show', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'menu'},
{'methods': ['focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'option'},
{'methods': ['show', 'close', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver', 'addChild'], 'type': 'panel'},
{'methods': ['show', 'animate', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'picker'},
{
'methods': ['rotation', 'animate', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['rotation', 'animate', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'picker-view'
},
{'methods': ['focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'piece'},
{'methods': ['focus', 'show', 'hide', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'popup'},
{'methods': ['animate', 'focus', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'search'},
{'methods': ['focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'piece'},
{'methods': ['focus', 'addChild', 'show', 'hide', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'popup'},
{'methods': ['animate', 'focus', 'addChild', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'], 'type': 'search'},
{
'methods': ['rotation', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['rotation', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'slider'
},
{'methods': ['focus', 'animate', 'getScrollOffset', 'scrollBy', 'getBoundingClientRect', 'scrollTo', 'createIntersectionObserver'], 'type': 'stack'},
{'methods': ['focus', 'addChild', 'animate', 'getScrollOffset', 'scrollBy', 'getBoundingClientRect', 'scrollTo', 'createIntersectionObserver'], 'type': 'stack'},
{
'methods': ['swipeTo', 'focus', 'showPrevious', 'showNext', 'rotation', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['swipeTo', 'focus', 'addChild', 'showPrevious', 'showNext', 'rotation', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'swiper'
},
{
'methods': ['start', 'pause', 'stop', 'setCurrentTime', 'requestFullscreen', 'exitFullscreen', 'focus', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['start', 'pause', 'stop', 'setCurrentTime', 'requestFullscreen', 'exitFullscreen', 'focus', 'addChild', 'animate', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'video'
},
{
'methods': ['setNextButtonStatus', 'focus', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['setNextButtonStatus', 'focus', 'addChild', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'stepper'
},
{
'methods': ['focus', 'animate', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'methods': ['focus', 'addChild', 'animate', 'delete', 'getBoundingClientRect', 'scrollBy', 'getScrollOffset', 'scrollTo', 'createIntersectionObserver'],
'type': 'textarea'
},
{'methods': ['reload', 'createIntersectionObserver'], 'type': 'web'},
{'methods': ['reload', 'createIntersectionObserver', 'addChild'], 'type': 'web'},
{
'methods': ['takePhoto', 'startRecorder', 'closeRecorder', 'scrollTo', 'createIntersectionObserver'],
'methods': ['takePhoto', 'startRecorder', 'closeRecorder', 'scrollTo', 'createIntersectionObserver', 'addChild'],
'type': 'camera'
}
];

View File

@ -30,7 +30,8 @@ export {
remove,
hasOwn,
isObject,
isPlainObject
isPlainObject,
bufferToBase64
} from '../main/util/shared';
export {

View File

@ -74,8 +74,10 @@ class DocumentElement extends Element {
element.docId = document.id;
element.ownerDocument = document;
this.linkChild(this);
if (this.ownerDocument) {
delete this.ownerDocument.nodeMap[element.nodeId];
}
}
this.pureChildren.push(element);
this.ownerDocument.sentBodyToNative(element);
} else {

View File

@ -26,13 +26,17 @@ import Node from './Node';
import NativeElementClassFactory from './NativeElementClassFactory';
import Document from './Document';
import { TaskCenter } from '../main/manage/event/TaskCenter';
import { FragBlockInterface } from '../main/model/compiler';
import { FragBlockInterface,
TemplateInterface,
compileCustomComponent,
targetIsComposed
} from '../main/model/compiler';
import Vm from '../main/model';
import { CSS_INHERITANCE } from '../main/app/bundle';
import { interceptCallback } from '../main/manage/event/callbackIntercept';
import { mockwebgl } from '../main/extend/systemplugin/napi/webgl';
import { mockwebgl2 } from '../main/extend/systemplugin/napi/webgl2';
import {interceptCallback} from '../main/manage/event/callbackIntercept';
import {mockwebgl} from '../main/extend/systemplugin/napi/webgl';
import {mockwebgl2} from '../main/extend/systemplugin/napi/webgl2';
import { VmOptions } from '../main/model/vmOptions';
/**
* Element is a basic class to describe a tree node in vdom.
* @extends Node
@ -43,18 +47,21 @@ class Element extends Node {
private _event: any;
private _idStyle: any;
private _tagStyle: any;
private _universalStyle: any;
private _id: string | null;
private _classList: any[];
private _block: FragBlockInterface;
private _vm: Vm;
private _isCustomComponent: boolean;
private _inheritedStyle: object;
private _target:TemplateInterface;
protected _children: Node[];
protected _pureChildren: Element[];
protected _role: string;
protected _attr: any;
protected _dataSet: any;
protected _isFirstDyanmicName: boolean;
constructor(type = 'div', props:any = {}, isExtended: boolean = false) {
super();
@ -97,6 +104,7 @@ class Element extends Node {
this._event = {};
this._idStyle = {};
this._tagStyle = {};
this._universalStyle = {};
this._id = null;
this._classList = [];
this._children = [];
@ -104,6 +112,7 @@ class Element extends Node {
this._isCustomComponent = false;
this._inheritedStyle = {};
this._dataSet = {};
this._isFirstDyanmicName = true;
}
/**
@ -163,13 +172,21 @@ class Element extends Node {
}
/**
* Style object of this Element, which keys is style name, and values is style values.
* Class style object of this Element, which keys is style name, and values is style values.
* @type {JSON}
*/
public get classStyle() {
return this._classStyle;
}
/**
* Id style object of this Element, which keys is style name, and values is style values.
* @type {JSON}
*/
public get idStyle() {
return this._idStyle;
}
/**
* Block in this Element.
* @type {FragBlock}
@ -266,6 +283,18 @@ class Element extends Node {
return this._style;
}
/**
* target object of this Element.
* @type {Object}
*/
public set target(target: TemplateInterface) {
this._target = target;
}
public get target() {
return this._target;
}
/**
* Get TaskCenter instance by id.
* @param {string} id
@ -288,7 +317,9 @@ class Element extends Node {
if (this._docId) {
child.docId = this._docId;
child.ownerDocument = this._ownerDocument;
if (child.ownerDocument) {
child.ownerDocument.nodeMap[child.nodeId] = child;
}
child.depth = this._depth + 1;
}
if (child.nodeType === Node.NodeType.Element) {
@ -656,6 +687,26 @@ class Element extends Node {
result[key] = value;
taskCenter.send('dom', { action: 'updateAttrs' }, [this.ref, result]);
}
if (this._type === 'compontent' && key === 'name') {
if (this._isFirstDyanmicName === true) {
Log.info('compontent first setAttr name = ' + value);
this._isFirstDyanmicName = false;
} else {
Log.info('compontent second setAttr name,' + value);
if (taskCenter) {
const node = this._nextSibling;
taskCenter.send('dom', { action: 'removeElement' }, [node.ref]);
}
const parentNode = this._parentNode as Element;
const component: VmOptions | null = targetIsComposed(this._vm, value.toString());
const meta = {};
if (component) {
compileCustomComponent(this._vm, component, this._target, parentNode, value.toString(), meta);
return;
}
}
}
}
/**
@ -732,9 +783,7 @@ class Element extends Node {
this._idStyle[key] = value;
const taskCenter = this.getTaskCenter(this.docId);
if (!silent && taskCenter) {
const result = {};
result[key] = value;
taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, result]);
taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, this._idStyle]);
if (CSS_INHERITANCE.includes(key)) {
this.broadcastStyle();
}
@ -764,6 +813,24 @@ class Element extends Node {
}
}
public setUniversalStyle(key: string, value: string | number, silent: boolean = false): void {
if (this._universalStyle[key] === value && silent !== false) {
return;
}
// If inline id class style has define return.
if (this.style[key] || this._idStyle[key] || this._classStyle[key] || this._tagStyle[key]) {
return;
}
this._universalStyle[key] = value;
const taskCenter = this.getTaskCenter(this.docId);
if (!silent && taskCenter) {
const result = {};
result[key] = value;
taskCenter.send('dom', { action: 'updateStyle' }, [this.ref, result]);
}
}
/**
* Add an event handler.
* @param {string} type - Event name.
@ -853,6 +920,7 @@ class Element extends Node {
public toStyle(): any {
// Selector Specificity inline > #id > .class > tag > inheritance.
const style = Object.assign({}, this._inheritedStyle);
this.assignStyle(style, this._universalStyle);
this.assignStyle(style, this._tagStyle);
this.assignStyle(style, this._classStyle);
this.assignStyle(style, this._idStyle);
@ -956,6 +1024,7 @@ class Element extends Node {
this._event = {};
this._idStyle = {};
this._tagStyle = {};
this._universalStyle = {};
this._classList.length = 0;
if (this.destroyHook) {
@ -1057,8 +1126,10 @@ class Element extends Node {
private registerNode(node) {
const doc = this._ownerDocument;
if (doc) {
doc.nodeMap[node.nodeId] = node;
}
}
}
export default Element;

View File

@ -45,7 +45,7 @@ describe('receiveTasks', () => {
'aspect-ratio': 'string',
'device-width': '1176',
'device-height': '2400',
roundScreen: false,
'round-screen': false,
width: '0',
height: '0',
isInit: true,

View File

@ -30,7 +30,8 @@ import {
} from '../../fakeLog';
import {
bindSubVm,
bindSubVmAfterInitialized
bindSubVmAfterInitialized,
setAttr
} from '../../../runtime/main/model/directive';
import { initState } from '../../../runtime/main/reactivity/state';
import config from '../../../runtime/main/config';
@ -97,7 +98,7 @@ describe('bind external infomations to sub vm', () => {
b: String
}
},
props: []
_props: []
};
});
@ -112,7 +113,7 @@ describe('bind external infomations to sub vm', () => {
}, {});
expect(subVm.a).eql(3);
expect(subVm.b).to.be.undefined;
expect(subVm.rootEl).to.be.undefined;
expect(subVm._rootEl).to.be.undefined;
});
it('bind props with external data', () => {
@ -126,7 +127,7 @@ describe('bind external infomations to sub vm', () => {
});
it('bind styles to a sub vm with root element', () => {
subVm.rootEl = {
subVm._rootEl = {
attr: {},
style: {},
event: []
@ -136,14 +137,161 @@ describe('bind external infomations to sub vm', () => {
return this.data.a;
} }
};
initElement(subVm.rootEl);
initElement(subVm._rootEl);
bindSubVm(vm, subVm, template, {});
// @ts-ignore
bindSubVmAfterInitialized(vm, subVm, template, {});
expect(subVm.rootEl.style.aaa).eql(2);
expect(subVm.rootEl.style.bbb).eql(1);
expect(subVm._rootEl.style.aaa).eql(2);
expect(subVm._rootEl.style.bbb).eql(1);
});
fakeLogRestore();
});
/*
1. api 7 data* ->$data set to dataset ,data ->data data set to attr;
2. api 6 data* -> data set to datasetdata -> data set to attrdata and data* are not compatible ar compile time);
3. api 5 data -> data set to attr.
*/
describe('set $data and data to element to check API 7 scene', () => {
fakeLog();
let vm: any;
let attr1: any;
let attr2: any;
let element: any
let SETTERS = {
attr: 'setAttr',
data: 'setData',
$data: 'setData'
}
before(() => {
vm = {
__data: { c: '333', d: '444'},
_watchers: [],
};
attr1 = {
data: '111',
$data: { b: '222' }
};
attr2 = {
data: function () {return vm.__data.c},
$data: { url: function () {return vm.__data.d} }
};
element = {
dataSet: {},
attr: {},
watchers: [],
setData: function setData(key: string, value: string): void {
this.dataSet[key] = value;
},
setAttr: function(key: string, value: string | number): void {
if (this.attr[key] === value) {
return;
}
this.attr[key] = value;
}
};
});
it('set data and $data to element', () => {
setAttr(vm, element, attr1)
expect(element.attr.data).eql('111');
expect(element.dataSet.b).eql('222');
})
it('set data and $data which is function to element', () => {
setAttr(vm, element, attr2)
expect(element.attr.data).eql('333');
expect(element.dataSet.url).eql('444');
})
fakeLogRestore();
});
describe('set data and data* to element to check API 6 scene', () => {
fakeLog();
let vm: any;
let attr1: any;
let attr2: any;
let element: any
let SETTERS = {
attr: 'setAttr',
data: 'setData'
}
before(() => {
vm = {};
attr1 = {
data: '111'
};
attr2 = {
data: { url: '222'}
};
element = {
dataSet: {},
attr: {},
setData: function setData(key: string, value: string): void {
this.dataSet[key] = value;
},
setAttr: function(key: string, value: string | number): void {
if (this.attr[key] === value) {
return;
}
this.attr[key] = value;
}
};
});
it('set data to element', () => {
setAttr(vm, element, attr1)
expect(element.attr.data).eql('111');
})
it('set data* to element', () => {
setAttr(vm, element, attr2)
expect(element.dataSet.url).eql('222');
})
fakeLogRestore();
});
describe('set data only to element attr to to check API 5 scene', () => {
fakeLog();
let vm: any;
let attr: any;
let element: any
let SETTERS = {
attr: 'setAttr',
data: 'setData'
}
before(() => {
vm = {};
attr = {
data: '111'
};
element = {
dataSet: {},
attr: {},
setData: function setData() {},
setAttr: function(key: string, value: string | number): void {
if (this.attr[key] === value) {
return;
}
this.attr[key] = value;
}
};
});
it('set data to element', () => {
setAttr(vm, element, attr)
expect(element.attr.data).eql('111');
})
fakeLogRestore();
});

View File

@ -40,9 +40,9 @@ describe('api of communication between vm and data methods', () => {
orientation: 1,
width: 1,
height: 1,
aspectRatio: 1,
deviceWidth: 1,
deviceHeight: 1,
'aspect-ratio': 1,
'device-width': 1,
'device-height': 1,
resolution: 1,
accessType: 1
};
@ -87,8 +87,8 @@ describe('api of communication between vm and data methods', () => {
'parent',
null,
{
_app: page,
_rootVm: true
__app: page,
__rootVm: true
},
null,
null,
@ -97,24 +97,24 @@ describe('api of communication between vm and data methods', () => {
const spyParent = sinon.spy();
const spyChild = sinon.spy();
const subVm = vm.childrenVms[0];
const subVm = vm._childrenVms[0];
vm.$on('event1', spyParent);
subVm.$on('event1', spyChild);
it('$on && $off', () => {
const fn = function() {};
vm.$on('event1', fn);
expect(vm.vmEvents['event1'].length).eql(2);
expect(typeof vm.vmEvents['event1'][1]).eql('function');
expect(vm._vmEvents['event1'].length).eql(2);
expect(typeof vm._vmEvents['event1'][1]).eql('function');
vm.$off('event1', fn);
expect(vm.vmEvents['event1'].length).eql(1);
expect(typeof vm.vmEvents['event1'][1]).eql('undefined');
expect(vm._vmEvents['event1'].length).eql(1);
expect(typeof vm._vmEvents['event1'][1]).eql('undefined');
});
it('$emit', () => {
expect(vm.type).eql('parent');
expect(subVm.type).eql('child');
expect(vm._type).eql('parent');
expect(subVm._type).eql('child');
let detail = { lunch: 'banana' };
vm.$emit('event1', detail);
@ -164,15 +164,15 @@ describe('api of communication between vm and data methods', () => {
});
it('$root', () => {
expect(subVm.$root().type).eql('parent');
expect(subVm.$root()._type).eql('parent');
});
it('$parent', () => {
expect(subVm.$parent().type).eql('parent');
expect(subVm.$parent()._type).eql('parent');
});
it('$child', () => {
expect(vm.$child('myChild').type).eql('child');
expect(vm.$child('myChild')._type).eql('child');
});
it('$element', () => {
@ -199,13 +199,13 @@ describe('api of communication between vm and data methods', () => {
};
const app = { doc, customComponentMap, differ, options };
const vm = new Vm('foo', customComponentMap.foo, { _app: app, _rootVm: true }, null, data, null);
const vm = new Vm('foo', customComponentMap.foo, { __app: app, __rootVm: true }, null, data, null);
doc.destroy();
const detail = { aaa: 1 };
vm.$set('test.aaa', detail);
expect(typeof vm.__data['test.aaa']).eql('object');
expect(typeof vm._data['test.aaa']).eql('object');
vm.$delete('test.aaa');
expect(typeof vm.__data['test.aaa']).eql('undefined');
expect(typeof vm._data['test.aaa']).eql('undefined');
});
it('$watch', () => {
@ -222,8 +222,8 @@ describe('api of communication between vm and data methods', () => {
};
const app = { doc, customComponentMap, differ, options };
const vm = new Vm('foo', customComponentMap.foo, { _app: app, _rootVm: true }, null, data, null);
expect(vm.app).to.deep.equal(app);
const vm = new Vm('foo', customComponentMap.foo, { __app: app, __rootVm: true }, null, data, null);
expect(vm._app).to.deep.equal(app);
expect(typeof doc.body).eql('object');
data.x.y = 5;

View File

@ -54,16 +54,16 @@ describe('framework entry', () => {
let instanceId;
const options = {
orientation: 'portrait',
deviceType: 'phone',
'device-type': 'phone',
resolution: '3.0',
aspectRatio: 'string',
deviceWidth: '1176',
deviceHeight: '2400',
roundScreen: false,
'aspect-ratio': 'string',
'device-width': '1176',
'device-height': '2400',
'round-screen': false,
width: '0',
height: '0',
isInit: true,
darkMode: 'false',
'dark-mode': 'false',
pcPreview: 'disable',
appInstanceId: '10002',
packageName: 'com.example.helloworld',