UNPKG

dijit

Version:

Dijit provides a complete collection of user interface controls based on Dojo, giving you the power to create web applications that are highly optimized for usability, performance, internationalization, accessibility, but above all deliver an incredible u

398 lines (329 loc) 12.7 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>doh.robot Editor A11Y Test</title> <style> @import "../../../../util/doh/robot/robot.css"; </style> <script type="text/javascript" src="../../../../dojo/dojo.js"></script> <script type="text/javascript"> require([ "doh/runner", "dojo/robotx", "dojo/_base/array", "dojo/dom", "dojo/keys", "dojo/_base/lang", "dojo/sniff", "dojo/window", "dijit/tests/helpers", "dojo/domReady!" ], function(doh, robot, array, dom, keys, lang, has, winUtils, helpers){ function normalize(str){ // try to do some normalization to make all browsers look // the same. Would be nice if we didn't need this, the normalization should // probably happen as pre and post filters on the editor return str. replace(' />', '/>'). replace('<br/>', ''). // FF. Because of EnterKeyHandling plugin? replace(/^<p>/, '').replace(/<\/p>$/, ''). // Safari. Because of EnterKeyHandling plugin? replace(new RegExp(String.fromCharCode(160), "g"), " "); // Safari: nbsp (char code 160) to normal space (char code 32) } robot.initRobot('../test_Editor.html'); // For some reason the meta key (meta-a for selection, meta-b for bold, etc) doesn't work // on mac/safari... use ctrl- instead, just like on windows. (#9553) var metaKey = {ctrl: true}; var editor0, editor1, editor1oldValue, editor1newValue, editor1onChange = "no onchange event yet"; var registry, focus; doh.register("setup", [ { name: "wait for editors to load", timeout: 5000, runTest: helpers.waitForLoad }, function setVars(){ registry = robot.window.require("dijit/registry"); focus = robot.window.require("dijit/focus"); editor0 = registry.byId("editor0"); editor1 = registry.byId("editor1"); editor1.watch("value", function(attr, oldVal, newVal){ editor1oldValue = normalize(oldVal); editor1newValue = normalize(newVal); }); editor1.onChange = function(newValue){ editor1onChange = normalize(newValue); }; } ]); doh.register("keyboard shortcuts", [ { name: "bold/italic", timeout: 15000, runTest: function(){ var d = new doh.Deferred(); winUtils.scrollIntoView(editor1.domNode); // Set contents of editor1 robot.sequence(d.getTestErrback(function(){ editor1.focus(); }), 500); robot.keyPress("a", 500, metaKey); // select all robot.typeKeys("hello ", 500, 750); // and erase (by typing something new) robot.keyPress("b", 500, metaKey); // start bold robot.typeKeys("bold", 500, 600); robot.keyPress("b", 500, metaKey); // stop bold robot.typeKeys(" and ", 500, 750); robot.keyPress("i", 500, metaKey); // start italic robot.typeKeys("exciting", 500, 1200); robot.keyPress("i", 500, metaKey); // stop italic robot.typeKeys(" new world.", 500, 1650); robot.sequence(d.getTestCallback(function(){ var val = normalize(editor1.get('value')); doh.is("hello <b>bold</b> and <i>exciting</i> new world.", val); }), 500); return d; } } ]); // Check that toolbar buttons are depressed/not depressed (etc.) based on // where caret is in document doh.register("toolbar state", [ { name: "setup", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); winUtils.scrollIntoView(editor1.domNode); // strange things happen if you alter an editor's value while it is focused, // so temporarily move to the toolbar while setting content robot.keyPress(keys.TAB, 500, {shift: true}); // go to toolbar robot.sequence(d.getTestErrback(function(){ editor1.set("value", "toolbar <b>state</b> <i>test</i>."); // set() should fire watch() callbacks but not call onChange() doh.is("toolbar <b>state</b> <i>test</i>.", editor1newValue, "value set successfully"); doh.is("no onchange event yet", editor1onChange, "onChange not called"); }), 500); robot.keyPress(keys.TAB, 500); // goes to content robot.keyPress(keys.HOME, 500, {}); // go to start of content robot.sequence(d.getTestCallback(function(){ // just to signal that we are done })); return d; } }, { name: "no buttons depressed", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); robot.sequence(d.getTestCallback(function(){ var toolbar = editor1.toolbar; doh.t(toolbar, "found toolbar"); var boldButton = toolbar.getChildren()[7]; doh.t(boldButton, "found bold button"); doh.f(boldButton.get("checked"), "bold button not depressed"); var italicButton = toolbar.getChildren()[8]; doh.t(italicButton, "found italic button"); doh.f(italicButton.get("checked"), "italic button not depressed"); }), 500); return d; } }, { name: "bold button depressed", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); robot.sequence(d.getTestErrback(function(){ editor1.placeCursorAtStart(); }), 500); for(var i = 0; i < 9; i++){ // Move to second letter of second word. robot.keyPress(keys.RIGHT_ARROW, 500); } robot.sequence(d.getTestCallback(function(){ var toolbar = editor1.toolbar; doh.t(toolbar, "found toolbar"); var boldButton = toolbar.getChildren()[7]; doh.t(boldButton, "found bold button"); doh.t(boldButton.get("checked"), "bold button depressed"); var italicButton = toolbar.getChildren()[8]; doh.t(italicButton, "found italic button"); doh.f(italicButton.get("checked"), "italic button not depressed"); }), 1000); return d; } }, { name: "italic button depressed", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); robot.sequence(d.getTestErrback(function(){ editor1.placeCursorAtStart(); }), 500); for(var i = 0; i < 15; i++){ // Move to second letter of third word. robot.keyPress(keys.RIGHT_ARROW, 500); } robot.sequence(d.getTestCallback(function(){ var toolbar = editor1.toolbar; doh.t(toolbar, "found toolbar"); var boldButton = toolbar.getChildren()[7]; doh.t(boldButton, "found bold button"); doh.f(boldButton.get("checked"), "bold button not depressed"); var italicButton = toolbar.getChildren()[8]; doh.t(italicButton, "found italic button"); doh.t(italicButton.get("checked"), "italic button depressed"); }), 1000); return d; } } ]); doh.register("toolbar navigation", [ { name: "bold", timeout: 15000, runTest: function(){ var d = new doh.Deferred(); winUtils.scrollIntoView(editor1.domNode); // Write "hello" in editor and also make sure there's something in the system // clipboard, so that the paste button in the toolbar is guaranteed to be enabled. // (otherwise the two RIGHT_ARROW commands below will overshoot the bold button // and end up on the italic button) robot.sequence(d.getTestErrback(function(){ editor1.focus(); }), 500); robot.keyPress("a", 1000, metaKey); // select all robot.keyPress("c", 500, has("mac") ? {meta: true} : {ctrl: true}); // copy into clipboard robot.typeKeys("hello ", 500, 900); // and erase (by typing something new) // Go to toolbar and turn on bold. // We only have to right-arrow twice because it skips the vertical divider bars // and also skips cut and copy (they are disabled b/c nothing is selected) robot.keyPress(keys.TAB, 500, {shift: true}); robot.keyPress(keys.RIGHT_ARROW, 1000); robot.keyPress(keys.RIGHT_ARROW, 500); robot.keyPress(keys.SPACE, 500); // Focus and caret should be back after "hello ", type "world" in bold robot.typeKeys("world", 1000, 750); robot.sequence(d.getTestCallback(function(){ // Get the value and try to do some normalization to make all browsers look // the same. Would be nice if we didn't need this, the normalization should // probably happen as pre and post filters on the editor var val = normalize(editor1.get('value')); doh.is("hello <b>world</b>", val); }), 1500); return d; } } ]); doh.register("tabbing", [ { name: "into editor1 toolbar", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); winUtils.scrollIntoView(editor1.domNode); // Focus on link before editor robot.sequence(d.getTestErrback(function(){ dom.byId("focusBefore", robot.doc).focus(); }), 500); // Go to toolbar of editor1 robot.keyPress(keys.TAB, 500); // We should get focus on one of the toolbar buttons, although which one depends // on whether the editor's contents have been modified (undo button enabled), and // whether there is something in the browser's paste buffer, etc.) robot.sequence(d.getTestCallback(function(){ var curFocus = registry.getEnclosingWidget(focus.curNode); doh.isNot(-1, array.indexOf(editor1.toolbar.getChildren(), curFocus), "focused on button of editor1 toolbar"); }), 500); return d; } }, { name: "into editor1", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); // Go to content of editor1 robot.keyPress(keys.TAB, 500); robot.sequence(d.getTestErrback(function(){ doh.is("editor1_iframe", focus.curNode.id, "focused on editor content"); }), 500); robot.keyPress("a", 500, metaKey); // select all robot.typeKeys("tabbing test", 500, 1800); // and replace with "tabbing test" robot.sequence(d.getTestCallback(function(){ // just here to make deferred fire }), 500); return d; } }, { name: "out of editor1", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); // Go to link after editor1 robot.keyPress(keys.TAB, 500); robot.sequence(d.getTestCallback(function(){ doh.is("focusAfter", focus.curNode.id, "focused after editor1"); doh.is("tabbing test", editor1newValue, "watch()"); doh.is("tabbing test", editor1onChange, "onChange"); }), 500); return d; } }, { name: "shift-tab back into editor1", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); // Go to content of editor1 robot.keyPress(keys.TAB, 500, {shift: true}); robot.sequence(d.getTestCallback(function(){ doh.is("editor1_iframe", focus.curNode.id, "focused on editor content"); }), 500); return d; } }, { name: "shift-tab back to toolbar", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); robot.keyPress(keys.TAB, 500, {shift: true}); robot.sequence(d.getTestCallback(function(){ var curFocus = registry.getEnclosingWidget(focus.curNode); doh.isNot(-1, array.indexOf(editor1.toolbar.getChildren(), curFocus), "focused on button of editor1 toolbar"); }), 500); return d; } }, { name: "shift-tab to before editor", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); robot.keyPress(keys.TAB, 500, {shift: true}); robot.sequence(d.getTestCallback(function(){ doh.is("focusBefore", focus.curNode.id, "focused before editor1"); }), 500); return d; } } ]); doh.register("clear then focus", { name: "#10268", timeout: 10000, runTest: function(){ var d = new doh.Deferred(); dom.byId("focusBefore", robot.doc).focus(); winUtils.scrollIntoView(editor1.domNode); editor1.set("value", ""); editor1.focus(); robot.typeKeys("hello ", 500, 750); robot.sequence(d.getTestCallback(function(){ doh.is("hello", lang.trim(editor1.get("value")), "get('value')"); }), 500); return d; } }); doh.run(); }); </script> </head> </html>