summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_bug641552.html
blob: ab76c74a3f64625103d426a545dad1ea83d164cc (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=641552
-->
<head>
  <title>Test for Bug 641552</title>
  <script type="application/javascript" src="/MochiKit/packed.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=641552">Mozilla Bug 641552</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 641552 **/

SimpleTest.waitForExplicitFinish();

var contractId = "@mozilla.org/xmlextras/xmlhttprequest;1";
var categoryEntries = [
  {category: "JavaScript-global-property", entry: "randomname", contractId: contractId},
];

function addCategoryEntries(func) {
  for (var categoryEntry of categoryEntries) {
    SpecialPowers.addCategoryEntry(categoryEntry.category, categoryEntry.entry, categoryEntry.contractId,
                                   false, true);
  }
  SimpleTest.executeSoon(func);
}

function removeCategoryEntries(func) {
  for (var categoryEntry of categoryEntries) {
    SpecialPowers.deleteCategoryEntry(categoryEntry.category, categoryEntry.entry, false);
  }
  SimpleTest.executeSoon(func);
}

function checkNamesPresent() {
  ok(window.randomname, "window.randomname should return an object");
}

function checkNamesAbsent() {
  ok(!window.randomname, "window.randomname should return undefined");
}

// Ensure the initial state
checkNamesAbsent();

addCategoryEntries(function test1() {
  ok(window.randomname, "window.randomname should return an object");

  delete window.randomname;

  // The delete opertor should have no effect as long as the category entry is registered.
  checkNamesPresent();

  removeCategoryEntries(test2);
});

function test2() {
  // The object should be cached on the global/navigator object once accessed.
  checkNamesPresent();

  delete window.randomname;

  // Now the delete opertor should have the effect.
  checkNamesAbsent();

  addCategoryEntries(function() {
    removeCategoryEntries(test3);
  });
}

function test3() {
  // The object should not be cached until the first access.
  checkNamesAbsent();

  SimpleTest.finish();
}

</script>
</pre>
</body>
</html>