• 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 mockStorageInfoManager() {
19  const infoMock = {
20    storageInfo: {
21      appSize: 472897,
22      cacheSize: 483,
23      dataSize: 32543
24    },
25    totalSize: 12800000,
26    freeSize: 23700000,
27  }
28  global.ohosplugin.storageInfoManager = {
29    queryInfoByPackageName: function (...args) {
30      console.warn("storageInfoManager.queryInfoByPackageName interface mocked in the Previewer. How this interface works on the" +
31        " Previewer may be different from that on a real device.");
32      const len = args.length;
33      if (typeof args[len - 1] === 'function') {
34        args[len - 1].call(this, paramMock.businessErrorMock, infoMock.storageInfo);
35      } else {
36        return new Promise((resolve) => {
37          resolve(infoMock.storageInfo);
38        })
39      }
40    },
41    getTotalSize: function (...args) {
42      console.warn("storageInfoManager.getTotalSize interface mocked in the Previewer. How this interface works on the" +
43        " Previewer may be different from that on a real device.")
44      const len = args.length;
45      if (typeof args[len - 1] === 'function') {
46        args[len - 1].call(this, paramMock.businessErrorMock, infoMock.totalSize);
47      } else {
48        return new Promise((resolve) => {
49          resolve(infoMock.totalSize);
50        })
51      }
52    },
53    getFreeSize: function (...args) {
54      console.warn("storageInfoManager.getFreeSize interface mocked in the Previewer. How this interface works on the" +
55        " Previewer may be different from that on a real device.")
56      const len = args.length;
57      if (typeof args[len - 1] === 'function') {
58        args[len - 1].call(this, paramMock.businessErrorMock, infoMock.freeSize);
59      } else {
60        return new Promise((resolve) => {
61          resolve(infoMock.freeSize);
62        })
63      }
64    },
65    queryInfoByUid: function (...args) {
66      console.warn("storageInfoManager.queryInfoByUid interface mocked in the Previewer. How this interface works on the" +
67        " Previewer may be different from that on a real device.")
68      const len = args.length;
69      if (typeof args[len - 1] === 'function') {
70        args[len - 1].call(this, paramMock.businessErrorMock, infoMock.storageInfo);
71      } else {
72        return new Promise((resolve) => {
73          resolve(infoMock.storageInfo);
74        })
75      }
76    },
77  }
78}