index.html revision 97313c46f83d59ff6ac32b852c5d055a0ca57e2d
a48fa4b49c58246b297e0fd38e5fb85b985379f1Bob Halley<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley<html>
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley<head>
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley<title>Cache Tests</title>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<script type="text/javascript" src="/build/yui/yui.js"></script>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<script type="text/javascript" src="/build/cache/cache-debug.js" id="buildsrc"></script>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson</head>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<body class="yui-skin-sam">
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<h1>Cache Tests</h1>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<script type="text/javascript">
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson(function() {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson YUI({
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson base: "/build/",
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson //filter: "debug",
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson useConsole: true,
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson insertBefore: "buildsrc"
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson }).use("console", "test", "dump", "cache", function(Y) {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // Set up the page
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson var ASSERT = Y.Assert,
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson ARRAYASSERT = Y.ArrayAssert,
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson BTNRUN = Y.get("#btnRun");
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson BTNRUN.set("disabled", false);
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson Y.on("click", function(e){
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson Y.Test.Runner.run();
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson }, BTNRUN);
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley var myConsole = new Y.Console().render();
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley var testClass = new Y.Test.Case({
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson name: "Class Tests",
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson testDefaults: function() {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // TODO: remove empty config
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson var cache = new Y.Cache({});
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson cache.add(1, "a");
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson ASSERT.isInstanceOf(Y.Cache, cache, "Expected instance of Y.Cache.");
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson ASSERT.areSame(0, cache.get("max"), "Expected default max of 0.");
70680fa51b0147c726b939b72b2420249429756aBob Halley ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
70680fa51b0147c726b939b72b2420249429756aBob Halley },
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley testDestructor: function() {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // TODO: remove empty config
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson cache.destroy();
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.isNull(cache.get("entries"), "Expected null array.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson }
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson });
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var testBasic = new Y.Test.Case({
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson name: "Basic Tests",
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax0: function() {
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson // TODO: remove empty config
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(0, cache.get("max"), "Expected max to be 0.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson cache.add(1, "a");
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson ASSERT.areSame(0, cache.get("size"), "Expected 0 entries.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.isNull(cache.retrieve(1), "Expected null cached response.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson },
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax2: function() {
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({max:2});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("max"), "Expected max to be 2.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson cache.add(1, "a");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson cache.add(2, "b");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("size"), "Expected 2 entries.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson cache.add(3, "c");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("size"), "Expected 2 entries (still).");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson },
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax2to1: function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(2, "b");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.set("max", 1);
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(3, "c");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry (still).");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson },
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testmax2to0: function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(2, "b");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.set("max", 0);
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(3, "c");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array (still).");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson },
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testmax2toNegative: function() {
2fdaa940ccd0c671a3675d4674c0bd9b8a3f3fb4Andreas Gustafsson var cache = new Y.Cache({max:2});
2fdaa940ccd0c671a3675d4674c0bd9b8a3f3fb4Andreas Gustafsson cache.add(1, "a");
2fdaa940ccd0c671a3675d4674c0bd9b8a3f3fb4Andreas Gustafsson cache.add(2, "b");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.set("max", -5);
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews cache.add(3, "c");
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array (still).");
7c956aeeeb8da3fd3912b1fb8024ff274e3b07ebAndreas Gustafsson ASSERT.areSame(-5, cache.get("max"), "Expected negative value normalized to 0.");
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews },
7c956aeeeb8da3fd3912b1fb8024ff274e3b07ebAndreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testRetrieve: function() {
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley var cache = new Y.Cache({max:2}),
e5256e34b4a26a26088b2dc5ca621b42c0750256Andreas Gustafsson cachedresponse;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence cache.add(1, "a");
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley cache.add(2, "b");
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley cachedresponse = cache.retrieve(1).response;
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley ASSERT.areSame("a", cachedresponse, "Expected first cached response.");
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley
8db66dc4eb654a2e295eaeab3aaf96e24c9ae7b7Bob Halley cachedresponse = cache.retrieve(2).response;
76860484adfbadeecfeb3a7132ede916ee2102ffBrian Wellington ASSERT.areSame("b", cachedresponse, "Expected second cached response.");
8db66dc4eb654a2e295eaeab3aaf96e24c9ae7b7Bob Halley },
501da430e2f16f496f8e8d1b57ab77f78428c682David Lawrence
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFlush: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:2});
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(2, "b");
2ecf7f63a01ca8a96d76f7d2d4de0fa37f3e3fabOlafur Gudmundsson cache.flush();
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley ASSERT.areSame(0, cache.get("size"), "Expected empty cache.");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley }
557ab3bef6dbb33623f6ff26e9bbb0566b27d9bfAndreas Gustafsson });
b3d8bec59201fd0edbe38f909bda5014d7776b89Brian Wellington
997e3113b7c91ec94e6274d31735f122e6e8209cAndreas Gustafsson var testEvents = new Y.Test.Case({
d80ccd47ad4b526f82590b6c182b4dd80006712eAndreas Gustafsson name: "Event Tests",
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testAdd: function() {
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson var cache = new Y.Cache({max:2});
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson cache.on("add", function(e) {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson this.resume(function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ASSERT.areSame(1, e.entry.request);
e544b507b8019a62c5d2716281f6832519a8791dDavid Lawrence ASSERT.areSame("a", e.entry.response);
6905fe248b89a0fd5b892ab8569e50cffe763ed0Andreas Gustafsson });
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson }, this, true);
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley this.wait();
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley },
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFlush: function() {
8eb5937a7e4cb8b5d7fcc1be17d34fdd014bbbb1Andreas Gustafsson var cache = new Y.Cache({max:2});
8eb5937a7e4cb8b5d7fcc1be17d34fdd014bbbb1Andreas Gustafsson cache.on("flush", function(e) {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson this.resume(function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson // This function intentionally left blank
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence });
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson }, this, true);
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.flush()
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence this.wait();
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson },
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testRequest: function() {
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.on("request", function(e) {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson this.resume(function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ASSERT.areSame(2, e.request);
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson });
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence }, this, true);
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.retrieve(2)
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson this.wait();
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence },
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson
69930116e30137705d3b87d05cbfbc5712386fdeAndreas Gustafsson testRetrieveSuccess: function() {
69930116e30137705d3b87d05cbfbc5712386fdeAndreas Gustafsson var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.on("retrieve", function(e) {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson this.resume(function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ASSERT.areSame(1, e.entry.request);
e21262ae8af5d12f64a2242e26338f36901ba4ccAndreas Gustafsson ASSERT.areSame("a", e.entry.response);
e21262ae8af5d12f64a2242e26338f36901ba4ccAndreas Gustafsson });
e21262ae8af5d12f64a2242e26338f36901ba4ccAndreas Gustafsson }, this, true);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence cache.add(1, "a");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.retrieve(1)
9e87fd676ee62e6e11d29611731b80839fc305b3David Lawrence this.wait();
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley },
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testRetrieveFailure: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:2});
5f5bb44065a3e7f506e4afd4d81c89da2931bf1bBob Halley cache.on("retrieve", function(e) {
5f5bb44065a3e7f506e4afd4d81c89da2931bf1bBob Halley this.resume(function() {
5f5bb44065a3e7f506e4afd4d81c89da2931bf1bBob Halley ASSERT.fail();
5f5bb44065a3e7f506e4afd4d81c89da2931bf1bBob Halley });
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley }, this, true);
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.retrieve(2)
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson this.wait(function() {
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson // This function intentionally left blank
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson }, 0);
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson },
9b19b39170eaf78ae1baf39acca0be462c2faa4cAndreas Gustafsson
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson testCancelAdd: function() {
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson var cache = new Y.Cache({max:2});
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson cache.on("add", function(e) {
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson e.preventDefault();
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley }, this, true);
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson cache.add(1, "a");
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson // Test the cancel
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson ASSERT.areSame(0, cache.get("size"), "Expected 0 entries.");
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson },
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson testCancelFlush: function() {
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson var cache = new Y.Cache({max:2});
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson cache.on("flush", function(e) {
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson e.preventDefault();
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson }, this, true);
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson cache.add(1, "a");
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson cache.flush();
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson // Test the cancel
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson }
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley });
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson var testEntryManagement = new Y.Test.Case({
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley name: "Entry Management Tests",
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testAllowDuplicateEntries: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:3});
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(2, "b");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley ASSERT.areSame(3, cache.get("size"), "Expected 3 entries.");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley },
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFreshness: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:3});
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(1, "a");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley cache.add(2, "b");
a48fa4b49c58246b297e0fd38e5fb85b985379f1Bob Halley cache.add(3, "c");
cache.retrieve(1);
ASSERT.areSame(3, cache.get("size"), "Expected 3 entries.");
ASSERT.areSame(1, cache.get("entries")[2].request, "Expected entry to be refreshed.");
},
testPayload: function() {
//TODO
}
});
Y.Test.Runner.add(testClass);
Y.Test.Runner.add(testBasic);
Y.Test.Runner.add(testEvents);
Y.Test.Runner.add(testEntryManagement);
Y.Test.Runner.run();
});
})();
</script>
</body>
</html>