1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { paramMock } from '../utils'; 17 18export function mockAccessibility() { 19 const AbilityTypeMock = '[PC Preview] unknown AbilityType'; 20 21 const CapabilityMock = '[PC Preview] unknown Capability'; 22 23 const EventTypeMock = '[PC Preview] unknown EventType'; 24 25 const AccessibilityAbilityInfo = { 26 id: '[PC Preview] unknown id', 27 name: '[PC Preview] unknown name', 28 bundleName: '[PC Preview] unknown bundleName', 29 TargetBundleName: ['[PC Preview] unknown TargetBundleName'], 30 abilityTypes: [AbilityTypeMock], 31 capabilities: [CapabilityMock], 32 description: '[PC Preview] unknown description', 33 eventTypes: [EventTypeMock] 34 }; 35 36 const CaptionsFontEdgeTypeMock = '[PC Preview] unknown CaptionsFontEdgeType'; 37 38 const CaptionsFontFamilyMock = '[PC Preview] unknown CaptionsFontFamily'; 39 40 const CaptionStyle = { 41 fontFamily: CaptionsFontFamilyMock, 42 fontScale: '[PC Preview] unknown fontScale', 43 fontColor: '[PC Preview] unknown fontColor', 44 fontEdgeType: CaptionsFontEdgeTypeMock, 45 backgroundColor: '[PC Preview] unknown backgroundColor', 46 windowColor: '[PC Preview] unknown windowColor' 47 }; 48 49 const CaptionsManagerMock = { 50 enabled: '[PC Preview] unknown enabled', 51 style: CaptionStyle, 52 on: function (...args) { 53 console.warn('CaptionsManager.on interface mocked in the Previewer.' + 54 ' How this interface works on the Previewer may be different from that on a real device.'); 55 const len = args.length; 56 if (len > 1 && typeof args[len - 1] === 'function') { 57 if (args[0] === 'enableChange') { 58 args[len - 1].call(this, paramMock.paramBooleanMock); 59 } else if (args[0] === 'styleChange') { 60 args[len - 1].call(this, CaptionStyle); 61 } 62 } 63 }, 64 off: function (...args) { 65 console.warn('CaptionsManager.off interface mocked in the Previewer.' + 66 ' How this interface works on the Previewer may be different from that on a real device.'); 67 const len = args.length; 68 if (len > 1 && typeof args[len - 1] === 'function') { 69 if (args[0] === 'enableChange') { 70 args[len - 1].call(this, paramMock.paramBooleanMock); 71 } else if (args[0] === 'styleChange') { 72 args[len - 1].call(this, CaptionStyle); 73 } 74 } 75 }, 76 }; 77 78 const WindowUpdateTypeMock = '[PC Preview] unknown WindowUpdateType'; 79 80 const ActionMock = '[PC Preview] unknown Action'; 81 82 const TextMoveUnitMock = '[PC Preview] unknown TextMoveUnit'; 83 84 const EventInfoClass = class EventInfo { 85 constructor(...args) { 86 console.warn('accessibility.EventInfoClass.constructor interface mocked in the Previewer.' + 87 ' How this interface works on the Previewer may be different from that on a real device.'); 88 this.type = EventTypeMock; 89 this.windowUpdateType = WindowUpdateTypeMock; 90 this.bundleName = '[PC Preview] unknown bundleName'; 91 this.componentType = '[PC Preview] unknown componentType'; 92 this.pageId = '[PC Preview] unknown pageId'; 93 this.description = '[PC Preview] unknown description'; 94 this.triggerAction = ActionMock; 95 this.textMoveUnit = TextMoveUnitMock; 96 this.contents = ['[PC Preview] unknown content']; 97 this.lastContent = '[PC Preview] unknown lastContent'; 98 this.beginIndex = '[PC Preview] unknown beginIndex'; 99 this.currentIndex = '[PC Preview] unknown currentIndex'; 100 this.endIndex = '[PC Preview] unknown endIndex'; 101 this.itemCount = '[PC Preview] unknown itemCount'; 102 } 103 }; 104 105 const accessibility = { 106 EventInfo: EventInfoClass, 107 isOpenAccessibility: function (...args) { 108 console.warn('accessibility.isOpenAccessibility interface mocked in the Previewer.' + 109 ' How this interface works on the Previewer may be different from that on a real device.'); 110 const len = args.length; 111 if (typeof args[len - 1] === 'function') { 112 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 113 } else { 114 return new Promise((resolve, reject) => { 115 resolve(paramMock.paramBooleanMock); 116 }); 117 } 118 }, 119 isOpenTouchGuide: function (...args) { 120 console.warn('accessibility.isOpenTouchGuide interface mocked in the Previewer.' + 121 ' How this interface works on the Previewer may be different from that on a real device.'); 122 const len = args.length; 123 if (typeof args[len - 1] === 'function') { 124 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 125 } else { 126 return new Promise((resolve) => { 127 resolve(paramMock.paramBooleanMock); 128 }); 129 } 130 }, 131 on: function (...args) { 132 console.warn('accessibility.on interface mocked in the Previewer.' + 133 ' How this interface works on the Previewer may be different from that on a real device.'); 134 const len = args.length; 135 if (typeof args[len - 1] === 'function') { 136 if (args[0] == 'accessibilityStateChange') { 137 args[len - 1].call(this, this, paramMock.paramBooleanMock); 138 } else if (args[0] == 'touchGuideStateChange') { 139 args[len - 1].call(this, paramMock.paramBooleanMock); 140 } else { 141 args[len - 1].call(this, this, paramMock.paramBooleanMock); 142 } 143 } 144 }, 145 off: function (...args) { 146 console.warn('accessibility.off interface mocked in the Previewer.' + 147 ' How this interface works on the Previewer may be different from that on a real device.'); 148 const len = args.length; 149 if (len > 1 && typeof args[len - 1] === 'function') { 150 if (args[0] === 'accessibilityStateChange') { 151 args[len - 1].call(this, paramMock.paramBooleanMock); 152 } else if (args[0] === 'touchGuideStateChange') { 153 args[len - 1].call(this, paramMock.paramBooleanMock); 154 } 155 } 156 }, 157 getAbilityLists: function (...args) { 158 console.warn('accessibility.getAbilityLists interface mocked in the Previewer.' + 159 ' How this interface works on the Previewer may be different from that on a real device.'); 160 const len = args.length; 161 if (typeof args[len - 1] === 'function') { 162 args[len - 1].call(this, paramMock.businessErrorMock, [AccessibilityAbilityInfo]); 163 } else { 164 return new Promise((resolve, reject) => { 165 resolve([AccessibilityAbilityInfo]); 166 }); 167 } 168 }, 169 sendEvent: function (...args) { 170 console.warn('accessibility.sendEvent interface mocked in the Previewer.' + 171 ' How this interface works on the Previewer may be different from that on a real device.'); 172 const len = args.length; 173 if (typeof args[len - 1] === 'function') { 174 args[len - 1].call(this, paramMock.businessErrorMock); 175 } else { 176 return new Promise((resolve, reject) => { 177 resolve(); 178 }); 179 } 180 }, 181 getCaptionsManager: function () { 182 console.warn('accessibility.getCaptionsManager interface mocked in the Previewer. How this interface works on the' + 183 ' Previewer may be different from that on a real device.'); 184 return CaptionsManagerMock; 185 } 186 }; 187 188 return accessibility; 189}