// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. // // /// /// /// module ContentDialogTests { "use strict"; var ContentDialog = WinJS.UI.ContentDialog; var testRoot: HTMLElement; var Utils = ContentDialogTests.Utilities; var createDialog; export class FocusTests { setUp() { Helper.initUnhandledErrors(); testRoot = document.createElement("div"); createDialog = Utils.makeCreateDialog(testRoot); document.body.appendChild(testRoot); } tearDown() { Helper.cleanupUnhandledErrors(); WinJS.Utilities.disposeSubTree(testRoot); var parent = testRoot.parentNode; parent && parent.removeChild(testRoot); } testInitialFocusWithoutFocusableContent(complete) { var dialog = Utils.useSynchronousAnimations(createDialog({ innerHTML: "Some text" })); Helper.waitForFocusWithin(dialog.element, function () { dialog.show(); }).then(function () { LiveUnit.Assert.areEqual( dialog.element.querySelector("." + ContentDialog._ClassNames.dialog), document.activeElement, "When no content is focusable, the dialog itself should receive focus" ); dialog.hide(); Helper.validateUnhandledErrors(); complete(); }); } testInitialFocusWithFocusableContent(complete) { var innerHTML = 'Some text' + '' + '' + ''; var dialog = Utils.useSynchronousAnimations(createDialog({ innerHTML: innerHTML })); Helper.waitForFocusWithin(dialog.element, function () { dialog.show(); }).then(function () { LiveUnit.Assert.areEqual( dialog.element.querySelector("." + ContentDialog._ClassNames.dialog), document.activeElement, "The dialog itself should receive focus" ); dialog.hide(); Helper.validateUnhandledErrors(); complete(); }); } testFocusIsRestoredAfterHiding(complete) { testRoot.innerHTML = 'Some text' + '' + '' + ''; var externalButton2 = testRoot.querySelector(".externalButton2"); var innerHTML = 'Some text' + '' + '' + ''; var dialog = Utils.useSynchronousAnimations(createDialog({ innerHTML: innerHTML })); Helper.focus(externalButton2).then(function () { LiveUnit.Assert.areEqual(externalButton2, document.activeElement, "externalButton2 should have received focus"); return Helper.waitForFocusWithin(dialog.element, function () { dialog.show(); }); }).then(function () { LiveUnit.Assert.isTrue((dialog.element).contains(document.activeElement), "Focus should moved into the dialog"); Helper.waitForFocus(externalButton2, function () { dialog.hide(); }); }).then(function () { LiveUnit.Assert.areEqual(externalButton2, document.activeElement, "Focus should have been restored to externalButton2 after hiding the dialog"); Helper.validateUnhandledErrors(); complete(); }); } } } LiveUnit.registerTestClass("ContentDialogTests.FocusTests");