forked from mirrors/gecko-dev
		
	NOTE: The '__SSi' and '__SS_lastSessionWindowID' properties on windows are kept,
      because they are expected to stick around longer during application shutdown.
The benefits is are:
1. Cleaner code - Sessionstore implementation details are not leaked outside its
   module.
2. Observing the lifetime of objects becomes unnecessary, because the WeakMaps are
   cleaned up when objects are GC'd, making leakage of their references impossible
   and Sessionstore can't hold objects hostage anymore.
3. Simplification - all state is now maintained in SessionStore.jsm, which allows
   for additional refactoring later on to simplify the implementation further.
MozReview-Commit-ID: C1II8qHkQ6F
--HG--
extra : rebase_source : e5fc6984558bd455a33e275f7060d42c93c21720
		
	
			
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/* Any copyright is dedicated to the Public Domain.
 | 
						|
   http://creativecommons.org/publicdomain/zero/1.0/ */
 | 
						|
 | 
						|
var url = "data:text/html;charset=utf-8,<input%20id='foo'>";
 | 
						|
var tabState = {
 | 
						|
  entries: [{ url, triggeringPrincipal_base64 }], formdata: { id: { "foo": "bar" }, url }
 | 
						|
};
 | 
						|
 | 
						|
function test() {
 | 
						|
  waitForExplicitFinish();
 | 
						|
  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
 | 
						|
 | 
						|
  registerCleanupFunction(function() {
 | 
						|
    if (gBrowser.tabs.length > 1)
 | 
						|
      gBrowser.removeTab(gBrowser.tabs[1]);
 | 
						|
    Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
 | 
						|
  });
 | 
						|
 | 
						|
  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
 | 
						|
  let browser = tab.linkedBrowser;
 | 
						|
 | 
						|
  promiseBrowserLoaded(browser).then(() => {
 | 
						|
    isnot(gBrowser.selectedTab, tab, "newly created tab is not selected");
 | 
						|
 | 
						|
    ss.setTabState(tab, JSON.stringify(tabState));
 | 
						|
    is(ss.getInternalObjectState(browser), TAB_STATE_NEEDS_RESTORE, "tab needs restoring");
 | 
						|
 | 
						|
    let {formdata} = JSON.parse(ss.getTabState(tab));
 | 
						|
    is(formdata && formdata.id.foo, "bar", "tab state's formdata is valid");
 | 
						|
 | 
						|
    promiseTabRestored(tab).then(() => {
 | 
						|
      ContentTask.spawn(browser, null, function() {
 | 
						|
        let input = content.document.getElementById("foo");
 | 
						|
        is(input.value, "bar", "formdata has been restored correctly");
 | 
						|
      }).then(() => { finish(); });
 | 
						|
    });
 | 
						|
 | 
						|
    // Restore the tab by selecting it.
 | 
						|
    gBrowser.selectedTab = tab;
 | 
						|
  });
 | 
						|
}
 |