Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: remoting/webapp/crd/js/host_table_entry_unittest.js

Issue 1017613002: Migrate Remoting Webapp Unittests to use QUnit 2.0 syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Async test migration Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 (function() { 5 (function() {
6 6
7 'use strict'; 7 'use strict';
8 8
9 /** @type {remoting.HostTableEntry} */ 9 /** @type {remoting.HostTableEntry} */
10 var hostTableEntry_ = null; 10 var hostTableEntry_ = null;
11 var onConnect_ = null; 11 var onConnect_ = null;
12 var onRename_ = null; 12 var onRename_ = null;
13 var onDelete_ = null; 13 var onDelete_ = null;
14 14
15 module('HostTableEntry', { 15 QUnit.module('HostTableEntry', {
16 setup: function() { 16 beforeEach: function() {
17 onConnect_ = /** @type {function(string)} */ (sinon.spy()); 17 onConnect_ = /** @type {function(string)} */ (sinon.spy());
18 onRename_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy()); 18 onRename_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy());
19 onDelete_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy()); 19 onDelete_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy());
20 hostTableEntry_ = 20 hostTableEntry_ =
21 new remoting.HostTableEntry(10, 21 new remoting.HostTableEntry(10,
22 onConnect_, onRename_, onDelete_); 22 onConnect_, onRename_, onDelete_);
23 23
24 // Setup the DOM dependencies on the confirm delete dialog. 24 // Setup the DOM dependencies on the confirm delete dialog.
25 var fixture = document.getElementById('qunit-fixture'); 25 var fixture = document.getElementById('qunit-fixture');
26 fixture.innerHTML = '<div id="confirm-host-delete-message"></div>' + 26 fixture.innerHTML = '<div id="confirm-host-delete-message"></div>' +
27 '<div id="confirm-host-delete"></div>' + 27 '<div id="confirm-host-delete"></div>' +
28 '<div id="cancel-host-delete"></div>'; 28 '<div id="cancel-host-delete"></div>';
29 setHost('LocalHost', 'ONLINE'); 29 setHost('LocalHost', 'ONLINE');
30 fixture.appendChild(hostTableEntry_.element()); 30 fixture.appendChild(hostTableEntry_.element());
31 sinon.stub(chrome.i18n, 'getMessage', function(/** string */ tag){ 31 sinon.stub(chrome.i18n, 'getMessage', function(/** string */ tag){
32 return tag; 32 return tag;
33 }); 33 });
34 }, 34 },
35 teardown: function() { 35 afterEach: function() {
36 hostTableEntry_.dispose(); 36 hostTableEntry_.dispose();
37 hostTableEntry_ = null; 37 hostTableEntry_ = null;
38 $testStub(chrome.i18n.getMessage).restore(); 38 $testStub(chrome.i18n.getMessage).restore();
39 } 39 }
40 }); 40 });
41 41
42 /** 42 /**
43 * @param {string} hostName 43 * @param {string} hostName
44 * @param {string} status 44 * @param {string} status
45 * @param {string=} opt_offlineReason 45 * @param {string=} opt_offlineReason
(...skipping 21 matching lines...) Expand all
67 67
68 function verifyVisible( 68 function verifyVisible(
69 /** HTMLElement*/ element, 69 /** HTMLElement*/ element,
70 /** boolean */ isVisible, 70 /** boolean */ isVisible,
71 /** string= */ opt_name) { 71 /** string= */ opt_name) {
72 var expectedVisibility = (isVisible) ? 'visible' : 'hidden'; 72 var expectedVisibility = (isVisible) ? 'visible' : 'hidden';
73 QUnit.equal(element.hidden, !isVisible, 73 QUnit.equal(element.hidden, !isVisible,
74 'Element ' + opt_name + ' should be ' + expectedVisibility); 74 'Element ' + opt_name + ' should be ' + expectedVisibility);
75 } 75 }
76 76
77 test('Clicking on the confirm button in the confirm dialog deletes the host', 77 QUnit.test(
78 'Clicking on the confirm button in the confirm dialog deletes the host',
78 function() { 79 function() {
79 // Setup. 80 // Setup.
80 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { 81 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) {
81 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { 82 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) {
82 document.getElementById('confirm-host-delete').click(); 83 document.getElementById('confirm-host-delete').click();
83 } 84 }
84 }); 85 });
85 86
86 // Invoke. 87 // Invoke.
87 hostTableEntry_.element().querySelector('.delete-button').click(); 88 hostTableEntry_.element().querySelector('.delete-button').click();
88 89
89 // Verify. 90 // Verify.
90 sinon.assert.calledWith(onDelete_, hostTableEntry_); 91 sinon.assert.calledWith(onDelete_, hostTableEntry_);
91 92
92 // Cleanup. 93 // Cleanup.
93 $testStub(remoting.setMode).restore(); 94 $testStub(remoting.setMode).restore();
94 }); 95 });
95 96
96 test( 97 QUnit.test(
97 'Clicking on the cancel button in the confirm dialog cancels host deletion', 98 'Clicking on the cancel button in the confirm dialog cancels host deletion',
98 function() { 99 function() {
99 // Setup. 100 // Setup.
100 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { 101 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) {
101 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { 102 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) {
102 document.getElementById('cancel-host-delete').click(); 103 document.getElementById('cancel-host-delete').click();
103 } 104 }
104 }); 105 });
105 106
106 // Invoke. 107 // Invoke.
107 hostTableEntry_.element().querySelector('.delete-button').click(); 108 hostTableEntry_.element().querySelector('.delete-button').click();
108 109
109 // Verify. 110 // Verify.
110 sinon.assert.notCalled(onDelete_); 111 sinon.assert.notCalled(onDelete_);
111 112
112 // Cleanup. 113 // Cleanup.
113 $testStub(remoting.setMode).restore(); 114 $testStub(remoting.setMode).restore();
114 }); 115 });
115 116
116 test('Clicking on the rename button shows the input field.', function() { 117 QUnit.test('Clicking on the rename button shows the input field.', function() {
117 // Invoke. 118 // Invoke.
118 hostTableEntry_.element().querySelector('.rename-button').click(); 119 hostTableEntry_.element().querySelector('.rename-button').click();
119 120
120 // Verify. 121 // Verify.
121 var inputField = 122 var inputField =
122 hostTableEntry_.element().querySelector('.host-rename-input'); 123 hostTableEntry_.element().querySelector('.host-rename-input');
123 124
124 verifyVisible(inputField, true, 'inputField'); 125 verifyVisible(inputField, true, 'inputField');
125 QUnit.equal(document.activeElement, inputField); 126 QUnit.equal(document.activeElement, inputField);
126 }); 127 });
127 128
128 test('Host renaming is canceled on ESCAPE key.', function() { 129 QUnit.test('Host renaming is canceled on ESCAPE key.', function() {
129 // Invoke. 130 // Invoke.
130 var inputField = 131 var inputField =
131 hostTableEntry_.element().querySelector('.host-rename-input'); 132 hostTableEntry_.element().querySelector('.host-rename-input');
132 hostTableEntry_.element().querySelector('.rename-button').click(); 133 hostTableEntry_.element().querySelector('.rename-button').click();
133 134
134 // Verify. 135 // Verify.
135 verifyVisible(inputField, true, 'inputField'); 136 verifyVisible(inputField, true, 'inputField');
136 QUnit.equal(document.activeElement, inputField); 137 QUnit.equal(document.activeElement, inputField);
137 sendKeydown(inputField, 27 /* ESCAPE */); 138 sendKeydown(inputField, 27 /* ESCAPE */);
138 verifyVisible(inputField, false, 'inputField'); 139 verifyVisible(inputField, false, 'inputField');
139 }); 140 });
140 141
141 test('Host renaming commits on ENTER.', function() { 142 QUnit.test('Host renaming commits on ENTER.', function() {
142 // Invoke. 143 // Invoke.
143 var inputField = 144 var inputField =
144 hostTableEntry_.element().querySelector('.host-rename-input'); 145 hostTableEntry_.element().querySelector('.host-rename-input');
145 hostTableEntry_.element().querySelector('.rename-button').click(); 146 hostTableEntry_.element().querySelector('.rename-button').click();
146 inputField.value = 'Renamed Host'; 147 inputField.value = 'Renamed Host';
147 sendKeydown(inputField, 13 /* ENTER */); 148 sendKeydown(inputField, 13 /* ENTER */);
148 149
149 // Verify 150 // Verify
150 verifyVisible(inputField, false, 'inputField'); 151 verifyVisible(inputField, false, 'inputField');
151 sinon.assert.called(onRename_); 152 sinon.assert.called(onRename_);
152 QUnit.equal(hostTableEntry_.host.hostName, 'Renamed Host'); 153 QUnit.equal(hostTableEntry_.host.hostName, 'Renamed Host');
153 154
154 // Renaming shouldn't trigger a connection request. 155 // Renaming shouldn't trigger a connection request.
155 sinon.assert.notCalled(onConnect_); 156 sinon.assert.notCalled(onConnect_);
156 }); 157 });
157 158
158 test('HostTableEntry renders the host name correctly.', function() { 159 QUnit.test('HostTableEntry renders the host name correctly.', function() {
159 var label = hostTableEntry_.element().querySelector('.host-name-label'); 160 var label = hostTableEntry_.element().querySelector('.host-name-label');
160 QUnit.equal(label.innerText, 'LocalHost'); 161 QUnit.equal(label.innerText, 'LocalHost');
161 }); 162 });
162 163
163 test('HostTableEntry renders an offline host correctly.', function() { 164 QUnit.test('HostTableEntry renders an offline host correctly.', function() {
164 setHost('LocalHost', 'OFFLINE', 'INITIALIZATION_FAILED'); 165 setHost('LocalHost', 'OFFLINE', 'INITIALIZATION_FAILED');
165 var label = hostTableEntry_.element().querySelector('.host-name-label'); 166 var label = hostTableEntry_.element().querySelector('.host-name-label');
166 QUnit.equal(label.innerText, 'OFFLINE'); 167 QUnit.equal(label.innerText, 'OFFLINE');
167 QUnit.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED'); 168 QUnit.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED');
168 }); 169 });
169 170
170 test('HostTableEntry renders an out-of-date host correctly', function() { 171 QUnit.test('HostTableEntry renders an out-of-date host correctly', function() {
171 sinon.stub(remoting.Host, 'needsUpdate').returns(true); 172 sinon.stub(remoting.Host, 'needsUpdate').returns(true);
172 setHost('LocalHost', 'ONLINE'); 173 setHost('LocalHost', 'ONLINE');
173 var warningOverlay = 174 var warningOverlay =
174 hostTableEntry_.element().querySelector('.warning-overlay'); 175 hostTableEntry_.element().querySelector('.warning-overlay');
175 var label = hostTableEntry_.element().querySelector('.host-name-label'); 176 var label = hostTableEntry_.element().querySelector('.host-name-label');
176 verifyVisible(warningOverlay, true, 'warning overlay'); 177 verifyVisible(warningOverlay, true, 'warning overlay');
177 QUnit.equal(label.innerText, 'UPDATE_REQUIRED'); 178 QUnit.equal(label.innerText, 'UPDATE_REQUIRED');
178 }); 179 });
179 180
180 test('Clicking on an online host connects it', function() { 181 QUnit.test('Clicking on an online host connects it', function() {
181 hostTableEntry_.element().querySelector('.host-name-label').click(); 182 hostTableEntry_.element().querySelector('.host-name-label').click();
182 sinon.assert.calledWith(onConnect_, 183 sinon.assert.calledWith(onConnect_,
183 encodeURIComponent(hostTableEntry_.host.hostId)); 184 encodeURIComponent(hostTableEntry_.host.hostId));
184 }); 185 });
185 186
186 test('Clicking on an offline host should be a no-op', function() { 187 QUnit.test('Clicking on an offline host should be a no-op', function() {
187 setHost('LocalHost', 'OFFLINE'); 188 setHost('LocalHost', 'OFFLINE');
188 hostTableEntry_.element().querySelector('.host-name-label').click(); 189 hostTableEntry_.element().querySelector('.host-name-label').click();
189 sinon.assert.notCalled(onConnect_); 190 sinon.assert.notCalled(onConnect_);
190 }); 191 });
191 192
192 test('HostTableEntry handles host that is null', function() { 193 QUnit.test('HostTableEntry handles host that is null', function() {
193 hostTableEntry_.setHost(null); 194 hostTableEntry_.setHost(null);
194 hostTableEntry_.element().querySelector('.host-name-label').click(); 195 hostTableEntry_.element().querySelector('.host-name-label').click();
195 sinon.assert.notCalled(onConnect_); 196 sinon.assert.notCalled(onConnect_);
196 }); 197 });
197 198
198 })(); 199 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698