File: tutorial_test.js

package info (click to toggle)
chromium 140.0.7339.185-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,193,740 kB
  • sloc: cpp: 35,093,945; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,515; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (734 lines) | stat: -rw-r--r-- 30,442 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Include test fixture.
GEN_INCLUDE(['panel_test_base.js']);
GEN_INCLUDE(['../testing/mock_feedback.js']);

/**
 * Test fixture for the interactive tutorial.
 */
ChromeVoxTutorialTest = class extends ChromeVoxPanelTestBase {
  /** @override */
  async setUpDeferred() {
    await super.setUpDeferred();
    globalThis.Gesture = chrome.accessibilityPrivate.Gesture;
  }

  async assertActiveLessonIndex(expectedIndex) {
    assertEquals(expectedIndex, await this.getTutorialActiveLessonIndex());
  }

  async assertActiveScreen(expectedScreen) {
    assertEquals(expectedScreen, await this.getTutorialActiveScreen());
  }

  async disableTutorialRestartNudges() {
    await PanelBridge.disableTutorialRestartNudges();
  }

  async getTutorialActiveLessonIndex() {
    return await PanelBridge.getTutorialActiveLessonIndex();
  }

  async getTutorialActiveScreen() {
    return await PanelBridge.getTutorialActiveScreen();
  }

  async getTutorialInteractiveMode() {
    return await PanelBridge.getTutorialInteractiveMode();
  }

  async giveTutorialNudge() {
    await PanelBridge.giveTutorialNudge();
  }

  async initializeTutorialNudges(context) {
    await PanelBridge.initializeTutorialNudges(context);
  }

  async launchAndWaitForTutorial() {
    new PanelCommand(PanelCommandType.TUTORIAL).send();
    await this.waitForTutorial_();
  }

  async restartTutorialNudges() {
    await PanelBridge.restartTutorialNudges();
  }

  async setTutorialCurriculum(curriculum) {
    await PanelBridge.setTutorialCurriculum(curriculum);
  }

  async setTutorialMedium(medium) {
    await PanelBridge.setTutorialMedium(medium);
  }

  async showTutorialLesson(lessonNum) {
    await PanelBridge.showTutorialLesson(lessonNum);
  }

  async showTutorialLessonMenu() {
    await PanelBridge.showTutorialLessonMenu();
  }

  async showTutorialMainMenu() {
    await PanelBridge.showTutorialMainMenu();
  }

  async showTutorialNextLesson() {
    await PanelBridge.showTutorialNextLesson();
  }

  get simpleDoc() {
    return `
      <p>Some web content</p>
    `;
  }

  /** Waits for the tutorial to load. */
  async waitForTutorial_() {
    return new Promise(resolve => {
      const intervalId = setInterval(async () => {
        const ready = await PanelBridge.getTutorialReadyForTest();
        if (ready) {
          clearInterval(intervalId);
          resolve();
        }
      }, 500);
    });
  }
};

// TODO(crbug.com/40941587): Flaky on ChromeOS.
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_BasicTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback
      .expectSpeech(
          'ChromeVox tutorial', 'Heading 1',
          'Press Search + Right Arrow, or Search + Left Arrow to browse' +
              ' topics')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Essential keys', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Navigation', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Command references', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Sounds and settings', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Resources', 'Link')
      .call(doCmd('nextObject'))
      .expectSpeech('Exit tutorial', 'Button');
  await mockFeedback.replay();
});

// Tests that different lessons are shown when choosing an experience from the
// main menu.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_LessonSetTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Quick Orientation Tutorial, [0-9]+ Lessons/)
      .expectSpeech(
          'Press Search + Right Arrow, or Search + Left Arrow to browse ' +
          'lessons for this topic')
      .call(doCmd('nextObject'))
      .expectSpeech('Welcome to ChromeVox!')
      .call(() => this.showTutorialMainMenu())
      .expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('nextObject'))
      .expectSpeech('Essential keys', 'Link')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
      .call(doCmd('nextObject'))
      .expectSpeech('On, Off, and Stop');
  await mockFeedback.replay();
});

