summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/parakeet/createAdRequest.tentative.https.sub.window.js
blob: 1cb3b7d9af765727cce09e93de3c5c0047cce620 (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
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
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
'use strict';

const okayAdRequest = {
  adRequestUrl: "https://{{host}}:{{ports[https][0]}}",
  adProperties: [
    { width: "42", height: "32", slot: "first", lang: "en-ca", adType: "test-ad1", bidFloor: 42.0 },
    { width: "24", height: "48", slot: "first", lang: "en-us", adType: "test-ad2", bidFloor: 42.0 }],
  publisherCode: "pubCode123",
  targeting: { interests: ["interest1", "interest2"] },
  anonymizedProxiedSignals: [],
  fallbackSource: "https://{{domains[www2]}}:{{ports[https][0]}}"
};

test(() => {
  assert_not_equals(navigator.createAdRequest, undefined);
}, "createAdRequest() should be supported on the navigator interface.");

promise_test(async t => {
  const createPromise = navigator.createAdRequest(okayAdRequest);

  await promise_rejects_dom(t, "NotSupportedError", createPromise);
}, "createAdRequest() should reject with NotSupported initially.");

promise_test(async t => {
  const createPromise = navigator.createAdRequest();

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject missing parameters.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  delete adRequest.adRequestUrl;

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject a missing adRequestUrl.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  adRequest.adRequestUrl = "http://{{host}}:{{ports[https][0]}}";

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject a HTTP adRequestUrl.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  delete adRequest.adProperties;

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject missing adProperties.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  adRequest.adProperties = [];

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject empty adProperties.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  adRequest.fallbackSource = "http://{{host}}:{{ports[https][0]}}";

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject a HTTP fallbackSource.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);

  // delete all optional params and the request should still be okay.
  delete adRequest.anonymizedProxiedSignals;
  delete adRequest.fallbackSource;
  delete adRequest.publisherCode;
  delete adRequest.targeting;

  const createPromise = navigator.createAdRequest(adRequest);

  // Until fully implemented we expect a NotSupportedError instead of success.
  await promise_rejects_dom(t, "NotSupportedError", createPromise);
}, "createAdRequest() should have optional params.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  // A single adProperties object should be accepted as well as a sequence.
  adRequest.adProperties = { width: "24", height: "48", slot: "first", lang: "en-us", adType: "test-ad2", bidFloor: 42.0 };

  const createPromise = navigator.createAdRequest(adRequest);

  // Until fully implemented we expect a NotSupportedError instead of success.
  await promise_rejects_dom(t, "NotSupportedError", createPromise);
}, "createAdRequest() should accept a single adProperties.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  adRequest.anonymizedProxiedSignals = ["coarse-geolocation", "coarse-ua", "targeting", "user-ad-interests"];

  const createPromise = navigator.createAdRequest(adRequest);

  // Until fully implemented we expect a NotSupportedError instead of success.
  await promise_rejects_dom(t, "NotSupportedError", createPromise);
}, "createAdRequest() should accept valid anonymizedProxiedSignals.");

promise_test(async t => {
  const adRequest = Object.assign({}, okayAdRequest);
  adRequest.anonymizedProxiedSignals = ["coarse-geolocation", "unknown-type"];

  const createPromise = navigator.createAdRequest(adRequest);

  await promise_rejects_js(t, TypeError, createPromise);
}, "createAdRequest() should reject unknown anonymizedPRoxiedSignals.");