AccessibilityEventTest.test.ets 17.8 KB
Newer Older
M
Mupceet 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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.
 */
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import accessibility from '@ohos.accessibility'
import commonEvent from '@ohos.commonEvent'

export default function abilityTest(abilityContext) {
    let targetBundleName = 'com.example.myapplication';
    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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
                }
            });

            setTimeout(async () => {
                await abilityContext.startAbility({
                    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 81 82 83 84 85 86 87 88 89
            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`);
            let eventType = 'accessibilityFocus';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'accessibilityFocus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
90 91
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
                        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`);
            let eventType = 'accessibilityFocusClear';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'clearAccessibilityFocus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
120 121
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
                        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`);
            let eventType = 'click';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'click';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
150 151
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
                        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`);
            let eventType = 'longClick';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'longClick';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
180 181
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                        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`);
            let eventType = 'focus';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
210 211
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
                        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`);
            let eventType = 'select';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'select';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
240 241
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
                        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`);
            let eventType = 'hoverEnter';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
270 271
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                        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`);
            let eventType = 'hoverExit';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'focus';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
300 301
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
                        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`);
            let eventType = 'textUpdate';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'cut';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
330 331
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
                        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`);
            let eventType = 'textSelectionUpdate';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'setSelection';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
360 361
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
                        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`);
            let eventType = 'scroll';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            event.bundleName = targetBundleName;
            event.triggerAction = 'scrollForward';
            await accessibility.sendEvent(event);

            setTimeout(() => {
                let findResult = false;
M
Mupceet 已提交
390 391
                for (let item of events) {
                    if (item.eventType == eventType) {
M
Mupceet 已提交
392 393 394 395 396 397 398 399
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1100 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })
M
Mupceet 已提交
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

        /*
         * @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 eventType = 'scroll';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            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}`);
                    if (item.eventType == eventType && item.haveTarget) {
                        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 eventType = 'scroll';
            let event = new accessibility.EventInfo({});
            event.type = eventType;
            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}`);
                    if (item.eventType == eventType && typeof(item.timeStamp) == 'number') {
                        findResult = true;
                    }
                }
                console.info('AccessibilityEventTest_1300 case: ' + findResult);
                expect(findResult).assertTrue();
                done();
            }, 3000);
        })
M
Mupceet 已提交
462 463
    })
}