browser_focus_document.js (2955B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Test that switching from a remote document to a non-remote document fires 8 * focus correctly. 9 */ 10 addAccessibleTask(``, async function testRemoteThenLocal(browser) { 11 info("Loading about:support into same tab"); 12 let focused = waitForEvent(EVENT_FOCUS, event => { 13 const acc = event.accessible; 14 acc.QueryInterface(nsIAccessibleDocument); 15 return acc.URL == "about:support"; 16 }); 17 browser.loadURI(Services.io.newURI("about:support"), { 18 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 19 }); 20 await focused; 21 }); 22 23 /** 24 * Test that switching from a non-remote document to a remote document fires 25 * focus correctly. 26 */ 27 addAccessibleTask( 28 ``, 29 async function testLocalThenRemote(browser) { 30 info("Loading example.com into same tab"); 31 let focused = waitForEvent(EVENT_FOCUS, event => { 32 const acc = event.accessible; 33 acc.QueryInterface(nsIAccessibleDocument); 34 return acc.URL == "https://example.com/"; 35 }); 36 // The accessibility test harness removes maychangeremoteness when we run a 37 // chrome test, but we explicitly want to change remoteness now. 38 browser.setAttribute("maychangeremoteness", "true"); 39 browser.loadURI(Services.io.newURI("https://example.com/"), { 40 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 41 }); 42 await focused; 43 is(Services.focus.focusedElement, browser, "<browser> should be focused"); 44 is( 45 Services.focus.focusedWindow, 46 window, 47 "window should be properly focused" 48 ); 49 }, 50 { chrome: true, topLevel: false } 51 ); 52 53 /** 54 * Test that switching from a non-remote document to a remote document fires 55 * focus correctly. 56 */ 57 addAccessibleTask( 58 ``, 59 async function testLocalThenRemoteWithAutofocus(browser) { 60 info("Loading example.com with autofocus into same tab"); 61 // The accessibility test harness removes maychangeremoteness when we run a 62 // chrome test, but we explicitly want to change remoteness now. 63 browser.setAttribute("maychangeremoteness", "true"); 64 const url = 65 "https://example.com/document-builder.sjs?html=" + 66 encodeURIComponent(`<!doctype html><input autofocus>`); 67 let loaded = BrowserTestUtils.browserLoaded(browser); 68 browser.loadURI(Services.io.newURI(url), { 69 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 70 }); 71 await loaded; 72 is(Services.focus.focusedElement, browser, "<browser> should be focused"); 73 is( 74 Services.focus.focusedWindow, 75 window, 76 "window should be properly focused" 77 ); 78 await SpecialPowers.spawn(browser, [], async () => { 79 is( 80 content.windowUtils.IMEStatus, 81 content.windowUtils.IME_STATUS_ENABLED, 82 "IME should be enabled" 83 ); 84 }); 85 }, 86 { chrome: true, topLevel: false } 87 );