summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/presentation-api/controlling-ua/getAvailability.html
blob: de6ca2b74fb8aae2fac45b6fd334e24056149809 (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Presentation API - monitor screen availability tests for Controlling User Agent</title>
<link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de">
<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>
    // ---------------------------------
    // Helper Function
    // ---------------------------------
    var createRequestObject = function () {
        var validUnixDate = new Date().getTime() + String(Math.floor(Math.random() * 1e5)),
                presUrl = "../receiving-ua/idlharness.html#__castAppId__=2334D33A/__castClientId__=" + validUnixDate,
                request = new PresentationRequest(presUrl);
        return request;
    }

    // ---------------------------------
    // Screen Availability Tests - begin
    // ---------------------------------

    // Instance of Promise Test
    test(function () {
        var request = createRequestObject();
        assert_true(request.getAvailability() instanceof Promise);
    }, 'The request is an Promise.')

    // Instance of PresentationRequest Test
    test(function () {
        var request = createRequestObject();
        assert_true(request instanceof PresentationRequest);
    }, 'The request is an instance of PresentationRequest.')

    // Instance of PresentationAvailability Test
    promise_test(function () {
        var request = createRequestObject();

        return request.getAvailability()
                .then(function (availability) {
                    assert_true(availability instanceof PresentationAvailability);
                });
    }, "The promise is an instance of PresentationAvailability");

    // Availability.value is set Test
    promise_test(function () {
        var request = createRequestObject();

        return request.getAvailability()
                .then(function (availability) {
                    assert_true(typeof availability.value == 'boolean');
                });
    }, "The availability has an boolean value.");


    // Best Case Scenario Test
    // -----------------------
    promise_test(function () {
        var request = createRequestObject();

        return request.getAvailability()
                .then(function (availability) {
                    assert_true(availability.value);
                });
    }, "There is an availability.");


    // Invalid Presentation URL Test
    promise_test(function () {
        var validUnixDate = new Date().getTime() + String(Math.floor(Math.random() * 1e5)),
                invalidPresUrl = "../receiving-ua/idlharness.html#__castAppId__=3445E44B/__castClientId__=" + validUnixDate,
                request = new PresentationRequest(invalidPresUrl);

        return request.getAvailability()
                .then(function (availability) {
                    assert_false(availability.value);
                });
    }, "There is no availability for an invalid presentation URL.");
    // -------------------------------
    // Screen Availability Tests - end
    // -------------------------------
</script>