content/html/document/test/test_document.watch.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=903332
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 903332</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 <script type="application/javascript">
michael@0 12
michael@0 13 /** Test for Bug 903332 **/
michael@0 14
michael@0 15 var watch1Called;
michael@0 16 function watch1(prop, oldValue, newValue)
michael@0 17 {
michael@0 18 is(watch1Called, false, "watch1Called not reset properly?");
michael@0 19 watch1Called = true;
michael@0 20
michael@0 21 is(prop, "cookie", "wrong property name passed to watch1");
michael@0 22 return newValue;
michael@0 23 }
michael@0 24
michael@0 25 var watch2Called;
michael@0 26 function watch2(prop, oldValue, newValue)
michael@0 27 {
michael@0 28 is(watch2Called, false, "watch2Called not reset properly?");
michael@0 29 watch2Called = true;
michael@0 30
michael@0 31 is(prop, "cookie", "wrong property name passed to watch2");
michael@0 32 return newValue;
michael@0 33 }
michael@0 34
michael@0 35 // Just in case subsequent tests depend on a particular value...
michael@0 36 var originalValue = document.cookie;
michael@0 37 ok(true, "originalValue: " + originalValue);
michael@0 38
michael@0 39 var originalPrefix = originalValue.length > 0 ? originalValue + "; " : "";
michael@0 40
michael@0 41 try
michael@0 42 {
michael@0 43 // trial set (no watch) to verify things work
michael@0 44 document.cookie = "first=set";
michael@0 45 is(document.cookie, originalPrefix + "first=set",
michael@0 46 "first value correct");
michael@0 47
michael@0 48 // add a watch
michael@0 49 document.watch("cookie", watch1);
michael@0 50
michael@0 51 // set, check for watch invoked
michael@0 52 watch1Called = false;
michael@0 53 document.cookie = "second=set";
michael@0 54 is(watch1Called, true, "watch1 function should be called");
michael@0 55 is(document.cookie, originalPrefix + "first=set; second=set",
michael@0 56 "second value correct");
michael@0 57
michael@0 58 // and a second time, just in case
michael@0 59 watch1Called = false;
michael@0 60 document.cookie = "third=set";
michael@0 61 is(watch1Called, true, "watch1 function should be called");
michael@0 62 is(document.cookie, originalPrefix + "first=set; second=set; third=set",
michael@0 63 "third value correct");
michael@0 64
michael@0 65 // overwrite the current watch with a new one
michael@0 66 document.watch("cookie", watch2);
michael@0 67
michael@0 68 // set, check for watch invoked
michael@0 69 watch1Called = false;
michael@0 70 watch2Called = false;
michael@0 71 document.cookie = "fourth=set";
michael@0 72 is(watch1Called, false, "watch1 invoked erroneously");
michael@0 73 is(watch2Called, true, "watch2 function should be called");
michael@0 74 is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set",
michael@0 75 "fourth value correct");
michael@0 76
michael@0 77 // and a second time, just in case
michael@0 78 watch1Called = false;
michael@0 79 watch2Called = false;
michael@0 80 document.cookie = "fifth=set";
michael@0 81 is(watch1Called, false, "watch1 invoked erroneously");
michael@0 82 is(watch2Called, true, "watch2 function should be called");
michael@0 83 is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set; fifth=set",
michael@0 84 "fifth value correct");
michael@0 85
michael@0 86 // remove the watch
michael@0 87 document.unwatch("cookie");
michael@0 88
michael@0 89 // check for non-invocation now
michael@0 90 watch1Called = false;
michael@0 91 watch2Called = false;
michael@0 92 document.cookie = "sixth=set";
michael@0 93 is(watch1Called, false, "watch1 shouldn't be called");
michael@0 94 is(watch2Called, false, "watch2 shouldn't be called");
michael@0 95 is(document.cookie, originalPrefix + "first=set; second=set; third=set; fourth=set; fifth=set; sixth=set",
michael@0 96 "sixth value correct");
michael@0 97 }
michael@0 98 finally
michael@0 99 {
michael@0 100 // reset
michael@0 101 document.unwatch("cookie"); // harmless, should be no-op except if bugs
michael@0 102
michael@0 103 var d = new Date();
michael@0 104 d.setTime(0);
michael@0 105 var suffix = "=; expires=" + d.toGMTString();
michael@0 106
michael@0 107 document.cookie = "first" + suffix;
michael@0 108 document.cookie = "second" + suffix;
michael@0 109 document.cookie = "third" + suffix;
michael@0 110 document.cookie = "fourth" + suffix;
michael@0 111 document.cookie = "fifth" + suffix;
michael@0 112 document.cookie = "sixth" + suffix;
michael@0 113 }
michael@0 114
michael@0 115 is(document.cookie, originalValue,
michael@0 116 "document.cookie isn't what it was initially! expect bustage further " +
michael@0 117 "down the line");
michael@0 118 </script>
michael@0 119 </head>
michael@0 120 <body>
michael@0 121 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=903332">Mozilla Bug 903332</a>
michael@0 122 <p id="display"></p>
michael@0 123 <div id="content" style="display: none">
michael@0 124
michael@0 125 </div>
michael@0 126 <pre id="test">
michael@0 127 </pre>
michael@0 128 </body>
michael@0 129 </html>

mercurial