forked from mirrors/gecko-dev
		
	Along with removing the view source standalone windows and prefs this patch: 1) Re-structures several of the view source tests that were only testing the old standalone windows to now test view source in tab. 2) Adds support viewSourceUtils.viewSource() to open a browser window when there aren't any open (for browser toolbox view source). 3) Cleans up some of the API for viewSourceUtils and removes the old deprecated ways of calling it. MozReview-Commit-ID: DI6sgZwbCf --HG-- extra : rebase_source : 64677186122f74ab95912d5f3f173cf37472458a
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
function wait_while_tab_is_busy() {
 | 
						|
  return new Promise(resolve => {
 | 
						|
    let progressListener = {
 | 
						|
      onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
 | 
						|
        if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
 | 
						|
          gBrowser.removeProgressListener(this);
 | 
						|
          setTimeout(resolve, 0);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    };
 | 
						|
    gBrowser.addProgressListener(progressListener);
 | 
						|
  });
 | 
						|
}
 | 
						|
 | 
						|
// This function waits for the tab to stop being busy instead of waiting for it
 | 
						|
// to load, since the canViewSource change happens at that time.
 | 
						|
var with_new_tab_opened = async function(options, taskFn) {
 | 
						|
  let busyPromise = wait_while_tab_is_busy();
 | 
						|
  let tab = await BrowserTestUtils.openNewForegroundTab(options.gBrowser, options.url, false);
 | 
						|
  await busyPromise;
 | 
						|
  await taskFn(tab.linkedBrowser);
 | 
						|
  gBrowser.removeTab(tab);
 | 
						|
};
 | 
						|
 | 
						|
add_task(async function test_regular_page() {
 | 
						|
  function test_expect_view_source_enabled(browser) {
 | 
						|
    ok(!XULBrowserWindow.canViewSource.hasAttribute("disabled"),
 | 
						|
       "View Source should be enabled");
 | 
						|
  }
 | 
						|
 | 
						|
  await with_new_tab_opened({
 | 
						|
    gBrowser,
 | 
						|
    url: "http://example.com",
 | 
						|
  }, test_expect_view_source_enabled);
 | 
						|
});
 | 
						|
 | 
						|
add_task(async function test_view_source_page() {
 | 
						|
  function test_expect_view_source_disabled(browser) {
 | 
						|
    ok(XULBrowserWindow.canViewSource.hasAttribute("disabled"),
 | 
						|
       "View Source should be disabled");
 | 
						|
  }
 | 
						|
 | 
						|
  await with_new_tab_opened({
 | 
						|
    gBrowser,
 | 
						|
    url: "view-source:http://example.com",
 | 
						|
  }, test_expect_view_source_disabled);
 | 
						|
});
 |