• 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 {resolve} from 'path/posix'
18import {BundleInfoMock} from './bundle/bundleInfo'
19import {ApplicationInfoMock} from './bundle/applicationInfo'
20import {AbilityInfoMock} from './bundle/abilityInfo'
21import {WantMock} from './bundle/applicationInfo'
22import {ShortcutInfoMock} from './bundle/applicationInfo'
23import {ModuleUsageRecordMock} from './bundle/applicationInfo'
24
25export function mockBundle() {
26
27    const bundle = {
28        getBundleInfo: function(...args) {
29            console.warn("bundle.getBundleInfo interface mocked in the Previewer. How this interface works on the" +
30            " Previewer may be different from that on a real device.")
31            const len = args.length;
32            if (typeof args[len - 1] === 'function') {
33                args[len - 1].call(this, paramMock.businessErrorMock, BundleInfoMock);
34            } else {
35                return new Promise((resolve) => {
36                    resolve(BundleInfoMock);
37                })
38            }
39        },
40        getBundleInstaller: function(...args) {
41            console.warn("bundle.getBundleInstaller interface mocked in the Previewer. How this interface works on the" +
42            " Previewer may be different from that on a real device.")
43            const len = args.length;
44            if (typeof args[len - 1] === 'function') {
45                args[len - 1].call(this, paramMock.businessErrorMock);
46            } else {
47                return new Promise((resolve) => {
48                    resolve(paramMock.paramNumberMock);
49                })
50            }
51        },
52        getApplicationInfo: function(...args) {
53            console.warn("bundle.getApplicationInfo interface mocked in the Previewer. How this interface works on the" +
54            " Previewer may be different from that on a real device.")
55            const len = args.length;
56            if (typeof args[len - 1] === 'function') {
57                args[len - 1].call(this, paramMock.businessErrorMock, ApplicationInfoMock);
58            } else {
59                return new Promise((resolve) => {
60                    resolve(ApplicationInfoMock);
61                })
62            }
63        },
64        checkPermission: function(...args) {
65            console.warn("bundle.checkPermission interface mocked in the Previewer. How this interface works on the" +
66            " Previewer may be different from that on a real device.")
67            const len = args.length;
68            if (typeof args[len - 1] === 'function') {
69                args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
70            } else {
71                return new Promise((resolve) => {
72                    resolve(paramMock.paramNumberMock);
73                })
74            }
75        },
76        queryAbilityByWant: function(...args) {
77            console.warn("bundle.queryAbilityByWant interface mocked in the Previewer. How this interface works on the" +
78            " Previewer may be different from that on a real device.")
79            const len = args.length;
80            if (typeof args[len - 1] === 'function') {
81                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfoMock));
82            } else {
83                return new Promise((resolve) => {
84                    resolve(Array(BundleInfoMock));
85                })
86            }
87        },
88        getAllApplicationInfo: function(...args){
89            console.warn("bundle.getAllApplicationInfo interface mocked in the Previewer. How this interface works on the" +
90            " Previewer may be different from that on a real device.")
91            const len = args.length;
92            if (typeof args[len - 1] === 'function') {
93                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfoMock));
94            } else {
95                return new Promise((resolve) => {
96                    resolve(Array(BundleInfoMock));
97                })
98            }
99        },
100        getAllBundleInfo: function(...args) {
101            console.warn("bundle.getAllBundleInfo interface mocked in the Previewer. How this interface works on the" +
102            " Previewer may be different from that on a real device.")
103            const len = args.length;
104            if (typeof args[len - 1] === 'function') {
105                args[len - 1].call(this, paramMock.businessErrorMock, Array(ApplicationInfoMock));
106            } else {
107                return new Promise((resolve) => {
108                    resolve(Array(ApplicationInfoMock));
109                })
110            }
111        },
112        getBundleArchiveInfo:  function(...args) {
113            console.warn("bundle.getBundleArchiveInfo interface mocked in the Previewer. How this interface works on the" +
114            " Previewer may be different from that on a real device.")
115            const len = args.length;
116            if (typeof args[len - 1] === 'function') {
117                args[len - 1].call(this, paramMock.businessErrorMock, Array(BundleInfoMock));
118            } else {
119                return new Promise((resolve) => {
120                    resolve(Array(BundleInfoMock));
121                })
122            }
123        },
124        getLaunchWantForBundle: function(...args) {
125            console.warn("bundle.getBundleArchiveInfo interface mocked in the Previewer. How this interface works on the" +
126            " Previewer may be different from that on a real device.")
127            const len = args.length;
128            if (typeof args[len - 1] === 'function') {
129                args[len - 1].call(this, paramMock.businessErrorMock, Array(WantMock));
130            } else {
131                return new Promise((resolve) => {
132                    resolve(Array(WantMock));
133                })
134            }
135        },
136        getAllShortcutInfo: function(...args) {
137            console.warn("bundle.getAllShortcutInfo interface mocked in the Previewer. How this interface works on the" +
138            " Previewer may be different from that on a real device.")
139            const len = args.length;
140            if (typeof args[len - 1] === 'function') {
141                args[len - 1].call(this, paramMock.businessErrorMock, Array(ShortcutInfoMock));
142            } else {
143                return new Promise((resolve) => {
144                    resolve(Array(ShortcutInfoMock));
145                })
146            }
147        },
148        getModuleUsageRecords: function(...args) {
149            console.warn("bundle.getAllShortcutInfo interface mocked in the Previewer. How this interface works on the" +
150            " Previewer may be different from that on a real device.")
151            const len = args.length;
152            if (typeof args[len - 1] === 'function') {
153                args[len - 1].call(this, paramMock.businessErrorMock, Array(ModuleUsageRecordMock));
154            } else {
155                return new Promise((resolve) => {
156                    resolve(Array(ModuleUsageRecordMock));
157                })
158            }
159        },
160        cleanBundleCacheFiles: function(...args) {
161            console.warn("bundle.cleanBundleCacheFiles interface mocked in the Previewer. How this interface works on the" +
162            " Previewer may be different from that on a real device.")
163            const len = args.length;
164            if (typeof args[len - 1] === 'function') {
165                args[len - 1].call(this, paramMock.businessErrorMock);
166            } else {
167                return new Promise((resolve) => {
168                    resolve(paramMock.paramNumberMock);
169                })
170            }
171        },
172        setApplicationEnabled: function(...args) {
173            console.warn("bundle.setApplicationEnabled interface mocked in the Previewer. How this interface works on the" +
174            " Previewer may be different from that on a real device.")
175            const len = args.length;
176            if (typeof args[len - 1] === 'function') {
177                args[len - 1].call(this, paramMock.businessErrorMock);
178            } else {
179                return new Promise((resolve) => {
180                    resolve(paramMock.paramNumberMock);
181                })
182            }
183        },
184        setAbilityEnabled: function(...args) {
185            console.warn("bundle.setApplicationEnabled interface mocked in the Previewer. How this interface works on the" +
186            " Previewer may be different from that on a real device.")
187            const len = args.length;
188            if (typeof args[len - 1] === 'function') {
189                args[len - 1].call(this, paramMock.businessErrorMock);
190            } else {
191                return new Promise((resolve) => {
192                    resolve(paramMock.paramNumberMock);
193                })
194            }
195        }
196    };
197    return bundle;
198}