// Tests that a static lesson does not show the 'Practice area' button.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_NoPracticeAreaTest', async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(doCmd('nextObject'))
          .expectSpeech('Quick orientation')
          .call(doCmd('nextObject'))
          .expectSpeech('Essential keys')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
          .call(() => this.showTutorialLesson(0))
          .expectSpeech(
              'On, Off, and Stop', 'Heading 1',
              'Press Search + Right Arrow, or Search + Left Arrow to ' +
                  'navigate this lesson')
          .call(doCmd('nextButton'))
          .expectSpeech('Next lesson');
      await mockFeedback.replay();
    });

// Tests that an interactive lesson shows the 'Practice area' button.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_HasPracticeAreaTest', async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(doCmd('nextObject'))
          .expectSpeech('Quick orientation')
          .call(doCmd('nextObject'))
          .expectSpeech('Essential keys')
          .call(doCmd('nextObject'))
          .expectSpeech('Navigation')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Navigation Tutorial, [0-9]+ Lessons/)
          .call(() => this.showTutorialLesson(1))
          .expectSpeech('Jump Commands', 'Heading 1')
          .call(doCmd('nextButton'))
          .expectSpeech('Practice area');
      await mockFeedback.replay();
    });

// Tests nudges given in the general tutorial context.
// The first three nudges should read the current item with full context.
// Afterward, general hints will be given about using ChromeVox. Lastly,
// we will give a hint for exiting the tutorial.
AX_TEST_F('ChromeVoxTutorialTest', 'GeneralNudgesTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  this.disableTutorialRestartNudges();
  const giveNudge = () => this.giveTutorialNudge();
  mockFeedback.expectSpeech('ChromeVox tutorial');
  for (let i = 0; i < 3; ++i) {
    mockFeedback.call(giveNudge).expectSpeech(
        'ChromeVox tutorial', 'Heading 1');
  }
  mockFeedback.call(giveNudge)
      .expectSpeech('Hint: Hold Search and press the arrow keys to navigate.')
      .call(giveNudge)
      .expectSpeech('Hint: Press Search + Space to activate the current item.')
      .call(giveNudge)
      .expectSpeech(
          'Hint: Press Escape if you would like to exit this tutorial.');
  await mockFeedback.replay();
});

// Tests nudges given in the practice area context. Note, each practice area
// can have different nudge messages; this test confirms that nudges given in
// the practice area differ from those given in the general tutorial context.
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_PracticeAreaNudgesTest',
    async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      const giveNudge = () => this.giveTutorialNudge();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(doCmd('nextObject'))
          .expectSpeech('Quick orientation')
          .call(doCmd('nextObject'))
          .expectSpeech('Essential keys')
          .call(doCmd('nextObject'))
          .expectSpeech('Navigation')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Navigation Tutorial, [0-9]+ Lessons/)
          .call(() => this.showTutorialLesson(0))
          .expectSpeech('Basic Navigation', 'Heading 1')
          .call(doCmd('nextButton'))
          .expectSpeech('Practice area')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Try using basic navigation to navigate/)
          .call(giveNudge)
          .expectSpeech(
              'Try pressing Search + left/right arrow. The search key is ' +
              'directly above the shift key')
          .call(giveNudge)
          .expectSpeech('Press Search + Space to activate the current item.');
      await mockFeedback.replay();
    });

// Tests that the tutorial closes when the 'Exit tutorial' button is clicked.
// TODO(crbug.com/1332510): Failing on ChromeOS.
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_ExitButtonTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('previousButton'))
      .expectSpeech('Exit tutorial')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech('Some web content');
  await mockFeedback.replay();
});

