| 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/Back Button Restore 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/dom", "dojo/keys", "dojo/query", "dojo/robotx", "dijit/tests/helpers", "dojo/domReady!" |
| 16 | ], function(doh, dom, keys, query, robot, helpers){ |
| 17 | |
| 18 | // This page tests that the editor's value won't be lost if the user |
| 19 | // accidentally navigates to a different page, and then returns to the |
| 20 | // page w/the editor by pressing the back button. |
| 21 | |
| 22 | robot.initRobot('../BackForwardState.html'); |
| 23 | |
| 24 | var registry; |
| 25 | doh.register("setup", [ |
| 26 | { |
| 27 | name: "wait for editors to load", |
| 28 | timeout: 5000, |
| 29 | runTest: helpers.waitForLoad |
| 30 | }, |
| 31 | function setVars(){ |
| 32 | registry = robot.window.require("dijit/registry"); |
| 33 | } |
| 34 | ]); |
| 35 | |
| 36 | doh.register("back button restore", [ |
| 37 | { |
| 38 | name: "set editor value", |
| 39 | timeout: 10000, |
| 40 | runTest: function(){ |
| 41 | var d = new doh.Deferred(); |
| 42 | |
| 43 | var editor0 = registry.byId("editor0"), |
| 44 | editor1 = registry.byId("editor1"); |
| 45 | |
| 46 | doh.is("editor0 original contents", editor0.get('value')); |
| 47 | doh.is("editor1 original contents", editor1.get('value')); |
| 48 | |
| 49 | editor0.set('value', 'hello'); |
| 50 | editor1.set('value', 'goodbye'); |
| 51 | |
| 52 | robot.sequence(d.getTestCallback(function(){ |
| 53 | doh.is("hello", editor0.get('value')); |
| 54 | doh.is("goodbye", editor1.get('value')); |
| 55 | }), 500); |
| 56 | |
| 57 | return d; |
| 58 | } |
| 59 | }, |
| 60 | { |
| 61 | name: "navigate away", |
| 62 | timeout: 10000, |
| 63 | runTest: function(){ |
| 64 | return robot.waitForPageToLoad(function(){ |
| 65 | // On most browsers just focusing causes navigation. On safari |
| 66 | // need to click... |
| 67 | var away = dom.byId("away", robot.doc); |
| 68 | dom.byId("away", robot.doc).focus(); |
| 69 | robot.keyPress(keys.ENTER, 500); |
| 70 | }); |
| 71 | } |
| 72 | }, |
| 73 | { |
| 74 | name: "confirm navigation to new page worked", |
| 75 | runTest: function(){ |
| 76 | // Confirm that we successfully navigated away |
| 77 | doh.is("Back/forward test helper page", (query("h1", robot.doc)[0]||{}).innerHTML); |
| 78 | } |
| 79 | }, |
| 80 | { |
| 81 | name: "go back to original page", |
| 82 | timeout: 10000, |
| 83 | runTest: function(){ |
| 84 | return robot.waitForPageToLoad(function(){ |
| 85 | // On most browsers just focusing causes navigation. On safari |
| 86 | // need to click... |
| 87 | var back = dom.byId("back", robot.doc); |
| 88 | back.focus(); |
| 89 | robot.keyPress(keys.ENTER, 500); |
| 90 | }); |
| 91 | } |
| 92 | }, |
| 93 | { |
| 94 | name: "wait for editors to load again", |
| 95 | timeout: 5000, |
| 96 | runTest: helpers.waitForLoad |
| 97 | }, |
| 98 | function setVarsAgain(){ |
| 99 | registry = robot.window.require("dijit/registry"); |
| 100 | }, |
| 101 | { |
| 102 | name: "check that editor values restored", |
| 103 | timeout: 10000, |
| 104 | runTest: function(){ |
| 105 | var d = new doh.Deferred(); |
| 106 | |
| 107 | robot.sequence(d.getTestCallback(function(){ |
| 108 | var editor0 = registry.byId("editor0"), |
| 109 | editor1 = registry.byId("editor1"); |
| 110 | |
| 111 | doh.t(editor0, "editor0 found"); |
| 112 | doh.is("hello", editor0.get('value')); |
| 113 | |
| 114 | doh.t(editor1, "editor1 found"); |
| 115 | doh.is("goodbye", editor1.get('value')); |
| 116 | }), 500); |
| 117 | |
| 118 | return d; |
| 119 | } |
| 120 | } |
| 121 | ]); |
| 122 | |
| 123 | doh.run(); |
| 124 | }); |
| 125 | </script> |
| 126 | </head> |
| 127 | </html> |