forked from mirrors/gecko-dev
		
	 2a5c775eea
			
		
	
	
		2a5c775eea
		
	
	
	
	
		
			
			The problem with this test was that it was actually relying on the old broken behaviour where the initial browser of the new window it opens would be flipped from remote back to non-remote before loading its contents and flipping remote again. Because it now starts remote (and stays there instead of doing all of the extra work), the test was more likely to fall into the trap that I described in https://groups.google.com/forum/#!searchin/mozilla.dev.platform/1261842%7Csort:relevance/mozilla.dev.platform/gthFqog3J-M/Ypx-SNhEQgAJ where the promiseBrowserLoaded was firing for the wrong page load, which meant that the cookie hadn't had a chance to be set yet. I've converted the test to use the properly instrumented BrowserTestUtils functions which wait for the window to be properly ready, and it appears to pass on try with multiple retriggers. MozReview-Commit-ID: BtQRx7og52A --HG-- extra : rebase_source : 83a9c36533505167198b62ddc189c6fa62cec8cd
		
			
				
	
	
		
			59 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| 
 | |
| /**
 | |
|  * Tests that cookies are stored and restored correctly
 | |
|  * by sessionstore (bug 423132).
 | |
|  */
 | |
| add_task(function*() {
 | |
|   const testURL = "http://mochi.test:8888/browser/" +
 | |
|     "browser/components/sessionstore/test/browser_423132_sample.html";
 | |
| 
 | |
|   Services.cookies.removeAll();
 | |
|   // make sure that sessionstore.js can be forced to be created by setting
 | |
|   // the interval pref to 0
 | |
|   yield SpecialPowers.pushPrefEnv({
 | |
|     set: [["browser.sessionstore.interval", 0]]
 | |
|   });
 | |
| 
 | |
|   let win = yield BrowserTestUtils.openNewBrowserWindow();
 | |
|   let browser = win.gBrowser.selectedBrowser;
 | |
|   browser.loadURI(testURL);
 | |
|   yield BrowserTestUtils.browserLoaded(browser);
 | |
| 
 | |
|   yield TabStateFlusher.flush(browser);
 | |
| 
 | |
|   // get the sessionstore state for the window
 | |
|   let state = ss.getWindowState(win);
 | |
| 
 | |
|   // verify our cookie got set during pageload
 | |
|   let enumerator = Services.cookies.enumerator;
 | |
|   let cookie;
 | |
|   let i = 0;
 | |
|   while (enumerator.hasMoreElements()) {
 | |
|     cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
 | |
|     i++;
 | |
|   }
 | |
|   Assert.equal(i, 1, "expected one cookie");
 | |
| 
 | |
|   // remove the cookie
 | |
|   Services.cookies.removeAll();
 | |
| 
 | |
|   // restore the window state
 | |
|   ss.setWindowState(win, state, true);
 | |
| 
 | |
|   // at this point, the cookie should be restored...
 | |
|   enumerator = Services.cookies.enumerator;
 | |
|   let cookie2;
 | |
|   while (enumerator.hasMoreElements()) {
 | |
|     cookie2 = enumerator.getNext().QueryInterface(Ci.nsICookie);
 | |
|     if (cookie.name == cookie2.name)
 | |
|       break;
 | |
|   }
 | |
|   is(cookie.name, cookie2.name, "cookie name successfully restored");
 | |
|   is(cookie.value, cookie2.value, "cookie value successfully restored");
 | |
|   is(cookie.path, cookie2.path, "cookie path successfully restored");
 | |
| 
 | |
|   // clean up
 | |
|   Services.cookies.removeAll();
 | |
|   yield BrowserTestUtils.closeWindow(win);
 | |
| });
 |