// Tests that the tutorial closes when Escape is pressed.
// TODO(crbug.com/1332510): Failing on ChromeOS.
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_EscapeTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(() => PanelBridge.fireMockEventForTest('Escape'))
      .expectSpeech('Some web content');
  await mockFeedback.replay();
});

// Tests that the main menu button navigates the user to the main menu screen.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_MainMenuButton', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(() => this.assertActiveScreen('main_menu'))
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('nextObject'))
      .expectSpeech('Essential keys')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
      .call(() => this.assertActiveScreen('lesson_menu'))
      .call(doCmd('previousButton'))
      .expectSpeech('Exit tutorial')
      .call(doCmd('previousButton'))
      .expectSpeech('Main menu')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech('ChromeVox tutorial')
      .call(() => this.assertActiveScreen('main_menu'));
  await mockFeedback.replay();
});

// Tests that the all lessons button navigates the user to the lesson menu
// screen.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_AllLessonsButton', async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(() => this.assertActiveScreen('main_menu'))
          .call(doCmd('nextObject'))
          .expectSpeech('Quick orientation')
          .call(doCmd('nextObject'))
          .expectSpeech('Essential keys')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
          .call(() => this.assertActiveScreen('lesson_menu'))
          .call(doCmd('nextObject'))
          .expectSpeech('On, Off, and Stop')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech('On, Off, and Stop', 'Heading 1')
          .call(() => this.assertActiveScreen('lesson'))
          .call(doCmd('nextButton'))
          .expectSpeech('Next lesson')
          .call(doCmd('nextButton'))
          .expectSpeech('All lessons')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
          .call(() => this.assertActiveScreen('lesson_menu'));
      await mockFeedback.replay();
    });

// Tests that the next and previous lesson buttons navigate properly.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_NextPreviousButtons', async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(async () => {
            await this.setTutorialCurriculum('essential_keys');
            await this.showTutorialLesson(0);
            await this.assertActiveLessonIndex(0);
            await this.assertActiveScreen('lesson');
          })
          .expectSpeech('On, Off, and Stop', 'Heading 1')
          .call(doCmd('nextButton'))
          .expectSpeech('Next lesson')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech('The ChromeVox modifier key', 'Heading 1')
          .call(() => this.assertActiveLessonIndex(1))
          .call(doCmd('nextButton'))
          .expectSpeech('Previous lesson')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech('On, Off, and Stop', 'Heading 1')
          .call(() => this.assertActiveLessonIndex(0));
      await mockFeedback.replay();
    });

// Tests that the title of an interactive lesson is read when shown.
AX_TEST_F('ChromeVoxTutorialTest', 'AutoReadTitle', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Quick Orientation Tutorial, [0-9]+ Lessons/)
      .call(() => {
        this.showTutorialLesson(0);
      })
      .expectSpeech('Welcome to ChromeVox!')
      .expectSpeech(
          'Welcome to the ChromeVox tutorial. To exit this tutorial at any ' +
          'time, press the Escape key on the top left corner of the ' +
          'keyboard. To turn off ChromeVox, hold Control and Alt, and ' +
          `press Z. When you're ready, use the spacebar to move to the ` +
          'next lesson.');
  await mockFeedback.replay();
});

// Tests that we read a hint for navigating a lesson when it is shown.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_LessonHint', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('nextObject'))
      .expectSpeech('Essential keys')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Essential Keys Tutorial, [0-9]+ Lessons/)
      .call(() => this.showTutorialLesson(0))
      .expectSpeech('On, Off, and Stop', 'Heading 1')
      .expectSpeech(
          'Press Search + Right Arrow, or Search + Left Arrow to navigate' +
          ' this lesson');
  await mockFeedback.replay();
});

