summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_document.watch.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/html/test/test_document.watch.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/html/test/test_document.watch.html')
-rw-r--r--dom/html/test/test_document.watch.html129
1 files changed, 129 insertions, 0 deletions
diff --git a/dom/html/test/test_document.watch.html b/dom/html/test/test_document.watch.html
new file mode 100644
index 000000000..54509823b
--- /dev/null
+++ b/dom/html/test/test_document.watch.html
@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=903332
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 903332</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+
+ /** Test for Bug 903332 **/
+
+ var watch1Called;
+ function watch1(prop, oldValue, newValue)
+ {
+ is(watch1Called, false, "watch1Called not reset properly?");
+ watch1Called = true;
+
+ is(prop, "cookie", "wrong property name passed to watch1");
+ return newValue;
+ }
+
+ var watch2Called;
+ function watch2(prop, oldValue, newValue)
+ {
+ is(watch2Called, false, "watch2Called not reset properly?");
+ watch2Called = true;
+
+ is(prop, "cookie", "wrong property name passed to watch2");
+ return newValue;
+ }
+
+ // Just in case subsequent tests depend on a particular value...
+ var originalValue = document.cookie;
+ ok(true, "originalValue: " + originalValue);
+
+ var originalPrefix = originalValue.length > 0 ? originalValue + "; " : "";
+
+ try
+ {
+ // trial set (no watch) to verify things work
+ document.cookie = "first=set";
+ is(document.cookie, originalPrefix + "first=set",
+ "first value correct");
+
+ // add a watch
+ document.watch("cookie", watch1);
+
+ // set, check for watch invoked
+ watch1Called = false;
+ document.cookie = "second=set";
+ is(watch1Called, true, "watch1 function should be called");
+ is(document.cookie, originalPrefix + "first=set; second=set",
+ "second value correct");
+
+ // and a second time, just in case
+ watch1Called = false;
+ document.cookie = "third=set";
+ is(watch1Called, true, "watch1 function should be called");
+ is(document.cookie, originalPrefix + "first=set; second=set; third=set",
+ "third value correct");
+
+ // overwrite the current watch with a new one
+ document.watch("cookie", watch2);
+
+ // set, check for watch invoked
+ watch1Called = false;
+ watch2Called = false;
+ document.cookie = "fourth=set";
+ is(watch1Called, false, "watch1 invoked erroneously");
+ is(watch2Called, true, "watch2 function should be called");
+ is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set",
+ "fourth value correct");
+
+ // and a second time, just in case
+ watch1Called = false;
+ watch2Called = false;
+ document.cookie = "fifth=set";
+ is(watch1Called, false, "watch1 invoked erroneously");
+ is(watch2Called, true, "watch2 function should be called");
+ is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set; fifth=set",
+ "fifth value correct");
+
+ // remove the watch
+ document.unwatch("cookie");
+
+ // check for non-invocation now
+ watch1Called = false;
+ watch2Called = false;
+ document.cookie = "sixth=set";
+ is(watch1Called, false, "watch1 shouldn't be called");
+ is(watch2Called, false, "watch2 shouldn't be called");
+ is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set; fifth=set; sixth=set",
+ "sixth value correct");
+ }
+ finally
+ {
+ // reset
+ document.unwatch("cookie"); // harmless, should be no-op except if bugs
+
+ var d = new Date();
+ d.setTime(0);
+ var suffix = "=; expires=" + d.toGMTString();
+
+ document.cookie = "first" + suffix;
+ document.cookie = "second" + suffix;
+ document.cookie = "third" + suffix;
+ document.cookie = "fourth" + suffix;
+ document.cookie = "fifth" + suffix;
+ document.cookie = "sixth" + suffix;
+ }
+
+ is(document.cookie, originalValue,
+ "document.cookie isn't what it was initially! expect bustage further " +
+ "down the line");
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=903332">Mozilla Bug 903332</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>