File: events_input_sources_change.https.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (125 lines) | stat: -rw-r--r-- 4,326 bytes parent folder | download | duplicates (10)
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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.js"></script>

<script>
"use strict"
let testName = "Transient input sources fire events in the right order";

let watcherDone = new Event("watcherdone");

let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;

let testFunction = function(session, fakeDeviceController, t) {
  let eventWatcher = new EventWatcher(
    t, session, ["inputsourceschange", "selectstart", "select", "selectend", "watcherdone"]);
  let eventPromise = eventWatcher.wait_for(
    ["inputsourceschange", "selectstart", "select", "selectend", "inputsourceschange", "watcherdone"]);

  let inputChangeEvents = 0;
  let cached_input_source = null;
  function onInputSourcesChange(event) {
    t.step(() => {
      inputChangeEvents++;
      assert_equals(event.session, session);
      validateSameObject(event);

      assert_throws_js(
          TypeError,
          () => { event.added[0] = "test"; },
          "added array must be frozen"
      );
      assert_throws_js(
          TypeError,
          () => { event.removed[0] = "test"; },
          "removed array must be frozen"
      );

      // The first change event should be adding our controller.
      if (inputChangeEvents === 1) {
        validateAdded(event.added, 1);
        validateRemoved(event.removed, 0);
        cached_input_source = session.inputSources[0];
        assert_not_equals(cached_input_source, null);
      } else if (inputChangeEvents === 2) {
        // The second event should be removing our controller.
        validateAdded(event.added, 0);
        validateRemoved(event.removed, 1);
        assert_true(event.removed.includes(cached_input_source));
        session.dispatchEvent(watcherDone);
      }
    });
  }

  function validateAdded(added, length) {
    t.step(() => {
      assert_not_equals(added, null);
      assert_equals(added.length, length,
          "Added length matches expectations");

      let currentSources = Array.from(session.inputSources.values());
      added.forEach((source) => {
        assert_true(currentSources.includes(source),
          "Every element in added should be in the input source list");
      });
    });
  }

  function validateRemoved(removed, length) {
    t.step(() => {
      assert_not_equals(removed, null);
        assert_equals(removed.length, length,
            "Removed length matches expectations");

      let currentSources = Array.from(session.inputSources.values());
      removed.forEach((source) => {
        assert_false(currentSources.includes(source),
          "No element in removed should be in the input source list");
      });
    });
  }

  // Verifies that the same object is returned each time attributes are accessed
  // on an XRInputSourcesChangeEvent, as required by the spec.
  function validateSameObject(event) {
    let eventSession = event.session;
    let added = event.added;
    let removed = event.removed;

    t.step(() => {
      assert_equals(eventSession, event.session,
        "XRInputSourcesChangeEvent.session returns the same object.");
      assert_equals(added, event.added,
        "XRInputSourcesChangeEvent.added returns the same object.");
      assert_equals(removed, event.removed,
        "XRInputSourcesChangeEvent.removed returns the same object.");
    });
  }

  session.addEventListener('inputsourceschange', onInputSourcesChange, false);

  // Create our input source and immediately toggle the primary input so that
  // it appears as already needing to send a click event when it appears.
  let input_source = fakeDeviceController.simulateInputSourceConnection({
    handedness: "right",
    targetRayMode: "tracked-pointer",
    pointerOrigin: VALID_POINTER_TRANSFORM,
    profiles: [],
    selectionClicked: true
  });

  // Make our input source disappear after one frame, and wait an additional
  // frame for that disappearance to propogate.
  requestSkipAnimationFrame(session, (time, xrFrame) => {
    input_source.disconnect();
    session.requestAnimationFrame((time, xrFrame) => {});
  });

  return eventPromise;
};

xr_session_promise_test(
  testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
</script>