• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 result = {
20    Worker: function (params) {
21      console.warn("worker.Worker interface mocked in the Previewer. How this interface works on the Previewer" +
22        " may be different from that on a real device.")
23      return WorkerMock;
24    }
25  }
26  const WorkerMock = {
27    postMessage: function (...args) {
28      console.warn("Worker.postMessage interface mocked in the Previewer. How this interface works on the Previewer" +
29        " may be different from that on a real device.")
30    },
31    terminate: function (...args) {
32      console.warn("Worker.terminate interface mocked in the Previewer. How this interface works on the Previewer" +
33        " may be different from that on a real device.")
34    },
35    on: function (...args) {
36      console.warn("Worker.on interface mocked in the Previewer. How this interface works on the Previewer" +
37        " may be different from that on a real device.")
38    },
39    once: function (...args) {
40      console.warn("Worker.once interface mocked in the Previewer. How this interface works on the Previewer" +
41        " may be different from that on a real device.")
42    },
43    off: function (...args) {
44      console.warn("Worker.off interface mocked in the Previewer. How this interface works on the Previewer" +
45        " may be different from that on a real device.")
46    },
47    addEventListener: function (...args) {
48      console.warn("Worker.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("Worker.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("Worker.removeEventListener interface mocked in the Previewer. How this interface works on the" +
58        " Previewer may be different from that on a real device.")
59    },
60    removeAllListener: function (...args) {
61      console.warn("Worker.removeAllListener interface mocked in the Previewer. How this interface works on the" +
62        " Previewer may be different from that on a real device.")
63    },
64    onmessage: function (...args) {
65      console.warn("Worker.onmessage interface mocked in the Previewer. How this interface works on the Previewer" +
66        " may be different from that on a real device.")
67    },
68    onmessageerror: function (...agrs) {
69      console.warn("Worker.onmessageerror interface mocked in the Previewer. How this interface works on the" +
70        " Previewer may be different from that on a real device.")
71    },
72    onerror: function (...args) {
73      console.warn("Worker.onerror interface mocked in the Previewer. How this interface works on the Previewer" +
74        " may be different from that on a real device.")
75    },
76    onclose: function (...args) {
77      console.warn("Worker.onclose interface mocked in the Previewer. How this interface works on the Previewer" +
78        " may be different from that on a real device.")
79    },
80    onexit: function (...args) {
81      console.warn("Worker.onexit interface mocked in the Previewer. How this interface works on the Previewer" +
82        " may be different from that on a real device.")
83    }
84  }
85  return result;
86}