// Tests for correct speech and earcons on the earcons lesson.
// TODO(crbug.com/431756859): The earcon lesson is not working in both mv2 and
// mv3. Fix it and re-enable this test.
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_EarconLesson', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  const nextObjectAndExpectSpeechAndEarcon = (speech, earcon) => {
    mockFeedback.call(doCmd('nextObject'))
        .expectSpeech(speech)
        .expectEarcon(earcon);
  };
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(async () => {
        // Show the lesson.
        await this.setTutorialCurriculum('sounds_and_settings');
        await this.showTutorialLesson(0);
      })
      .expectSpeech('Sounds')
      .call(doCmd('nextObject'))
      .expectSpeech(new RegExp(
          'ChromeVox uses sounds to give you essential and additional ' +
          'information.'));
  nextObjectAndExpectSpeechAndEarcon('A modal alert', EarconId.ALERT_MODAL);
  nextObjectAndExpectSpeechAndEarcon(
      'A non modal alert', EarconId.ALERT_NONMODAL);
  // TODO(anastasi): Identify why the button is not present in the tutorial.
  // nextObjectAndExpectSpeechAndEarcon('A button', EarconId.BUTTON);
  await mockFeedback.replay();
});

// Tests that a lesson from the quick orientation blocks ChromeVox execution
// until the specified keystroke is pressed.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_QuickOrientationLessonTest',
    async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      const keyboardHandler = ChromeVoxState.instance.keyboardHandler_;

      // Helper functions. For this test, activate commands by hooking into
      // the BackgroundKeyboardHandler. This is necessary because
      // ForcedActionPath intercepts key sequences before they are routed to
      // CommandHandler.
      const getRangeStartNode = () => ChromeVoxRange.current.start.node;

      const simulateKeyPress = (keyCode, opt_modifiers) => {
        const keyEvent = TestUtils.createMockKeyEvent(keyCode, opt_modifiers);
        keyboardHandler.onKeyDown(keyEvent);
        keyboardHandler.onKeyUp(keyEvent);
      };

      let firstLessonNode;
      await mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(doCmd('nextObject'))
          .expectSpeech('Quick orientation')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Quick Orientation Tutorial, [0-9]+ Lessons/)
          .call(doCmd('nextObject'))
          .expectSpeech('Welcome to ChromeVox!')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech(/Welcome to the ChromeVox tutorial./)
          .call(async () => {
            assertEquals(0, await this.getTutorialActiveLessonIndex());
            firstLessonNode = getRangeStartNode();
          })
          .call(
              simulateKeyPress.bind(this, KeyCode.RIGHT, {searchKeyHeld: true}))
          .call(async () => {
            assertEquals(firstLessonNode, getRangeStartNode());
            assertEquals(0, await this.getTutorialActiveLessonIndex());
          })
          .call(
              simulateKeyPress.bind(this, KeyCode.LEFT, {searchKeyHeld: true}))
          .call(async () => {
            assertEquals(firstLessonNode, getRangeStartNode());
            assertEquals(0, await this.getTutorialActiveLessonIndex());
          })
          // Pressing space, which is the desired key sequence, should move us
          // to the next lesson.
          .call(simulateKeyPress.bind(this, KeyCode.SPACE, {}))
          .expectSpeech('Essential Keys: Control')
          .expectSpeech(/Let's start with a few keys you'll use regularly./)
          .call(async () => {
            assertEquals(1, await this.getTutorialActiveLessonIndex());
            assertNotEquals(firstLessonNode, getRangeStartNode());
          })
          // Pressing control, which is the desired key sequence, should move
          // us to the next lesson.
          .call(simulateKeyPress.bind(this, KeyCode.CONTROL, {}))
          .expectSpeech('Essential Keys: Shift')
          .call(
              async () =>
                  assertEquals(2, await this.getTutorialActiveLessonIndex()));
      await mockFeedback.replay();
    });

