• 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"
17import { ShortcutInfo } from './bundle/shortcutInfo'
18import { LauncherAbilityInfo } from './bundle/launcherAbilityInfo'
19
20export function mockInnerBundle() {
21    const innerBundleManager = {
22        getLauncherAbilityInfos: function(...args){
23            console.warn("innerBundle.getLauncherAbilityInfos interface mocked in the Previewer. How this interface works on the" +
24            " Previewer may be different from that on a real device.")
25            const len = args.length;
26            if (typeof args[len - 1] === 'function') {
27                args[len - 1].call(this, paramMock.businessErrorMock, LauncherAbilityInfo);
28            } else {
29                return new Promise((resolve) => {
30                    resolve(LauncherAbilityInfo);
31                })
32            }
33        },
34        on: function(...args) {
35            console.warn("innerBundle.on interface mocked in the Previewer. How this interface works on the" +
36            " Previewer may be different from that on a real device.")
37        },
38        off: function(...args) {
39            console.warn("innerBundle.off interface mocked in the Previewer. How this interface works on the" +
40            " Previewer may be different from that on a real device.")
41        },
42        getAllLauncherAbilityInfos: function(...args){
43            console.warn("innerBundle.getAllLauncherAbilityInfos interface mocked in the Previewer. How this interface works on the" +
44            " Previewer may be different from that on a real device.")
45            const len = args.length;
46            if (typeof args[len - 1] === 'function') {
47                args[len - 1].call(this, paramMock.businessErrorMock, Array(LauncherAbilityInfo));
48            } else {
49                return new Promise((resolve) => {
50                    resolve(Array(LauncherAbilityInfo));
51                })
52            }
53        },
54        getShortcutInfos: function(...args){
55            console.warn("innerBundle.getShortcutInfos interface mocked in the Previewer. How this interface works on the" +
56            " Previewer may be different from that on a real device.")
57            const len = args.length;
58            if (typeof args[len - 1] === 'function') {
59                args[len - 1].call(this, paramMock.businessErrorMock, Array(ShortcutInfo));
60            } else {
61                return new Promise((resolve) => {
62                    resolve(Array(ShortcutInfo));
63                })
64            }
65        },
66    };
67    return innerBundleManager;
68}