summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/geolocation-API/non-secure-contexts.http.html
blob: d491086cf8aeb601f406f802bec30e2fbc5880eb (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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Geolocation Test: non-secure contexts</title>
<link rel="help" href="https://github.com/w3c/geolocation-api/pull/34" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
  promise_test(() => {
    return new Promise(resolve => {
      let isAsync = true;
      const successCallback = () => {
        assert_unreached(
          "successCallback must never be invoked in non-secure contexts."
        );
      };
      const errorCallBack = () => {
        isAsync = false;
        resolve();
      };
      navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);
      assert_true(
        isAsync,
        "Expected the errorCallback to be called asynchronously."
      );
    });
  }, "When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called.");

  promise_test(async () => {
    return new Promise(resolve => {
      let isAsync = true;
      const successCallback = () => {
        assert_unreached(
          "successCallback must never be invoked in non-secure contexts."
        );
      };
      const errorCallBack = () => {
        isAsync = false;
        resolve();
      };
      navigator.geolocation.watchPosition(successCallback, errorCallBack);
      assert_true(isAsync, "errorCallback must be called asynchronously.");
    });
  }, "When in a non-secure context, watchPosition()'s errorCallback is asynchronously called.");

  promise_test(async () => {
    const positionErrorPromise = new Promise(errorCallBack => {
      const successCallback = () => {
        assert_unreached(
          "successCallback must never be invoked in non-secure contexts."
        );
      };
      navigator.geolocation.getCurrentPosition(successCallback, errorCallBack);
    });
    const positionError = await positionErrorPromise;
    assert_equals(
      positionError.code,
      1,
      "Expected the value for PERMISSION_DENIED, which is 1."
    );
  }, "When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");

  promise_test(async () => {
    const positionErrorPromise = new Promise(errorCallBack => {
      const successCallback = () => {
        assert_unreached(
          "successCallback must never be invoked in non-secure contexts."
        );
      };
      const id = navigator.geolocation.watchPosition(
        successCallback,
        errorCallBack
      );
      assert_true(Number.isInteger(id), "Must return an identifier.");
    });
    const positionError = await positionErrorPromise;
    assert_equals(
      positionError.code,
      1,
      "Expected the value for PERMISSION_DENIED, which is 1."
    );
  }, "When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code.");
</script>