3 function expect(test
, msg
) {
7 log
.innerText
= 'FAIL: expected ' + msg
;
8 testRunner
.notifyDone();
12 function testBackspaceNavigatesBack() {
13 eventSender
.keyDown('\u0008');
15 // We expected to navigate; set a timeout that causes the test
16 // to fail quickly if we didn't navigate.
17 setTimeout(function() {
18 expect(false, 'navigation back');
22 function doStep(step
, location
) {
23 // This function is called on each page load.
24 // 'step' increases with each page load, while 'location' is the query param for the page load.
25 // Since we go back and forwards, we assert that 'location' is what we expect upon the entry to each step.
29 document
.location
= '?test-start';
32 if (!expect(location
== 'test-start', 'navigation to test-start'))
34 document
.location
= '?test-mac';
37 if (!expect(location
== 'test-mac', 'navigation to test-mac'))
40 internals
.settings
.setEditingBehavior('mac');
41 testBackspaceNavigatesBack();
45 if (!expect(location
== 'test-start', 'navigation back to test-start'))
47 document
.location
= '?test-win';
50 if (!expect(location
== 'test-win', 'navigation to test-win'))
53 internals
.settings
.setEditingBehavior('win');
54 testBackspaceNavigatesBack();
58 if (!expect(location
== 'test-start', 'navigation back to test-start'))
60 document
.location
= '?test-unix';
63 if (!expect(location
== 'test-unix', 'navigation to test-unix'))
66 // Test unix behavior: that backspace does not go back.
67 internals
.settings
.setEditingBehavior('unix');
69 // We expect backspace to *not* navigate.
70 // Start a navigation to the success page; if backspace causes us to go back,
71 // it will cancel that navigation and navigate us elsewhere, causing the test
73 document
.location
= '?test-complete';
74 eventSender
.keyDown('\u0008');
78 if (!expect(location
== 'test-complete', 'navigation to test-complete'))
80 log
.innerText
+= 'PASS: test complete';
81 sessionStorage
.removeItem('step');
82 testRunner
.notifyDone();
86 window
.onpageshow = function() {
87 if (!window
.testRunner
|| !window
.eventSender
|| !window
.internals
) {
89 'This test requires eventSender, testRunner and window.internals. ' +
90 'It cannot be run manually.';
93 if (!location
.search
) {
94 sessionStorage
.step
= 0;
95 testRunner
.dumpAsText();
96 testRunner
.clearBackForwardList();
97 testRunner
.waitUntilDone();
100 setTimeout(function() {
101 doStep(sessionStorage
.step
++, location
.search
.substring(1));
105 <body>This test passes if it says PASS below.