forked from mirrors/gecko-dev
		
	 cf6ef6a24b
			
		
	
	
		cf6ef6a24b
		
	
	
	
	
		
			
			I think I caught all the places in our tree that add event listeners for these events on a non-Window (and hence depend on bubbling behavior), but I'm a little worried about what happens if webextensions do bareword addEventListener() for these events... Differential Revision: https://phabricator.services.mozilla.com/D66798 --HG-- extra : moz-landing-system : lando
		
			
				
	
	
		
			87 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| 
 | |
| const PATH = getRootDirectory(gTestPath).replace(
 | |
|   "chrome://mochitests/content/",
 | |
|   "http://example.com/"
 | |
| );
 | |
| const URL = PATH + "file_async_duplicate_tab.html";
 | |
| 
 | |
| add_task(async function test_duplicate() {
 | |
|   // Create new tab.
 | |
|   let tab = BrowserTestUtils.addTab(gBrowser, URL);
 | |
|   let browser = tab.linkedBrowser;
 | |
|   await promiseBrowserLoaded(browser);
 | |
| 
 | |
|   // Flush to empty any queued update messages.
 | |
|   await TabStateFlusher.flush(browser);
 | |
| 
 | |
|   // Click the link to navigate, this will add second shistory entry.
 | |
|   await SpecialPowers.spawn(browser, [], async function() {
 | |
|     return new Promise(resolve => {
 | |
|       docShell.chromeEventHandler.addEventListener(
 | |
|         "hashchange",
 | |
|         () => resolve(),
 | |
|         { once: true, capture: true }
 | |
|       );
 | |
| 
 | |
|       // Click the link.
 | |
|       content.document.querySelector("a").click();
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   // Duplicate the tab.
 | |
|   let tab2 = ss.duplicateTab(window, tab);
 | |
| 
 | |
|   // Wait until the tab has fully restored.
 | |
|   await promiseTabRestored(tab2);
 | |
|   await TabStateFlusher.flush(tab2.linkedBrowser);
 | |
| 
 | |
|   // There should be two history entries now.
 | |
|   let { entries } = JSON.parse(ss.getTabState(tab2));
 | |
|   is(entries.length, 2, "there are two shistory entries");
 | |
| 
 | |
|   // Cleanup.
 | |
|   BrowserTestUtils.removeTab(tab2);
 | |
|   BrowserTestUtils.removeTab(tab);
 | |
| });
 | |
| 
 | |
| add_task(async function test_duplicate_remove() {
 | |
|   // Create new tab.
 | |
|   let tab = BrowserTestUtils.addTab(gBrowser, URL);
 | |
|   let browser = tab.linkedBrowser;
 | |
|   await promiseBrowserLoaded(browser);
 | |
| 
 | |
|   // Flush to empty any queued update messages.
 | |
|   await TabStateFlusher.flush(browser);
 | |
| 
 | |
|   // Click the link to navigate, this will add second shistory entry.
 | |
|   await SpecialPowers.spawn(browser, [], async function() {
 | |
|     return new Promise(resolve => {
 | |
|       docShell.chromeEventHandler.addEventListener(
 | |
|         "hashchange",
 | |
|         () => resolve(),
 | |
|         { once: true, capture: true }
 | |
|       );
 | |
| 
 | |
|       // Click the link.
 | |
|       content.document.querySelector("a").click();
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   // Duplicate the tab.
 | |
|   let tab2 = ss.duplicateTab(window, tab);
 | |
| 
 | |
|   // Before the duplication finished, remove the tab.
 | |
|   await Promise.all([
 | |
|     promiseRemoveTabAndSessionState(tab),
 | |
|     promiseTabRestored(tab2),
 | |
|   ]);
 | |
|   await TabStateFlusher.flush(tab2.linkedBrowser);
 | |
| 
 | |
|   // There should be two history entries now.
 | |
|   let { entries } = JSON.parse(ss.getTabState(tab2));
 | |
|   is(entries.length, 2, "there are two shistory entries");
 | |
| 
 | |
|   // Cleanup.
 | |
|   BrowserTestUtils.removeTab(tab2);
 | |
| });
 |