• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 */
15import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect , Level, TestType, Size} from '@ohos/hypium';
16import window from '@ohos.window';
17import common from '@ohos.app.ability.common';
18import injectTouchEvent from 'libentry.so';
19import { BusinessError } from '@ohos.base';
20import { image } from '@kit.ImageKit';
21import settings from '@ohos.settings';
22import { Driver, ON } from '@kit.TestKit';
23
24function sleep(ms: number): Promise<string> {
25  return new Promise((resolve) => {
26    setTimeout(() => {
27      resolve('');
28    }, ms);
29  });
30}
31
32export default function InjectTouchEvent() {
33  describe('injectTouchEvent', () => {
34    let windowStage:window.WindowStage;
35    let Tag = 'ActsWindowNdkTest';
36    let WindowClass:window.Window;
37    let windowId:number;
38    let context : common.UIAbilityContext;
39    let isAutoWindow:string = '';
40    let isPCStatus: string = '';
41    beforeAll(async() => {
42      windowStage = AppStorage.get("windowStage") as window.WindowStage;
43      console.log(`${Tag}:beforeAll start... `);
44      WindowClass = await windowStage.getMainWindow();
45      windowId = WindowClass.getWindowProperties().id;
46      console.log(`${Tag}:windowId:${windowId} `);
47      context = AppStorage.get("context") as common.UIAbilityContext;
48      isAutoWindow = settings.getValueSync(context,'window_pcmode_switch_status','',settings.domainName.DEVICE_SHARED);
49      //isAutoWindow == '' 非PAD设备
50      //isAutoWindow == 'true' PAD设备自由多窗模式
51      //isAutoWindow == 'false' PAD设备非自由多窗模式
52      console.info(`isAutoWindow: ${JSON.stringify(isAutoWindow)}`);
53      isPCStatus = settings.getValueSync(context, 'isStatusBarExist', '', settings.domainName.USER_PROPERTY)
54      //isPCStatus == '' 非PC设备
55      //isPCStatus == '1' PC设备状态栏dock未融合
56      //isPCStatus == '0' PC设备状态栏dock融合
57      console.info(`beforeAll isPCStatus: `+ isPCStatus);
58    })
59    beforeEach(() => {
60      console.log(`${Tag}:beforeEach start... `);
61    })
62    afterEach(() => {
63      console.log(`${Tag}:afterEach start... `);
64    })
65    afterAll(() => {
66      console.log(`${Tag}:afterAll start... `);
67    })
68
69
70    /**
71     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0100
72     * @tc.name      : testInjectTouchEventwithTouchEventNullptr
73     * @tc.desc      : 验证injectTouchEvent接口中入参touchEvent为空返回401错误码
74     * @tc.size      : MediumTest
75     * @tc.type      : Function
76     * @tc.level     : Level3
77     */
78    it('testInjectTouchEventwithTouchEventNullptr', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
79      let caseName = 'testInjectTouchEventwithTouchEventNullptr';
80      console.info(`${Tag}: ${caseName} windowId: ${windowId}`);
81      try {
82        let result = injectTouchEvent.testInjectTouchEventwithTouchEventNullptr(windowId);
83        console.info(`${Tag}: ${caseName} result: ${result}`);
84        expect(result).assertEqual(401);
85        done()
86      } catch (err) {
87        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
88        expect(false).assertTrue();
89        done();
90      }
91    })
92
93    /**
94     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0200
95     * @tc.name      : testInjectTouchEventwithTouchEventActionOutofRange
96     * @tc.desc      : 验证injectTouchEvent接口中入参toucheEvent中Action超出范围取值10时返回1300003错误码
97     * @tc.size      : MediumTest
98     * @tc.type      : Function
99     * @tc.level     : Level3
100     */
101    it('testInjectTouchEventwithTouchEventActionOutofRange', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
102      let caseName = 'testInjectTouchEventwithTouchEventActionOutofRange';
103      console.info(`${Tag}: ${caseName} windowId: ${windowId}`);
104      try {
105        let result = injectTouchEvent.testInjectTouchEventwithTouchEventActionOutofRange(windowId);
106        console.info(`${Tag}: ${caseName} result: ${result}`);
107        expect(result).assertEqual(1300003);
108        done()
109      } catch (err) {
110        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
111        expect(false).assertTrue();
112        done();
113      }
114    })
115
116    /**
117     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0300
118     * @tc.name      : testInjectTouchEventwithWindowidNotloadcontent
119     * @tc.desc      : 验证injectTouchEvent接口中入参windowid窗口未loadcontent抛出1300003错误码
120     * @tc.size      : MediumTest
121     * @tc.type      : Function
122     * @tc.level     : Level2
123     */
124    it('testInjectTouchEventwithWindowidNotloadcontent', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done:Function) => {
125      let caseName = 'testInjectTouchEventwithWindowidNotloadcontent';
126      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithWindowidNotloadcontent');
127      try {
128        let subWindowId = subWindowClass.getWindowProperties().id;
129        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
130        let result = injectTouchEvent.testInjectTouchEventwithWindowidNotloadcontent(subWindowId);
131        console.info(`${Tag}: ${caseName} result: ${result}`);
132        await subWindowClass.destroyWindow();
133        expect(result).assertEqual(1300003);
134        done()
135      } catch (err) {
136        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
137        await subWindowClass.destroyWindow();
138        expect(false).assertTrue();
139        done();
140      }
141    })
142
143    /**
144     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0400
145     * @tc.name      : testInjectTouchEventwithDestoryedSubwindow
146     * @tc.desc      : 验证injectTouchEvent接口中入参windowid为销毁后的子窗返回1300002错误码
147     * @tc.size      : MediumTest
148     * @tc.type      : Function
149     * @tc.level     : Level2
150     */
151    it('testInjectTouchEventwithDestoryedSubwindow', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done:Function) => {
152      let caseName = 'testInjectTouchEventwithDestoryedSubwindow';
153      try {
154        let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithDestoryedSubwindow');
155        let subWindowId = subWindowClass.getWindowProperties().id;
156        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
157        await subWindowClass.destroyWindow();
158        let result = injectTouchEvent.testInjectTouchEventwithDestoryedSubwindow(subWindowId);
159        console.info(`${Tag}: ${caseName} result: ${result}`);
160        expect(result).assertEqual(1300002);
161        done()
162      } catch (err) {
163        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
164        expect(false).assertTrue();
165        done();
166      }
167    })
168
169    /**
170     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0500
171     * @tc.name      : testInjectTouchEventwithWindowXWindowYBeyondScreen
172     * @tc.desc      : 验证injectTouchEvent接口中入参windowX、windowY超出窗口范围
173     * @tc.size      : MediumTest
174     * @tc.type      : Function
175     * @tc.level     : Level3
176     */
177    it('testInjectTouchEventwithWindowXWindowYBeyondScreen', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
178      let caseName = 'testInjectTouchEventwithWindowXWindowYBeyondScreen';
179      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithWindowXWindowYBeyondScreen');
180      await sleep(200);
181      await subWindowClass.setUIContent('testability/pages/subWindow');
182      await sleep(200);
183      await subWindowClass.showWindow();
184      await sleep(200);
185      try {
186        let windowLimits = subWindowClass.getWindowLimits();
187        console.info(`${Tag}: ${caseName} windowLimits: ${JSON.stringify(windowLimits)}`);
188        let width = windowLimits.minWidth as number;
189        let height = windowLimits.minHeight as number;
190        await subWindowClass.resize(width, height);
191        await sleep(200);
192        let subWindowId = subWindowClass.getWindowProperties().id;
193        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
194        let result = injectTouchEvent.testInjectTouchEventwithWindowXWindowYBeyondScreen(subWindowId, width + 50, height + 50);
195        console.info(`${Tag}: ${caseName} result: ${result}`);
196        if(result==1300003){
197          await subWindowClass.destroyWindow();
198          done()
199        }else{
200          await subWindowClass.destroyWindow();
201          expect(result).assertEqual(0);
202          done()
203        }
204
205      } catch (err) {
206        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
207        await subWindowClass.destroyWindow();
208        if(err.code == 801){
209          done();
210        }else{
211          expect(false).assertTrue();
212          done();
213        }
214
215      }
216    })
217
218    /**
219     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0600
220     * @tc.name      : testInjectTouchEventwithFloatWindowXWindowY
221     * @tc.desc      : 验证injectTouchEvent接口中入参windowX、windowY为float类型会截断取整
222     * @tc.size      : MediumTest
223     * @tc.type      : Function
224     * @tc.level     : Level3
225     */
226    it('testInjectTouchEventwithFloatWindowXWindowY', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
227      let caseName = 'testInjectTouchEventwithFloatWindowXWindowY';
228      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithFloatWindowXWindowY');
229      await sleep(200);
230      await subWindowClass.setUIContent('testability/pages/subWindow');
231      await sleep(200);
232      await subWindowClass.showWindow();
233      await sleep(200);
234      try {
235        let windowLimits = subWindowClass.getWindowLimits();
236        console.info(`${Tag}: ${caseName} windowLimits: ${JSON.stringify(windowLimits)}`);
237        let width = windowLimits.minWidth as number;
238        let height = windowLimits.minHeight as number;
239        await subWindowClass.resize(width, height);
240        await sleep(200);
241        let subWindowId = subWindowClass.getWindowProperties().id;
242        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
243        let result = injectTouchEvent.testInjectTouchEventwithFloatWindowXWindowY(subWindowId, width - 0.001, height - 0.001);
244        console.info(`${Tag}: ${caseName} result: ${result}`);
245        if(result==1300003){
246          await subWindowClass.destroyWindow();
247          done()
248        }else{
249          await subWindowClass.destroyWindow();
250          expect(result).assertEqual(0);
251          done()
252        }
253      } catch (err) {
254        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
255        await subWindowClass.destroyWindow();
256        if(err.code == 801){
257          done();
258        }else{
259          expect(false).assertTrue();
260          done();
261        }
262
263      }
264    })
265
266    /**
267     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0700
268     * @tc.name      : testInjectTouchEventwithNonExistedWindowID
269     * @tc.desc      : 验证injectTouchEvent接口中入参windowId传入大于0但不存在的windowid
270     * @tc.size      : MediumTest
271     * @tc.type      : Function
272     * @tc.level     : Level3
273     */
274    it('testInjectTouchEventwithNonExistedWindowID', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
275      let caseName = 'testInjectTouchEventwithNonExistedWindowID';
276      try {
277        let invalidId = 1000;
278        let result = injectTouchEvent.testInjectTouchEventwithNonExistedWindowID(invalidId);
279        console.info(`${Tag}: ${caseName} result: ${result}`);
280        expect(result).assertEqual(1300002);
281        done()
282      } catch (err) {
283        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
284        expect(false).assertTrue();
285        done();
286      }
287    })
288
289    /**
290     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0800
291     * @tc.name      : testInjectTouchEventwithFloatWindowID
292     * @tc.desc      : 验证injectTouchEvent接口中入参windowId为float类型会向下取整
293     * @tc.size      : MediumTest
294     * @tc.type      : Function
295     * @tc.level     : Level2
296     */
297    it('testInjectTouchEventwithFloatWindowID', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async (done:Function) => {
298      let caseName = 'testInjectTouchEventwithFloatWindowID';
299      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithFloatWindowID');
300      await sleep(200);
301      await subWindowClass.setUIContent('testability/pages/subWindow');
302      await sleep(200);
303      await subWindowClass.showWindow();
304      await sleep(200);
305      try {
306        let driver = Driver.create();
307        let btn = await driver.findComponent(ON.id('buttonId'));
308        console.info(`${Tag}: ${caseName} btn: ${btn}`);
309        // 获取button的位置
310        let point = await btn.getBoundsCenter();
311        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
312        let x = point.x
313        let y = point.y
314        await sleep(200);
315        let subWindowId = subWindowClass.getWindowProperties().id;
316        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
317        let result = injectTouchEvent.testInjectTouchEventwithFloatWindowID(subWindowId + 0.4, x, y);
318        console.info(`${Tag}: ${caseName} result: ${result}`);
319        if(result == 1300003){
320          await subWindowClass.destroyWindow();
321          done();
322        }else{
323          expect(result).assertEqual(0);
324          await sleep(200);
325          let newText = await btn.getText();
326          await sleep(200);
327          expect(newText).assertEqual('TextChanged');
328          await subWindowClass.destroyWindow();
329          done()
330        }
331
332      } catch (err) {
333        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
334        await subWindowClass.destroyWindow();
335        expect(false).assertTrue();
336        done();
337      }
338    })
339
340    /**
341     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_0900
342     * @tc.name      : testInjectTouchEventwithNegativeWindowID
343     * @tc.desc      : 验证injectTouchEvent接口中入参windowId传入-1
344     * @tc.size      : MediumTest
345     * @tc.type      : Function
346     * @tc.level     : Level3
347     */
348    it('testInjectTouchEventwithNegativeWindowID', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
349      let caseName = 'testInjectTouchEventwithNegativeWindowID';
350      try {
351        let result = injectTouchEvent.testInjectTouchEventwithNegativeWindowID();
352        console.info(`${Tag}: ${caseName} result: ${result}`);
353        expect(result).assertEqual(401);
354        done()
355      } catch (err) {
356        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
357        expect(false).assertTrue();
358        done();
359      }
360    })
361
362    /**
363     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1000
364     * @tc.name      : testInjectTouchEventwithTouchActionCancel
365     * @tc.desc      : 验证injectTouchEvent接口向子窗注入0触屏取消场景
366     * @tc.size      : MediumTest
367     * @tc.type      : Function
368     * @tc.level     : Level3
369     */
370    it('testInjectTouchEventwithTouchActionCancel', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
371      let caseName = 'testInjectTouchEventwithTouchActionCancel';
372      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithTouchActionCancel');
373      await sleep(200);
374      await subWindowClass.setUIContent('testability/pages/subWindow');
375      await sleep(200);
376      await subWindowClass.showWindow();
377      await sleep(200);
378      try {
379        let driver = Driver.create();
380        let btn = await driver.findComponent(ON.id('buttonId'));
381        console.info(`${Tag}: ${caseName} btn: ${btn}`);
382        let point = await btn.getBoundsCenter();
383        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
384        let x = point.x
385        let y = point.y
386        await sleep(200);
387        let subWindowId = subWindowClass.getWindowProperties().id;
388        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
389        let result = injectTouchEvent.testInjectTouchEventwithTouchActionCancel(subWindowId, x, y);
390        console.info(`${Tag}: ${caseName} result: ${result}`);
391        if(result == 1300003){
392          await subWindowClass.destroyWindow();
393          done()
394        }else{
395          expect(result).assertEqual(0);
396          let newText = await btn.getText();
397          await sleep(200);
398          expect(newText).assertEqual('Button');
399          await subWindowClass.destroyWindow();
400          done()
401        }
402      } catch (err) {
403        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
404        await subWindowClass.destroyWindow();
405        expect(false).assertTrue();
406        done();
407      }
408    })
409
410    /**
411     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1100
412     * @tc.name      : testInjectTouchEventwithTouchActionDown
413     * @tc.desc      : 验证injectTouchEvent接口向子窗注入1触屏按下场景
414     * @tc.size      : MediumTest
415     * @tc.type      : Function
416     * @tc.level     : Level3
417     */
418    it('testInjectTouchEventwithTouchActionDown', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
419      let caseName = 'testInjectTouchEventwithTouchActionDown';
420      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithTouchActionDown');
421      await sleep(200);
422      await subWindowClass.setUIContent('testability/pages/subWindow');
423      await sleep(200);
424      await subWindowClass.showWindow();
425      await sleep(200);
426      try {
427        let driver = Driver.create();
428        let btn = await driver.findComponent(ON.id('buttonId'));
429        console.info(`${Tag}: ${caseName} btn: ${btn}`);
430        let point = await btn.getBoundsCenter();
431        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
432        let x = point.x
433        let y = point.y
434        await sleep(200);
435        let subWindowId = subWindowClass.getWindowProperties().id;
436        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
437        let result = injectTouchEvent.testInjectTouchEventwithTouchActionDown(subWindowId, x, y);
438        console.info(`${Tag}: ${caseName} result: ${result}`);
439        if(result==1300003){
440          await subWindowClass.destroyWindow();
441          done()
442        }else{
443          expect(result).assertEqual(0);
444          let newText = await btn.getText();
445          await sleep(200);
446          expect(newText).assertEqual('Button');
447          await subWindowClass.destroyWindow();
448          done()
449        }
450
451      } catch (err) {
452        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
453        await subWindowClass.destroyWindow();
454        expect(false).assertTrue();
455        done();
456      }
457    })
458
459    /**
460     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1200
461     * @tc.name      : testInjectTouchEventwithTouchActionMove
462     * @tc.desc      : 验证injectTouchEvent接口向子窗注入2触屏移动场景
463     * @tc.size      : MediumTest
464     * @tc.type      : Function
465     * @tc.level     : Level3
466     */
467    it('testInjectTouchEventwithTouchActionMove', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
468      let caseName = 'testInjectTouchEventwithTouchActionMove';
469      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithTouchActionMove');
470      await sleep(200);
471      await subWindowClass.setUIContent('testability/pages/subWindow');
472      await sleep(200);
473      await subWindowClass.showWindow();
474      await sleep(200);
475      try {
476        let driver = Driver.create();
477        let btn = await driver.findComponent(ON.id('buttonId'));
478        console.info(`${Tag}: ${caseName} btn: ${btn}`);
479        let point = await btn.getBoundsCenter();
480        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
481        let x = point.x
482        let y = point.y
483        await sleep(200);
484        let subWindowId = subWindowClass.getWindowProperties().id;
485        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
486        let result = injectTouchEvent.testInjectTouchEventwithTouchActionMove(subWindowId, x, y);
487        console.info(`${Tag}: ${caseName} result: ${result}`);
488        if(result==1300003){
489          await subWindowClass.destroyWindow();
490          done()
491        }else{
492          expect(result).assertEqual(0);
493          let sliderText = await driver.findComponent(ON.id('sliderTextId'));
494          console.info(`${Tag}: ${caseName} sliderText: ${sliderText}`);
495          await sleep(500);
496          let newText = await sliderText.getText();
497          console.info(`${Tag}: ${caseName} newText: ${newText}`);
498          await sleep(200);
499          if (newText == '40') {
500            expect(true).assertTrue();
501          } else {
502            expect(false).assertTrue();
503          }
504          await subWindowClass.destroyWindow();
505          done()
506        }
507
508
509      } catch (err) {
510        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
511        await subWindowClass.destroyWindow();
512        expect(false).assertTrue();
513        done();
514      }
515    })
516
517    /**
518     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1300
519     * @tc.name      : testInjectTouchEventwithTouchActionUp
520     * @tc.desc      : 验证injectTouchEvent接口向子窗注入3触屏抬起场景
521     * @tc.size      : MediumTest
522     * @tc.type      : Function
523     * @tc.level     : Level3
524     */
525    it('testInjectTouchEventwithTouchActionUp', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async (done:Function) => {
526      let caseName = 'testInjectTouchEventwithTouchActionUp';
527      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithTouchActionUp');
528      await sleep(200);
529      await subWindowClass.setUIContent('testability/pages/subWindow');
530      await sleep(200);
531      await subWindowClass.showWindow();
532      await sleep(200);
533      try {
534        let driver = Driver.create();
535        let btn = await driver.findComponent(ON.id('buttonId'));
536        console.info(`${Tag}: ${caseName} btn: ${btn}`);
537        let point = await btn.getBoundsCenter();
538        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
539        let x = point.x
540        let y = point.y
541        await sleep(200);
542        let subWindowId = subWindowClass.getWindowProperties().id;
543        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
544        let result = injectTouchEvent.testInjectTouchEventwithTouchActionUp(subWindowId, x, y);
545        console.info(`${Tag}: ${caseName} result: ${result}`);
546        if(result==1300003){
547          await subWindowClass.destroyWindow();
548          done()
549        }else{
550          expect(result).assertEqual(0);
551          let newText = await btn.getText();
552          await sleep(200);
553          expect(newText).assertEqual('Button');
554          await subWindowClass.destroyWindow();
555          done()
556        }
557
558      } catch (err) {
559        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
560        await subWindowClass.destroyWindow();
561        expect(false).assertTrue();
562        done();
563      }
564    })
565
566    /**
567     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1400
568     * @tc.name      : testInjectTouchEventwithMainWindowClick
569     * @tc.desc      : 验证injectTouchEvent接口向主窗注入13点击事件
570     * @tc.size      : MediumTest
571     * @tc.type      : Function
572     * @tc.level     : Level0
573     */
574    it('testInjectTouchEventwithMainWindowClick', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
575      let caseName = 'testInjectTouchEventwithMainWindowClick';
576      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithMainWindowClick');
577      await sleep(200);
578      await subWindowClass.setUIContent('testability/pages/subWindow');
579      await sleep(200);
580      await subWindowClass.showWindow();
581      await sleep(200);
582      try {
583        let driver = Driver.create();
584        let btn = await driver.findComponent(ON.id('buttonId'));
585        console.info(`${Tag}: ${caseName} btn: ${btn}`);
586        let point = await btn.getBoundsCenter();
587        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
588        let x = point.x
589        let y = point.y
590        await sleep(200);
591        let subWindowId = subWindowClass.getWindowProperties().id;
592        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
593        let result = injectTouchEvent.testInjectTouchEventwithMainWindowClick(subWindowId, x, y);
594        console.info(`${Tag}: ${caseName} result: ${result}`);
595        if(result==1300003){
596          await subWindowClass.destroyWindow();
597          done()
598        }else{
599          expect(result).assertEqual(0);
600          await sleep(200);
601          let newText = await btn.getText();
602          await sleep(200);
603          expect(newText).assertEqual('TextChanged');
604          await subWindowClass.destroyWindow();
605          done()
606        }
607
608      } catch (err) {
609        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
610        await subWindowClass.destroyWindow();
611        expect(false).assertTrue();
612        done();
613      }
614    })
615
616    /**
617     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1500
618     * @tc.name      : testInjectTouchEventwithSubWindowClick
619     * @tc.desc      : 验证injectTouchEvent接口向子窗注入13点击事件
620     * @tc.size      : MediumTest
621     * @tc.type      : Function
622     * @tc.level     : Level0
623     */
624    it('testInjectTouchEventwithSubWindowClick', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
625      let caseName = 'testInjectTouchEventwithSubWindowClick';
626      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithSubWindowClick');
627      await sleep(200);
628      await subWindowClass.setUIContent('testability/pages/subWindow');
629      await sleep(200);
630      await subWindowClass.showWindow();
631      await sleep(200);
632      try {
633        let driver = Driver.create();
634        let btn = await driver.findComponent(ON.id('buttonId'));
635        console.info(`${Tag}: ${caseName} btn: ${btn}`);
636        let point = await btn.getBoundsCenter();
637        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
638        let x = point.x
639        let y = point.y
640        await sleep(200);
641        let subWindowId = subWindowClass.getWindowProperties().id;
642        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
643        let result = injectTouchEvent.testInjectTouchEventwithSubWindowClick(subWindowId, x, y);
644        console.info(`${Tag}: ${caseName} result: ${result}`);
645        if(result==1300003){
646          await subWindowClass.destroyWindow();
647          done()
648        }else{
649          expect(result).assertEqual(0);
650          await sleep(400);
651          let newText = await btn.getText();
652          await sleep(200);
653          expect(newText).assertEqual('TextChanged');
654          await subWindowClass.destroyWindow();
655          done()
656        }
657
658      } catch (err) {
659        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
660        await subWindowClass.destroyWindow();
661        expect(false).assertTrue();
662        done();
663      }
664    })
665
666    /**
667     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1600
668     * @tc.name      : testInjectTouchEventwithDialogWindowClick
669     * @tc.desc      : 验证injectTouchEvent接口向系统窗注入13点击事件
670     * @tc.size      : MediumTest
671     * @tc.type      : Function
672     * @tc.level     : Level0
673     */
674    it('testInjectTouchEventwithDialogWindowClick', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
675      let caseName = 'testInjectTouchEventwithDialogWindowClick';
676      let config: window.Configuration = {
677        name: "dialogWindow",
678        windowType: window.WindowType.TYPE_DIALOG,
679        ctx: context
680      };
681      let subWindowClass = await window.createWindow(config);
682      await sleep(200);
683      await subWindowClass.setUIContent('testability/pages/subWindow');
684      await sleep(200);
685      await subWindowClass.showWindow();
686      await sleep(200);
687      try {
688        let driver = Driver.create();
689        let btn = await driver.findComponent(ON.id('buttonId'));
690        console.info(`${Tag}: ${caseName} btn: ${btn}`);
691        let point = await btn.getBoundsCenter();
692        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
693        let x = point.x
694        let y = point.y
695        await sleep(200);
696        let subWindowId = subWindowClass.getWindowProperties().id;
697        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
698        let result = injectTouchEvent.testInjectTouchEventwithDialogWindowClick(subWindowId, x, y);
699        console.info(`${Tag}: ${caseName} result: ${result}`);
700        if(result==1300003){
701          await subWindowClass.destroyWindow();
702          done()
703        }else{
704          expect(result).assertEqual(0);
705          await sleep(400);
706          let newText = await btn.getText();
707          await sleep(200);
708          expect(newText).assertEqual('TextChanged');
709          await subWindowClass.destroyWindow();
710          done()
711        }
712
713      } catch (err) {
714        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
715        await subWindowClass.destroyWindow();
716        expect(false).assertTrue();
717        done();
718      }
719    })
720
721    /**
722     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1700
723     * @tc.name      : testInjectTouchEventwithSubWindowSlide
724     * @tc.desc      : 验证injectTouchEvent接口向子窗注入123滑动事件
725     * @tc.size      : MediumTest
726     * @tc.type      : Function
727     * @tc.level     : Level0
728     */
729    it('testInjectTouchEventwithSubWindowSlide', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
730      let caseName = 'testInjectTouchEventwithSubWindowSlide';
731      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithSubWindowSlide');
732      await sleep(200);
733      await subWindowClass.setUIContent('testability/pages/subWindow');
734      await sleep(200);
735      await subWindowClass.showWindow();
736      await sleep(200);
737      try {
738        let driver = Driver.create();
739        let slider = await driver.findComponent(ON.id('sliderId'));
740        console.info(`${Tag}: ${caseName} slider: ${slider}`);
741        let point = await slider.getBoundsCenter();
742        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
743        let x = point.x
744        let y = point.y
745        await sleep(200);
746        let subWindowId = subWindowClass.getWindowProperties().id;
747        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
748        let result = injectTouchEvent.testInjectTouchEventwithSubWindowSlide(subWindowId, x, y);
749        console.info(`${Tag}: ${caseName} result: ${result}`);
750        if(result==1300003){
751          await subWindowClass.destroyWindow();
752          done()
753        }else{
754          expect(result).assertEqual(0);
755          let sliderText = await driver.findComponent(ON.id('sliderTextId'));
756          console.info(`${Tag}: ${caseName} sliderText: ${sliderText}`);
757          await sleep(500);
758          let newText = await sliderText.getText();
759          console.info(`${Tag}: ${caseName} newText: ${newText}`);
760          await sleep(200);
761          if (newText != '40') {
762            expect(true).assertTrue();
763          } else {
764            expect(false).assertTrue();
765          }
766          await subWindowClass.destroyWindow();
767          done()
768        }
769
770      } catch (err) {
771        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
772        await subWindowClass.destroyWindow();
773        expect(false).assertTrue();
774        done();
775      }
776    })
777
778    /**
779     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_1800
780     * @tc.name      : testInjectTouchEventwithSubWindowEdgeSlide
781     * @tc.desc      : 验证injectTouchEvent接口向子窗边缘注入123滑动事件不响应
782     * @tc.size      : MediumTest
783     * @tc.type      : Function
784     * @tc.level     : Level1
785     */
786    it('testInjectTouchEventwithSubWindowEdgeSlide', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done:Function) => {
787      let caseName = 'testInjectTouchEventwithSubWindowEdgeSlide';
788      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithSubWindowEdgeSlide');
789      await sleep(200);
790      await subWindowClass.setUIContent('testability/pages/subWindow');
791      await sleep(200);
792      await subWindowClass.showWindow();
793      await sleep(200);
794      try {
795        let windowLimits = subWindowClass.getWindowLimits();
796        console.info(`${Tag}: ${caseName} windowLimits: ${JSON.stringify(windowLimits)}`);
797        let minWidth = windowLimits.minWidth as number;
798        let minHeight = windowLimits.minHeight as number;
799        await subWindowClass.resize(minWidth, minHeight);
800        await sleep(200);
801        let windowRect = subWindowClass.getWindowProperties().windowRect;
802        console.info(`${Tag}: ${caseName} windowRect: ${JSON.stringify(windowRect)}`);
803        let x = windowRect.width + windowRect.left;
804        let y = windowRect.height + windowRect.top;
805        await sleep(200);
806        let subWindowId = subWindowClass.getWindowProperties().id;
807        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
808        let result = injectTouchEvent.testInjectTouchEventwithSubWindowEdgeSlide(subWindowId, x, y);
809        console.info(`${Tag}: ${caseName} result: ${result}`);
810        if(result==1300003){
811          await subWindowClass.destroyWindow();
812          done()
813        }else{
814          expect(result).assertEqual(0);
815          let windowProperties =  subWindowClass.getWindowProperties();
816          let windowWidth = windowProperties.windowRect.width;
817          let windowHeight = windowProperties.windowRect.height;
818          console.info(`${Tag}: ${caseName} windowWidth: ${windowWidth}; windowHeight: ${windowHeight}`);
819          expect(Math.abs(windowWidth-minWidth)).assertLessOrEqual(1);
820          expect(Math.abs(windowHeight-minHeight)).assertLessOrEqual(1);
821          await subWindowClass.destroyWindow();
822          done()
823        }
824
825      } catch (err) {
826        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
827        await subWindowClass.destroyWindow();
828        if(err.code == 801){
829          done();
830        }else{
831          expect(false).assertTrue();
832          done();
833        }
834      }
835    })
836
837    /**
838     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_2100
839     * @tc.name      : testInjectTouchEventwithSubWindowButtonDownCancle
840     * @tc.desc      : 验证injectTouchEvent接口向子窗button组件注入10按下后取消事件
841     * @tc.size      : MediumTest
842     * @tc.type      : Function
843     * @tc.level     : Level1
844     */
845    it('testInjectTouchEventwithSubWindowButtonDownCancle', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done:Function) => {
846      let caseName = 'testInjectTouchEventwithSubWindowButtonDownCancle';
847      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithSubWindowButtonDownCancle');
848      await sleep(200);
849      await sleep(200);
850      await subWindowClass.setUIContent('testability/pages/subWindow');
851      await sleep(200);
852      await subWindowClass.showWindow();
853      await sleep(200);
854      try {
855        let driver = Driver.create();
856        let btn = await driver.findComponent(ON.id('buttonId'));
857        console.info(`${Tag}: ${caseName} btn: ${btn}`);
858        let point = await btn.getBoundsCenter();
859        console.info(`${Tag}: ${caseName} point: ${JSON.stringify(point)}`);
860        let x = point.x
861        let y = point.y
862        await sleep(200);
863        let subWindowId = subWindowClass.getWindowProperties().id;
864        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
865        let result = injectTouchEvent.testInjectTouchEventwithSubWindowButtonDownCancle(subWindowId, x, y);
866        console.info(`${Tag}: ${caseName} result: ${result}`);
867        if(result==1300003){
868          await subWindowClass.destroyWindow();
869          done()
870        }else{
871          expect(result).assertEqual(0);
872          let newText = await btn.getText();
873          await sleep(200);
874          expect(newText).assertEqual('Button');
875          await subWindowClass.destroyWindow();
876          done()
877        }
878
879      } catch (err) {
880        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
881        await subWindowClass.destroyWindow();
882        expect(false).assertTrue();
883        done();
884      }
885    })
886
887    /**
888     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_2200
889     * @tc.name      : testInjectTouchEventwithSubWindowSlideDownCancle
890     * @tc.desc      : 验证injectTouchEvent接口向子窗滑动组件注入10按下后取消事件
891     * @tc.size      : MediumTest
892     * @tc.type      : Function
893     * @tc.level     : Level0
894     */
895    it('testInjectTouchEventwithSubWindowSlideDownCancle', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
896      let caseName = 'testInjectTouchEventwithSubWindowSlideDownCancle';
897      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithSubWindowSlideDownCancle');
898      await sleep(200);
899      await subWindowClass.setUIContent('testability/pages/subWindow');
900      await sleep(200);
901      await subWindowClass.showWindow();
902      await sleep(200);
903      try {
904        let driver = Driver.create();
905        let slider = await driver.findComponent(ON.id('sliderId'));
906        console.info(`${Tag}: ${caseName} slider: ${slider}`);
907        let rect = await slider.getBounds();
908        console.info(`${Tag}: ${caseName} rect: ${JSON.stringify(rect)}`);
909        let x = rect.right
910        let y = Math.abs(rect.top - rect.bottom) / 2;
911        await sleep(200);
912        let subWindowId = subWindowClass.getWindowProperties().id;
913        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
914        let result = injectTouchEvent.testInjectTouchEventwithSubWindowSlideDownCancle(subWindowId, x, y);
915        console.info(`${Tag}: ${caseName} result: ${result}`);
916        if(result==1300003){
917          await subWindowClass.destroyWindow();
918          done()
919        }else{
920          expect(result).assertEqual(0);
921          let sliderText = await driver.findComponent(ON.id('sliderTextId'));
922          await sleep(500);
923          let newText = await sliderText.getText();
924          await sleep(200);
925          if (newText != '100') {
926            expect(true).assertTrue();
927          } else {
928            expect(false).assertTrue();
929          }
930          await subWindowClass.destroyWindow();
931          done()
932        }
933
934      } catch (err) {
935        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
936        await subWindowClass.destroyWindow();
937        expect(false).assertTrue();
938        done();
939      }
940    })
941
942    /**
943     * @tc.number    : SUB_BASIC_WMS_INJECTOUCHEVENT_2300
944     * @tc.name      : testInjectTouchEventwithHideSubWindowDown
945     * @tc.desc      : 验证injectTouchEvent接口向被遮挡子窗注入13按下事件
946     * @tc.size      : MediumTest
947     * @tc.type      : Function
948     * @tc.level     : Level0
949     */
950    it('testInjectTouchEventwithHideSubWindowDown', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done:Function) => {
951      let caseName = 'testInjectTouchEventwithHideSubWindowDown';
952      let subWindowClass = await windowStage.createSubWindow('testInjectTouchEventwithHideSubWindowDown1');
953      await sleep(200);
954      let subWindowClass2 = await windowStage.createSubWindow('testInjectTouchEventwithHideSubWindowDown2');
955      await sleep(200);
956      await subWindowClass.setUIContent('testability/pages/subWindow');
957      await sleep(200);
958      await subWindowClass.showWindow();
959      await sleep(200);
960      try {
961      let windowLimits = subWindowClass.getWindowLimits();
962      console.info(`${Tag}: ${caseName} subWindowClass windowLimits: ${JSON.stringify(windowLimits)}`);
963      let minWidth = windowLimits.minWidth as number;
964      let minHeight = windowLimits.minHeight as number;
965      await subWindowClass.moveWindowTo(minWidth, minHeight);
966      await sleep(200);
967      await subWindowClass.resize(minWidth + 100, minHeight + 100);
968      await subWindowClass2.setUIContent('testability/pages/subWindow');
969      await sleep(200);
970      await subWindowClass2.showWindow();
971      await sleep(200);
972      let windowLimits2 = subWindowClass2.getWindowLimits();
973      console.info(`${Tag}: ${caseName} subWindowClass2 windowLimits2: ${JSON.stringify(windowLimits2)}`);
974      let minWidth2 = windowLimits2.minWidth as number;
975      let minHeight2 = windowLimits2.minHeight as number;
976      await subWindowClass.moveWindowTo(minWidth2, minHeight2);
977      await sleep(200);
978      await subWindowClass.resize(minWidth2 + 50, minHeight2 + 50);
979
980        let subWindowId = subWindowClass.getWindowProperties().id;
981        console.info(`${Tag}: ${caseName} subWindowId: ${subWindowId}`);
982        let subWindowId2 =  subWindowClass2.getWindowProperties().id;
983        console.info(`${Tag}: ${caseName} subWindowId2: ${subWindowId2}`);
984        let result = injectTouchEvent.testInjectTouchEventwithHideSubWindowDown(subWindowId, 70, 70);
985        console.info(`${Tag}: ${caseName} result: ${result}`);
986        if(result==1300003){
987          await subWindowClass.destroyWindow();
988          await subWindowClass2.destroyWindow();
989          done()
990        }else{
991          expect(result).assertEqual(0);
992          let focused = subWindowClass.isFocused();
993          console.info(`${Tag}: ${caseName} focused: ${focused}`);
994          expect(focused).assertEqual(false);
995          let topWindow = await window.getLastWindow(context);
996          await sleep(200);
997          let topWindowId = topWindow.getWindowProperties().id;
998          console.info(`${Tag}: ${caseName} topWindowId: ${topWindowId}`);
999          expect(topWindowId).assertEqual(subWindowId2);
1000          await subWindowClass.destroyWindow();
1001          await subWindowClass2.destroyWindow();
1002          done()
1003        }
1004
1005      } catch (err) {
1006        console.info(`${Tag}: ${caseName} Failed, err: ${JSON.stringify(err)}`);
1007        await subWindowClass.destroyWindow();
1008        await subWindowClass2.destroyWindow();
1009        if(err.code == 801){
1010          done();
1011        }else{
1012          expect(false).assertTrue();
1013          done();
1014        }
1015
1016      }
1017    })
1018
1019
1020  })
1021}