michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const URL = "about:config"; michael@0: michael@0: /** michael@0: * Bug 393716 - Basic tests for getTabState(), setTabState(), and duplicateTab(). michael@0: */ michael@0: add_task(function test_set_tabstate() { michael@0: let key = "Unique key: " + Date.now(); michael@0: let value = "Unique value: " + Math.random(); michael@0: michael@0: // create a new tab michael@0: let tab = gBrowser.addTab(URL); michael@0: ss.setTabValue(tab, key, value); michael@0: yield promiseBrowserLoaded(tab.linkedBrowser); michael@0: michael@0: // get the tab's state michael@0: SyncHandlers.get(tab.linkedBrowser).flush(); michael@0: let state = ss.getTabState(tab); michael@0: ok(state, "get the tab's state"); michael@0: michael@0: // verify the tab state's integrity michael@0: state = JSON.parse(state); michael@0: ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0, michael@0: "state object seems valid"); michael@0: ok(state.entries.length == 1 && state.entries[0].url == URL, michael@0: "Got the expected state object (test URL)"); michael@0: ok(state.extData && state.extData[key] == value, michael@0: "Got the expected state object (test manually set tab value)"); michael@0: michael@0: // clean up michael@0: gBrowser.removeTab(tab); michael@0: }); michael@0: michael@0: add_task(function test_set_tabstate_and_duplicate() { michael@0: let key2 = "key2"; michael@0: let value2 = "Value " + Math.random(); michael@0: let value3 = "Another value: " + Date.now(); michael@0: let state = { entries: [{ url: URL }], extData: { key2: value2 } }; michael@0: michael@0: // create a new tab michael@0: let tab = gBrowser.addTab(); michael@0: // set the tab's state michael@0: ss.setTabState(tab, JSON.stringify(state)); michael@0: yield promiseBrowserLoaded(tab.linkedBrowser); michael@0: michael@0: // verify the correctness of the restored tab michael@0: ok(ss.getTabValue(tab, key2) == value2 && tab.linkedBrowser.currentURI.spec == URL, michael@0: "the tab's state was correctly restored"); michael@0: michael@0: // add text data michael@0: yield setInputValue(tab.linkedBrowser, {id: "textbox", value: value3}); michael@0: michael@0: // duplicate the tab michael@0: let tab2 = ss.duplicateTab(window, tab); michael@0: yield promiseTabRestored(tab2); michael@0: michael@0: // verify the correctness of the duplicated tab michael@0: ok(ss.getTabValue(tab2, key2) == value2 && michael@0: tab2.linkedBrowser.currentURI.spec == URL, michael@0: "correctly duplicated the tab's state"); michael@0: let textbox = yield getInputValue(tab2.linkedBrowser, {id: "textbox"}); michael@0: is(textbox, value3, "also duplicated text data"); michael@0: michael@0: // clean up michael@0: gBrowser.removeTab(tab2); michael@0: gBrowser.removeTab(tab); michael@0: });