Title: [104606] trunk/LayoutTests
Revision
104606
Author
[email protected]
Date
2012-01-10 11:43:08 -0800 (Tue, 10 Jan 2012)

Log Message

Improve keyboard navigation in layout test results
https://bugs.webkit.org/show_bug.cgi?id=75901

Reviewed by Ojan Vafai.

Add support for keyboard shortcuts for navigating the list of tests,
and for flagging tests.

'i', 'k', 'k', and 'l' go foward, back, to first and to last, denoting
the current test with a red expand indicator.

'e', 'c' and 't' expand, collapse and toggle the current test.

'f' toggled a test as "flagged", which adds it to a copyable list
at the bottom of the document. The user can use flagging for whatever they want.

* fast/harness/resources/results-test.js:
(runTests):
(runTests.isCollapsed):
():
* fast/harness/results-expected.txt:
* fast/harness/results.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (104605 => 104606)


--- trunk/LayoutTests/ChangeLog	2012-01-10 19:38:09 UTC (rev 104605)
+++ trunk/LayoutTests/ChangeLog	2012-01-10 19:43:08 UTC (rev 104606)
@@ -1,3 +1,28 @@
+2012-01-10  Simon Fraser  <[email protected]>
+
+        Improve keyboard navigation in layout test results
+        https://bugs.webkit.org/show_bug.cgi?id=75901
+
+        Reviewed by Ojan Vafai.
+        
+        Add support for keyboard shortcuts for navigating the list of tests,
+        and for flagging tests.
+        
+        'i', 'k', 'k', and 'l' go foward, back, to first and to last, denoting
+        the current test with a red expand indicator.
+        
+        'e', 'c' and 't' expand, collapse and toggle the current test.
+        
+        'f' toggled a test as "flagged", which adds it to a copyable list
+        at the bottom of the document. The user can use flagging for whatever they want.
+
+        * fast/harness/resources/results-test.js:
+        (runTests):
+        (runTests.isCollapsed):
+        ():
+        * fast/harness/results-expected.txt:
+        * fast/harness/results.html:
+
 2012-01-10  Elliot Poger  <[email protected]>
 
         rebaselining some canvas images

Modified: trunk/LayoutTests/fast/harness/resources/results-test.js (104605 => 104606)


--- trunk/LayoutTests/fast/harness/resources/results-test.js	2012-01-10 19:38:09 UTC (rev 104605)
+++ trunk/LayoutTests/fast/harness/resources/results-test.js	2012-01-10 19:43:08 UTC (rev 104606)
@@ -181,6 +181,17 @@
         assertTrue(document.getElementById('timeout-tests-table').textContent.indexOf('expected actual diff') != -1);
     });
 
+    function isExpanded(expandLink)
+    {
+        var enDash = '\u2013';
+        return expandLink.textContent == enDash;
+    }
+
+    function isCollapsed(expandLink)
+    {
+        return expandLink.textContent == '+';
+    }
+
     results = mockResults();
     var subtree = results.tests['foo'] = {}
     subtree['bar.html'] = mockExpectation('TEXT', 'PASS');
@@ -194,21 +205,19 @@
         expandAllExpectations();
         assertTrue(document.querySelectorAll('tbody tr').length == 8);
         var expandLinks = document.querySelectorAll('.expand-button-text');
-        var enDash = '\u2013';
-        for (var i = 0; i < expandLinks.length; i++) {
-            assertTrue(expandLinks[i].textContent == enDash);
-        }
+        for (var i = 0; i < expandLinks.length; i++)
+            assertTrue(isExpanded(expandLinks[i]));
         
         collapseAllExpectations();
         // Collapsed expectations stay in the dom, but are display:none.
         assertTrue(document.querySelectorAll('tbody tr').length == 8);
         var expandLinks = document.querySelectorAll('.expand-button-text');
         for (var i = 0; i < expandLinks.length; i++)
-            assertTrue(expandLinks[i].textContent == '+');
+            assertTrue(isCollapsed(expandLinks[i]));
             
         expandExpectations(expandLinks[1]);
-        assertTrue(expandLinks[0].textContent == '+');
-        assertTrue(expandLinks[1].textContent == enDash);
+        assertTrue(isCollapsed(expandLinks[0]));
+        assertTrue(isExpanded(expandLinks[1]));
 
         collapseExpectations(expandLinks[1]);
         assertTrue(expandLinks[1].textContent == '+');
@@ -548,7 +557,60 @@
         expandAllExpectations();
         assertTrue(visibleExpandLinks().length == 2);
     });
+    
 
