AccessibilityErrCode.test.ets 39.5 KB
Newer Older
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.
 */
Z
zhangfuzhi 已提交
15 16 17 18 19
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium';
import accessibility from '@ohos.accessibility';
import GesturePath from '@ohos.accessibility.GesturePath';
import GesturePoint from '@ohos.accessibility.GesturePoint';
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
20 21 22 23 24 25

const bundleName = 'com.sample.testfora11y';
const triggerAction = 'accessibilityFocus';
const eventType = 'accessibilityFocus';

export default function abilityTest() {
Z
zhangfuzhi 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 90 91 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 120 121 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 150 151 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 180 181 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 210 211 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 240 241 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 270 271 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 300 301 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 330 331 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 360 361 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 390 391 392 393 394 395 396 397 398 399 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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
  describe('AccessibilityErrCode', function () {
    let axContext = null;
    let object = null;
    beforeEach(async function (done) {
      console.info(`AccessibilityErrCode: beforeEach starts`);
      done();
    })

    afterEach(async function (done) {
      console.info(`AccessibilityErrCode: afterEach starts`);
      setTimeout(done, 1000);
    })

    /* Cases for namespace accessibility */
    /*
    * @tc.number  AbilityExtensionList_0100
    * @tc.name    AbilityExtensionList_0100
    * @tc.desc    The parameters input are 'audible' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0100', 0, async function (done) {
      console.info('AbilityExtensionList_0100');
      accessibility.getAccessibilityExtensionList('audible', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0100 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0100 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0200
    * @tc.name    AbilityExtensionList_0200
    * @tc.desc    The parameters input are 'audible' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0200', 0, async function (done) {
      console.info('AbilityExtensionList_0200');
      accessibility.getAccessibilityExtensionList('audible', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0200 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0200 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0300
    * @tc.name    AbilityExtensionList_0300
    * @tc.desc    The parameters input are 'generic' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0300', 0, async function (done) {
      console.info('AbilityExtensionList_0300');
      accessibility.getAccessibilityExtensionList('generic', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0300 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0300 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0400
    * @tc.name    AbilityExtensionList_0400
    * @tc.desc    The parameters input are 'generic' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0400', 0, async function (done) {
      console.info('AbilityExtensionList_0400');
      accessibility.getAccessibilityExtensionList('generic', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0400 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0400 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0500
    * @tc.name    AbilityExtensionList_0500
    * @tc.desc    The parameters input are 'generic' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0500', 0, async function (done) {
      console.info('AbilityExtensionList_0500');
      accessibility.getAccessibilityExtensionList('generic', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0500 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0500 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0600
    * @tc.name    AbilityExtensionList_0600
    * @tc.desc    The parameters input are 'generic' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0600', 0, async function (done) {
      console.info('AbilityExtensionList_0600');
      accessibility.getAccessibilityExtensionList('generic', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0600 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0600 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0700
    * @tc.name    AbilityExtensionList_0700
    * @tc.desc    The parameters input are 'haptic' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0700', 0, async function (done) {
      console.info('AbilityExtensionList_0700');
      accessibility.getAccessibilityExtensionList('haptic', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0700 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0700 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0800
    * @tc.name    AbilityExtensionList_0800
    * @tc.desc    The parameters input are 'haptic' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0800', 0, async function (done) {
      console.info('AbilityExtensionList_0800');
      accessibility.getAccessibilityExtensionList('haptic', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0800 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0800 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_0900
    * @tc.name    AbilityExtensionList_0900
    * @tc.desc    The parameters input are 'spoken' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_0900', 0, async function (done) {
      console.info('AbilityExtensionList_0900');
      accessibility.getAccessibilityExtensionList('spoken', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_0900 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_0900 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1000
    * @tc.name    AbilityExtensionList_1000
    * @tc.desc    The parameters input are 'spoken' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1000', 0, async function (done) {
      console.info('AbilityExtensionList_1000');
      accessibility.getAccessibilityExtensionList('spoken', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1000 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1000 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1100
    * @tc.name    AbilityExtensionList_1100
    * @tc.desc    The parameters input are 'visual' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1100', 0, async function (done) {
      console.info('AbilityExtensionList_1100');
      accessibility.getAccessibilityExtensionList('visual', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1100 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1100 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1200
    * @tc.name    AbilityExtensionList_1200
    * @tc.desc    The parameters input are 'visual' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1200', 0, async function (done) {
      console.info('AbilityExtensionList_1200');
      accessibility.getAccessibilityExtensionList('visual', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1200 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1200 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1300
    * @tc.name    AbilityExtensionList_1300
    * @tc.desc    The parameters input are 'all' and 'enable', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1300', 0, async function (done) {
      console.info('AbilityExtensionList_1300');
      accessibility.getAccessibilityExtensionList('all', 'enable', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1300 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1300 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1400
    * @tc.name    AbilityExtensionList_1400
    * @tc.desc    The parameters input are 'all' and 'enable', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1400', 0, async function (done) {
      console.info('AbilityExtensionList_1400');
      accessibility.getAccessibilityExtensionList('all', 'enable').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1400 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1400 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1500
    * @tc.name    AbilityExtensionList_1500
    * @tc.desc    The parameters input are 'all' and 'disable', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1500', 0, async function (done) {
      console.info('AbilityExtensionList_1500');
      accessibility.getAccessibilityExtensionList('all', 'disable', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1500 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1500 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1600
    * @tc.name    AbilityExtensionList_1600
    * @tc.desc    The parameters input are 'all' and 'disable', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1600', 0, async function (done) {
      console.info('AbilityExtensionList_1600');
      accessibility.getAccessibilityExtensionList('all', 'disable').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1600 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1600 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1700
    * @tc.name    AbilityExtensionList_1700
    * @tc.desc    The parameters input are 'all' and 'install', test the getAccessibilityExtensionList()
    *             function, and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1700', 0, async function (done) {
      console.info('AbilityExtensionList_1700');
      accessibility.getAccessibilityExtensionList('all', 'install', (err, data) => {
        if (err && err.code != 0) {
          console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1700 has error: ${err.code}`);
          expect(null).assertFail();
          done();
        }
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1700 result ${data.length}`);
        expect(Array.isArray(data)).assertEqual(true);
        done();
      });
    })

    /*
    * @tc.number  AbilityExtensionList_1800
    * @tc.name    AbilityExtensionList_1800
    * @tc.desc    The parameters input are 'all' and 'install', test the getAccessibilityExtensionList() function,
    *             and the output is the list of AccessibilityAbilityInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityExtensionList_1800', 0, async function (done) {
      console.info('AbilityExtensionList_1800');
      accessibility.getAccessibilityExtensionList('all', 'install').then((result) => {
        console.info(`AccessibilityErrCodeTest: AbilityExtensionList_1800 result ${result.length}`);
        expect(Array.isArray(result)).assertEqual(true);
        done();
      }).catch((err) => {
        console.error(`AccessibilityErrCodeTest: AbilityExtensionList_1800 has error: ${err}`);
        expect(null).assertFail();
        done();
      });
    })

    /*
    * @tc.number  AccessibilityEventInfo_0100
    * @tc.name    AccessibilityEventInfo_0100
    * @tc.desc    test Accessibility EventInfo
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityEventInfo_0100', 0, async function (done) {
      let eventInfo = new accessibility.EventInfo({
        'type': 'click',
        'bundleName': 'com.example.MyApplication',
        'triggerAction': 'click'
      });
      expect(eventInfo != null).assertTrue();
      done();
    })


    /*
    * @tc.number  AccessibilitySendEventCallBack_0100
    * @tc.name    AccessibilitySendEventCallBack_0100
    * @tc.desc    test Accessibility SendEvent CallBack
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilitySendEventCallBack_0100', 0, async function (done) {
      let event = null;
      accessibility.sendEvent(event, (err, data) => {
        if (err) {
          console.error('failed to sendEvent because ' + JSON.stringify(err));
          done();
          return;
        }
        console.info('success data:sendEvent : ' + JSON.stringify(data))
        expect(null).assertFail();
        done();
      })
    })
    /*
    * @tc.number  AbilityCapability_0100
    * @tc.name    AbilityCapability_0100
    * @tc.desc    test Ability Capability
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityCapability_0100', 0, async function (done) {
      accessibility.getAbilityLists('audible', 'enable', (err, data) => {
        if (err) {
          console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
          done();
          return;
        }
        for (let accessibilityAbilityInfo of data) {
          expect(accessibilityAbilityInfo.capabilities.length >= 0).assertTrue();
          expect(accessibilityAbilityInfo.abilityTypes.length >= 0).assertTrue();
          expect(accessibilityAbilityInfo.eventTypes.length >= 0).assertTrue();
          expect(accessibilityAbilityInfo.targetBundleNames.length >= 0).assertTrue();
          expect(accessibilityAbilityInfo.bundleName != null).assertTrue();
          expect(accessibilityAbilityInfo.description != null).assertTrue();
          expect(accessibilityAbilityInfo.id != null).assertTrue();
          expect(accessibilityAbilityInfo.name != null).assertTrue();
          for (let capability of accessibilityAbilityInfo.capabilities) {
            let cap = capability.toString();
            expect(cap == 'retrieve' ||
            cap == 'touchGuide' ||
            cap == 'keyEventObserver' ||
            cap == 'zoom' ||
            cap == 'gesture')
              .assertTrue();
          }
        }
        console.info('get accessibility extension list success');
        done();
      })
    })

    /*
    * @tc.number  AbilityCaptionsManager_0100
    * @tc.name    AbilityCaptionsManager_0100
    * @tc.desc    test Ability Captions Manager
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AbilityCaptionsManager_0100', 0, async function (done) {
      let captionsManager = accessibility.getCaptionsManager();
      expect(captionsManager.enabled == true || captionsManager.enabled == false).assertTrue();
      expect(captionsManager.style != null).assertTrue();
      expect(captionsManager.style.backgroundColor != null).assertTrue();
      expect(captionsManager.style.fontColor != null).assertTrue();
      expect(captionsManager.style.fontEdgeType != null).assertTrue();
      expect(captionsManager.style.fontFamily != null).assertTrue();
      expect(captionsManager.style.fontScale != null).assertTrue();
      expect(captionsManager.style.windowColor != null).assertTrue();
      done();
    })

    /*
    * @tc.number  GesturePathAndPoint_0100
    * @tc.name    GesturePathAndPoint_0100
    * @tc.desc    test GesturePath And GesturePoint
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('GesturePathAndPoint_0100', 0, async function (done) {
      let gesturePath = new GesturePath.GesturePath(20);
      let gesturePoint = new GesturePoint.GesturePoint(1, 2);
      gesturePath.points.push(gesturePoint);
      expect(gesturePath.points.length != 0).assertTrue();
      expect(gesturePath.durationTime == 20).assertTrue();
      expect(gesturePoint.positionX == 1).assertTrue();
      expect(gesturePoint.positionY == 2).assertTrue();
      done();
    })

    function init() {
      class MainAbility extends AccessibilityExtensionAbility {
        onConnect(): void {
          console.log('AxExtensionAbility onConnect');
          axContext = this.context;
        }

        onDisconnect() {
          console.log('AxExtensionAbility onDisconnect');
        }

        onAccessibilityEvent(event) {
          console.log('AxExtensionAbility onAccessibilityEvent');
          expect(event.eventType != null).assertTrue();
          expect(event.target != null).assertTrue();
          expect(event.timeStamp != null).assertTrue();
        }

        onKeyEvent(keyEvent) {
          console.log('AxExtensionAbility onKeyEvent');
          if (keyEvent.keyCode == 22) {
            console.log('AxExtensionAbility onKeyEvent: intercept 22');
            return true;
          }
          return false;
        }
      }

      object = new MainAbility();
      object.onConnect();
    }
572

Z
zhangfuzhi 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585
    /*
    * @tc.number  AccessibilitySetTargetBundleName_0100
    * @tc.name    AccessibilitySetTargetBundleName_0100
    * @tc.desc    test AccessibilitySetTargetBundleName
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilitySetTargetBundleName_0100', 0, async function (done) {
      init();
      if (axContext != null) {
        let targetNames = ['com.ohos.xyz'];
        try {
          axContext.setTargetBundleName(targetNames).then(() => {
586
            done();
Z
zhangfuzhi 已提交
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
          }).catch((err) => {
            console.info('AccessibilitySetTargetBundleName_0100 err:' + JSON.stringify(err));
            done();
          });
        } catch (exception) {
          console.error('failed to set target bundle names, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })

    /*
    * @tc.number  AccessibilitySetTargetBundleName_0200
    * @tc.name    AccessibilitySetTargetBundleName_0200
    * @tc.desc    test AccessibilitySetTargetBundleName
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilitySetTargetBundleName_0200', 0, async function (done) {
      if (axContext != null) {
        let targetNames = ['com.ohos.xyz'];
        try {
          axContext.setTargetBundleName(targetNames, (err, data) => {
            console.info('AccessibilitySetTargetBundleName_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to set target bundle names, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })

    /*
    * @tc.number  AccessibilityGetFocusElement_0100
    * @tc.name    AccessibilityGetFocusElement_0100
    * @tc.desc    test AccessibilityGetFocusElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetFocusElement_0100', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getFocusElement().then((rootElement) => {
            console.info('AccessibilityGetFocusElement_0100 rootElement:' + JSON.stringify(rootElement));
            rootElement.attributeNames().then((data) => {
              console.log('get attribute names success');
              if (data != null) {
                expect(data.rect.left != -1).assertTrue();
                expect(data.rect.top != -1).assertTrue();
                expect(data.rect.width != -1).assertTrue();
                expect(data.rect.height != -1).assertTrue();
              }
648
            }).catch((err) => {
Z
zhangfuzhi 已提交
649
              console.log('failed to get attribute names, because ' + JSON.stringify(err));
650
            });
Z
zhangfuzhi 已提交
651 652
            rootElement.attributeValue('name').then((data) => {
              console.log('get attribute value by name success');
653
            }).catch((err) => {
Z
zhangfuzhi 已提交
654
              console.log('failed to get attribute value, because ' + JSON.stringify(err));
655
            });
Z
zhangfuzhi 已提交
656 657
            rootElement.actionNames().then((data) => {
              console.log('get action names success');
658
            }).catch((err) => {
Z
zhangfuzhi 已提交
659
              console.log('failed to get action names because ' + JSON.stringify(err));
660
            });
Z
zhangfuzhi 已提交
661 662
            rootElement.performAction('action').then((data) => {
              console.info('perform action success');
663
            }).catch((err) => {
Z
zhangfuzhi 已提交
664
              console.log('failed to perform action, because ' + JSON.stringify(err));
665
            });
Z
zhangfuzhi 已提交
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
            done();
          }).catch((err) => {
            console.info('AccessibilityGetFocusElement_0100 err:' + JSON.stringify(err));
            done();
          });
        } catch (exception) {
          console.error('failed to get focus element, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })
    /*
    * @tc.number  AccessibilityGetFocusElement_0200
    * @tc.name    AccessibilityGetFocusElement_0200
    * @tc.desc    test AccessibilityGetFocusElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetFocusElement_0200', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getFocusElement((err, rootElement) => {
            if (err) {
              console.error('failed to get focus element, because ' + JSON.stringify(err));
              done();
              return;
            }
            rootElement.attributeNames((err, data) => {
              console.info('AccessibilityGetFocusElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
699
            });
Z
zhangfuzhi 已提交
700 701
            rootElement.attributeValue('name', (err, data) => {
              console.info('AccessibilityGetFocusElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
702
            });
Z
zhangfuzhi 已提交
703 704
            rootElement.actionNames((err, data) => {
              console.info('AccessibilityGetFocusElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
705
            });
Z
zhangfuzhi 已提交
706 707
            rootElement.performAction('action', (err, data) => {
              console.info('AccessibilityGetFocusElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
708
            });
Z
zhangfuzhi 已提交
709 710 711 712 713 714
            let actionName = 'action';
            let parameters = {
              'setText': 'test text'
            };
            rootElement.performAction(actionName, parameters, (err, data) => {
              console.info('AccessibilityGetFocusElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
715
            });
Z
zhangfuzhi 已提交
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
            done();
          });
        } catch (exception) {
          console.error('failed to get focus element, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })
    /*
    * @tc.number  AccessibilityGetFocusElement_0300
    * @tc.name    AccessibilityGetFocusElement_0300
    * @tc.desc    test AccessibilityGetFocusElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetFocusElement_0300', 0, async function (done) {
      if (axContext != null) {
        let isAccessibilityFocus = true;
        try {
          axContext.getFocusElement(isAccessibilityFocus, (err, rootElement) => {
            if (err) {
              console.error('failed to get focus element, because ' + JSON.stringify(err));
              done();
              return;
            }
            rootElement.findElement('content', 'keyword').then((data) => {
              console.log('data' + JSON.stringify(data));
747
            }).catch((err) => {
Z
zhangfuzhi 已提交
748
              console.log('failed to find element, because ' + JSON.stringify(err));
749
            });
Z
zhangfuzhi 已提交
750 751
            rootElement.findElement('content', 'keyword', (err, data) => {
              console.info('AccessibilityGetFocusElement_0300 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
752
            });
Z
zhangfuzhi 已提交
753 754
            rootElement.findElement('focusType', 'normal').then((data) => {
              console.log('data' + JSON.stringify(data));
755
            }).catch((err) => {
Z
zhangfuzhi 已提交
756
              console.log('failed to find element, because ' + JSON.stringify(err));
757
            });
Z
zhangfuzhi 已提交
758 759
            rootElement.findElement('focusType', 'normal', (err, data) => {
              console.info('AccessibilityGetFocusElement_0300 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
760
            });
Z
zhangfuzhi 已提交
761 762
            rootElement.findElement('focusDirection', 'up').then((data) => {
              console.log('data' + JSON.stringify(data));
763
            }).catch((err) => {
Z
zhangfuzhi 已提交
764 765 766 767
              console.log('failed to find element, because ' + JSON.stringify(err));
            });
            rootElement.findElement('focusDirection', 'up', (err, data) => {
              console.info('AccessibilityGetFocusElement_0300 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
768
            });
Z
zhangfuzhi 已提交
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
            done();
          });
        } catch (exception) {
          console.error('failed to get focus element, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })

    /*
    * @tc.number  AccessibilityGetWindowRootElement_0100
    * @tc.name    AccessibilityGetWindowRootElement_0100
    * @tc.desc    test AccessibilityGetWindowRootElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindowRootElement_0100', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getWindowRootElement().then((data) => {
            console.info('AccessibilityGetWindowRootElement_0100 data:' + JSON.stringify(data));
            done();
          }).catch((err) => {
            console.info('AccessibilityGetWindowRootElement_0100 err:' + JSON.stringify(err));
            done();
          });
        } catch (exception) {
          console.error('failed to get root element of the window, ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityGetWindowRootElement_0200
    * @tc.name    AccessibilityGetWindowRootElement_0200
    * @tc.desc    test AccessibilityGetWindowRootElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindowRootElement_0200', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getWindowRootElement((err, data) => {
            console.info('AccessibilityGetWindowRootElement_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to get root element of the window, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityGetWindowRootElement_0300
    * @tc.name    AccessibilityGetWindowRootElement_0300
    * @tc.desc    test AccessibilityGetWindowRootElement
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindowRootElement_0300', 0, async function (done) {
      if (axContext != null) {
        let windowId = 10;
        try {
          axContext.getWindowRootElement(windowId, (err, data) => {
            console.info('AccessibilityGetWindowRootElement_0300 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to get root element of the window, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityGetWindows_0100
    * @tc.name    AccessibilityGetWindows_0100
    * @tc.desc    test AccessibilityGetWindows
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindows_0100', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getWindows().then((data) => {
            console.info('AccessibilityGetWindows_0100  data:' + JSON.stringify(data));
            done();
          }).catch((err) => {
            console.info('AccessibilityGetWindows_0100 err' + JSON.stringify(err));
            done();
          });
        } catch (exception) {
          console.error('failed to get windows, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityGetWindows_0200
    * @tc.name    AccessibilityGetWindows_0200
    * @tc.desc    test AccessibilityGetWindows
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindows_0200', 0, async function (done) {
      if (axContext != null) {
        try {
          axContext.getWindows((err, data) => {
            console.info('AccessibilityGetWindows_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to get windows, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityGetWindows_0300
    * @tc.name    AccessibilityGetWindows_0300
    * @tc.desc    test AccessibilityGetWindows
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityGetWindows_0300', 0, async function (done) {
      if (axContext != null) {
        let displayId = 10;
        try {
          axContext.getWindows(displayId, (err, data) => {
            console.info('AccessibilityGetWindows_0300 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to get windows, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityInjectGesture_0100
    * @tc.name    AccessibilityInjectGesture_0100
    * @tc.desc    test AccessibilityInjectGesture
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityInjectGesture_0100', 0, async function (done) {
      if (axContext != null) {
        let gesturePath = new GesturePath.GesturePath(100);
        try {
          for (let i = 0; i < 10; i++) {
            let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
            gesturePath.points.push(gesturePoint);
          }
          axContext.injectGesture(gesturePath).then(() => {
            done();
          }).catch((err) => {
            console.info('AccessibilityInjectGesture_0100 err' + JSON.stringify(err));
            done();
          });
        } catch (exception) {
          console.error('failed to inject gesture, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
    })


    /*
    * @tc.number  AccessibilityInjectGesture_0200
    * @tc.name    AccessibilityInjectGesture_0200
    * @tc.desc    test AccessibilityInjectGesture
    * @tc.size    SmallTest
    * @tc.type    User
    */
    it('AccessibilityInjectGesture_0200', 0, async function (done) {
      if (axContext != null) {
        let gesturePath = new GesturePath.GesturePath(100);
        try {
          for (let i = 0; i < 10; i++) {
            let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
            gesturePath.points.push(gesturePoint);
          }
          axContext.injectGesture(gesturePath, (err, data) => {
            console.info('AccessibilityInjectGesture_0200 err' + JSON.stringify(err) + ' data:' + JSON.stringify(data));
            done();
          });
        } catch (exception) {
          console.error('failed to inject gesture, because ' + JSON.stringify(exception));
          expect(false).assertTrue();
          done();
        }
      } else {
        console.log('axContext null');
        done();
      }
1007
    })
Z
zhangfuzhi 已提交
1008
  })
1009
}