Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const URL = "about:config";
8 /**
9 * Bug 393716 - Basic tests for getTabState(), setTabState(), and duplicateTab().
10 */
11 add_task(function test_set_tabstate() {
12 let key = "Unique key: " + Date.now();
13 let value = "Unique value: " + Math.random();
15 // create a new tab
16 let tab = gBrowser.addTab(URL);
17 ss.setTabValue(tab, key, value);
18 yield promiseBrowserLoaded(tab.linkedBrowser);
20 // get the tab's state
21 SyncHandlers.get(tab.linkedBrowser).flush();
22 let state = ss.getTabState(tab);
23 ok(state, "get the tab's state");
25 // verify the tab state's integrity
26 state = JSON.parse(state);
27 ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0,
28 "state object seems valid");
29 ok(state.entries.length == 1 && state.entries[0].url == URL,
30 "Got the expected state object (test URL)");
31 ok(state.extData && state.extData[key] == value,
32 "Got the expected state object (test manually set tab value)");
34 // clean up
35 gBrowser.removeTab(tab);
36 });
38 add_task(function test_set_tabstate_and_duplicate() {
39 let key2 = "key2";
40 let value2 = "Value " + Math.random();
41 let value3 = "Another value: " + Date.now();
42 let state = { entries: [{ url: URL }], extData: { key2: value2 } };
44 // create a new tab
45 let tab = gBrowser.addTab();
46 // set the tab's state
47 ss.setTabState(tab, JSON.stringify(state));
48 yield promiseBrowserLoaded(tab.linkedBrowser);
50 // verify the correctness of the restored tab
51 ok(ss.getTabValue(tab, key2) == value2 && tab.linkedBrowser.currentURI.spec == URL,
52 "the tab's state was correctly restored");
54 // add text data
55 yield setInputValue(tab.linkedBrowser, {id: "textbox", value: value3});
57 // duplicate the tab
58 let tab2 = ss.duplicateTab(window, tab);
59 yield promiseTabRestored(tab2);
61 // verify the correctness of the duplicated tab
62 ok(ss.getTabValue(tab2, key2) == value2 &&
63 tab2.linkedBrowser.currentURI.spec == URL,
64 "correctly duplicated the tab's state");
65 let textbox = yield getInputValue(tab2.linkedBrowser, {id: "textbox"});
66 is(textbox, value3, "also duplicated text data");
68 // clean up
69 gBrowser.removeTab(tab2);
70 gBrowser.removeTab(tab);
71 });