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 mockStorageStatistics() { 19 const BundleStats = { 20 appSize: '[PC preview] unknow appSize', 21 cacheSize: '[PC preview] unknow cacheSize', 22 dataSize: '[PC preview] unknow dataSize' 23 }; 24 const StorageStats= { 25 total: '[PC preview] unknow total', 26 audio: '[PC preview] unknow audio', 27 video: '[PC preview] unknow video', 28 image: '[PC preview] unknow image', 29 file: '[PC preview] unknow file', 30 app: '[PC preview] unknow app' 31 } 32 const storageStatistics = { 33 BundleStats: BundleStats, 34 StorageStats: StorageStats, 35 getTotalSizeOfVolume: function(...args) { 36 console.warn('storageStatistics.getTotalSizeOfVolume interface mocked in the Previewer. How this interface works on the' + 37 ' Previewer may be different from that on a real device.'); 38 const len = args.length; 39 if (typeof args[len - 1] === 'function') { 40 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 41 } else { 42 return new Promise((resolve, reject) => { 43 resolve(paramMock.paramNumberMock); 44 }); 45 } 46 }, 47 getFreeSizeOfVolume: function(...args) { 48 console.warn('storageStatistics.getFreeSizeOfVolume interface mocked in the Previewer. How this interface works on the' + 49 ' Previewer may be different from that on a real device.'); 50 const len = args.length; 51 if (typeof args[len - 1] === 'function') { 52 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 53 } else { 54 return new Promise((resolve, reject) => { 55 resolve(paramMock.paramNumberMock); 56 }); 57 } 58 }, 59 getBundleStats: function(...args) { 60 console.warn('storageStatistics.getBundleStats interface mocked in the Previewer. How this interface works on the' + 61 ' Previewer may be different from that on a real device.'); 62 const len = args.length; 63 if (typeof args[len - 1] === 'function') { 64 args[len - 1].call(this, paramMock.businessErrorMock, BundleStatsMock); 65 } else { 66 return new Promise((resolve, reject) => { 67 resolve(BundleStatsMock); 68 }); 69 } 70 }, 71 getCurrentBundleStats: function(...args) { 72 console.warn('storageStatistics.getCurrentBundleStats interface mocked in the Previewer. How this interface works on the' + 73 ' Previewer may be different from that on a real device.'); 74 const len = args.length; 75 if (typeof args[len - 1] === 'function') { 76 args[len - 1].call(this, paramMock.businessErrorMock, BundleStats); 77 } else { 78 return new Promise((resolve, reject) => { 79 resolve(BundleStats); 80 }); 81 } 82 }, 83 getSystemSize: function(...args) { 84 console.warn('storageStatistics.getSystemSize interface mocked in the Previewer. How this interface works on the' + 85 ' Previewer may be different from that on a real device.'); 86 const len = args.length; 87 if (typeof args[len - 1] === 'function') { 88 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 89 } else { 90 return new Promise((resolve, reject) => { 91 resolve(paramMock.paramNumberMock); 92 }); 93 } 94 }, 95 getUserStorageStats: function(...args) { 96 console.warn('storageStatistics.getUserStorageStats interface mocked in the Previewer. How this interface works on the' + 97 ' Previewer may be different from that on a real device.'); 98 const len = args.length; 99 if (typeof args[len - 1] === 'function') { 100 args[len - 1].call(this, paramMock.businessErrorMock, StorageStats); 101 } else { 102 return new Promise((resolve, reject) => { 103 resolve(StorageStats); 104 }); 105 } 106 }, 107 getTotalSize: function(...args) { 108 console.warn('storageStatistics.getTotalSize interface mocked in the Previewer. How this interface works on the' + 109 ' Previewer may be different from that on a real device.'); 110 const len = args.length; 111 if (typeof args[len - 1] === 'function') { 112 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 113 } else { 114 return new Promise((resolve, reject) => { 115 resolve(paramMock.paramNumberMock); 116 }); 117 } 118 }, 119 getFreeSize: function(...args) { 120 console.warn('storageStatistics.getFreeSize interface mocked in the Previewer. How this interface works on the' + 121 ' Previewer may be different from that on a real device.'); 122 const len = args.length; 123 if (typeof args[len - 1] === 'function') { 124 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 125 } else { 126 return new Promise((resolve, reject) => { 127 resolve(paramMock.paramNumberMock); 128 }); 129 } 130 } 131 }; 132 return storageStatistics; 133} 134