1/* 2 * Copyright (c) 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 mockWorker() { 19 const WorkerOptionsMock = { 20 type: '[PC preview] unknow type', 21 name: '[PC preview] unknow name', 22 shared: '[PC preview] unknow shared' 23 }; 24 25 const EventMock = { 26 type: '[PC preview] unknow type', 27 timeStamp: '[PC preview] unknow timeStamp' 28 }; 29 30 const ErrorEventMock = { 31 message: '[PC preview] unknow message', 32 filename: '[PC preview] unknow filename', 33 lineno: '[PC preview] unknow lineno', 34 colno: '[PC preview] unknow colno', 35 error: '[PC preview] unknow error' 36 }; 37 38 const MessageEventMock = { 39 data: '[PC preview] unknow data' 40 }; 41 42 const PostMessageOptionsMock = { 43 transfer:'[PC preview] unknow transfer' 44 }; 45 46 const EventTargetMock = { 47 addEventListener : function (...args) { 48 console.warn('PostMessageOptions.addEventListener interface mocked in the Previewer. How this interface works on the' + 49 ' Previewer may be different from that on a real device.'); 50 }, 51 dispatchEvent : function (...args) { 52 console.warn('PostMessageOptions.dispatchEvent interface mocked in the Previewer. How this interface works on the' + 53 ' Previewer may be different from that on a real device.'); 54 return paramMock.paramBooleanMock; 55 }, 56 removeEventListener : function (...args) { 57 console.warn("PostMessageOptions.removeEventListener interface mocked in the Previewer. How this interface works on the Previewer" + 58 " may be different from that on a real device."); 59 }, 60 removeAllListener : function (...args) { 61 console.warn("PostMessageOptions.removeAllListener interface mocked in the Previewer. How this interface works on the Previewer" + 62 " may be different from that on a real device."); 63 } 64 }; 65 66 const WorkerGlobalScopeMock = { 67 name: '[PC preview] unknow name', 68 onerror: function (...args) { 69 console.warn("WorkerGlobalScope.onerror interface mocked in the Previewer. How this interface works on the Previewer" + 70 " may be different from that on a real device."); 71 }, 72 self: '[PC preview] unknow self' 73 }; 74 75 const DedicatedWorkerGlobalScopeMock = { 76 onmessage: function (...args) { 77 console.warn("DedicatedWorkerGlobalScope.onmessage interface mocked in the Previewer. How this interface works on the Previewer" + 78 " may be different from that on a real device."); 79 }, 80 onmessageerror: function (...args) { 81 console.warn("DedicatedWorkerGlobalScope.onmessageerror interface mocked in the Previewer. How this interface works on the Previewer" + 82 " may be different from that on a real device."); 83 }, 84 close : function (...args) { 85 console.warn("DedicatedWorkerGlobalScope.close interface mocked in the Previewer. How this interface works on the Previewer" + 86 " may be different from that on a real device."); 87 }, 88 postMessage : function (...args) { 89 console.warn("DedicatedWorkerGlobalScope.postMessage interface mocked in the Previewer. How this interface works on the Previewer" + 90 " may be different from that on a real device."); 91 }, 92 postMessage : function (...args) { 93 console.warn("DedicatedWorkerGlobalScope.postMessage interface mocked in the Previewer. How this interface works on the Previewer" + 94 " may be different from that on a real device."); 95 } 96 }; 97 98 const WorkerClass = class Worker { 99 constructor(...args){ 100 console.warn('Worker.constructor interface mocked in the Previewer. How this interface works on the' + 101 ' Previewer may be different from that on a real device.'); 102 this.postMessage = function (...args) { 103 console.warn("Worker.postMessage interface mocked in the Previewer. How this interface works on the Previewer" + 104 " may be different from that on a real device."); 105 }; 106 this.terminate = function (...args) { 107 console.warn("Worker.terminate interface mocked in the Previewer. How this interface works on the Previewer" + 108 " may be different from that on a real device."); 109 }; 110 this.on = function (...args) { 111 console.warn("Worker.on interface mocked in the Previewer. How this interface works on the Previewer" + 112 " may be different from that on a real device."); 113 }; 114 this.once = function (...args) { 115 console.warn("Worker.once interface mocked in the Previewer. How this interface works on the Previewer" + 116 " may be different from that on a real device."); 117 }; 118 this.off = function (...args) { 119 console.warn("Worker.off interface mocked in the Previewer. How this interface works on the Previewer" + 120 " may be different from that on a real device."); 121 }; 122 this.addEventListener = function (...args) { 123 console.warn("Worker.addEventListener interface mocked in the Previewer. How this interface works on the" + 124 " Previewer may be different from that on a real device."); 125 }; 126 this.dispatchEvent = function (...args) { 127 console.warn("Worker.dispatchEvent interface mocked in the Previewer. How this interface works on the" + 128 " Previewer may be different from that on a real device."); 129 return paramMock.paramBooleanMock; 130 }; 131 this.removeEventListener = function (...args) { 132 console.warn("Worker.removeEventListener interface mocked in the Previewer. How this interface works on the" + 133 " Previewer may be different from that on a real device."); 134 }; 135 this.removeAllListener = function (...args) { 136 console.warn("Worker.removeAllListener interface mocked in the Previewer. How this interface works on the" + 137 " Previewer may be different from that on a real device."); 138 }; 139 this.onmessage = function (...args) { 140 console.warn("Worker.onmessage interface mocked in the Previewer. How this interface works on the Previewer" + 141 " may be different from that on a real device."); 142 }; 143 this.onmessageerror = function (...agrs) { 144 console.warn("Worker.onmessageerror interface mocked in the Previewer. How this interface works on the" + 145 " Previewer may be different from that on a real device."); 146 }; 147 this.onerror = function (...args) { 148 console.warn("Worker.onerror interface mocked in the Previewer. How this interface works on the Previewer" + 149 " may be different from that on a real device."); 150 }; 151 this.onclose = function (...args) { 152 console.warn("Worker.onclose interface mocked in the Previewer. How this interface works on the Previewer" + 153 " may be different from that on a real device."); 154 }; 155 this.onexit = function (...args) { 156 console.warn("Worker.onexit interface mocked in the Previewer. How this interface works on the Previewer" + 157 " may be different from that on a real device."); 158 } 159 } 160 }; 161 162 const workerMock = { 163 Worker : WorkerClass, 164 parentPort : '[PC preview] unknow parentPort' 165 }; 166 return workerMock; 167} 168 169