File: tutorial_test.js

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (769 lines) | stat: -rw-r--r-- 31,498 bytes parent folder | download | duplicates (6)
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
// 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;
  }

  assertActiveLessonIndex(expectedIndex) {
    assertEquals(expectedIndex, this.getTutorial().activeLessonIndex);
  }

  assertActiveScreen(expectedScreen) {
    assertEquals(expectedScreen, this.getTutorial().activeScreen);
  }

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

  /** Waits for the tutorial to load. */
  async waitForTutorial() {
    return new Promise(resolve => {
      const doc = this.getPanelWindow().document;
      if (doc.getElementById('chromevox-tutorial-container')) {
        resolve();
      } else {
        /**
         * @param {Array<MutationRecord>} mutationsList
         * @param {MutationObserver} observer
         */
        const onMutation = (mutationsList, observer) => {
          for (const mutation of mutationsList) {
            if (mutation.type === 'childList') {
              for (const node of mutation.addedNodes) {
                if (node.id === 'chromevox-tutorial-container') {
                  // Once the tutorial has been added to the document, we need
                  // to wait for the lesson templates to load.
                  const panel = this.getPanel();
                  if (panel.instance.tutorialReadyForTesting_) {
                    resolve();
                  } else {
                    panel.instance.tutorial_.addEventListener(
                        'readyfortesting', () => resolve());
                  }
                  observer.disconnect();
                }
              }
            }
          }
        };

        const observer = new MutationObserver(onMutation);
        observer.observe(
            doc.body /* target */, {childList: true} /* options */);
      }
    });
  }

  getTutorial() {
    return this.getPanel().instance.tutorial_;
  }

  disableRestartNudges() {
    this.getPanel().instance.tutorial_.restartNudges = null;
  }

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

