| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>doh.robot Editor FontChoice Plugin Test</title> |
| 6 | |
| 7 | <style> |
| 8 | @import "../../../../util/doh/robot/robot.css"; |
| 9 | </style> |
| 10 | |
| 11 | <script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
| 12 | |
| 13 | <script type="text/javascript"> |
| 14 | require([ |
| 15 | "doh/runner", "dojo/robotx", |
| 16 | "dojo/_base/array", "dojo/dom", "dojo/sniff", "dojo/window", "dijit/tests/helpers", "dojo/domReady!" |
| 17 | ], function(doh, robot, array, dom, has, winUtils, helpers){ |
| 18 | |
| 19 | robot.initRobot('../test_FontChoice.html'); |
| 20 | |
| 21 | var editor; // points to one of the editors (editor0, editor1, etc.) |
| 22 | var fcPlugin; // formatBlock, fontSize, or fontName plugin |
| 23 | var value; // HTML value of editor |
| 24 | |
| 25 | function getPlugin(/*String*/ command){ |
| 26 | var editor = registry.byId("editor0"); |
| 27 | var edPlugins = editor._plugins, i; |
| 28 | for(i = 0; i < edPlugins.length; i++){ |
| 29 | var p = edPlugins[i]; |
| 30 | if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command == command){ |
| 31 | return p; |
| 32 | } |
| 33 | } |
| 34 | throw new Error("didn't find plugin " + command); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | var registry; |
| 39 | doh.register("setup", [ |
| 40 | { |
| 41 | name: "wait for editors to load", |
| 42 | timeout: 5000, |
| 43 | runTest: helpers.waitForLoad |
| 44 | }, |
| 45 | function setVars(){ |
| 46 | registry = robot.window.require("dijit/registry"); |
| 47 | } |
| 48 | ]); |
| 49 | |
| 50 | // Verify that the formatBlock, fontSize, and fontName |
| 51 | // plugins correctly display the format / font-size / font-name of the selected text. |
| 52 | |
| 53 | doh.register("FontChoice: verify current format/font-size/font-name", |
| 54 | array.map( |
| 55 | [ |
| 56 | {id: "para0", format: "p"}, |
| 57 | {id: "pre0", format: "pre"}, |
| 58 | {id: "h10", format: "h1"}, |
| 59 | {id: "h20", format: "h2"}, |
| 60 | {id: "h30", format: "h3"}, |
| 61 | {id: "sizedText1", size: "1"}, |
| 62 | {id: "sizedText4", size: "4"}, |
| 63 | {id: "sizedText7", size: "7"}, |
| 64 | {id: "comicText", name: "Comic Sans MS"} |
| 65 | ], |
| 66 | function(params){ |
| 67 | return { |
| 68 | name: [ |
| 69 | "Verify", |
| 70 | params.format ? "format " + params.format.toUpperCase() : "", |
| 71 | params.size ? "font size " + params.size : "", |
| 72 | params.name ? "font name " + params.name : "", |
| 73 | "Identified" |
| 74 | ].join(" ").replace(/ +/g, " "), |
| 75 | timeout: 20000, |
| 76 | setUp: function(){ |
| 77 | editor = registry.byId("editor0"); |
| 78 | value = editor.get("value"); |
| 79 | }, |
| 80 | runTest: function(){ |
| 81 | var d = new doh.Deferred(); |
| 82 | |
| 83 | // Focus on the editor window |
| 84 | winUtils.scrollIntoView(editor.domNode); |
| 85 | editor.focus(); |
| 86 | robot.mouseMoveAt(editor.iframe, 1000); |
| 87 | robot.mouseClick({left:true}, 1000); |
| 88 | |
| 89 | robot.sequence(d.getTestErrback(function(){ |
| 90 | // Find node w/specified id |
| 91 | var node = dom.byId(params.id, editor.document); |
| 92 | doh.is(params.id, node && node.id, "found " + params.id); |
| 93 | |
| 94 | // Select the text, collapse to the start of it |
| 95 | editor.selection.selectElementChildren(node); |
| 96 | editor.selection.collapse(true); |
| 97 | }),1000); |
| 98 | robot.sequence(d.getTestErrback(function(){ |
| 99 | // Make sure states update. |
| 100 | editor.onDisplayChanged(); |
| 101 | }), 1000); |
| 102 | robot.sequence(d.getTestCallback(function(){ |
| 103 | if(params.format){ |
| 104 | doh.is(params.format, getPlugin("formatBlock").button.get("value"), "format " + params.format + " identified."); |
| 105 | } |
| 106 | if(params.size){ |
| 107 | doh.is(params.size, getPlugin("fontSize").button.get("value"), "font size " + params.size + " identified."); |
| 108 | } |
| 109 | if(params.name){ |
| 110 | doh.is(params.name, getPlugin("fontName").button.get("value"), "font name" + params.name + " identified."); |
| 111 | } |
| 112 | }), 2000); |
| 113 | |
| 114 | return d; |
| 115 | }, |
| 116 | tearDown: function(){ |
| 117 | if(editor){editor.set("value", value);} |
| 118 | } |
| 119 | }; // end of return { ... |
| 120 | } // end of function() |
| 121 | ) // end of array.map() |
| 122 | ); // end of doh.register() |
| 123 | |
| 124 | // Test changing format/font-size/font-name (ex: changing an <h1> to an <h2>) |
| 125 | doh.register("FontChoice: change format/font-size/font", |
| 126 | array.map( |
| 127 | [ |
| 128 | {id: "text", type: "formatBlock", from: "p", to: "pre"}, |
| 129 | {id: "text", type: "formatBlock", from: "pre", to: "h1"}, |
| 130 | {id: "text", type: "formatBlock", from: "h1", to: "h2"}, |
| 131 | {id: "text", type: "formatBlock", from: "h2", to: "h3"}, |
| 132 | {id: "sizedText7", type: "fontSize", from: "7", to: "3"}, |
| 133 | {id: "comicText", type: "fontName", from: "Comic Sans MS", to: "Times New Roman"} |
| 134 | ], |
| 135 | function(params){ |
| 136 | return { |
| 137 | name: "formatBlock: Verify can change " + params.type + " " + |
| 138 | params.from.toUpperCase() + " to " + params.to.toUpperCase(), |
| 139 | timeout: 20000, |
| 140 | setUp: function(){ |
| 141 | fcPlugin = getPlugin(params.type); |
| 142 | value = editor.get("value"); |
| 143 | }, |
| 144 | runTest: function(){ |
| 145 | var d = new doh.Deferred(); |
| 146 | |
| 147 | // Focus on the editor window |
| 148 | winUtils.scrollIntoView(editor.domNode); |
| 149 | editor.focus(); |
| 150 | robot.mouseMoveAt(editor.iframe, 1000); |
| 151 | robot.mouseClick({left:true}, 1000); |
| 152 | |
| 153 | robot.sequence(d.getTestErrback(function(){ |
| 154 | // Find node |
| 155 | var p = dom.byId(params.id, editor.document); |
| 156 | doh.is(params.id, p && p.id, "found node"); |
| 157 | |
| 158 | // Select the text, collapse to the start of it |
| 159 | editor.selection.selectElementChildren(p); |
| 160 | // Disable collapse. Webkit changed behavior so it now requires |
| 161 | // a selection. |
| 162 | if(!has("webkit")){ editor.selection.collapse(true) } |
| 163 | |
| 164 | // Set the format / font-size / font-name plugin to the new value |
| 165 | // TODO: use mouse/keyboard to set the value |
| 166 | fcPlugin.button.set("value", params.to); |
| 167 | }),1000); |
| 168 | robot.sequence(d.getTestErrback(function(){ |
| 169 | // Make sure states update. |
| 170 | editor.onDisplayChanged(); |
| 171 | }), 1000); |
| 172 | robot.sequence(d.getTestCallback(function(){ |
| 173 | doh.is(params.to, fcPlugin.button.get("value"), "verify converted"); |
| 174 | |
| 175 | // TODO: check that it actually changed the format / font-size / font-name (in the editor contents) |
| 176 | }), 2000); |
| 177 | |
| 178 | return d; |
| 179 | }, |
| 180 | tearDown: function(){ |
| 181 | if(editor){editor.set("value", value);} |
| 182 | } |
| 183 | }; // end of return { ... |
| 184 | } // end of function() |
| 185 | ) // end of array.map() |
| 186 | ); // end of doh.register() |
| 187 | |
| 188 | doh.register("formatBlock: multiple changes", |
| 189 | { |
| 190 | name: "formatBlock: Verify changing multiple nodes to h3", |
| 191 | timeout: 20000, |
| 192 | setUp: function(){ |
| 193 | editor = registry.byId("editor0"); |
| 194 | fcPlugin = getPlugin("formatBlock"); |
| 195 | value = editor.get("value"); |
| 196 | }, |
| 197 | runTest: function(){ |
| 198 | var d = new doh.Deferred(); |
| 199 | |
| 200 | // Focus on the editor window |
| 201 | winUtils.scrollIntoView(editor.domNode); |
| 202 | editor.focus(); |
| 203 | robot.mouseMoveAt(editor.iframe, 1000); |
| 204 | robot.mouseClick({left:true}, 1000); |
| 205 | |
| 206 | // Verify the formatBlock plugin was found |
| 207 | doh.t(fcPlugin !== null, "formatBlock was found"); |
| 208 | |
| 209 | robot.sequence(d.getTestErrback(function(){ |
| 210 | var p = dom.byId("text", editor.document); |
| 211 | doh.is("text", p && p.id, "found text"); |
| 212 | |
| 213 | // Select the text, collapse to the start of it |
| 214 | editor.selection.selectElementChildren(p); |
| 215 | editor.selection.collapse(true); |
| 216 | |
| 217 | // Set the format / font-size / font-name plugin to the new value |
| 218 | // TODO: use mouse/keyboard to set the value |
| 219 | fcPlugin.button.set("value", "h3"); |
| 220 | }),1000); |
| 221 | robot.sequence(d.getTestErrback(function(){ |
| 222 | // Make sure states update. |
| 223 | editor.onDisplayChanged(); |
| 224 | }), 1000); |
| 225 | robot.sequence(d.getTestErrback(function(){ |
| 226 | doh.is("h3", fcPlugin.button.get("value"), "Verify first P converted to H3."); |
| 227 | // TODO: check that it actually changed the format (in the editor contents) |
| 228 | }), 2000); |
| 229 | |
| 230 | // Move to the next block and try to change it to h3 too. |
| 231 | robot.sequence(d.getTestErrback(function(){ |
| 232 | var p = dom.byId("text1", editor.document); |
| 233 | doh.is("text1", p && p.id, "found text1"); |
| 234 | |
| 235 | // Select the text, collapse to the start of it |
| 236 | editor.selection.selectElementChildren(p); |
| 237 | editor.selection.collapse(true); |
| 238 | |
| 239 | // Set the format / font-size / font-name plugin to the new value |
| 240 | // TODO: use mouse/keyboard to set the value |
| 241 | fcPlugin.button.set("value", "h3"); |
| 242 | }),1000); |
| 243 | robot.sequence(d.getTestErrback(function(){ |
| 244 | // Make sure states update. |
| 245 | editor.onDisplayChanged(); |
| 246 | }), 1000); |
| 247 | robot.sequence(d.getTestErrback(function(){ |
| 248 | // state should have updated, so, now set value. |
| 249 | // TODO: use mouse/keyboard to set the value |
| 250 | fcPlugin.button.set("value", "h3"); |
| 251 | }),1000); |
| 252 | robot.sequence(d.getTestErrback(function(){ |
| 253 | // Make sure states update. |
| 254 | editor.onDisplayChanged(); |
| 255 | }), 1000); |
| 256 | robot.sequence(d.getTestCallback(function(){ |
| 257 | doh.is("h3", fcPlugin.button.get("value"), "Verify second P converted to H3."); |
| 258 | // TODO: check that it actually changed the format (in the editor contents) |
| 259 | }), 2000); |
| 260 | |
| 261 | return d; |
| 262 | }, |
| 263 | tearDown: function(){ |
| 264 | if(editor){editor.set("value", value);} |
| 265 | } |
| 266 | } |
| 267 | ); |
| 268 | |
| 269 | doh.register("FontChoice: Format Removal Tests", [ |
| 270 | { |
| 271 | name: "formatBlock: Verify single level format is removed (inside format block).", |
| 272 | timeout: 20000, |
| 273 | setUp: function(){ |
| 274 | editor = registry.byId("editor0"); |
| 275 | fcPlugin = getPlugin("formatBlock"); |
| 276 | value = editor.get("value"); |
| 277 | }, |
| 278 | runTest: function(){ |
| 279 | var d = new doh.Deferred(); |
| 280 | |
| 281 | // Focus on the editor window |
| 282 | winUtils.scrollIntoView(editor.domNode); |
| 283 | editor.focus(); |
| 284 | robot.mouseMoveAt(editor.iframe, 1000); |
| 285 | robot.mouseClick({left:true}, 1000); |
| 286 | |
| 287 | // Verify the formatBlock plugin was found |
| 288 | doh.t(fcPlugin !== null, "formatBlock was found"); |
| 289 | |
| 290 | robot.sequence(d.getTestErrback(function(){ |
| 291 | var p = dom.byId("text", editor.document); |
| 292 | doh.is("text", p && p.id, "found text"); |
| 293 | |
| 294 | // Select the text, collapse to the start of it |
| 295 | editor.selection.selectElementChildren(p); |
| 296 | editor.selection.collapse(true); |
| 297 | }),1000); |
| 298 | robot.sequence(d.getTestErrback(function(){ |
| 299 | // Make sure states update. |
| 300 | editor.onDisplayChanged(); |
| 301 | }), 1000); |
| 302 | robot.sequence(d.getTestErrback(function(){ |
| 303 | fcPlugin.button.set("value", "noFormat"); |
| 304 | }), 1000); |
| 305 | robot.sequence(d.getTestErrback(function(){ |
| 306 | // Make sure states update. |
| 307 | // If change occurred, then the value should |
| 308 | // still be noFormat. |
| 309 | editor.onDisplayChanged(); |
| 310 | }), 1000); |
| 311 | robot.sequence(d.getTestCallback(function(){ |
| 312 | doh.is("noFormat", fcPlugin.button.get("value"), |
| 313 | "Validating current cursor point format is noFormat"); |
| 314 | }), 1000); |
| 315 | |
| 316 | return d; |
| 317 | }, |
| 318 | tearDown: function(){ |
| 319 | if(editor){editor.set("value", value);} |
| 320 | } |
| 321 | }, |
| 322 | { |
| 323 | name: "formatBlock: Verify multiple format removal via selection", |
| 324 | timeout: 20000, |
| 325 | setUp: function(){ |
| 326 | editor = registry.byId("editor0"); |
| 327 | fcPlugin = getPlugin("formatBlock"); |
| 328 | value = editor.get("value"); |
| 329 | }, |
| 330 | runTest: function(){ |
| 331 | var d = new doh.Deferred(); |
| 332 | |
| 333 | // Focus on the editor window |
| 334 | winUtils.scrollIntoView(editor.domNode); |
| 335 | editor.focus(); |
| 336 | robot.mouseMoveAt(editor.iframe, 1000); |
| 337 | robot.mouseClick({left:true}, 1000); |
| 338 | |
| 339 | // Verify the formatBlock plugin was found |
| 340 | doh.isNot(null, fcPlugin, "formatBlock was found"); |
| 341 | |
| 342 | robot.sequence(d.getTestErrback(function(){ |
| 343 | var p = dom.byId("text", editor.document); |
| 344 | doh.is("text", p && p.id, "found text"); |
| 345 | |
| 346 | // Select the text, collapse to the start of it |
| 347 | editor.selection.selectElementChildren(p); |
| 348 | editor.selection.collapse(true); |
| 349 | }),1000); |
| 350 | robot.sequence(d.getTestErrback(function(){ |
| 351 | // Make sure states update. |
| 352 | editor.onDisplayChanged(); |
| 353 | }), 1000); |
| 354 | robot.sequence(d.getTestErrback(function(){ |
| 355 | // Select the children of the block and try to flatten the formatting. |
| 356 | var selection = dom.byId("selectionContainer", editor.document); |
| 357 | winUtils.scrollIntoView(selection); |
| 358 | editor.selection.selectElementChildren(selection); |
| 359 | fcPlugin.button.set("value", "noFormat"); |
| 360 | }), 1000); |
| 361 | robot.sequence(d.getTestCallback(function(){ |
| 362 | // Now check that the elements are all gone. |
| 363 | var selection = dom.byId("selectionContainer", editor.document); |
| 364 | doh.t(selection.childNodes.length > 0, |
| 365 | "Checking that there are still child nodes, actual was " + selection.childNodes.length); |
| 366 | |
| 367 | var i; |
| 368 | var nodes = selection.childNodes; |
| 369 | for(i = 0; i < nodes.length; i++){ |
| 370 | var n = nodes[i]; |
| 371 | if(n.nodeType == 1){ |
| 372 | var tag = n.nodeName ? n.nodeName.toLowerCase() : ""; |
| 373 | doh.isNot("p", tag, "selection node #" + i + " of " + nodes.length); |
| 374 | doh.isNot("h3", tag, "selection node #" + i + " of " + nodes.length); |
| 375 | doh.isNot("pre", tag, "selection node #" + i + " of " + nodes.length); |
| 376 | } |
| 377 | } |
| 378 | }), 1000); |
| 379 | |
| 380 | return d; |
| 381 | }, |
| 382 | tearDown: function(){ |
| 383 | if(editor){editor.set("value", value);} |
| 384 | } |
| 385 | } |
| 386 | ]); |
| 387 | |
| 388 | doh.register("FontChoice: miscellaneous tests", [ |
| 389 | { |
| 390 | name: "FontChoice: Plain Text labels", |
| 391 | timeout: 20000, |
| 392 | setUp: function(){ |
| 393 | editor = registry.byId("editor1"); |
| 394 | fcPlugin = []; |
| 395 | var edPlugins = editor._plugins, i; |
| 396 | for(i = 0; i < edPlugins.length; i++){ |
| 397 | var p = edPlugins[i]; |
| 398 | if(p.declaredClass === "dijit._editor.plugins.FontChoice"){ |
| 399 | fcPlugin.push(p); |
| 400 | } |
| 401 | } |
| 402 | value = editor.get("value"); |
| 403 | }, |
| 404 | runTest: function(){ |
| 405 | // summary: |
| 406 | // This test goes through all the registered FontChoice plugins |
| 407 | // and verifies that they're all using plain text labels in the dropdown. |
| 408 | var d = new doh.Deferred(); |
| 409 | |
| 410 | // Focus on the editor window |
| 411 | winUtils.scrollIntoView(editor.domNode); |
| 412 | editor.focus(); |
| 413 | robot.mouseMoveAt(editor.iframe, 1000); |
| 414 | robot.mouseClick({left:true}, 1000); |
| 415 | robot.sequence(d.getTestCallback(function(){ |
| 416 | for(var i = 0; i < fcPlugin.length; i++){ |
| 417 | var p = fcPlugin[i]; |
| 418 | var store = p.button.select.store; |
| 419 | var items = store.query(); |
| 420 | for(var j = 0; j < items.length; j++){ |
| 421 | var item = items[j]; |
| 422 | doh.f(item.name.indexOf("<") === 0, "failed on: " + item.name); |
| 423 | } |
| 424 | } |
| 425 | }), 1000); |
| 426 | |
| 427 | return d; |
| 428 | }, |
| 429 | tearDown: function(){ |
| 430 | if(editor){editor.set("value", value);} |
| 431 | } |
| 432 | }, |
| 433 | { |
| 434 | name: "FontChoice: Validate usage of generic names", |
| 435 | timeout: 20000, |
| 436 | setUp: function(){ |
| 437 | editor = registry.byId("generic"); |
| 438 | fcPlugin = null; |
| 439 | var edPlugins = editor._plugins, i; |
| 440 | for(i = 0; i < edPlugins.length; i++){ |
| 441 | var p = edPlugins[i]; |
| 442 | if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command === "fontName" && p.generic){ |
| 443 | fcPlugin = p; |
| 444 | } |
| 445 | } |
| 446 | value = editor.get("value"); |
| 447 | }, |
| 448 | runTest: function(){ |
| 449 | // summary: |
| 450 | // This test goes through the font choice plugin registered as generic font names and validates |
| 451 | // the font names in the values are the generic map. |
| 452 | var d = new doh.Deferred(); |
| 453 | |
| 454 | // Focus on the editor window |
| 455 | winUtils.scrollIntoView(editor.domNode); |
| 456 | editor.focus(); |
| 457 | robot.mouseMoveAt(editor.iframe, 1000); |
| 458 | robot.mouseClick({left:true}, 1000); |
| 459 | robot.sequence(d.getTestCallback(function(){ |
| 460 | var map = { |
| 461 | "sans-serif": false, |
| 462 | "serif": false, |
| 463 | "cursive": false, |
| 464 | "monospace": false, |
| 465 | "fantasy": false |
| 466 | }; |
| 467 | var store = fcPlugin.button.select.store; |
| 468 | var items = store.query(); |
| 469 | for(var j = 0; j < items.length; j++){ |
| 470 | var item = items[j]; |
| 471 | map[item.value] = true; |
| 472 | } |
| 473 | for(j in map){ |
| 474 | doh.t(map[j], j); |
| 475 | } |
| 476 | }), 1000); |
| 477 | |
| 478 | return d; |
| 479 | }, |
| 480 | tearDown: function(){ |
| 481 | if(editor){editor.set("value", value);} |
| 482 | } |
| 483 | }, |
| 484 | { |
| 485 | name: "FontChoice: Validate custom font names", |
| 486 | timeout: 20000, |
| 487 | setUp: function(){ |
| 488 | editor = registry.byId("custom"); |
| 489 | fcPlugin = null; |
| 490 | var edPlugins = editor._plugins, i; |
| 491 | for(i = 0; i < edPlugins.length; i++){ |
| 492 | var p = edPlugins[i]; |
| 493 | if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command === "fontName" && p.custom){ |
| 494 | fcPlugin = p; |
| 495 | } |
| 496 | } |
| 497 | value = editor.get("value"); |
| 498 | }, |
| 499 | runTest: function(){ |
| 500 | // summary: |
| 501 | // This test goes through the font choice plugin registered as custom font names and validates |
| 502 | // the font names in the values are the provided names. |
| 503 | var d = new doh.Deferred(); |
| 504 | |
| 505 | // Focus on the editor window |
| 506 | winUtils.scrollIntoView(editor.domNode); |
| 507 | editor.focus(); |
| 508 | robot.mouseMoveAt(editor.iframe, 1000); |
| 509 | robot.mouseClick({left:true}, 1000); |
| 510 | robot.sequence(d.getTestCallback(function(){ |
| 511 | var map = { |
| 512 | "Verdana": false, |
| 513 | "Myriad": false, |
| 514 | "Garamond": false |
| 515 | }; |
| 516 | var store = fcPlugin.button.select.store; |
| 517 | var items = store.query(); |
| 518 | for(var j = 0; j < items.length; j++){ |
| 519 | var item = items[j]; |
| 520 | map[item.value] = true; |
| 521 | } |
| 522 | for(j in map){ |
| 523 | doh.t(map[j], j); |
| 524 | } |
| 525 | }), 1000); |
| 526 | |
| 527 | return d; |
| 528 | }, |
| 529 | tearDown: function(){ |
| 530 | if(editor){editor.set("value", value);} |
| 531 | } |
| 532 | } |
| 533 | ]); |
| 534 | doh.run(); |
| 535 | }); |
| 536 | </script> |
| 537 | </head> |
| 538 | </html> |