aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojo/tests/cookie.html
blob: a89b0f84feb7f62d498c8d226bbc08741e9c7971 (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
<html>
	<head>
		<title>testing Cookies</title>
		<style type="text/css">
			@import "../resources/dojo.css";
		</style>
		<script type="text/javascript"
			src="../dojo.js"
			djConfig="isDebug:true"></script>
		<script type="text/javascript" src="../cookie.js"></script>
		<script type="text/javascript">
			dojo.require("doh.runner");
			dojo.addOnLoad(function(){
				doh.register("t",
					[
						{
							name: "basicSet",
							runTest: function(t){
								// make sure the cookie is dead
								var old = new Date(1976, 8, 15);
								document.cookie = "dojo_test=blah; expires=" + old.toUTCString();
								t.is(-1, document.cookie.indexOf("dojo_test="));
								
								// set the new one
								var n = "dojo_test";
								var v = "test value";
								dojo.cookie(n, v);
								t.t(document.cookie.indexOf(n+"=") >= 0);
								var start = document.cookie.indexOf(n+"=") + n.length + 1;
								var end = document.cookie.indexOf(";", start);
								if(end == -1){ end = document.cookie.length; }
								t.is(v, decodeURIComponent(document.cookie.substring(start, end)));
							}
						},
						{
							name: "basicGet",
							runTest: function(t){
								// set the cookie
								var n = "dojo_test";
								var v = "foofoo";
								document.cookie = n + "=" + v;
								
								t.is(v, dojo.cookie(n));
							}
						},
						{
							name: "daysAsNumber",
							runTest: function(t){
								// set a cookie with a numerical expires
								dojo.cookie("dojo_num", "foo", { expires: 10 });
								t.is("foo", dojo.cookie("dojo_num"));
								
								// remove the cookie by setting it with a negative
								// numerical expires. value doesn't really matter here
								dojo.cookie("dojo_num", "-deleted-", { expires: -10 });
								t.is(null, dojo.cookie("dojo_num"));
							}
						},
						{
							name: "nameSuffix",
							runTest: function(t){
								// set two cookies with the same suffix
								dojo.cookie("user", "123", { expires: 10 });
								dojo.cookie("xuser", "abc", { expires: 10 });
								t.is("123", dojo.cookie("user"));
								t.is("abc", dojo.cookie("xuser"));

								// remove the cookie by setting it with a negative
								// numerical expires. value doesn't really matter here
								dojo.cookie("user", "-deleted-", { expires: -10 });
								t.is(null, dojo.cookie("user"));
								dojo.cookie("xuser", "-deleted-", { expires: -10 });
								t.is(null, dojo.cookie("xuser"));
							}
						}
					]
				);
				doh.run();
			});
		</script>
	</head>
	<body>
	</body>
</html>