// 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();
  const tutorial = this.getTutorial();
  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(() => {
        // Call from the tutorial directly, instead of navigating to and
        // clicking on the main menu button.
        tutorial.showMainMenu_();
      })
      .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();
      const tutorial = this.getTutorial();
      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(() => {
            tutorial.showLesson_(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();
      const tutorial = this.getTutorial();
      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(() => {
            tutorial.showLesson_(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.disableRestartNudges();
  const tutorial = this.getTutorial();
  const giveNudge = () => {
    tutorial.giveNudge();
  };
  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 tutorial = this.getTutorial();
      const giveNudge = () => {
        tutorial.giveNudge();
      };
      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(() => {
            tutorial.showLesson_(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();
  const tutorial = this.getTutorial();
  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();
  const tutorial = this.getTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(() => {
        // Press Escape.
        tutorial.onKeyDown({
          key: 'Escape',
          preventDefault: () => {},
          stopPropagation: () => {},
        });
      })
      .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();
  const tutorial = this.getTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(this.assertActiveScreen.bind(this, '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.bind(this, 'lesson_menu'))
      .call(doCmd('previousButton'))
      .expectSpeech('Exit tutorial')
      .call(doCmd('previousButton'))
      .expectSpeech('Main menu')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech('ChromeVox tutorial')
      .call(this.assertActiveScreen.bind(this, '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();
      const tutorial = this.getTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(this.assertActiveScreen.bind(this, '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.bind(this, 'lesson_menu'))
          .call(doCmd('nextObject'))
          .expectSpeech('On, Off, and Stop')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech('On, Off, and Stop', 'Heading 1')
          .call(this.assertActiveScreen.bind(this, '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.bind(this, '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();
      const tutorial = this.getTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(() => {
            tutorial.curriculum = 'essential_keys';
            tutorial.showLesson_(0);
            this.assertActiveLessonIndex(0);
            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.bind(this, 1))
          .call(doCmd('nextButton'))
          .expectSpeech('Previous lesson')
          .call(doCmd('forceClickOnCurrentItem'))
          .expectSpeech('On, Off, and Stop', 'Heading 1')
          .call(this.assertActiveLessonIndex.bind(this, 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();
  const tutorial = this.getTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(doCmd('nextObject'))
      .expectSpeech('Quick orientation')
      .call(doCmd('forceClickOnCurrentItem'))
      .expectSpeech(/Quick Orientation Tutorial, [0-9]+ Lessons/)
      .call(() => {
        tutorial.showFirstLesson_();
      })
      .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();
  const tutorial = this.getTutorial();
  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(() => {
        tutorial.showLesson_(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.
AX_TEST_F('ChromeVoxTutorialTest', 'EarconLesson', async function() {
  const mockFeedback = this.createMockFeedback();
  const root = await this.runWithLoadedTree(this.simpleDoc);
  await this.launchAndWaitForTutorial();
  const tutorial = this.getTutorial();
  const nextObjectAndExpectSpeechAndEarcon = (speech, earcon) => {
    mockFeedback.call(doCmd('nextObject'))
        .expectSpeech(speech)
        .expectEarcon(earcon);
  };
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(() => {
        // Show the lesson.
        tutorial.curriculum = 'sounds_and_settings';
        tutorial.showLesson_(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 tutorial = this.getTutorial();
      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(() => {
            assertEquals(0, tutorial.activeLessonId);
            firstLessonNode = getRangeStartNode();
          })
          .call(
              simulateKeyPress.bind(this, KeyCode.RIGHT, {searchKeyHeld: true}))
          .call(() => {
            assertEquals(firstLessonNode, getRangeStartNode());
            assertEquals(0, tutorial.activeLessonId);
          })
          .call(
              simulateKeyPress.bind(this, KeyCode.LEFT, {searchKeyHeld: true}))
          .call(() => {
            assertEquals(firstLessonNode, getRangeStartNode());
            assertEquals(0, tutorial.activeLessonId);
          })
          // 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(() => {
            assertEquals(1, tutorial.activeLessonId);
            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(() => {
            assertEquals(2, tutorial.activeLessonId);
          });
      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();
  const tutorial = this.getTutorial();
  // Swap in below function to track when nudges get restarted.
  const reset = () => new Promise(resolve => tutorial.restartNudges = resolve);

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

  // Show a lesson.
  tutorial.curriculum = 'essential_keys';
  tutorial.showLesson_(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();
  const tutorial = this.getTutorial();
  mockFeedback.expectSpeech('ChromeVox tutorial')
      .call(() => {
        tutorial.curriculum = 'resources';
        tutorial.showLesson_(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();
  const tutorial = this.getTutorial();
  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();
      const tutorial = this.getTutorial();
      let userActionMonitorCreatedCount = 0;
      let userActionMonitorDestroyedCount = 0;
      let isForcedActionPathActive = false;
      // Expose the correct BackgroundBridge so we can override the functions
      this.getPanel().exportBackgroundBridgeForTesting();
      // Swap in functions below so we can track the number of times
      // ForcedActionPath is created and destroyed.
      this.getPanelWindow().BackgroundBridge.ForcedActionPath.listenFor =
          () => {
            userActionMonitorCreatedCount += 1;
            isForcedActionPathActive = true;
          };
      this.getPanelWindow().BackgroundBridge.ForcedActionPath.stopListening =
          () => {
            userActionMonitorDestroyedCount += 1;
            isForcedActionPathActive = false;
          };

      // A helper to make assertions on four variables of interest.
      const makeAssertions = expectedVars => {
        assertEquals(expectedVars.createdCount, userActionMonitorCreatedCount);
        assertEquals(
            expectedVars.destroyedCount, userActionMonitorDestroyedCount);
        assertEquals(expectedVars.interactiveMode, tutorial.interactiveMode_);
        // Note: Interactive mode and ForcedActionPath should always be in
        // sync in the context of the tutorial.
        assertEquals(expectedVars.interactiveMode, isForcedActionPathActive);
      };

      makeAssertions(
          {createdCount: 0, destroyedCount: 0, interactiveMode: false});
      // Show the first lesson of the quick orientation, which is interactive.
      tutorial.curriculum = 'quick_orientation';
      tutorial.showLesson_(0);
      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.
      tutorial.showNextLesson();
      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.
      tutorial.showLessonMenu_();
      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();
      const tutorial = this.getTutorial();
      mockFeedback.expectSpeech('ChromeVox tutorial')
          .call(() => {
            tutorial.curriculum = 'touch_orientation';
            tutorial.medium = 'touch';
            tutorial.showLesson_(0);
            this.assertActiveLessonIndex(0);
            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(() => {
            // Jump to the penultimate lesson.
            tutorial.showLesson_(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.disableRestartNudges();
  const tutorial = this.getTutorial();
  const giveNudge = () => {
    tutorial.giveNudge();
  };
  mockFeedback.expectSpeech('ChromeVox tutorial');
  mockFeedback.call(() => {
    tutorial.medium = 'touch';
    tutorial.initializeNudges('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();
});