Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / test / test_window_define_nonconfigurable.html
blob2bca58542d4dfe7270b7aa179ac5ca54368e25ba
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=1107443
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 1107443</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script type="application/javascript">
13 var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
15 /**
16 * Test for Bug 1107443, modified when it was backed out in bug 1329323.
17 * This is now testing the _current_ behavior, not the desired one; expect
18 * failures in this test and needing to update it when bug 1329324 is
19 * fixed.
21 var retval = Object.defineProperty(window, "nosuchprop",
22 { value: 5, configurable: false });
23 if (AppConstants.RELEASE_OR_BETA) {
24 todo_is(retval, null,
25 "Should return null when 'failing' to define non-configurable property via Object.defineProperty.")
26 } else {
27 is(retval, null,
28 "Should return null when 'failing' to define non-configurable property via Object.defineProperty.")
30 var desc = Object.getOwnPropertyDescriptor(window, "nosuchprop");
31 is(typeof(desc), "object", "Should have a property 'nosuchprop' now");
32 if (AppConstants.RELEASE_OR_BETA) {
33 todo_is(desc.configurable, true,
34 "Property 'nosuchprop' should be configurable");
35 } else {
36 is(desc.configurable, true,
37 "Property 'nosuchprop' should be configurable");
39 is(desc.writable, false, "Property 'nosuchprop' should be readonly");
40 is(desc.value, 5, "Property 'nosuchprop' should have the right value");
42 retval = Object.defineProperties(window, {
43 "firstProp": { value: 1 },
44 "secondProp": { value: 2, configurable: false },
45 "thirdProp": { value: 3 },
46 });
47 if (AppConstants.RELEASE_OR_BETA) {
48 todo_is(retval, null,
49 "Should return null when 'failing' to define non-configurable property via Object.defineProperties.")
50 } else {
51 is(retval, null,
52 "Should return null when 'failing' to define non-configurable property via Object.defineProperties.")
54 // The properties should all be defined.
55 for (var [prop, val] of [["firstProp", 1], ["secondProp", 2], ["thirdProp", 3]]) {
56 desc = Object.getOwnPropertyDescriptor(window, prop);
57 is(typeof(desc), "object", `Should have a property '${prop}' now`);
58 if (AppConstants.RELEASE_OR_BETA) {
59 todo_is(desc.configurable, true,
60 `Property '${prop}' should be configurable`);
61 } else {
62 is(desc.configurable, true,
63 `Property '${prop}' should be configurable`);
65 is(desc.writable, false, `Property '${prop}' should be readonly`);
66 is(desc.value, val, `Property '${prop}' should have the right value`);
69 retval = Object.defineProperty(window, "nosuchprop2", { value: 6 });
70 is(retval, window,
71 "Should return object when succesfully defining 'nosuchprop2'");
72 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop2");
73 is(typeof(desc), "object", "Should have a property 'nosuchprop2' now");
74 if (AppConstants.RELEASE_OR_BETA) {
75 todo_is(desc.configurable, true,
76 "Property 'nosuchprop2' should be configurable");
77 } else {
78 is(desc.configurable, true,
79 "Property 'nosuchprop2' should be configurable");
81 is(desc.writable, false, "Property 'nosuchprop2' should be readonly");
82 is(desc.value, 6, "Property 'nosuchprop2' should have the right value");
84 retval = Object.defineProperty(window, "nosuchprop3",
85 { value: 7, configurable: true });
86 is(retval, window,
87 "Should return object when succesfully defining 'nosuchprop3'");
88 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop3");
89 is(typeof(desc), "object", "Should have a property 'nosuchprop3' now");
90 is(desc.configurable, true,
91 "Property 'nosuchprop3' should be configurable");
92 is(desc.writable, false, "Property 'nosuchprop3' should be readonly");
93 is(desc.value, 7, "Property 'nosuchprop3' should have the right value");
95 retval = Reflect.defineProperty(window, "nosuchprop4",
96 { value: 8, configurable: false });
97 if (AppConstants.RELEASE_OR_BETA) {
98 todo_is(retval, false,
99 "Should not be able to Reflect.defineProperty if non-configurable");
100 } else {
101 is(retval, false,
102 "Should not be able to Reflect.defineProperty if non-configurable");
104 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop4");
105 is(typeof(desc), "object", "Should have a property 'nosuchprop4' now");
106 if (AppConstants.RELEASE_OR_BETA) {
107 todo_is(desc.configurable, true,
108 "Property 'nosuchprop4' should be configurable");
109 } else {
110 is(desc.configurable, true,
111 "Property 'nosuchprop4' should be configurable");
113 is(desc.writable, false, "Property 'nosuchprop4' should be readonly");
114 is(desc.value, 8, "Property 'nosuchprop4' should have the right value");
116 retval = Reflect.defineProperty(window, "nosuchprop5",
117 { value: 9 });
118 is(retval, true,
119 "Should be able to Reflect.defineProperty with default configurability");
120 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop5");
121 is(typeof(desc), "object", "Should have a property 'nosuchprop5' now");
122 if (AppConstants.RELEASE_OR_BETA) {
123 todo_is(desc.configurable, true,
124 "Property 'nosuchprop5' should be configurable");
125 } else {
126 is(desc.configurable, true,
127 "Property 'nosuchprop5' should be configurable");
129 is(desc.writable, false, "Property 'nosuchprop5' should be readonly");
130 is(desc.value, 9, "Property 'nosuchprop5' should have the right value");
132 retval = Reflect.defineProperty(window, "nosuchprop6",
133 { value: 10, configurable: true });
134 is(retval, true,
135 "Should be able to Reflect.defineProperty if configurable");
136 desc = Object.getOwnPropertyDescriptor(window, "nosuchprop6");
137 is(typeof(desc), "object", "Should have a property 'nosuchprop6' now");
138 is(desc.configurable, true, "Property 'nosuchprop6' should be configurable");
139 is(desc.writable, false, "Property 'nosuchprop6' should be readonly");
140 is(desc.value, 10, "Property 'nosuchprop6' should have the right value");
141 </script>
142 </head>
143 <body>
144 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107443">Mozilla Bug 1107443</a>
145 <p id="display"></p>
146 <div id="content" style="display: none">
148 </div>
149 <pre id="test">
150 </pre>
151 </body>
152 </html>