1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_global_store.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests the API for saving global session data. 1.8 +function runTests() { 1.9 + const key1 = "Unique name 1: " + Date.now(); 1.10 + const key2 = "Unique name 2: " + Date.now(); 1.11 + const value1 = "Unique value 1: " + Math.random(); 1.12 + const value2 = "Unique value 2: " + Math.random(); 1.13 + 1.14 + let global = {}; 1.15 + global[key1] = value1; 1.16 + 1.17 + const testState = { 1.18 + windows: [ 1.19 + { 1.20 + tabs: [ 1.21 + { entries: [{ url: "about:blank" }] }, 1.22 + ] 1.23 + } 1.24 + ], 1.25 + global: global 1.26 + }; 1.27 + 1.28 + function testRestoredState() { 1.29 + is(ss.getGlobalValue(key1), value1, "restored state has global value"); 1.30 + } 1.31 + 1.32 + function testGlobalStore() { 1.33 + is(ss.getGlobalValue(key2), "", "global value initially not set"); 1.34 + 1.35 + ss.setGlobalValue(key2, value1); 1.36 + is(ss.getGlobalValue(key2), value1, "retreived value matches stored"); 1.37 + 1.38 + ss.setGlobalValue(key2, value2); 1.39 + is(ss.getGlobalValue(key2), value2, "previously stored value was overwritten"); 1.40 + 1.41 + ss.deleteGlobalValue(key2); 1.42 + is(ss.getGlobalValue(key2), "", "global value was deleted"); 1.43 + } 1.44 + 1.45 + yield waitForBrowserState(testState, next); 1.46 + testRestoredState(); 1.47 + testGlobalStore(); 1.48 +} 1.49 + 1.50 +function test() { 1.51 + TestRunner.run(); 1.52 +}