AccessibilityEventTest.test.ets 17.3 KB
Newer Older
M
Mupceet 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
J
jiyong_sd 已提交
15
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
M
Mupceet 已提交
16 17 18
import accessibility from '@ohos.accessibility'
import commonEvent from '@ohos.commonEvent'

J
jiyong_sd 已提交
19
export default function abilityTest() {
M
Mupceet 已提交
20
    let targetBundleName = 'com.example.accessibilityxts';
M
Mupceet 已提交
21 22
    let subScriber = undefined;
    let isConnected: boolean = false;
M
Mupceet 已提交
23
    let events: Array<any> = [];
M
Mupceet 已提交
24 25 26 27 28 29 30 31 32 33 34 35

    describe('AccessibilityEventTest', function () {
        beforeAll(async function (done) {
            console.info('AccessibilityEventTest beforeAll');
            subScriber = await commonEvent.createSubscriber({events: ['onConnectState', 'accessibilityEvent']});
            commonEvent.subscribe(subScriber, (err, data) => {
                console.info('AccessibilityEventTest beforeAll data:' + JSON.stringify(data) );
                if (data.data == 'connect') {
                    isConnected = true;
                } else if (data.data == 'disconnect') {
                    isConnected = false;
                } else if (data.data == 'accessibilityEvent') {
M
Mupceet 已提交
36
                    events.push(data.parameters);
M
Mupceet 已提交
37 38 39 40
                }
            });

            setTimeout(async () => {
J
jiyong_sd 已提交
41
                await globalThis.abilityContext.startAbility({
M
Mupceet 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
                    deviceId: "",
                    bundleName: "com.example.acetest",
                    abilityName: "MainAbility",
                    action: "action1",
                    parameters: {},
                });
                done();
            }, 5000);
        })

        afterAll(async function (done) {
            console.info('AccessibilityEventTest: afterAll');
            commonEvent.unsubscribe(subScriber);
            isConnected = false;
            done();
        })

        beforeEach(async function (done) {
            console.info(`AccessibilityEventTest: beforeEach`);
M
Mupceet 已提交
61
            events.length = 0;
M
Mupceet 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
            setTimeout(done, 2000);
        })

        afterEach(async function (done) {
            console.info(`AccessibilityEventTest: afterEach`);
            done();
        })


        /*
         * @tc.number  AccessibilityEventTest_0100
         * @tc.name    AccessibilityEventTest_0100
         * @tc.desc    The parameter input is 'accessibilityFocus', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0100', 0, async function (done) {
            console.info(`AccessibilityEventTest_0100`);
M
Mupceet 已提交
81
            let event = new accessibility.EventInfo({});
82
            event.type = 'accessibilityFocus';
M
Mupceet 已提交
83 84 85 86 87 88
            event.bundleName = targetBundleName;
            event.triggerAction = 'accessibilityFocus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
89
                for (let item of events) {
90
                    if (item.eventType == 'accessibilityFocus') {
M
Mupceet 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0100 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0200
         * @tc.name    AccessibilityEventTest_0200
         * @tc.desc    The parameter input is 'accessibilityFocusClear', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0200', 0, async function (done) {
            console.info(`AccessibilityEventTest_0200`);
M
Mupceet 已提交
110
            let event = new accessibility.EventInfo({});
111
            event.type = 'accessibilityFocusClear';
M
Mupceet 已提交
112 113 114 115 116 117
            event.bundleName = targetBundleName;
            event.triggerAction = 'clearAccessibilityFocus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
118
                for (let item of events) {
119
                    if (item.eventType == 'accessibilityFocusClear') {
M
Mupceet 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0200 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0300
         * @tc.name    AccessibilityEventTest_0300
         * @tc.desc    The parameter input is 'click', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0300', 0, async function (done) {
            console.info(`AccessibilityEventTest_0300`);
M
Mupceet 已提交
139
            let event = new accessibility.EventInfo({});
140
            event.type = 'click';
M
Mupceet 已提交
141 142 143 144 145 146
            event.bundleName = targetBundleName;
            event.triggerAction = 'click';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
147
                for (let item of events) {
148
                    if (item.eventType == 'click') {
M
Mupceet 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0300 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0400
         * @tc.name    AccessibilityEventTest_0400
         * @tc.desc    The parameter input is 'longClick', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0400', 0, async function (done) {
            console.info(`AccessibilityEventTest_0400`);
M
Mupceet 已提交
168
            let event = new accessibility.EventInfo({});
169
            event.type = 'longClick';
M
Mupceet 已提交
170 171 172 173 174 175
            event.bundleName = targetBundleName;
            event.triggerAction = 'longClick';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
176
                for (let item of events) {
177
                    if (item.eventType == 'longClick') {
M
Mupceet 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0400 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0500
         * @tc.name    AccessibilityEventTest_0500
         * @tc.desc    The parameter input is 'focus', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0500', 0, async function (done) {
            console.info(`AccessibilityEventTest_0500`);
M
Mupceet 已提交
197
            let event = new accessibility.EventInfo({});
198
            event.type = 'focus';
M
Mupceet 已提交
199 200 201 202 203 204
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
205
                for (let item of events) {
206
                    if (item.eventType == 'focus') {
M
Mupceet 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0500 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0600
         * @tc.name    AccessibilityEventTest_0600
         * @tc.desc    The parameter input is 'select', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0600', 0, async function (done) {
            console.info(`AccessibilityEventTest_0600`);
M
Mupceet 已提交
226
            let event = new accessibility.EventInfo({});
227
            event.type = 'select';
M
Mupceet 已提交
228 229 230 231 232 233
            event.bundleName = targetBundleName;
            event.triggerAction = 'select';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
234
                for (let item of events) {
235
                    if (item.eventType == 'select') {
M
Mupceet 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0600 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0700
         * @tc.name    AccessibilityEventTest_0700
         * @tc.desc    The parameter input is 'hoverEnter', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0700', 0, async function (done) {
            console.info(`AccessibilityEventTest_0700`);
M
Mupceet 已提交
255
            let event = new accessibility.EventInfo({});
256
            event.type = 'hoverEnter';
M
Mupceet 已提交
257 258 259 260 261 262
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
263
                for (let item of events) {
264
                    if (item.eventType == 'hoverEnter') {
M
Mupceet 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0700 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0800
         * @tc.name    AccessibilityEventTest_0800
         * @tc.desc    The parameter input is 'hoverExit', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0800', 0, async function (done) {
            console.info(`AccessibilityEventTest_0800`);
M
Mupceet 已提交
284
            let event = new accessibility.EventInfo({});
285
            event.type = 'hoverExit';
M
Mupceet 已提交
286 287 288 289 290 291
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
292
                for (let item of events) {
293
                    if (item.eventType == 'hoverExit') {
M
Mupceet 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0800 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_0900
         * @tc.name    AccessibilityEventTest_0900
         * @tc.desc    The parameter input is 'textUpdate', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_0900', 0, async function (done) {
            console.info(`AccessibilityEventTest_0900`);
M
Mupceet 已提交
313
            let event = new accessibility.EventInfo({});
314
            event.type = 'textUpdate';
M
Mupceet 已提交
315 316 317 318 319 320
            event.bundleName = targetBundleName;
            event.triggerAction = 'cut';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
321
                for (let item of events) {
322
                    if (item.eventType == 'textUpdate') {
M
Mupceet 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_0900 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_1000
         * @tc.name    AccessibilityEventTest_1000
         * @tc.desc    The parameter input is 'textSelectionUpdate', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_1000', 0, async function (done) {
            console.info(`AccessibilityEventTest_1000`);
M
Mupceet 已提交
342
            let event = new accessibility.EventInfo({});
343
            event.type = 'textSelectionUpdate';
M
Mupceet 已提交
344 345 346 347 348 349
            event.bundleName = targetBundleName;
            event.triggerAction = 'setSelection';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
350
                for (let item of events) {
351
                    if (item.eventType == 'textSelectionUpdate') {
M
Mupceet 已提交
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1000 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_1100
         * @tc.name    AccessibilityEventTest_1100
         * @tc.desc    The parameter input is 'scroll', test the Ability event function,
         *             and return void. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_1100', 0, async function (done) {
            console.info(`AccessibilityEventTest_1100`);
M
Mupceet 已提交
371
            let event = new accessibility.EventInfo({});
372
            event.type = 'scroll';
M
Mupceet 已提交
373 374 375 376 377 378
            event.bundleName = targetBundleName;
            event.triggerAction = 'scrollForward';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
379
                for (let item of events) {
380
                    if (item.eventType == 'scroll') {
M
Mupceet 已提交
381 382 383 384 385 386 387 388
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1100 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })
M
Mupceet 已提交
389 390 391 392 393 394 395 396 397 398 399 400

        /*
         * @tc.number  AccessibilityEventTest_1200
         * @tc.name    AccessibilityEventTest_1200
         * @tc.desc    The parameter input is 'scroll', test the Ability event function,
         *             and return void, verify existence of 'target'. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_1200', 0, async function (done) {
            console.info(`AccessibilityEventTest_1200`);
            let event = new accessibility.EventInfo({});
401
            event.type = 'scroll';
M
Mupceet 已提交
402 403 404 405 406 407 408 409
            event.bundleName = targetBundleName;
            event.triggerAction = 'scrollForward';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
                for (let item of events) {
                    console.info(`AccessibilityEventTest_1200 haveTarget: ${item.haveTarget}`);
410
                    if (item.eventType == 'scroll' && item.haveTarget) {
M
Mupceet 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1200 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })

        /*
         * @tc.number  AccessibilityEventTest_1300
         * @tc.name    AccessibilityEventTest_1300
         * @tc.desc    The parameter input is 'scroll', test the Ability event function,
         *             and return void, verify existence of 'timeStamp'. 
         * @tc.size    SmallTest
         * @tc.type    User
         */
        it('AccessibilityEventTest_1300', 0, async function (done) {
            console.info(`AccessibilityEventTest_1300`);
            let event = new accessibility.EventInfo({});
431
            event.type = 'scroll';
M
Mupceet 已提交
432 433 434 435 436 437 438 439
            event.bundleName = targetBundleName;
            event.triggerAction = 'scrollForward';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
                for (let item of events) {
                    console.info(`AccessibilityEventTest_1300 timeStamp: ${item.timeStamp}`);
440
                    if (item.eventType == 'scroll' && typeof(item.timeStamp) == 'number') {
M
Mupceet 已提交
441 442 443 444 445 446 447 448
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1300 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })
M
Mupceet 已提交
449 450
    })
}