2011-05-03 Evan Martin <evan@chromium.org>
authorevan@chromium.org <evan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2011 22:23:22 +0000 (22:23 +0000)
committerevan@chromium.org <evan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2011 22:23:22 +0000 (22:23 +0000)
        Reviewed by Ojan Vafai.

        REGRESSION: backspace should not go back on Linux
        https://bugs.webkit.org/show_bug.cgi?id=59731

        Add a test that verifies that pressing backspace goes back on Mac
        and Windows but does not go back on Linux.

        * fast/events/backspace-navigates-back-expected.txt: Added.
        * fast/events/backspace-navigates-back.html: Added.
2011-04-28  Evan Martin  <evan@chromium.org>

        Reviewed by Ojan Vafai.

        REGRESSION: backspace should not go back on Linux
        https://bugs.webkit.org/show_bug.cgi?id=59731

        Add a new EditingBehavior, shouldNavigateBackOnBackspace, which is false on
        Linux, and test for it in the default backspace handler.

        * editing/EditingBehavior.h:
        (WebCore::EditingBehavior::shouldNavigateBackOnBackspace):
        * page/EventHandler.cpp:
        (WebCore::EventHandler::defaultBackspaceEventHandler):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@85893 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/backspace-navigates-back-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/backspace-navigates-back.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/EditingBehavior.h
Source/WebCore/page/EventHandler.cpp

index a025089..6c7a121 100644 (file)
@@ -1,3 +1,16 @@
+2011-05-03  Evan Martin  <evan@chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        REGRESSION: backspace should not go back on Linux
+        https://bugs.webkit.org/show_bug.cgi?id=59731
+
+        Add a test that verifies that pressing backspace goes back on Mac
+        and Windows but does not go back on Linux.
+
+        * fast/events/backspace-navigates-back-expected.txt: Added.
+        * fast/events/backspace-navigates-back.html: Added.
+
 2011-05-05  Alpha Lam  <hclam@chromium.org>
 
         Build fix. Not reviewed.
diff --git a/LayoutTests/fast/events/backspace-navigates-back-expected.txt b/LayoutTests/fast/events/backspace-navigates-back-expected.txt
new file mode 100644 (file)
index 0000000..2e4eb64
--- /dev/null
@@ -0,0 +1,2 @@
+This test passes if it says PASS below.
+PASS: test complete
diff --git a/LayoutTests/fast/events/backspace-navigates-back.html b/LayoutTests/fast/events/backspace-navigates-back.html
new file mode 100644 (file)
index 0000000..eee7184
--- /dev/null
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<script>
+function expect(test, msg) {
+    if (test)
+        return true;
+
+    log.innerText = 'FAIL: expected ' + msg;
+    layoutTestController.notifyDone();
+    return false;
+}
+
+function testBackspaceNavigatesBack() {
+    eventSender.keyDown('\u0008');
+
+    // We expected to navigate; set a timeout that causes the test
+    // to fail quickly if we didn't navigate.
+    setTimeout(function() {
+        expect(false, 'navigation back');
+    }, 500);
+}
+
+function doStep(step, location) {
+    // This function is called on each page load.
+    // 'step' increases with each page load, while 'location' is the query param for the page load.
+    // Since we go back and forwards, we assert that 'location' is what we expect upon the entry to each step.
+
+    switch (step) {
+    case 0:
+        document.location = '?test-start';
+        break;
+    case 1:
+        if (!expect(location == 'test-start', 'navigation to test-start'))
+            return;
+        document.location = '?test-mac';
+        break;
+    case 2:
+        if (!expect(location == 'test-mac', 'navigation to test-mac'))
+            return;
+
+        layoutTestController.setEditingBehavior('mac');
+        testBackspaceNavigatesBack();
+
+        break;
+    case 3:
+        if (!expect(location == 'test-start', 'navigation back to test-start'))
+            return;
+        document.location = '?test-win';
+        break;
+    case 4:
+        if (!expect(location == 'test-win', 'navigation to test-win'))
+            return;
+
+        layoutTestController.setEditingBehavior('win');
+        testBackspaceNavigatesBack();
+
+        break;
+    case 5:
+        if (!expect(location == 'test-start', 'navigation back to test-start'))
+            return;
+        document.location = '?test-unix';
+        break;
+    case 6:
+        if (!expect(location == 'test-unix', 'navigation to test-unix'))
+            return;
+
+        // Test unix behavior: that backspace does not go back.
+        layoutTestController.setEditingBehavior('unix');
+
+        // We expect backspace to *not* navigate.
+        // Start a navigation to the success page; if backspace causes us to go back,
+        // it will cancel that navigation and navigate us elsewhere, causing the test
+        // to fail.
+        document.location = '?test-complete';
+        eventSender.keyDown('\u0008');
+
+        break;
+    case 7:
+        if (!expect(location == 'test-complete', 'navigation to test-complete'))
+            return;
+        log.innerText += 'PASS: test complete';
+        sessionStorage.removeItem('step');
+        layoutTestController.notifyDone();
+    }
+}
+
+window.onpageshow = function() {
+    if (!window.layoutTestController || !window.eventSender) {
+        log.innerText =
+            'This test requires eventSender and layoutTestController. ' +
+            'It cannot be run manually.';
+        return;
+    }
+    if (!location.search) {
+        sessionStorage.step = 0;
+        layoutTestController.dumpAsText();
+        layoutTestController.clearBackForwardList();
+        layoutTestController.waitUntilDone();
+    }
+
+    setTimeout(function() {
+        doStep(sessionStorage.step++, location.search.substring(1));
+    }, 0)
+}
+</script>
+<body>This test passes if it says PASS below.
+<div id=log></div>
+</body>
index 2b0a695..3a4cc50 100644 (file)
@@ -1,3 +1,18 @@
+2011-04-28  Evan Martin  <evan@chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        REGRESSION: backspace should not go back on Linux
+        https://bugs.webkit.org/show_bug.cgi?id=59731
+
+        Add a new EditingBehavior, shouldNavigateBackOnBackspace, which is false on
+        Linux, and test for it in the default backspace handler.
+
+        * editing/EditingBehavior.h:
+        (WebCore::EditingBehavior::shouldNavigateBackOnBackspace):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::defaultBackspaceEventHandler):
+
 2011-05-05  Igor Oliveira  <igor.oliveira@openbossa.org>
 
         Reviewed by Kenneth Russell.
index a367c52..003ddf8 100644 (file)
@@ -60,6 +60,9 @@ public:
     // On Mac, when processing a contextual click, the object being clicked upon should be selected.
     bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
 
+    // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back.
+    bool shouldNavigateBackOnBackspace() const { return m_type != EditingUnixBehavior; }
+
 private:
     EditingBehaviorType m_type;
 };
index 5db2a04..e66285f 100644 (file)
@@ -2906,6 +2906,9 @@ void EventHandler::defaultBackspaceEventHandler(KeyboardEvent* event)
     if (event->ctrlKey() || event->metaKey() || event->altKey() || event->altGraphKey())
         return;
 
+    if (!m_frame->editor()->behavior().shouldNavigateBackOnBackspace())
+        return;
+
     Page* page = m_frame->page();
     if (!page)
         return;