summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/presentation-api/controlling-ua/startNewPresentation_success-manual.https.html
blob: c9378c0e68006abe8fd877f8b5ec9b163da4f8e3 (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
<!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_equals(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>