cacheoffline.html revision 51cd1e3c989b1d9414c7749c72c369f0325cdb8e
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater<script type="text/javascript" src="/build/yui/yui.js"></script>
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater<script type="text/javascript" src="/build/cache/cache-debug.js"></script>
bef75d63d74f58abc0f834ed271526672777ba29Automatic Updater<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
c92c50783e4e93699f2a42643b8f200b9b719c87Automatic Updater //filter: "debug",
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater logInclude:{"TestRunner":true},
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater useConsole: true
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater }).use("console", "test", "dump", "cache-offline", function(Y) {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater // Set up the page
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater BTNRUN = Y.get("#btnRun");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater BTNRUN.set("disabled", false);
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater Y.on("click", function(e){
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater var myConsole = new Y.Console().render(),
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater tearDown = function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater var testClass = new Y.Test.Case({
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater name: "Class Tests",
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater tearDown : tearDown,
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater testDefaults: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.isInstanceOf(Y.Cache, this.cache, "Expected instance of Y.Cache.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.areSame(null, this.cache.get("max"), "Expected default max of null.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ARRAYASSERT.isEmpty(this.cache.get("entries"), "Expected empty array.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater testDestructor: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ARRAYASSERT.isEmpty(this.cache.get("entries"), "Expected empty array.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater var testBasic = new Y.Test.Case({
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater name: "Basic Tests",
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater tearDown : tearDown,
c92c50783e4e93699f2a42643b8f200b9b719c87Automatic Updater testMaxDefault: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.areSame(null, this.cache.get("max"), "Expected max to be null.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entries.");
c92c50783e4e93699f2a42643b8f200b9b719c87Automatic Updater ASSERT.isNotNull(this.cache.retrieve(1), "Expected null cached response.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater testMaxConfig: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater testMaxSet: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.areSame(1, this.cache.get("size"), "Expected 1 entry.");
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater testMaxSetNull: function() {
fc2381b901eb162810f54a11cc512b95f55a60dfAutomatic Updater ASSERT.isNull(null, this.cache.get("max"), "Expected max to be null.");
this.cache.add(4, "d");
this.cache.add(1, "a");
this.cache.add("b", "c");
var cachedentry = this.cache.retrieve(1);
cachedentry = this.cache.retrieve("b");
this.cache.add(1, "a");
this.cache.add("b", "c");
var cachedentry = this.cache.retrieve(1);
this.cache.add(1, "a");
var cachedentry = this.cache.retrieve(1);
this.cache.set("expires", 1);
this.cache.add(1, "a");
this.wait(function(){
cachedentry = this.cache.retrieve(1);
ASSERT.isNull(cachedentry, "Expected expired data.");
this.cache.add(1, "a");
var cachedentry = this.cache.retrieve(1);
this.cache.set("expires", new Date(new Date().getTime() - 86400000));
this.cache.add(1, "a");
cachedentry = this.cache.retrieve(1);
ASSERT.isNull(cachedentry, "Expected expired data.");
this.cache.add("a", "b");
var cachedentry = this.cache.retrieve("c");
ASSERT.areSame(null, cachedentry, "Expected no match.");
this.cache.add(1, "a");
this.cache.add(2, "b");
this.cache.add(1, "a");
this.cache.add(2, "b");
var cache = new Y.CacheOffline({sandbox:"another"});
cache.add(1, "a");
cache.add(2, "b");
if(window.localStorage) {
if(window.localStorage) {
var testEvents = new Y.Test.Case({
this.cache.on("add", function(e) {
this.resume(function() {
this.cache.add(1, "a");
this.wait();
this.cache.on("flush", function(e) {
this.cache.detach("flush");
this.resume(function() {
this.cache.add(1, "a");
this.wait();
this.cache.on("request", function(e) {
this.resume(function() {
this.cache.add(1, "a");
this.wait();
this.cache.on("retrieve", function(e) {
this.resume(function() {
this.cache.add(1, "a");
this.wait();
this.cache.on("retrieve", function(e) {
this.resume(function() {
ASSERT.fail();
this.cache.add(1, "a");
this.wait(function() {
this.cache.on("add", function(e) {
this.cache.add(1, "a");
this.cache.on("flush", function(e) {
this.cache.add(1, "a");
var testEntryManagement = new Y.Test.Case({
this.cache.add(1, "a");
this.cache.add(2, "b");
this.cache.add(1, "c");
this.cache.add(1, "a");
this.cache.add(2, "b");
this.cache.add(1, "c");
this.cache.add(1, "a");
this.cache.add(2, "b");
this.cache.add(3, "c");
var testBoundaryValues = new Y.Test.Case({
this.cache.add(undefined, "a");
this.cache.add(undefined, "b");
this.cache.add(null, "a");
this.cache.add(null, "b");
this.cache.add(NaN, "a");
this.cache.add(NaN, "b");
this.cache.add("", "a");
this.cache.add("", "b");
var suite = new Y.Test.Suite({name:"CacheOffline Test Suite"});
suite.add(testClass);
suite.add(testBasic);
suite.add(testEvents);
suite.add(testEntryManagement);
suite.add(testBoundaryValues);
Y.Test.Runner.setName("CacheOffline Test Runner");
Y.Test.Runner.add(suite);
if(window.localStorage) {