// Tests that tutorial nudges are restarted whenever the current range changes.
AX_TEST_F('ChromeVoxTutorialTest', 'RestartNudges', async function() {
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  // Swap in below function to track when nudges get restarted.
  const reset = () => this.restartTutorialNudges();

  let nudgesHaveRestarted = reset();
  CommandHandlerInterface.instance.onCommand('nextObject');
  await nudgesHaveRestarted;

  // Show a lesson.
  await this.setTutorialCurriculum('essential_keys');
  await this.showTutorialLesson(0);
  nudgesHaveRestarted = reset();
  CommandHandlerInterface.instance.onCommand('nextObject');
  await nudgesHaveRestarted;

  nudgesHaveRestarted = reset();
  CommandHandlerInterface.instance.onCommand('nextObject');
  await nudgesHaveRestarted;
});

// Tests that the tutorial closes and ChromeVox navigates to a resource link.
AX_TEST_F('ChromeVoxTutorialTest', 'ResourcesTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(async () => {
        await this.setTutorialCurriculum('resources');
        await this.showTutorialLesson(0);
      })
      .expectSpeech('Learn More')
      .call(doCmd('nextObject'))
      .expectSpeech(/Congratulations/)
      .call(doCmd('nextObject'))
      .expectSpeech('ChromeVox Command Reference', 'Link')
      .call(doCmd('forceClickOnCurrentItem'))
      // Expect the support page to be pulled up; it is read differently
      // depending on if this browsertest's browser has network access.
      .expectSpeech(/(support.google.com)|(Chromebook Help)/);
  await mockFeedback.replay();
});

// Tests that choosing a curriculum with only 1 lesson automatically opens the
// lesson.
AX_TEST_F('ChromeVoxTutorialTest', 'OnlyLessonTest', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('nextObject'))
      .expectSpeech('Essential keys')
      .call(doCmd('nextObject'))
      .expectSpeech('Navigation')
      .call(doCmd('nextObject'))
      .expectSpeech('Command references')
      .call(doCmd('nextObject'))
      .expectSpeech('Sounds and settings')
      .call(doCmd('nextObject'))
      .expectSpeech('Resources')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech('Learn More', 'Heading 1')
      .expectSpeech(
          'Press Search + Right Arrow, or Search + Left Arrow to' +
          ' navigate this lesson')
      // The 'All lessons' button should be hidden since this is the only
      // lesson for the curriculum.
      .call(doCmd('nextButton'))
      .expectSpeech('Main menu')
      .call(doCmd('nextButton'))
      .expectSpeech('Exit tutorial');
  await mockFeedback.replay();
});

// Tests that interactive mode and ForcedActionPath are properly set when
// showing different screens in the tutorial.
AX_TEST_F(
    'ChromeVoxTutorialTest', 'StartStopInteractiveMode', async function() {
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();

      // Swap in functions below so we can track the number of times
      // ForcedActionPath is created and destroyed.
      await PanelBridge.swapForcedActionPathMethodsForTesting();

      // A helper to make assertions on four variables of interest.
      const makeAssertions = async expectedVars => {
        const createdCount =
            await PanelBridge.getForcedActionPathCreatedCountForTest();
        assertEquals(expectedVars.createdCount, createdCount);
        const destroyedCount =
            await PanelBridge.getForcedActionPathDestroyedCountForTest();
        assertEquals(expectedVars.destroyedCount, destroyedCount);
        const interactiveMode = await this.getTutorialInteractiveMode();
        assertEquals(expectedVars.interactiveMode, interactiveMode);
        // Note: Interactive mode and ForcedActionPath should always be in
        // sync in the context of the tutorial.
        const isForcedActionPathActive =
            await PanelBridge.getIsForcedActionPathActiveForTest();
        assertEquals(expectedVars.interactiveMode, isForcedActionPathActive);
      };

      await makeAssertions(
          {createdCount: 0, destroyedCount: 0, interactiveMode: false});
      // Show the first lesson of the quick orientation, which is interactive.
      await this.setTutorialCurriculum('quick_orientation');
      await this.showTutorialLesson(0);
      await makeAssertions(
          {createdCount: 1, destroyedCount: 0, interactiveMode: true});

      // Move to the next lesson in the quick orientation. This lesson is also
      // interactive, so ForcedActionPath should be destroyed and re-created.
      await this.showTutorialNextLesson();
      await makeAssertions(
          {createdCount: 2, destroyedCount: 1, interactiveMode: true});

      // Leave the quick orientation by navigating to the lesson menu. This
      // should stop interactive mode and destroy ForcedActionPath.
      await this.showTutorialLessonMenu();
      await makeAssertions(
          {createdCount: 2, destroyedCount: 2, interactiveMode: false});
    });

