| 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 LinkDialog 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/dom", "dijit/tests/helpers", "dojo/domReady!" |
| 17 | ], function(doh, robot, dom, helpers){ |
| 18 | |
| 19 | robot.initRobot('../test_LinkDialog.html'); |
| 20 | |
| 21 | var editor; |
| 22 | var ldPlugin; |
| 23 | var value; |
| 24 | var node; |
| 25 | |
| 26 | var registry, focus; |
| 27 | doh.register("setup", [ |
| 28 | { |
| 29 | name: "wait for editors to load", |
| 30 | timeout: 5000, |
| 31 | runTest: helpers.waitForLoad |
| 32 | }, |
| 33 | function setVars(){ |
| 34 | registry = robot.window.require("dijit/registry"); |
| 35 | focus = robot.window.require("dijit/focus"); |
| 36 | } |
| 37 | ]); |
| 38 | |
| 39 | doh.register("LinkDialog_tests", [ |
| 40 | function setUp(){ |
| 41 | editor = registry.byId("editor"); |
| 42 | ldPlugin = null; |
| 43 | var edPlugins = editor._plugins, i; |
| 44 | for(i = 0; i < edPlugins.length; i++){ |
| 45 | var p = edPlugins[i]; |
| 46 | if(p.declaredClass === "dijit._editor.plugins.LinkDialog"){ |
| 47 | ldPlugin = p; |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | doh.t(ldPlugin != null, "found link dialog."); |
| 52 | }, |
| 53 | |
| 54 | { |
| 55 | name: "Anchor Tag: Create a new link", |
| 56 | timeout: 20000, |
| 57 | setUp: function(){ |
| 58 | value = editor.get("value"); |
| 59 | }, |
| 60 | runTest: function(){ |
| 61 | var d = new doh.Deferred(); |
| 62 | |
| 63 | // Focus on the editor window |
| 64 | editor.focus(); |
| 65 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 66 | robot.mouseClick({left:true}, 500); |
| 67 | |
| 68 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 69 | robot.mouseClick({left:true}, 500); |
| 70 | var url, desc; |
| 71 | robot.sequence(d.getTestErrback(function(){ |
| 72 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 73 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 74 | url.set("value", "http://example.com/"); |
| 75 | desc.set("value", "This is my example link."); |
| 76 | }),2000); |
| 77 | |
| 78 | robot.mouseMoveAt(function(){return registry.byId(ldPlugin._uniqueId + "_setButton").domNode;}, 500, 1); |
| 79 | robot.mouseClick({left:true}, 500); |
| 80 | robot.sequence(d.getTestCallback(function(){ |
| 81 | // Now check the state! |
| 82 | var newVal = editor.get("value"); |
| 83 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 84 | doh.t(new RegExp("href=(\"|\')http://example.com/(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 85 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.), newVal =" + newVal); |
| 86 | doh.t(new RegExp("target=(\"|\')_self(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 87 | doh.t(new RegExp(">This is my example link.<").test(newVal), "Verifying description has been inserted."); |
| 88 | }), 2000); |
| 89 | |
| 90 | return d; |
| 91 | }, |
| 92 | tearDown: function(){ |
| 93 | if(editor){editor.set("value", value);} |
| 94 | } |
| 95 | }, |
| 96 | { |
| 97 | name: "Anchor Tag: Create a new link with alternate target", |
| 98 | timeout: 20000, |
| 99 | setUp: function(){ |
| 100 | value = editor.get("value"); |
| 101 | }, |
| 102 | runTest: function(){ |
| 103 | var d = new doh.Deferred(); |
| 104 | |
| 105 | // Focus on the editor window |
| 106 | editor.focus(); |
| 107 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 108 | robot.mouseClick({left:true}, 500); |
| 109 | |
| 110 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 111 | robot.mouseClick({left:true}, 500); |
| 112 | |
| 113 | var url, target, desc; |
| 114 | robot.sequence(d.getTestErrback(function(){ |
| 115 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 116 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 117 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 118 | url.set("value", "http://example.com/"); |
| 119 | desc.set("value", "This is my example link."); |
| 120 | target.set("value", "_blank"); |
| 121 | }),2000); |
| 122 | robot.mouseMoveAt(function(){return registry.byId(ldPlugin._uniqueId + "_setButton").domNode;}, 500, 1); |
| 123 | robot.mouseClick({left:true}, 500); |
| 124 | robot.sequence(d.getTestCallback(function(){ |
| 125 | // Now check the state! |
| 126 | var newVal = editor.get("value"); |
| 127 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 128 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 129 | doh.t(new RegExp("href=(\"|\')http://example.com/(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 130 | doh.t(new RegExp("target=(\"|\')_blank(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 131 | doh.t(new RegExp(">This is my example link.<").test(newVal), "Verifying description has been inserted."); |
| 132 | }), 2000); |
| 133 | |
| 134 | return d; |
| 135 | }, |
| 136 | tearDown: function(){ |
| 137 | if(editor){editor.set("value", value);} |
| 138 | } |
| 139 | }, |
| 140 | { |
| 141 | name: "Anchor Tag: Test auto insertion of http:// for urls.", |
| 142 | timeout: 20000, |
| 143 | setUp: function(){ |
| 144 | value = editor.get("value"); |
| 145 | }, |
| 146 | runTest: function(){ |
| 147 | var d = new doh.Deferred(); |
| 148 | |
| 149 | // Focus on the editor window |
| 150 | editor.focus(); |
| 151 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 152 | robot.mouseClick({left:true}, 500); |
| 153 | |
| 154 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 155 | robot.mouseClick({left:true}, 500); |
| 156 | |
| 157 | var url, desc, target; |
| 158 | robot.sequence(d.getTestErrback(function(){ |
| 159 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 160 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 161 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 162 | url.set("value", "example.com/"); |
| 163 | desc.set("value", "This is my example link."); |
| 164 | target.set("value", "_blank"); |
| 165 | }),2000); |
| 166 | robot.mouseMoveAt(function(){return registry.byId(ldPlugin._uniqueId + "_setButton").domNode;}, 500, 1); |
| 167 | robot.mouseClick({left:true}, 500); |
| 168 | robot.sequence(d.getTestCallback(function(){ |
| 169 | // Now check the state! |
| 170 | var newVal = editor.get("value"); |
| 171 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 172 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 173 | doh.t(new RegExp("href=(\"|\')http://example.com/(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 174 | doh.t(new RegExp("target=(\"|\')_blank(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 175 | doh.t(new RegExp(">This is my example link.<").test(newVal), "Verifying description has been inserted."); |
| 176 | }), 2000); |
| 177 | |
| 178 | return d; |
| 179 | }, |
| 180 | tearDown: function(){ |
| 181 | if(editor){editor.set("value", value);} |
| 182 | } |
| 183 | }, |
| 184 | { |
| 185 | name: "Anchor Tag: Test insertion 'relative' urls (./)", |
| 186 | timeout: 20000, |
| 187 | setUp: function(){ |
| 188 | value = editor.get("value"); |
| 189 | }, |
| 190 | runTest: function(){ |
| 191 | var d = new doh.Deferred(); |
| 192 | |
| 193 | // Focus on the editor window |
| 194 | editor.focus(); |
| 195 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 196 | robot.mouseClick({left:true}, 500); |
| 197 | |
| 198 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 199 | robot.mouseClick({left:true}, 500); |
| 200 | |
| 201 | var url, desc, target; |
| 202 | robot.sequence(d.getTestErrback(function(){ |
| 203 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 204 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 205 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 206 | url.set("value", "./myDirectory/myfile.html"); |
| 207 | desc.set("value", "This is my example relative link."); |
| 208 | target.set("value", "_blank"); |
| 209 | }),2000); |
| 210 | robot.mouseMoveAt(function(){return registry.byId(ldPlugin._uniqueId + "_setButton").domNode;}, 500, 1); |
| 211 | robot.mouseClick({left:true}, 500); |
| 212 | robot.sequence(d.getTestCallback(function(){ |
| 213 | // Now check the state! |
| 214 | var newVal = editor.get("value"); |
| 215 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 216 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 217 | doh.t(new RegExp("href=(\"|\')\./myDirectory/myfile.html(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 218 | doh.t(new RegExp("target=(\"|\')_blank(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 219 | doh.t(new RegExp(">This is my example relative link.<").test(newVal), "Verifying description has been inserted."); |
| 220 | }), 2000); |
| 221 | |
| 222 | return d; |
| 223 | }, |
| 224 | tearDown: function(){ |
| 225 | if(editor){editor.set("value", value);} |
| 226 | } |
| 227 | }, |
| 228 | { |
| 229 | name: "Anchor Tag: Test insertion 'relative' url (../)", |
| 230 | timeout: 20000, |
| 231 | setUp: function(){ |
| 232 | value = editor.get("value"); |
| 233 | }, |
| 234 | runTest: function(){ |
| 235 | var d = new doh.Deferred(); |
| 236 | |
| 237 | // Focus on the editor window |
| 238 | editor.focus(); |
| 239 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 240 | robot.mouseClick({left:true}, 500); |
| 241 | |
| 242 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 243 | robot.mouseClick({left:true}, 500); |
| 244 | |
| 245 | var url, desc, target; |
| 246 | robot.sequence(d.getTestErrback(function(){ |
| 247 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 248 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 249 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 250 | url.set("value", "../myDirectory/myfile.html"); |
| 251 | desc.set("value", "This is my example relative link."); |
| 252 | target.set("value", "_blank"); |
| 253 | }),2000); |
| 254 | robot.mouseMoveAt(function(){return registry.byId(ldPlugin._uniqueId + "_setButton").domNode;}, 500, 1); |
| 255 | robot.mouseClick({left:true}, 500); |
| 256 | robot.sequence(d.getTestCallback(function(){ |
| 257 | // Now check the state! |
| 258 | var newVal = editor.get("value"); |
| 259 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 260 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 261 | doh.t(new RegExp("href=(\"|\')\.\./myDirectory/myfile.html(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 262 | doh.t(new RegExp("target=(\"|\')_blank(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 263 | doh.t(new RegExp(">This is my example relative link.<").test(newVal), "Verifying description has been inserted."); |
| 264 | }), 2000); |
| 265 | |
| 266 | return d; |
| 267 | }, |
| 268 | tearDown: function(){ |
| 269 | if(editor){editor.set("value", value);} |
| 270 | } |
| 271 | }, |
| 272 | { |
| 273 | name: "Anchor Tag: Update existing anchor tag", |
| 274 | timeout: 20000, |
| 275 | setUp: function(){ |
| 276 | node = dom.byId("exampleLink", editor.document); |
| 277 | value = editor.get("value"); |
| 278 | }, |
| 279 | runTest: function(){ |
| 280 | var d = new doh.Deferred(); |
| 281 | |
| 282 | // Focus on the editor window |
| 283 | editor.focus(); |
| 284 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 285 | robot.mouseClick({left:true}, 500); |
| 286 | |
| 287 | robot.sequence(d.getTestErrback(function(){ |
| 288 | // Okay, select the text of the hyperlink so we can then perform an edit on it. |
| 289 | editor.selection.selectElement(node); |
| 290 | }),500); |
| 291 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 292 | robot.mouseClick({left:true}, 500); |
| 293 | var url, desc, target, oldUrl, oldDesc; |
| 294 | robot.sequence(d.getTestErrback(function(){ |
| 295 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 296 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 297 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 298 | |
| 299 | oldUrl = url.get("value"); |
| 300 | doh.is("http://www.example.com/example.html", oldUrl, "old url"); |
| 301 | oldDesc = desc.get("value"); |
| 302 | doh.is("This is an example link in the page.", oldDesc, "old desc"); |
| 303 | |
| 304 | url.set("value", oldUrl + "_2"); |
| 305 | desc.set("value", oldDesc + "_2"); |
| 306 | target.set("value", "_blank"); |
| 307 | }), 2000); |
| 308 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 309 | robot.mouseClick({left:true}, 500); |
| 310 | robot.sequence(d.getTestCallback(function(){ |
| 311 | // Now check the state! |
| 312 | var newVal = editor.get("value"); |
| 313 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 314 | doh.t(new RegExp("href=(\"|\')"+ oldUrl + "_2" + "(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 315 | doh.f(new RegExp("href=(\"|\')"+ oldUrl + "(\"|\')").test(newVal), "Verifying old URL is gone."); |
| 316 | doh.f(new RegExp("<li><a").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 317 | doh.t(new RegExp("target=(\"|\')_blank(\"|\')").test(newVal), "Verifying target has been inserted."); |
| 318 | doh.f(new RegExp("target=(\"|\')_self(\"|\')").test(newVal), "Verifying old target is removed."); |
| 319 | doh.t(new RegExp(">" + oldDesc + "_2<").test(newVal), "Verifying description has been inserted."); |
| 320 | doh.f(new RegExp(">" + oldDesc + "<").test(newVal), "Verifying old desc is gone."); |
| 321 | }), 2000); |
| 322 | |
| 323 | return d; |
| 324 | }, |
| 325 | tearDown: function(){ |
| 326 | if(editor){editor.set("value", value);} |
| 327 | } |
| 328 | }, |
| 329 | { |
| 330 | name: "Anchor Tag: Blank description invalid.", |
| 331 | timeout: 20000, |
| 332 | setUp: function(){ |
| 333 | node = dom.byId("exampleLink", editor.document); |
| 334 | value = editor.get("value"); |
| 335 | }, |
| 336 | runTest: function(){ |
| 337 | var d = new doh.Deferred(); |
| 338 | |
| 339 | // Focus on the editor window |
| 340 | editor.focus(); |
| 341 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 342 | robot.mouseClick({left:true}, 500); |
| 343 | |
| 344 | robot.sequence(d.getTestErrback(function(){ |
| 345 | // Okay, select the text of the hyperlink so we can then perform an edit on it. |
| 346 | editor.selection.selectElement(node); |
| 347 | }),500); |
| 348 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 349 | robot.mouseClick({left:true}, 500); |
| 350 | var url, desc, target, oldDesc; |
| 351 | robot.sequence(d.getTestErrback(function(){ |
| 352 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 353 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 354 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 355 | oldDesc = desc.get("value"); |
| 356 | desc.set("value", ""); |
| 357 | target.set("value", "_blank"); |
| 358 | }), 2000); |
| 359 | robot.sequence(d.getTestErrback(function(){ |
| 360 | // Verify setting the content is disabled. |
| 361 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 362 | doh.t(setButton.get("disabled")); |
| 363 | }), 500); |
| 364 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_cancelButton").domNode; }, 500, 1); |
| 365 | robot.mouseClick({left:true}, 500); |
| 366 | robot.sequence(d.getTestCallback(function(){ |
| 367 | // Now check the state! |
| 368 | var newVal = editor.get("value"); |
| 369 | doh.is(value, newVal, "Verify the contents have not changed."); |
| 370 | }), 2000); |
| 371 | |
| 372 | return d; |
| 373 | }, |
| 374 | tearDown: function(){ |
| 375 | if(editor){editor.set("value", value);} |
| 376 | } |
| 377 | }, |
| 378 | { |
| 379 | name: "Anchor Tag: Test invalid url.", |
| 380 | timeout: 20000, |
| 381 | setUp: function(){ |
| 382 | value = editor.get("value"); |
| 383 | }, |
| 384 | runTest: function(){ |
| 385 | var d = new doh.Deferred(); |
| 386 | |
| 387 | // Focus on the editor window |
| 388 | editor.focus(); |
| 389 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 390 | robot.mouseClick({left:true}, 500); |
| 391 | |
| 392 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 393 | robot.mouseClick({left:true}, 500); |
| 394 | |
| 395 | var url, desc, target; |
| 396 | robot.sequence(d.getTestErrback(function(){ |
| 397 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 398 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 399 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 400 | url.set("value", "http://this is not/valid/bad.html"); |
| 401 | desc.set("value", "This is my example relative link."); |
| 402 | target.set("value", "_blank"); |
| 403 | url.validate(); |
| 404 | }),2000); |
| 405 | robot.sequence(d.getTestErrback(function(){ |
| 406 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 407 | doh.t(setButton.get("disabled"), "set button disabled"); |
| 408 | }), 500); |
| 409 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_cancelButton").domNode; }, 500, 1); |
| 410 | robot.mouseClick({left:true}, 500); |
| 411 | robot.mouseMoveAt(editor.iframe, 500, 0, 0, 0); |
| 412 | robot.mouseClick({left:true}, 500); |
| 413 | robot.sequence(d.getTestCallback(function(){ |
| 414 | // Now check the state! |
| 415 | var newVal = editor.get("value"); |
| 416 | doh.is(value, newVal, "Verify the contents have not changed."); |
| 417 | doh.f(url.isValid(), "url.isValid"); |
| 418 | }), 2000); |
| 419 | return d; |
| 420 | }, |
| 421 | tearDown: function(){ |
| 422 | if(editor){editor.set("value", value);} |
| 423 | } |
| 424 | }, |
| 425 | { |
| 426 | name: "Anchor Tag: Test mailto url.", |
| 427 | timeout: 20000, |
| 428 | setUp: function(){ |
| 429 | value = editor.get("value"); |
| 430 | }, |
| 431 | runTest: function(){ |
| 432 | var d = new doh.Deferred(); |
| 433 | |
| 434 | // Focus on the editor window |
| 435 | editor.focus(); |
| 436 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 437 | robot.mouseClick({left:true}, 500); |
| 438 | |
| 439 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 440 | robot.mouseClick({left:true}, 500); |
| 441 | |
| 442 | var url, desc, target; |
| 443 | robot.sequence(d.getTestErrback(function(){ |
| 444 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 445 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 446 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 447 | url.set("value", "mailto:[email protected]"); |
| 448 | desc.set("value", "Send a message to John."); |
| 449 | target.set("value", "_blank"); |
| 450 | url.isValid(); |
| 451 | }),2000); |
| 452 | robot.sequence(d.getTestErrback(function(){ |
| 453 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 454 | doh.t(!setButton.get("disabled")); |
| 455 | }), 500); |
| 456 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 457 | robot.mouseClick({left:true}, 500); |
| 458 | robot.mouseMoveAt(editor.iframe, 500, 0, 0, 0); |
| 459 | robot.mouseClick({left:true}, 500); |
| 460 | robot.sequence(d.getTestCallback(function(){ |
| 461 | // Now check the state! |
| 462 | var newVal = editor.get("value"); |
| 463 | doh.t((newVal.indexOf("mailto:[email protected]") > -1), "Verify the contents have the mailto url present, newVal=" + newVal); |
| 464 | }), 2000); |
| 465 | |
| 466 | return d; |
| 467 | }, |
| 468 | tearDown: function(){ |
| 469 | if(editor){editor.set("value", value);} |
| 470 | } |
| 471 | }, |
| 472 | { |
| 473 | name: "Anchor Tag: Test mailto url prepend.", |
| 474 | timeout: 20000, |
| 475 | setUp: function(){ |
| 476 | value = editor.get("value"); |
| 477 | }, |
| 478 | runTest: function(){ |
| 479 | var d = new doh.Deferred(); |
| 480 | |
| 481 | // Focus on the editor window |
| 482 | editor.focus(); |
| 483 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 484 | robot.mouseClick({left:true}, 500); |
| 485 | |
| 486 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 487 | robot.mouseClick({left:true}, 500); |
| 488 | |
| 489 | var url, desc, target; |
| 490 | robot.sequence(d.getTestErrback(function(){ |
| 491 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 492 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 493 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 494 | url.set("value", "[email protected]"); |
| 495 | desc.set("value", "Send a message to John."); |
| 496 | target.set("value", "_blank"); |
| 497 | url.isValid(); |
| 498 | }),2000); |
| 499 | robot.sequence(d.getTestErrback(function(){ |
| 500 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 501 | doh.t(!setButton.get("disabled")); |
| 502 | }), 500); |
| 503 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 504 | robot.mouseClick({left:true}, 500); |
| 505 | robot.mouseMoveAt(editor.iframe, 500, 0, 0, 0); |
| 506 | robot.mouseClick({left:true}, 500); |
| 507 | robot.sequence(d.getTestCallback(function(){ |
| 508 | // Now check the state! |
| 509 | var newVal = editor.get("value"); |
| 510 | doh.t((newVal.indexOf("mailto:[email protected]") > -1), "Verify the contents have the mailto url present, newVal=" + newVal); |
| 511 | }), 2000); |
| 512 | |
| 513 | return d; |
| 514 | }, |
| 515 | tearDown: function(){ |
| 516 | if(editor){editor.set("value", value);} |
| 517 | } |
| 518 | }, |
| 519 | { |
| 520 | name: "Anchor Tag: Test invalid mailto url.", |
| 521 | timeout: 20000, |
| 522 | setUp: function(){ |
| 523 | value = editor.get("value"); |
| 524 | }, |
| 525 | runTest: function(){ |
| 526 | var d = new doh.Deferred(); |
| 527 | |
| 528 | // Focus on the editor window |
| 529 | editor.focus(); |
| 530 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 531 | robot.mouseClick({left:true}, 500); |
| 532 | |
| 533 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 534 | robot.mouseClick({left:true}, 500); |
| 535 | |
| 536 | var url, desc, target; |
| 537 | robot.sequence(d.getTestErrback(function(){ |
| 538 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 539 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 540 | target = registry.byId(ldPlugin._uniqueId + "_targetSelect"); |
| 541 | url.set("value", "mailto:john [email protected]"); |
| 542 | desc.set("value", "Send a message to John."); |
| 543 | target.set("value", "_blank"); |
| 544 | url.isValid(); |
| 545 | }),2000); |
| 546 | robot.sequence(d.getTestErrback(function(){ |
| 547 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 548 | doh.t(setButton.get("disabled")); |
| 549 | }), 500); |
| 550 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_cancelButton").domNode; }, 500, 1); |
| 551 | robot.mouseClick({left:true}, 500); |
| 552 | robot.mouseMoveAt(editor.iframe, 500, 0, 0, 0); |
| 553 | robot.mouseClick({left:true}, 500); |
| 554 | robot.sequence(d.getTestCallback(function(){ |
| 555 | var newVal = editor.get("value"); |
| 556 | doh.t(newVal === value, "Verify the contents have not changed."); |
| 557 | doh.f(url.isValid()); |
| 558 | }), 2000); |
| 559 | |
| 560 | return d; |
| 561 | }, |
| 562 | tearDown: function(){ |
| 563 | if(editor){editor.set("value", value);} |
| 564 | } |
| 565 | }, |
| 566 | { |
| 567 | name: "Anchor Tag: Double-Click opens TooltipDialog.", |
| 568 | timeout: 20000, |
| 569 | setUp: function(){ |
| 570 | node = dom.byId("exampleLink", editor.document); |
| 571 | value = editor.get("value"); |
| 572 | }, |
| 573 | runTest: function(){ |
| 574 | var d = new doh.Deferred(); |
| 575 | |
| 576 | // Focus on the editor window |
| 577 | editor.focus(); |
| 578 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 579 | robot.mouseClick({left:true}, 500); |
| 580 | |
| 581 | robot.sequence(d.getTestErrback(function(){ |
| 582 | doh.t(ldPlugin && ldPlugin.dropDown && ldPlugin.dropDown.domNode, "found TooltipDialog"); |
| 583 | doh.t(helpers.isHidden(ldPlugin.dropDown.domNode), "tooltip dialog is hidden"); |
| 584 | })); |
| 585 | |
| 586 | // Double click |
| 587 | robot.mouseMoveAt(node, 500, 1); |
| 588 | robot.mouseClick({left:true}, 100); |
| 589 | robot.mouseClick({left:true}, 100); |
| 590 | |
| 591 | var f; |
| 592 | robot.sequence(d.getTestErrback(function(){ |
| 593 | doh.t(helpers.isVisible(ldPlugin.dropDown.domNode), "tooltip dialog is visible"); |
| 594 | f = focus.curNode; |
| 595 | doh.isNot(null, f, "is focus"); |
| 596 | var w = registry.getEnclosingWidget(f); |
| 597 | doh.isNot(null, w, "focused on widget"); |
| 598 | var val = w.get("value"); |
| 599 | doh.t(new RegExp("http://www.example.com/example.html").test(val), "Verifying the contents contained link url"); |
| 600 | }), 2000); |
| 601 | |
| 602 | // Clicking the <input> shouldn't close TooltipDialog (#14395) |
| 603 | robot.mouseMoveAt(function(){ return f; }, 500, 1); |
| 604 | robot.mouseClick({left:true}, 100); |
| 605 | robot.sequence(d.getTestCallback(function(){ |
| 606 | doh.t(helpers.isVisible(ldPlugin.dropDown.domNode), "tooltip dialog still visible"); |
| 607 | }), 1000); |
| 608 | |
| 609 | return d; |
| 610 | }, |
| 611 | tearDown: function(){ |
| 612 | ldPlugin.dropDown.onCancel(); |
| 613 | if(editor){editor.set("value", value);} |
| 614 | } |
| 615 | } |
| 616 | ]); |
| 617 | |
| 618 | doh.register("ImgDialog_tests", [ |
| 619 | function setUp(){ |
| 620 | editor = registry.byId("editor"); |
| 621 | ldPlugin = null; |
| 622 | var edPlugins = editor._plugins, i; |
| 623 | for(i = 0; i < edPlugins.length; i++){ |
| 624 | var p = edPlugins[i]; |
| 625 | if(p.declaredClass === "dijit._editor.plugins.ImgLinkDialog"){ |
| 626 | ldPlugin = p; |
| 627 | break; |
| 628 | } |
| 629 | } |
| 630 | doh.t(ldPlugin != null, "found image dialog."); |
| 631 | value = editor.get("value"); |
| 632 | }, |
| 633 | |
| 634 | { |
| 635 | name: "Image Tag: Create a new image", |
| 636 | timeout: 20000, |
| 637 | setUp: function(){ |
| 638 | value = editor.get("value"); |
| 639 | }, |
| 640 | runTest: function(){ |
| 641 | var d = new doh.Deferred(); |
| 642 | |
| 643 | // Focus on the editor window |
| 644 | editor.focus(); |
| 645 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 646 | robot.mouseClick({left:true}, 500); |
| 647 | |
| 648 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 649 | robot.mouseClick({left:true}, 500); |
| 650 | |
| 651 | var url, desc; |
| 652 | robot.sequence(d.getTestErrback(function(){ |
| 653 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 654 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 655 | url.set("value", "./sample2.jpg"); |
| 656 | desc.set("value", "This is my example image 2."); |
| 657 | }),2000); |
| 658 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 659 | robot.mouseClick({left:true}, 500); |
| 660 | robot.sequence(d.getTestCallback(function(){ |
| 661 | // Now check the state! |
| 662 | var newVal = editor.get("value"); |
| 663 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 664 | doh.f(new RegExp("<li><img").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.): " + newVal); |
| 665 | doh.t(new RegExp("src=(\"|\').*/sample2.jpg(\"|\')").test(newVal), "Verifying URL has been inserted: " + newVal); |
| 666 | doh.t(new RegExp("alt=(\"|\')This is my example image 2.(\"|\')").test(newVal), "Verifying alt description has been inserted: " + newVal); |
| 667 | }), 2000); |
| 668 | |
| 669 | return d; |
| 670 | }, |
| 671 | tearDown: function(){ |
| 672 | if(editor){editor.set("value", value);} |
| 673 | } |
| 674 | }, |
| 675 | { |
| 676 | name: "Image Tag: Verify http:// is prepended", |
| 677 | timeout: 20000, |
| 678 | setUp: function(){ |
| 679 | value = editor.get("value"); |
| 680 | }, |
| 681 | runTest: function(){ |
| 682 | var d = new doh.Deferred(); |
| 683 | |
| 684 | // Focus on the editor window |
| 685 | editor.focus(); |
| 686 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 687 | robot.mouseClick({left:true}, 500); |
| 688 | |
| 689 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 690 | robot.mouseClick({left:true}, 500); |
| 691 | |
| 692 | var url, desc; |
| 693 | robot.sequence(d.getTestErrback(function(){ |
| 694 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 695 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 696 | url.set("value", "example.com/example.jpg"); |
| 697 | desc.set("value", "This is my example image."); |
| 698 | }),2000); |
| 699 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 700 | robot.mouseClick({left:true}, 500); |
| 701 | robot.sequence(d.getTestCallback(function(){ |
| 702 | // Now check the state! |
| 703 | var newVal = editor.get("value"); |
| 704 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 705 | doh.f(new RegExp("<li><img").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 706 | doh.t(new RegExp("src=(\"|\')http://example.com/example.jpg(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 707 | doh.t(new RegExp("alt=(\"|\')This is my example image.(\"|\')").test(newVal), "Verifying alt description has been inserted."); |
| 708 | }), 2000); |
| 709 | |
| 710 | return d; |
| 711 | }, |
| 712 | tearDown: function(){ |
| 713 | if(editor){editor.set("value", value);} |
| 714 | } |
| 715 | }, |
| 716 | { |
| 717 | name: "Image Tag: Update existing image tag", |
| 718 | timeout: 20000, |
| 719 | setUp: function(){ |
| 720 | node = dom.byId("exampleImage", editor.document); |
| 721 | value = editor.get("value"); |
| 722 | }, |
| 723 | runTest: function(){ |
| 724 | var d = new doh.Deferred(); |
| 725 | |
| 726 | // Focus on the editor window |
| 727 | editor.focus(); |
| 728 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 729 | robot.mouseClick({left:true}, 500); |
| 730 | |
| 731 | robot.sequence(d.getTestErrback(function(){editor.selection.selectElement(node);}), 500); |
| 732 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 733 | robot.mouseClick({left:true}, 500); |
| 734 | var url, desc, oldDesc; |
| 735 | robot.sequence(d.getTestErrback(function(){ |
| 736 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 737 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 738 | doh.t(new RegExp(".*/sample.jpg").test(url.get("value")), "original URL"); |
| 739 | oldDesc = desc.get("value"); |
| 740 | doh.is("Sample Image", oldDesc, "original alt-text"); |
| 741 | url.set("value", "./sample2.jpg"); |
| 742 | desc.set("value", oldDesc + "_2"); |
| 743 | }), 2000); |
| 744 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 745 | robot.mouseClick({left:true}, 500); |
| 746 | robot.sequence(d.getTestCallback(function(){ |
| 747 | // Now check the state! |
| 748 | var newVal = editor.get("value"); |
| 749 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 750 | doh.f(new RegExp("<li><img").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.)"); |
| 751 | doh.t(new RegExp("src=(\"|\')"+ ".*/sample2.jpg" + "(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 752 | doh.f(new RegExp("src=(\"|\')"+ ".*/sample.jpg" + "(\"|\')").test(newVal), "Verifying old URL is gone."); |
| 753 | doh.t(new RegExp("alt=(\"|\")" + oldDesc + "_2" + "(\"|\')").test(newVal), "Verifying description has been inserted."); |
| 754 | doh.f(new RegExp("alt=(\"|\")" + oldDesc + "(\"|\')").test(newVal), "Verifying old desc is gone."); |
| 755 | }), 2000); |
| 756 | |
| 757 | return d; |
| 758 | }, |
| 759 | tearDown: function(){ |
| 760 | if(editor){editor.set("value", value);} |
| 761 | } |
| 762 | }, |
| 763 | { |
| 764 | name: "Image Tag: Blank description valid.", |
| 765 | timeout: 20000, |
| 766 | setUp: function(){ |
| 767 | node = dom.byId("exampleImage", editor.document); |
| 768 | value = editor.get("value"); |
| 769 | }, |
| 770 | runTest: function(){ |
| 771 | var d = new doh.Deferred(); |
| 772 | |
| 773 | // Focus on the editor window |
| 774 | editor.focus(); |
| 775 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 776 | robot.mouseClick({left:true}, 500); |
| 777 | |
| 778 | robot.sequence(d.getTestErrback(function(){editor.selection.selectElement(node);}), 500); |
| 779 | robot.mouseMoveAt(ldPlugin.button.domNode, 500, 1); |
| 780 | robot.mouseClick({left:true}, 500); |
| 781 | var url, desc, oldDesc; |
| 782 | robot.sequence(d.getTestErrback(function(){ |
| 783 | url = registry.byId(ldPlugin._uniqueId + "_urlInput"); |
| 784 | desc = registry.byId(ldPlugin._uniqueId + "_textInput"); |
| 785 | oldDesc = desc.get("value"); |
| 786 | url.set("value", "./sample2.jpg"); |
| 787 | desc.set("value", ""); |
| 788 | }), 2000); |
| 789 | robot.sequence(d.getTestErrback(function(){ |
| 790 | // Verify setting the content is disabled. |
| 791 | var setButton = registry.byId(ldPlugin._uniqueId + "_setButton"); |
| 792 | doh.f(setButton.get("disabled")); |
| 793 | }), 500); |
| 794 | robot.mouseMoveAt(function(){ return registry.byId(ldPlugin._uniqueId + "_setButton").domNode; }, 500, 1); |
| 795 | robot.mouseClick({left:true}, 500); |
| 796 | robot.sequence(d.getTestCallback(function(){ |
| 797 | // Now check the state! |
| 798 | var newVal = editor.get("value"); |
| 799 | doh.isNot(value, newVal, "Verify the contents have changed."); |
| 800 | doh.f(new RegExp("<li><img").test(newVal), "Verifying insert did not occur in the top li (IE test for selection restore.), newVal=" + newVal); |
| 801 | doh.t(new RegExp("src=(\"|\')"+ ".*/sample2.jpg" + "(\"|\')").test(newVal), "Verifying URL has been inserted."); |
| 802 | doh.f(new RegExp("src=(\"|\')"+ ".*/sample.jpg" + "(\"|\')").test(newVal), "Verifying old URL is gone."); |
| 803 | doh.t(new RegExp("alt=(\"|\")(\"|\')").test(newVal), "Verifying description has been cleared."); |
| 804 | doh.f(new RegExp("alt=(\"|\")" + oldDesc + "(\"|\')").test(newVal), "Verifying old desc is gone."); |
| 805 | }), 2000); |
| 806 | |
| 807 | return d; |
| 808 | }, |
| 809 | tearDown: function(){ |
| 810 | if(editor){editor.set("value", value);} |
| 811 | } |
| 812 | }, |
| 813 | { |
| 814 | name: "Image Tag: Single click selects image.", |
| 815 | timeout: 20000, |
| 816 | setUp: function(){ |
| 817 | node = dom.byId("exampleImage", editor.document); |
| 818 | value = editor.get("value"); |
| 819 | }, |
| 820 | runTest: function(){ |
| 821 | var d = new doh.Deferred(); |
| 822 | |
| 823 | // Focus on the editor window |
| 824 | editor.focus(); |
| 825 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 826 | robot.mouseClick({left:true}, 500); |
| 827 | |
| 828 | robot.mouseMoveAt(node, 500, 1); |
| 829 | robot.mouseClick({left:true}, 500); |
| 830 | robot.sequence(d.getTestCallback(function(){ |
| 831 | var selectedElement = editor.selection.getSelectedElement(null); |
| 832 | doh.t(selectedElement != null); |
| 833 | var tag = selectedElement.tagName? selectedElement.tagName.toLowerCase() : ""; |
| 834 | doh.is("img", tag); |
| 835 | doh.is("exampleImage", selectedElement.getAttribute("id")); |
| 836 | }), 2000); |
| 837 | |
| 838 | return d; |
| 839 | }, |
| 840 | tearDown: function(){ |
| 841 | if(editor){editor.set("value", value);} |
| 842 | } |
| 843 | }, |
| 844 | { |
| 845 | name: "Image Tag: Double-Click opens TooltipDialog.", |
| 846 | timeout: 20000, |
| 847 | setUp: function(){ |
| 848 | node = dom.byId("exampleImage", editor.document); |
| 849 | value = editor.get("value"); |
| 850 | }, |
| 851 | runTest: function(){ |
| 852 | var d = new doh.Deferred(); |
| 853 | |
| 854 | // Focus on the editor window |
| 855 | editor.focus(); |
| 856 | robot.mouseMoveAt(editor.iframe, 1000, 1); |
| 857 | robot.mouseClick({left:true}, 500); |
| 858 | |
| 859 | robot.sequence(d.getTestErrback(function(){ |
| 860 | doh.t(ldPlugin && ldPlugin.dropDown && ldPlugin.dropDown.domNode, "found TooltipDialog"); |
| 861 | doh.t(helpers.isHidden(ldPlugin.dropDown.domNode), "tooltip dialog is hidden"); |
| 862 | })); |
| 863 | |
| 864 | // Double click |
| 865 | robot.mouseMoveAt(node, 500, 1); |
| 866 | robot.mouseClick({left:true}, 100); |
| 867 | robot.mouseClick({left:true}, 100); |
| 868 | |
| 869 | var f; |
| 870 | robot.sequence(d.getTestErrback(function(){ |
| 871 | doh.t(helpers.isVisible(ldPlugin.dropDown.domNode), "tooltip dialog is visible"); |
| 872 | |
| 873 | f = focus.curNode; |
| 874 | doh.t(f, "got focus"); |
| 875 | |
| 876 | var w = registry.getEnclosingWidget(f); |
| 877 | doh.t(w, "found enclosing widget"); |
| 878 | |
| 879 | var val = w.get("value"); |
| 880 | doh.t(new RegExp(".*/sample.jpg").test(val), "Verifying the contents contained image name"); |
| 881 | }), 2000); |
| 882 | |
| 883 | // Clicking the <input> shouldn't close TooltipDialog (#14395) |
| 884 | robot.mouseMoveAt(function(){ return f; }, 500, 1); |
| 885 | robot.mouseClick({left:true}, 100); |
| 886 | robot.sequence(d.getTestCallback(function(){ |
| 887 | doh.t(helpers.isVisible(ldPlugin.dropDown.domNode), "tooltip dialog still visible"); |
| 888 | }), 1000); |
| 889 | |
| 890 | return d; |
| 891 | }, |
| 892 | tearDown: function(){ |
| 893 | ldPlugin.dropDown.onCancel(); |
| 894 | if(editor){editor.set("value", value);} |
| 895 | } |
| 896 | } |
| 897 | ]); |
| 898 | |
| 899 | doh.run(); |
| 900 | }); |
| 901 | </script> |
| 902 | </head> |
| 903 | </html> |