File: startNewPresentation_success-manual.https.html

package info (click to toggle)
firefox-esr 78.15.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,301,156 kB
  • sloc: cpp: 5,665,905; javascript: 4,798,386; ansic: 2,878,233; python: 977,004; asm: 270,347; xml: 181,456; java: 111,756; sh: 72,926; makefile: 21,819; perl: 13,380; cs: 4,725; yacc: 4,565; objc: 3,026; pascal: 1,787; lex: 1,720; ada: 1,681; exp: 505; php: 436; lisp: 260; awk: 152; ruby: 103; csh: 80; sed: 53; sql: 45
file content (95 lines) | stat: -rw-r--r-- 4,363 bytes parent folder | download | duplicates (8)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Checking the chain of events when starting a new presentation</title>
<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
<link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>

<p>Click the button below and select the available presentation display, to start the manual test.</p>
<button id="presentBtn">Start Presentation Test</button>


<script>
    // description of event order
    var description = [
        "Phase #1: Promise is resolved",
        "Phase #2: 'connectionavailable' event fired",
        "Phase #3: 'connect' event fired"
    ];
    var step = 0;

    // presentation connection
    var connection;

    // disable the timeout function for the tests
    setup({explicit_timeout: true});

    // ----------
    // DOM Object
    // ----------
    var presentBtn = document.getElementById("presentBtn");

    // ---------------------------------------------
    // Start New Presentation Test (success) - begin
    // ---------------------------------------------
    presentBtn.onclick = function () {
        presentBtn.disabled = true;
        promise_test(function (t) {
            var phase = -1, actual = -1;

            // increment the count in the actual event order
            var count = function(evt) { actual++; return evt; };
            // increment the count in the expected event order and compare it with the actual event order
            var checkPhase = function(evt) { phase++; assert_equals(description[actual], description[phase], 'Event order is incorrect.'); return evt; };

            var request = new PresentationRequest(presentationUrls);
            var eventWatcher = new EventWatcher(t, request, 'connectionavailable');
            var waitConnectionavailable = eventWatcher.wait_for('connectionavailable').then(count).then(function(evt) { connection = connection || evt.connection; return evt; });
            var waitConnect;

            t.add_cleanup(function() {
                if(connection)
                    connection.terminate();
            });

            return request.start().then(count)
                .then(checkPhase).then(function (c) {
                    // Phase #1: Promise is resolved
                    connection = c;

                    // No more user input needed, re-enable timeout
                    t.step_timeout(function() {
                        t.force_timeout();
                        t.done();
                    }, 5000);

                    // Check the initial state of the presentation connection
                    assert_equals(connection.state, 'connecting', 'Check the initial state of the presentation connection.');
                    assert_true(!!connection.id, 'The connection ID is set.');
                    assert_true(typeof connection.id === 'string', 'The connection ID is a string.');
                    assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');

                    var eventWatcher = new EventWatcher(t, connection, 'connect');
                    waitConnect = eventWatcher.wait_for('connect').then(count);

                    return waitConnectionavailable;
                })
                .then(checkPhase).then(function (evt) {
                    // Phase #2: "connectionavailable" event fired
                    assert_equals(connection, evt.connection, 'Both Promise from PresentationRequest() and a "connectionavailable" event handler receive the same presentation connection.');

                    return waitConnect;
                })
                .then(checkPhase).then(function () {
                    // Phase #3: "connect" event fired
                    assert_equals(connection.state, 'connected', 'The state of the presentation connection is "connected" when a "connect" event fires.');
                });
        });
    }
    // -------------------------------------------
    // Start New Presentation Test (success) - end
    // -------------------------------------------
</script>