// Tests that gestures can be used in the tutorial to navigate.
// TODO(crbug.com/1332510): Failing on ChromeOS.
AX_TEST_F('ChromeVoxTutorialTest', 'DISABLED_Gestures', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  const tutorial = this.getTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doGesture(Gesture.SWIPE_RIGHT1))
      .expectSpeech('Quick orientation', 'Link')
      .call(doGesture(Gesture.SWIPE_RIGHT1))
      .expectSpeech('Essential keys', 'Link')
      .call(doGesture(Gesture.SWIPE_LEFT1))
      .expectSpeech('Quick orientation', 'Link')
      .call(doGesture(Gesture.SWIPE_LEFT2))
      .expectSpeech('Some web content');
  await mockFeedback.replay();
});

// Tests that touch orientation loads properly. Tests string content, but does
// not test interactivity of lessons.
// TODO(crbug.com/1193799): fix ax node errors causing console spew and
// breaking tests
AX_TEST_F(
    'ChromeVoxTutorialTest', 'DISABLED_TouchOrientation', async function() {
      const mockFeedback = this.createMockFeedback();
      const root = await this.runWithLoadedTree(this.simpleDoc);
      await this.launchAndWaitForTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(async () => {
            await this.setTutorialCurriculum('touch_orientation');
            await this.setTutorialMedium('touch');
            await this.showTutorialLesson(0);
            await this.assertActiveLessonIndex(0);
            await this.assertActiveScreen('lesson');
          })
          .expectSpeech('ChromeVox touch tutorial')
          .expectSpeech(/Welcome to the ChromeVox tutorial/)
          .call(doGesture(Gesture.CLICK))
          .expectSpeech('Activate an item')
          .expectSpeech(/To continue, double-tap now/)
          .call(doGesture(Gesture.CLICK))
          .expectSpeech('Move to the next or previous item')
          .call(() => this.showTutorialLesson(6))
          .expectSpeech('Move to the next or previous section')
          .expectSpeech(/swipe from left to right with four fingers/)
          .call(doGesture(Gesture.SWIPE_RIGHT4))
          .expectSpeech(/swiping with four fingers from right to left/)
          .call(doGesture(Gesture.SWIPE_LEFT4))
          .expectSpeech('Touch tutorial complete');
      await mockFeedback.replay();
    });

AX_TEST_F('ChromeVoxTutorialTest', 'GeneralTouchNudges', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  this.disableTutorialRestartNudges();
  const giveNudge = () => this.giveTutorialNudge();
  mockFeedback.expectSpeech('ChromeVox tutorial');
  mockFeedback.call(async () => {
    await this.setTutorialMedium('touch');
    await this.initializeTutorialNudges('general');
  });
  for (let i = 0; i < 3; ++i) {
    mockFeedback.call(giveNudge).expectSpeech(
        'ChromeVox tutorial', 'Heading 1');
  }
  mockFeedback.call(giveNudge)
      .expectSpeech('Hint: Swipe left or right with one finger to navigate.')
      .call(giveNudge)
      .expectSpeech(
          'Hint: Double-tap with one finger to activate the current item.')
      .call(giveNudge)
      .expectSpeech(
          'Hint: Swipe from right to left with two fingers if you would ' +
          'like to exit this tutorial.');
  await mockFeedback.replay();
});