• 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 { WantClass } from "./ohos_application_Want"
18
19export const WantAgentFlags = {
20  ONE_TIME_FLAG: 0,
21  NO_BUILD_FLAG: 1,
22  CANCEL_PRESENT_FLAG: 2,
23  UPDATE_PRESENT_FLAG: 3,
24  CONSTANT_FLAG: 4,
25  REPLACE_ELEMENT: 5,
26  REPLACE_ACTION: 6,
27  REPLACE_URI: 7,
28  REPLACE_ENTITIES: 8,
29  REPLACE_BUNDLE: 9
30}
31export const OperationType = {
32  UNKNOWN_TYPE: 0,
33  START_ABILITY: 1,
34  START_ABILITIES: 2,
35  START_SERVICE: 3,
36  SEND_COMMON_EVENT: 4
37}
38export const CompleteData = {
39  info: WantAgent,
40  want: new WantClass(),
41  finalCode: '[PC preview] unknow finalCode',
42  finalData: '[PC preview] unknow finalData',
43  extraInfo: {},
44}
45export const WantAgent = {}
46export function mockWantAgent() {
47  const wantAgent = {
48    getBundleName: function (...args) {
49      console.warn("wantAgent.getBundleName interface mocked in the Previewer. How this interface works on the" +
50        " Previewer may be different from that on a real device.");
51      const len = args.length;
52      if (typeof args[len - 1] === 'function') {
53        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
54      } else {
55        return new Promise((resolve) => {
56          resolve(paramMock.paramStringMock);
57        });
58      }
59    },
60    getUid: function (...args) {
61      console.warn("wantAgent.getUid interface mocked in the Previewer. How this interface works on the" +
62        " Previewer may be different from that on a real device.");
63      const len = args.length;
64      if (typeof args[len - 1] === 'function') {
65        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
66      } else {
67        return new Promise((resolve) => {
68          resolve(paramMock.paramNumberMock);
69        });
70      }
71    },
72    getWant: function (...args) {
73      console.warn("wantAgent.getWant interface mocked in the Previewer. How this interface works on the" +
74        " Previewer may be different from that on a real device.");
75      const len = args.length;
76      if (typeof args[len - 1] === 'function') {
77        args[len - 1].call(this, paramMock.businessErrorMock, new WantClass());
78      } else {
79        return new Promise((resolve) => {
80          resolve(new WantClass());
81        });
82      }
83    },
84    cancel: function (...args) {
85      console.warn("wantAgent.cancel interface mocked in the Previewer. How this interface works on the" +
86        " Previewer may be different from that on a real device.");
87      const len = args.length;
88      if (typeof args[len - 1] === 'function') {
89        args[len - 1].call(this, paramMock.businessErrorMock);
90      } else {
91        return new Promise((resolve) => {
92          resolve();
93        });
94      }
95    },
96    trigger: function (...args) {
97      console.warn("wantAgent.trigger interface mocked in the Previewer. How this interface works on the" +
98        " Previewer may be different from that on a real device.");
99      const len = args.length;
100      if (typeof args[len - 1] === 'function') {
101        args[len - 1].call(this, paramMock.businessErrorMock, CompleteData);
102      }
103    },
104    equal: function (...args) {
105      console.warn("wantAgent.equal interface mocked in the Previewer. How this interface works on the" +
106        " Previewer may be different from that on a real device.");
107      const len = args.length;
108      if (typeof args[len - 1] === 'function') {
109        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
110      } else {
111        return new Promise((resolve) => {
112          resolve(paramMock.paramBooleanMock);
113        });
114      }
115    },
116    getWantAgent: function (...args) {
117      console.warn("wantAgent.getWantAgent interface mocked in the Previewer. How this interface works on the" +
118        " Previewer may be different from that on a real device.");
119      const len = args.length;
120      if (typeof args[len - 1] === 'function') {
121        args[len - 1].call(this, paramMock.businessErrorMock, WantAgent);
122      } else {
123        return new Promise((resolve) => {
124          resolve(WantAgent);
125        });
126      }
127    },
128    getOperationType: function (...args) {
129      console.warn("wantAgent.getOperationType interface mocked in the Previewer. How this interface works on the" +
130        " Previewer may be different from that on a real device.");
131      const len = args.length;
132      if (typeof args[len - 1] === 'function') {
133        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
134      } else {
135        return new Promise((resolve) => {
136          resolve(paramMock.paramNumberMock);
137        });
138      }
139    },
140  }
141  return wantAgent
142}
143