Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | const URL = "about:config"; |
michael@0 | 7 | |
michael@0 | 8 | /** |
michael@0 | 9 | * Bug 393716 - Basic tests for getTabState(), setTabState(), and duplicateTab(). |
michael@0 | 10 | */ |
michael@0 | 11 | add_task(function test_set_tabstate() { |
michael@0 | 12 | let key = "Unique key: " + Date.now(); |
michael@0 | 13 | let value = "Unique value: " + Math.random(); |
michael@0 | 14 | |
michael@0 | 15 | // create a new tab |
michael@0 | 16 | let tab = gBrowser.addTab(URL); |
michael@0 | 17 | ss.setTabValue(tab, key, value); |
michael@0 | 18 | yield promiseBrowserLoaded(tab.linkedBrowser); |
michael@0 | 19 | |
michael@0 | 20 | // get the tab's state |
michael@0 | 21 | SyncHandlers.get(tab.linkedBrowser).flush(); |
michael@0 | 22 | let state = ss.getTabState(tab); |
michael@0 | 23 | ok(state, "get the tab's state"); |
michael@0 | 24 | |
michael@0 | 25 | // verify the tab state's integrity |
michael@0 | 26 | state = JSON.parse(state); |
michael@0 | 27 | ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0, |
michael@0 | 28 | "state object seems valid"); |
michael@0 | 29 | ok(state.entries.length == 1 && state.entries[0].url == URL, |
michael@0 | 30 | "Got the expected state object (test URL)"); |
michael@0 | 31 | ok(state.extData && state.extData[key] == value, |
michael@0 | 32 | "Got the expected state object (test manually set tab value)"); |
michael@0 | 33 | |
michael@0 | 34 | // clean up |
michael@0 | 35 | gBrowser.removeTab(tab); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | add_task(function test_set_tabstate_and_duplicate() { |
michael@0 | 39 | let key2 = "key2"; |
michael@0 | 40 | let value2 = "Value " + Math.random(); |
michael@0 | 41 | let value3 = "Another value: " + Date.now(); |
michael@0 | 42 | let state = { entries: [{ url: URL }], extData: { key2: value2 } }; |
michael@0 | 43 | |
michael@0 | 44 | // create a new tab |
michael@0 | 45 | let tab = gBrowser.addTab(); |
michael@0 | 46 | // set the tab's state |
michael@0 | 47 | ss.setTabState(tab, JSON.stringify(state)); |
michael@0 | 48 | yield promiseBrowserLoaded(tab.linkedBrowser); |
michael@0 | 49 | |
michael@0 | 50 | // verify the correctness of the restored tab |
michael@0 | 51 | ok(ss.getTabValue(tab, key2) == value2 && tab.linkedBrowser.currentURI.spec == URL, |
michael@0 | 52 | "the tab's state was correctly restored"); |
michael@0 | 53 | |
michael@0 | 54 | // add text data |
michael@0 | 55 | yield setInputValue(tab.linkedBrowser, {id: "textbox", value: value3}); |
michael@0 | 56 | |
michael@0 | 57 | // duplicate the tab |
michael@0 | 58 | let tab2 = ss.duplicateTab(window, tab); |
michael@0 | 59 | yield promiseTabRestored(tab2); |
michael@0 | 60 | |
michael@0 | 61 | // verify the correctness of the duplicated tab |
michael@0 | 62 | ok(ss.getTabValue(tab2, key2) == value2 && |
michael@0 | 63 | tab2.linkedBrowser.currentURI.spec == URL, |
michael@0 | 64 | "correctly duplicated the tab's state"); |
michael@0 | 65 | let textbox = yield getInputValue(tab2.linkedBrowser, {id: "textbox"}); |
michael@0 | 66 | is(textbox, value3, "also duplicated text data"); |
michael@0 | 67 | |
michael@0 | 68 | // clean up |
michael@0 | 69 | gBrowser.removeTab(tab2); |
michael@0 | 70 | gBrowser.removeTab(tab); |
michael@0 | 71 | }); |