+    results = mockResults();
+    var subtree = results.tests['foo'] = {}
+    subtree['bar.html'] = mockExpectation('TEXT', 'FAIL');
+    subtree['bar1.html'] = mockExpectation('TEXT', 'FAIL');
+    subtree['bar2.html'] = mockExpectation('TEXT', 'FAIL');
+    
+    runTest(results, function() {
+        assertTrue(document.getElementById('results-table'));
+        assertTrue(visibleExpandLinks().length == 3);
+        
+        if (window.eventSender) {
+            eventSender.keyDown('i'); // first
+            var expandButtons = document.querySelectorAll('#results-table tbody .expand-button');
+            assertTrue(expandButtons[0].classList.contains('current'));
+            assertTrue(!expandButtons[1].classList.contains('current'));
+            assertTrue(!expandButtons[2].classList.contains('current'));
+
+            eventSender.keyDown('j'); // next
+            var expandButtons = document.querySelectorAll('#results-table tbody .expand-button');
+            assertTrue(!expandButtons[0].classList.contains('current'));
+            assertTrue(expandButtons[1].classList.contains('current'));
+            assertTrue(!expandButtons[2].classList.contains('current'));
+
+            eventSender.keyDown('k'); // previous
+            var expandButtons = document.querySelectorAll('#results-table tbody .expand-button');
+            assertTrue(expandButtons[0].classList.contains('current'));
+            assertTrue(!expandButtons[1].classList.contains('current'));
+            assertTrue(!expandButtons[2].classList.contains('current'));
+
+            eventSender.keyDown('l'); // last
+            var expandButtons = document.querySelectorAll('#results-table tbody .expand-button');
+            assertTrue(!expandButtons[0].classList.contains('current'));
+            assertTrue(!expandButtons[1].classList.contains('current'));
+            assertTrue(expandButtons[2].classList.contains('current'));
+
+            eventSender.keyDown('i'); // first
+            eventSender.keyDown('e'); // expand
+            var expandLinks = document.querySelectorAll('.expand-button-text');
+            assertTrue(isExpanded(expandLinks[0]));
+
+            eventSender.keyDown('c'); // collapse
+            assertTrue(isCollapsed(expandLinks[0]));
+
+            eventSender.keyDown('f'); // flag
+            var flaggedTestsTextbox = document.getElementById('flagged-tests');
+            flaggedTestsTextbox.innerText == 'bar.html';
+
+            eventSender.keyDown('f'); // unflag
+            flaggedTestsTextbox.innerText == '';
+        }
+    });
+
     document.body.innerHTML = '<pre>' + g_log.join('\n') + '</pre>';
 }
 

Modified: trunk/LayoutTests/fast/harness/results-expected.txt (104605 => 104606)


--- trunk/LayoutTests/fast/harness/results-expected.txt	2012-01-10 19:38:09 UTC (rev 104605)
+++ trunk/LayoutTests/fast/harness/results-expected.txt	2012-01-10 19:43:08 UTC (rev 104606)
@@ -177,3 +177,19 @@
 TEST-37: PASS
 TEST-37: PASS
 TEST-37: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS
+TEST-38: PASS

Modified: trunk/LayoutTests/fast/harness/results.html (104605 => 104606)


--- trunk/LayoutTests/fast/harness/results.html	2012-01-10 19:38:09 UTC (rev 104605)
+++ trunk/LayoutTests/fast/harness/results.html	2012-01-10 19:43:08 UTC (rev 104606)
@@ -2,12 +2,19 @@
 <style>
 body {
     margin: 4px;
+    font-family: Helvetica, sans-serif;
+    font-size: 11pt;
 }
 
 body > p:first-of-type {
     margin-top: 0;
 }
 
+h1 {
+    font-size: 14pt;
+    margin-top: 1.5em;
+}
+
 p {
     margin-bottom: 0.3em;
 }
@@ -25,7 +32,7 @@
 }
 
 td {
-    padding: 0 4px;
+    padding: 1px 4px;
 }
 
 th:empty, td:empty {
@@ -37,6 +44,11 @@
     -moz-user-select: none;
 }
 
+.note {
+    color: gray;
+    font-size: smaller;
+}
+
 .results-row {
     background-color: white;
 }
@@ -53,29 +65,39 @@
 #toolbar {
     position: fixed;
     padding: 4px;
-    top: 0;
-    right: 0;
+    top: 2px;
+    right: 2px;
     text-align: right;
-    background-color: white;
+    background-color: rgba(255, 255, 255, 0.85);
+    border: 1px solid silver;
+    border-radius: 4px;
 }
 
 .expand-button {
     background-color: white;
-    color: blue;
     width: 11px;
-    height: 11px;
-    border: 1px solid blue;
+    height: 12px;
+    border: 1px solid gray;
     display: inline-block;
     margin: 0 3px 0 0;
     position: relative;
+    cursor: default;
 }
 
