source: Dev/branches/rest-dojo-ui/client/dojo/tests/cookie.html @ 263

Last change on this file since 263 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.4 KB
Line 
1<html>
2        <head>
3                <title>testing Cookies</title>
4                <style type="text/css">
5                        @import "../resources/dojo.css";
6                </style>
7                <script type="text/javascript" src="../dojo.js" data-dojo-config="isDebug:true"></script>
8                <script type="text/javascript">
9                        require(["dojo", "doh", "dojo/cookie", "dojo/domReady!"], function(dojo, doh){
10                                doh.register([
11                                        {
12                                                name: "basicSet",
13                                                runTest: function(t){
14                                                        // make sure the cookie is dead
15                                                        var old = new Date(1976, 8, 15);
16                                                        document.cookie = "dojo_test=blah; expires=" + old.toUTCString();
17                                                        t.is(-1, document.cookie.indexOf("dojo_test="));
18                                                       
19                                                        // set the new one
20                                                        var n = "dojo_test";
21                                                        var v = "test value";
22                                                        dojo.cookie(n, v);
23                                                        t.t(document.cookie.indexOf(n+"=") >= 0);
24                                                        var start = document.cookie.indexOf(n+"=") + n.length + 1;
25                                                        var end = document.cookie.indexOf(";", start);
26                                                        if(end == -1){ end = document.cookie.length; }
27                                                        t.is(v, decodeURIComponent(document.cookie.substring(start, end)));
28                                                }
29                                        },
30                                        {
31                                                name: "basicGet",
32                                                runTest: function(t){
33                                                        // set the cookie
34                                                        var n = "dojo_test";
35                                                        var v = "foofoo";
36                                                        document.cookie = n + "=" + v;
37                                                       
38                                                        t.is(v, dojo.cookie(n));
39                                                }
40                                        },
41                                        {
42                                                name: "daysAsNumber",
43                                                runTest: function(t){
44                                                        // set a cookie with a numerical expires
45                                                        dojo.cookie("dojo_num", "foo", { expires: 10 });
46                                                        t.is("foo", dojo.cookie("dojo_num"));
47                                                       
48                                                        // remove the cookie by setting it with a negative
49                                                        // numerical expires. value doesn't really matter here
50                                                        dojo.cookie("dojo_num", "-deleted-", { expires: -10 });
51                                                        t.is(null, dojo.cookie("dojo_num"));
52                                                }
53                                        },
54                                        {
55                                                name: "nameSuffix",
56                                                runTest: function(t){
57                                                        // set two cookies with the same suffix
58                                                        dojo.cookie("user", "123", { expires: 10 });
59                                                        dojo.cookie("xuser", "abc", { expires: 10 });
60                                                        t.is("123", dojo.cookie("user"));
61                                                        t.is("abc", dojo.cookie("xuser"));
62
63                                                        // remove the cookie by setting it with a negative
64                                                        // numerical expires. value doesn't really matter here
65                                                        dojo.cookie("user", "-deleted-", { expires: -10 });
66                                                        t.is(null, dojo.cookie("user"));
67                                                        dojo.cookie("xuser", "-deleted-", { expires: -10 });
68                                                        t.is(null, dojo.cookie("xuser"));
69                                                }
70                                        }
71                                ]);
72                                doh.runOnLoad();
73                        });
74                </script>
75        </head>
76        <body>
77        </body>
78</html>
Note: See TracBrowser for help on using the repository browser.