df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass // Set up the page
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass tearDown = function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Y.Cache, this.cache, "Expected instance of Y.Cache.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(null, this.cache.get("max"), "Expected default max of null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ARRAYASSERT.isEmpty(this.cache.get("entries"), "Expected empty array.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ARRAYASSERT.isEmpty(this.cache.get("entries"), "Expected empty array.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(null, this.cache.get("max"), "Expected max to be null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNotNull(this.cache.retrieve(1), "Expected null cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testMaxSet: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("a", cachedentry.response, "Expected first cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.cached, "Expected first cached Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.expires, "Expected first expires Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("c", cachedentry.response, "Expected second cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.cached, "Expected second cached Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.expires, "Expected second expires Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("a", cachedentry.response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.cached, "Expected cached Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(cachedentry.expires, "Expected null expires.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("a", cachedentry.response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.expires, "Expected cached Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.wait(function(){
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(cachedentry, "Expected expired data.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache = new Y.CacheOffline({expires:new Date(new Date().getTime() + 86400000)}),
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("a", cachedentry.response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isInstanceOf(Date, cachedentry.expires, "Expected cached Date.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache.set("expires", new Date(new Date().getTime() - 86400000));
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.isNull(cachedentry, "Expected expired data.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testNoMatch: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(null, cachedentry, "Expected no match.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testFlush: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(0, this.cache.get("size"), "Expected empty this.cache.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass var cache = new Y.CacheOffline({sandbox:"another"});
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(4, localStorage.length, "Expected 4 items.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(0, localStorage.length, "Expected empty localStorage.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testAdd: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testFlush: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testRequest: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass }, this, true);
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass // Test the cancel
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(0, this.cache.get("size"), "Expected 0 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass }, this, true);
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass // Test the cancel
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache = new Y.CacheOffline({uniqueKeys:false}); // not supported
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(2, this.cache.get("size"), "Expected 2 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache = new Y.CacheOffline({uniqueKeys:true});
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(2, this.cache.get("size"), "Expected 2 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass NOT SUPPORTED IN CACHEOFFLINE
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass testFreshness: function() {
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache = new Y.CacheOffline();
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache.add(1, "a");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache.add(2, "b");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache.add(3, "c");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass this.cache.retrieve(1);
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(3, this.cache.get("size"), "Expected 3 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(1, this.cache.get("entries")[2].request, "Expected entry to be refreshed.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("b", this.cache.retrieve().response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("b", this.cache.retrieve(null).response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame(0, this.cache.get("size"), "Expected 0 entries.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass ASSERT.areSame("b", this.cache.retrieve("").response, "Expected cached response.");
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass var suite = new Y.Test.Suite({name:"CacheOffline Test Suite"});
df4c27342962c3f93a19eb762cb2c22584b186c6Dav Glass Y.Test.Runner.setName("CacheOffline Test Runner");