+.expand-button.current {
+    color: red;
+}
+
 .expand-button-text {
     position: absolute;
     top: -0.3em;
     left: 1px;
 }
 
+.test-link.flagged:after {
+    content: ' (flagged)';
+}
+
 .stopped-running-early-message {
     border: 3px solid #d00;
     font-weight: bold;
@@ -165,6 +187,9 @@
     image-rendering: -webkit-optimize-contrast;
 }
 
+#flagged-tests {
+    padding: 5px;
+}
 </style>
 <style id="unexpected-style"></style>
 
@@ -265,9 +290,9 @@
         prefix + '"></img></div>';
 }
 
-function toggleExpectations(e)
+function toggleExpectations(element)
 {
-    var expandLink = e.target;
+    var expandLink = element;
     if (expandLink.className != 'expand-button-text')
         expandLink = expandLink.querySelector('.expand-button-text');
 
@@ -401,7 +426,7 @@
 
 function testLinkWithExpandButton(test)
 {
-    return '<span class=expand-button _onclick_="toggleExpectations(event)"><span class=expand-button-text>+</span></span>' + testLink(test);
+    return '<span class=expand-button _onclick_="toggleExpectations(this)"><span class=expand-button-text>+</span></span>' + testLink(test);
 }
 
 function resultLink(testPrefix, suffix, contents)
@@ -613,7 +638,7 @@
 {
     tests.sort();
 
-    var html = '<p>' + header + ':</p><table id="' + tableId + '"';
+    var html = '<h1>' + header + ':</h1><table id="' + tableId + '"';
     if (!hasUnexpected(tests))
         html += ' class=expected';
     html += '>';
@@ -881,6 +906,165 @@
 document.addEventListener('mousemove', PixelZoomer.handleMouseMove, false);
 document.addEventListener('mouseout', PixelZoomer.handleMouseOut, false);
 
+var TestNavigator = {};
+
+TestNavigator.currentTestIndex = 0;
+TestNavigator.flaggedTests = {};
+
+TestNavigator.handleKeyEvent = function(event)
+{
+    switch (String.fromCharCode(event.charCode)) {
+        case 'i':
+            TestNavigator._scrollToFirstTest();
+            break;
+        case 'j':
+            TestNavigator._scrollToNextTest();
+            break;
+        case 'k':
+            TestNavigator._scrollToPreviousTest();
+            break;
+        case 'l':
+            TestNavigator._scrollToLastTest();
+            break;
+        case 'e':
+            TestNavigator._expandCurrentTest();
+            break;
+        case 'c':
+            TestNavigator._collapseCurrentTest();
+            break;
+        case 't':
+            TestNavigator._toggleCurrentTest();
+            break;
+        case 'f':
+            TestNavigator._toggleCurrentTestFlagged();
+            break;
+    }
+}
+
+TestNavigator._scrollToFirstTest = function()
+{
+    if (TestNavigator._setCurrentTest(0))
+        TestNavigator._scrollToCurrentTest();
+}
+
+TestNavigator._scrollToLastTest = function()
+{
+    var links = visibleExpandLinks();
+    if (TestNavigator._setCurrentTest(links.length - 1))
+        TestNavigator._scrollToCurrentTest();
+}
+
+TestNavigator._scrollToNextTest = function()
+{
+    if (TestNavigator._setCurrentTest(TestNavigator.currentTestIndex + 1))
+        TestNavigator._scrollToCurrentTest();
+}
+
+TestNavigator._scrollToPreviousTest = function()
+{
+    if (TestNavigator._setCurrentTest(TestNavigator.currentTestIndex - 1))
+        TestNavigator._scrollToCurrentTest();
+}
+
+TestNavigator._currentTestLink = function()
+{
+    var links = visibleExpandLinks();
+    return links[TestNavigator.currentTestIndex];
+}
+
+TestNavigator._expandCurrentTest = function()
+{
+    expandExpectations(TestNavigator._currentTestLink());
+}
+
+TestNavigator._collapseCurrentTest = function()
+{
+    collapseExpectations(TestNavigator._currentTestLink());
+}
+
+TestNavigator._toggleCurrentTest = function()
+{
+    toggleExpectations(TestNavigator._currentTestLink());
+}
+
+TestNavigator._toggleCurrentTestFlagged = function()
+{
+    var testLink = parentOfType(TestNavigator._currentTestLink(), 'tbody').querySelector('.test-link');
+    var testName = testLink.innerText;
+    
+    if (testLink.classList.contains('flagged')) {
+        testLink.classList.remove('flagged');
+        delete TestNavigator.flaggedTests[testName];
+    } else {
+        testLink.classList.add('flagged');
+        TestNavigator.flaggedTests[testName] = 1;
+    }
+    
+    var flaggedTestTextbox = document.getElementById('flagged-tests');
+    if (!flaggedTestTextbox) {
+        var flaggedTestContainer = document.createElement('div');
+        flaggedTestContainer.className = 'flagged-test-container';
+        flaggedTestContainer.innerHTML = '<h2>Flagged Tests</h2><div id="flagged-tests" contentEditable></div>';
+        document.body.appendChild(flaggedTestContainer);
+
+        flaggedTestTextbox = document.getElementById('flagged-tests');
+    }
+
+
+    var flaggedTests = Object.keys(this.flaggedTests);
+    flaggedTests.sort();
+    flaggedTestTextbox.innerHTML = flaggedTests.join('<br>');
+}
+
+TestNavigator._setCurrentTest = function(testIndex)
+{
+    var links = visibleExpandLinks();
+    if (testIndex < 0 || testIndex >= links.length)
+        return false;
+
+    var currExpandLink = links[TestNavigator.currentTestIndex];
+    if (currExpandLink)
+        currExpandLink.parentNode.classList.remove('current');
+
+    TestNavigator.currentTestIndex = testIndex;
+
+    currExpandLink = links[TestNavigator.currentTestIndex];
+    currExpandLink.parentNode.classList.add('current');
+
+    return true;
+}
+
+TestNavigator._scrollToCurrentTest = function()
+{
+    var targetLink = TestNavigator._currentTestLink();
+    if (!targetLink)
+        return;
+
+    var rowRect = targetLink.getBoundingClientRect();
+    // rowRect is in client coords (i.e. relative to viewport), so we just want to add its top to the current scroll position.
+    window.scrollTo(window.scrollX, window.scrollY + rowRect.top - 20);
+}
+
+TestNavigator._onlyShowUnexpectedFailuresChanged_ = function()
+{
+    var currentTestLink = document.querySelector('.current .expand-button-text');
+    if (!currentTestLink)
+        return;
+
+    // If our currentTest became hidden, reset the currentTestIndex.
+    if (onlyShowUnexpectedFailures() && parentOfType(currentTestLink, 'tbody').classList.contains('expected'))
+        TestNavigator._scrollToFirstTest();
+    else {
+        // Recompute TestNavigator.currentTestIndex
+        var links = visibleExpandLinks();
+        TestNavigator.currentTestIndex = links.indexOf(currentTestLink);
+        window.console.log('TestNavigator.currentTestIndex is ', TestNavigator.currentTestIndex)
+    }
+}
+
+document.addEventListener('keypress', TestNavigator.handleKeyEvent, false);
+
+
 function onlyShowUnexpectedFailures()
 {
     return document.getElementById('unexpected-results').checked;
@@ -896,6 +1080,10 @@
 {
     document.getElementById('unexpected-style').textContent = onlyShowUnexpectedFailures() ?
         '.expected { display: none; }' : '';
+
+    TestNavigator.onlyShowUnexpectedFailuresChanged();
+    // if (onlyShowUnexpectedFailures() && parentOfType(TestNavigator.currentTestLink(), 'tbody').classList.contains('expected'))
+    //     TestNavigator.currentTestLink().classList.remove('current');
 }
 
 var OptionWriter = {};
@@ -975,7 +1163,7 @@
         else if (url.match('-actual.png$')) {
             var name = parentOfType(node, 'tbody').querySelector('.test-link').textContent;
             getResultContainer(node).outerHTML = togglingImageFunction(stripExtension(name));
-        }   
+        }
     }
 }
 
@@ -1014,7 +1202,7 @@
     if (!hasUnexpected(tests))
         header += ' class=expected';
 
-    header += '><p>' + title + ':</p>' +
+    header += '><h1>' + title + ':</h1>' +
         '<table id="' + id + '"><thead><tr>' +
         '<th>test</th>' +
         '<th id="text-results-header">results</th>' +
@@ -1038,6 +1226,7 @@
     forEachTest(processGlobalStateFor);
 
     var html = '<div id=toolbar>' +
+        '<div class="note">Use the i, j, k and l keys to navigate, e, c to expand and collapse, and f to flag</div>' +
         '<a href="" _onclick_="expandAllExpectations()">expand all</a> ' +
         '<a href="" _onclick_="collapseAllExpectations()">collapse all</a> ' +
         '<a href="" id=options-link _onclick_="toggleOptionsMenu()">options</a>' +
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to