OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview hterm.Terminal unit tests. |
| 7 */ |
| 8 |
| 9 hterm.Terminal.Tests = new TestManager.Suite('hterm.Terminal.Tests'); |
| 10 |
| 11 hterm.Terminal.Tests.prototype.setup = function(cx) { |
| 12 this.setDefaults(cx, |
| 13 { visibleColumnCount: 80, |
| 14 visibleRowCount: 25, |
| 15 fontSize: 15, |
| 16 lineHeight: 17, |
| 17 charWidth: 9, |
| 18 scrollbarWidth: 16, |
| 19 }); |
| 20 }; |
| 21 |
| 22 /** |
| 23 * Clear out the current document and create a new hterm.Terminal object for |
| 24 * testing. |
| 25 * |
| 26 * Called before each test case in this suite. |
| 27 */ |
| 28 hterm.Terminal.Tests.prototype.preamble = function(result, cx) { |
| 29 var document = cx.window.document; |
| 30 |
| 31 document.body.innerHTML = ''; |
| 32 |
| 33 var div = document.createElement('div'); |
| 34 div.style.position = 'absolute'; |
| 35 div.style.height = this.lineHeight * this.visibleRowCount + 'px'; |
| 36 div.style.width = this.charWidth * this.visibleColumnCount + |
| 37 this.scrollbarWidth + 'px'; |
| 38 document.body.appendChild(div); |
| 39 |
| 40 cx.window.terminal = this.terminal = new hterm.Terminal( |
| 41 this.fontSize, this.lineHeight); |
| 42 |
| 43 this.terminal.decorate(div); |
| 44 }; |
| 45 |
| 46 /** |
| 47 * Overridden addTest method. |
| 48 * |
| 49 * Every test in this suite needs to wait for the terminal initialization to |
| 50 * complete asynchronously. Rather than stick a bunch of biolerplate into each |
| 51 * test case, we use this overridden addTest method to add a proxy around the |
| 52 * actual test. |
| 53 */ |
| 54 hterm.Terminal.Tests.addTest = function(name, callback) { |
| 55 function testProxy(result, cx) { |
| 56 setTimeout(function() { |
| 57 this.terminal.setCursorPosition(0, 0); |
| 58 callback.apply(this, [result, cx]); |
| 59 }, 0); |
| 60 |
| 61 result.requestTime(200); |
| 62 } |
| 63 |
| 64 TestManager.Suite.addTest.apply(this, [name, testProxy]); |
| 65 }; |
| 66 |
| 67 /** |
| 68 * Fill the screen with 'X' characters one character at a time, in a way |
| 69 * that should stress the cursor positioning code. |
| 70 */ |
| 71 hterm.Terminal.Tests.addTest('plaintext-stress-cursor-ltr', |
| 72 function(result, cx) { |
| 73 for (var col = 0; col < this.visibleColumnCount; col++) { |
| 74 for (var row = 0; row < this.visibleRowCount; row++) { |
| 75 console.log(row, col); |
| 76 this.terminal.screen_.setCursorPosition(row, col); |
| 77 this.terminal.screen_.insertString('X'); |
| 78 } |
| 79 } |
| 80 |
| 81 result.pass(); |
| 82 }); |
| 83 |
| 84 /** |
| 85 * Fill the screen with 'X' characters one character at a time, in a way |
| 86 * that should stress the cursor positioning code and the overwriteString() |
| 87 * code. |
| 88 */ |
| 89 hterm.Terminal.Tests.addTest('plaintext-stress-cursor-rtl', |
| 90 function(result, cx) { |
| 91 for (var col = this.visibleColumnCount - 1; col >= 0; col--) { |
| 92 for (var row = 0; row < this.visibleRowCount; row++) { |
| 93 this.terminal.screen_.setCursorPosition(row, col); |
| 94 this.terminal.screen_.overwriteString('X'); |
| 95 } |
| 96 } |
| 97 |
| 98 result.pass(); |
| 99 }); |
| 100 |
| 101 /** |
| 102 * Fill the terminal with a lot of text as quickly as possible. |
| 103 * |
| 104 * This test doesn't actually assert anything, but the timing data in the test |
| 105 * log is useful. |
| 106 */ |
| 107 hterm.Terminal.Tests.addTest('plaintext-stress-insert', |
| 108 function(result, cx) { |
| 109 var chunkSize = 1000; |
| 110 var testCount = 10; |
| 111 var self = this; |
| 112 |
| 113 function test(count) { |
| 114 for (var i = count * chunkSize; i < (count + 1) * chunkSize; i++) { |
| 115 if (i != 0) |
| 116 self.terminal.newLine(); |
| 117 self.terminal.screen_.insertString( |
| 118 'line ' + i + ': All work and no play makes jack a dull boy.'); |
| 119 } |
| 120 |
| 121 if (count + 1 >= testCount) { |
| 122 result.pass(); |
| 123 } else { |
| 124 result.requestTime(200); |
| 125 setTimeout(test, 0, count + 1); |
| 126 } |
| 127 } |
| 128 |
| 129 test(0); |
| 130 }); |
OLD | NEW |