| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 ScrollPort.Tests = new TestManager.Suite('ScrollPort.Tests'); | 5 hterm.ScrollPort.Tests = new TestManager.Suite('hterm.ScrollPort.Tests'); |
| 6 | 6 |
| 7 ScrollPort.Tests.prototype.setup = function(cx) { | 7 hterm.ScrollPort.Tests.prototype.setup = function(cx) { |
| 8 this.setDefaults(cx, | 8 this.setDefaults(cx, |
| 9 { visibleColumnCount: 80, | 9 { visibleColumnCount: 80, |
| 10 visibleRowCount: 25, | 10 visibleRowCount: 25, |
| 11 fontSize: 15, | 11 fontSize: 15, |
| 12 lineHeight: 17, | 12 lineHeight: 17, |
| 13 totalRowCount: 10000 | 13 totalRowCount: 10000 |
| 14 }); | 14 }); |
| 15 | 15 |
| 16 var document = cx.window.document; | 16 var document = cx.window.document; |
| 17 | 17 |
| 18 document.body.innerHTML = ''; | 18 document.body.innerHTML = ''; |
| 19 | 19 |
| 20 this.rowProvider = new MockRowProvider(document, this.totalRowCount); | 20 this.rowProvider = new MockRowProvider(document, this.totalRowCount); |
| 21 | 21 |
| 22 var div = document.createElement('div'); | 22 var div = document.createElement('div'); |
| 23 div.style.position = 'relative'; | 23 div.style.position = 'relative'; |
| 24 div.style.height = this.lineHeight * this.visibleRowCount + 'px'; | 24 div.style.height = this.lineHeight * this.visibleRowCount + 'px'; |
| 25 div.style.width = '100%'; | 25 div.style.width = '100%'; |
| 26 document.body.appendChild(div); | 26 document.body.appendChild(div); |
| 27 | 27 |
| 28 this.scrollPort = new ScrollPort(this.rowProvider, | 28 this.scrollPort = new hterm.ScrollPort(this.rowProvider, |
| 29 this.fontSize, this.lineHeight); | 29 this.fontSize, this.lineHeight); |
| 30 this.scrollPort.decorate(div); | 30 this.scrollPort.decorate(div); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Ensure the selection is collapsed, row caching is on, and we're at the | 34 * Ensure the selection is collapsed, row caching is on, and we're at the |
| 35 * top of the scroll port. | 35 * top of the scroll port. |
| 36 */ | 36 */ |
| 37 ScrollPort.Tests.prototype.preamble = function(result, cx) { | 37 hterm.ScrollPort.Tests.prototype.preamble = function(result, cx) { |
| 38 var selection = cx.window.getSelection(); | 38 var selection = cx.window.getSelection(); |
| 39 if (!selection.isCollapsed) | 39 if (!selection.isCollapsed) |
| 40 selection.collapseToStart(); | 40 selection.collapseToStart(); |
| 41 | 41 |
| 42 this.rowProvider.setCacheEnabled(true); | 42 this.rowProvider.setCacheEnabled(true); |
| 43 | 43 |
| 44 this.scrollPort.scrollRowToBottom(this.totalRowCount); | 44 this.scrollPort.scrollRowToBottom(this.totalRowCount); |
| 45 this.scrollPort.scrollRowToTop(0); | 45 this.scrollPort.scrollRowToTop(0); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Basic test to make sure that the viewport contains the right number of | 49 * Basic test to make sure that the viewport contains the right number of |
| 50 * rows at the right places after some scrolling. | 50 * rows at the right places after some scrolling. |
| 51 */ | 51 */ |
| 52 ScrollPort.Tests.addTest('basic-scroll', function(result, cx) { | 52 hterm.ScrollPort.Tests.addTest('basic-scroll', function(result, cx) { |
| 53 var topRow = this.scrollPort.getTopRowIndex(); | 53 var topRow = this.scrollPort.getTopRowIndex(); |
| 54 result.assertEQ(topRow, 0); | 54 result.assertEQ(topRow, 0); |
| 55 result.assertEQ(this.scrollPort.getBottomRowIndex(topRow), | 55 result.assertEQ(this.scrollPort.getBottomRowIndex(topRow), |
| 56 this.visibleRowCount - 1); | 56 this.visibleRowCount - 1); |
| 57 | 57 |
| 58 this.scrollPort.scrollRowToBottom(this.totalRowCount); | 58 this.scrollPort.scrollRowToBottom(this.totalRowCount); |
| 59 topRow = this.scrollPort.getTopRowIndex(); | 59 topRow = this.scrollPort.getTopRowIndex(); |
| 60 result.assertEQ(topRow, | 60 result.assertEQ(topRow, |
| 61 this.totalRowCount - this.visibleRowCount); | 61 this.totalRowCount - this.visibleRowCount); |
| 62 result.assertEQ(this.scrollPort.getBottomRowIndex(topRow), | 62 result.assertEQ(this.scrollPort.getBottomRowIndex(topRow), |
| 63 this.totalRowCount - 1); | 63 this.totalRowCount - 1); |
| 64 | 64 |
| 65 result.pass(); | 65 result.pass(); |
| 66 }); | 66 }); |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Make sure the ScrollPort is reusing the same row nodes when it can. | 69 * Make sure the hterm.ScrollPort is reusing the same row nodes when it can. |
| 70 */ | 70 */ |
| 71 ScrollPort.Tests.addTest('node-recycler', function(result, cx) { | 71 hterm.ScrollPort.Tests.addTest('node-recycler', function(result, cx) { |
| 72 this.rowProvider.resetCallCount('getRowNode'); | 72 this.rowProvider.resetCallCount('getRowNode'); |
| 73 this.scrollPort.scrollRowToTop(1); | 73 this.scrollPort.scrollRowToTop(1); |
| 74 var count = this.rowProvider.getCallCount('getRowNode'); | 74 var count = this.rowProvider.getCallCount('getRowNode'); |
| 75 | 75 |
| 76 // Scrolling from 0 to 1 should result in only one call to getRowNode. | 76 // Scrolling from 0 to 1 should result in only one call to getRowNode. |
| 77 result.assertEQ(count, 1); | 77 result.assertEQ(count, 1); |
| 78 | 78 |
| 79 result.pass(); | 79 result.pass(); |
| 80 }); | 80 }); |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Make sure the selection is maintained even after scrolling off screen. | 83 * Make sure the selection is maintained even after scrolling off screen. |
| 84 */ | 84 */ |
| 85 ScrollPort.Tests.addTest('scroll-selection', function(result, cx) { | 85 hterm.ScrollPort.Tests.addTest('scroll-selection', function(result, cx) { |
| 86 var doc = this.scrollPort.getDocument(); | 86 var doc = this.scrollPort.getDocument(); |
| 87 | 87 |
| 88 // Scroll into a part of the buffer that can be scrolled off the top | 88 // Scroll into a part of the buffer that can be scrolled off the top |
| 89 // and the bottom of the screen. | 89 // and the bottom of the screen. |
| 90 this.scrollPort.scrollRowToTop(50); | 90 this.scrollPort.scrollRowToTop(50); |
| 91 | 91 |
| 92 // And select some text in the middle of the visible range. | 92 // And select some text in the middle of the visible range. |
| 93 var s = doc.getSelection(); | 93 var s = doc.getSelection(); |
| 94 | 94 |
| 95 var anchorRow = this.rowProvider.getRowNode(55); | 95 var anchorRow = this.rowProvider.getRowNode(55); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 result.assertEQ(anchorNode, s.anchorNode); | 115 result.assertEQ(anchorNode, s.anchorNode); |
| 116 result.assertEQ(focusNode, s.focusNode); | 116 result.assertEQ(focusNode, s.focusNode); |
| 117 } | 117 } |
| 118 | 118 |
| 119 result.pass(); | 119 result.pass(); |
| 120 }); | 120 }); |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Test the select-all function. | 123 * Test the select-all function. |
| 124 */ | 124 */ |
| 125 ScrollPort.Tests.addTest('select-all', function(result, cx) { | 125 hterm.ScrollPort.Tests.addTest('select-all', function(result, cx) { |
| 126 this.scrollPort.selectAll(); | 126 this.scrollPort.selectAll(); |
| 127 result.assertEQ(0, this.scrollPort.selection_.startRow.rowIndex); | 127 result.assertEQ(0, this.scrollPort.selection_.startRow.rowIndex); |
| 128 result.assertEQ(this.totalRowCount - 1, | 128 result.assertEQ(this.totalRowCount - 1, |
| 129 this.scrollPort.selection_.endRow.rowIndex); | 129 this.scrollPort.selection_.endRow.rowIndex); |
| 130 result.pass(); | 130 result.pass(); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Remove the scrollPort that was set up and leave the user with a full-page | 134 * Remove the scrollPort that was set up and leave the user with a full-page |
| 135 * scroll port. | 135 * scroll port. |
| 136 * | 136 * |
| 137 * This should always be the last test of the suite, since it leaves the user | 137 * This should always be the last test of the suite, since it leaves the user |
| 138 * with a full page scrollPort to poke at. | 138 * with a full page scrollPort to poke at. |
| 139 */ | 139 */ |
| 140 ScrollPort.Tests.addTest('fullscreen', function(result, cx) { | 140 hterm.ScrollPort.Tests.addTest('fullscreen', function(result, cx) { |
| 141 var document = cx.window.document; | 141 var document = cx.window.document; |
| 142 | 142 |
| 143 document.body.innerHTML = ''; | 143 document.body.innerHTML = ''; |
| 144 | 144 |
| 145 this.rowProvider = new MockRowProvider(document, this.totalRowCount); | 145 this.rowProvider = new MockRowProvider(document, this.totalRowCount); |
| 146 | 146 |
| 147 var div = document.createElement('div'); | 147 var div = document.createElement('div'); |
| 148 div.style.position = 'absolute'; | 148 div.style.position = 'absolute'; |
| 149 div.style.height = '100%'; | 149 div.style.height = '100%'; |
| 150 div.style.width = '100%'; | 150 div.style.width = '100%'; |
| 151 document.body.appendChild(div); | 151 document.body.appendChild(div); |
| 152 | 152 |
| 153 this.scrollPort = new ScrollPort(this.rowProvider, | 153 this.scrollPort = new hterm.ScrollPort(this.rowProvider, |
| 154 this.fontSize, this.lineHeight); | 154 this.fontSize, this.lineHeight); |
| 155 this.scrollPort.decorate(div); | 155 this.scrollPort.decorate(div); |
| 156 | 156 |
| 157 cx.window.scrollPort = this.scrollPort; | 157 cx.window.scrollPort = this.scrollPort; |
| 158 | 158 |
| 159 result.assert(div.clientHeight > 0); | 159 result.assert(div.clientHeight > 0); |
| 160 result.assert(div.clientWidth > 0); | 160 result.assert(div.clientWidth > 0); |
| 161 result.assertEQ(div.clientHeight, this.scrollPort.iframe_.clientHeight); | 161 result.assertEQ(div.clientHeight, this.scrollPort.iframe_.clientHeight); |
| 162 | 162 |
| 163 result.pass(); | 163 result.pass(); |
| 164 }); | 164 }); |
| OLD | NEW |