summaryrefslogtreecommitdiffstats
path: root/toolkit/components/narrate/test/browser_voiceselect.js
blob: 0de6528dd4571bde0c914d7e1ed61353d1db3982 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* globals registerCleanupFunction, add_task, is, isnot */

"use strict";

registerCleanupFunction(teardown);

add_task(function* testVoiceselectDropdownAutoclose() {
  setup();

  yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
    let $ = content.document.querySelector.bind(content.document);

    yield NarrateTestUtils.waitForNarrateToggle(content);

    $(NarrateTestUtils.TOGGLE).click();
    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
      "popup is toggled");

    ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options are initially hidden");

    $(NarrateTestUtils.VOICE_SELECT).click();
    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options are toggled");

    $(NarrateTestUtils.TOGGLE).click();
    // A focus will follow a real click.
    $(NarrateTestUtils.TOGGLE).focus();
    ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
      "narrate popup is dismissed");

    $(NarrateTestUtils.TOGGLE).click();
    // A focus will follow a real click.
    $(NarrateTestUtils.TOGGLE).focus();
    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
      "narrate popup is showing again");
    ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options are hidden after popup comes back");
  });
});

add_task(function* testVoiceselectLabelChange() {
  setup();

  yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
    let $ = content.document.querySelector.bind(content.document);

    yield NarrateTestUtils.waitForNarrateToggle(content);

    $(NarrateTestUtils.TOGGLE).click();
    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
      "popup is toggled");

    ok(NarrateTestUtils.selectVoice(content, "urn:moz-tts:fake-direct:lenny"),
      "voice selected");

    let selectedOption = $(NarrateTestUtils.VOICE_SELECTED);
    let selectLabel = $(NarrateTestUtils.VOICE_SELECT_LABEL);

    is(selectedOption.textContent, selectLabel.textContent,
      "new label matches selected voice");
  });
});

add_task(function* testVoiceselectKeyboard() {
  setup();

  yield spawnInNewReaderTab(TEST_ARTICLE, function* () {
    let $ = content.document.querySelector.bind(content.document);

    yield NarrateTestUtils.waitForNarrateToggle(content);

    $(NarrateTestUtils.TOGGLE).click();
    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.POPUP)),
      "popup is toggled");

    let eventUtils = NarrateTestUtils.getEventUtils(content);

    let firstValue = $(NarrateTestUtils.VOICE_SELECTED).dataset.value;

    ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options initially are hidden");

    $(NarrateTestUtils.VOICE_SELECT).focus();

    eventUtils.sendKey("DOWN", content);

    yield ContentTaskUtils.waitForCondition(
      () => $(NarrateTestUtils.VOICE_SELECTED).dataset.value != firstValue,
      "value changed after pressing DOWN key");

    eventUtils.sendKey("RETURN", content);

    ok(NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options showing after pressing RETURN");

    eventUtils.sendKey("UP", content);

    eventUtils.sendKey("RETURN", content);

    ok(!NarrateTestUtils.isVisible($(NarrateTestUtils.VOICE_OPTIONS)),
      "voice options hidden after pressing RETURN");

    yield ContentTaskUtils.waitForCondition(
      () => $(NarrateTestUtils.VOICE_SELECTED).dataset.value == firstValue,
      "value changed back to original after pressing RETURN");
  });
});