|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 const URL = "about:config"; |
|
7 |
|
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(); |
|
14 |
|
15 // create a new tab |
|
16 let tab = gBrowser.addTab(URL); |
|
17 ss.setTabValue(tab, key, value); |
|
18 yield promiseBrowserLoaded(tab.linkedBrowser); |
|
19 |
|
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"); |
|
24 |
|
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)"); |
|
33 |
|
34 // clean up |
|
35 gBrowser.removeTab(tab); |
|
36 }); |
|
37 |
|
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 } }; |
|
43 |
|
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); |
|
49 |
|
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"); |
|
53 |
|
54 // add text data |
|
55 yield setInputValue(tab.linkedBrowser, {id: "textbox", value: value3}); |
|
56 |
|
57 // duplicate the tab |
|
58 let tab2 = ss.duplicateTab(window, tab); |
|
59 yield promiseTabRestored(tab2); |
|
60 |
|
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"); |
|
67 |
|
68 // clean up |
|
69 gBrowser.removeTab(tab2); |
|
70 gBrowser.removeTab(tab); |
|
71 }); |