OLD | NEW |
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; |
(...skipping 10 matching lines...) Expand all Loading... |
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.$setupStub(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 teardown: function() { |
36 hostTableEntry_.dispose(); | 36 hostTableEntry_.dispose(); |
37 hostTableEntry_ = null; | 37 hostTableEntry_ = null; |
38 chrome.i18n.getMessage.$testStub.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 |
46 */ | 46 */ |
47 function setHost(hostName, status, opt_offlineReason) { | 47 function setHost(hostName, status, opt_offlineReason) { |
48 var host = new remoting.Host(); | 48 var host = new remoting.Host(); |
(...skipping 21 matching lines...) Expand all Loading... |
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 test('Clicking on the confirm button in the confirm dialog deletes the host', |
78 function() { | 78 function() { |
79 // Setup. | 79 // Setup. |
80 sinon.$setupStub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { | 80 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { |
81 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { | 81 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { |
82 document.getElementById('confirm-host-delete').click(); | 82 document.getElementById('confirm-host-delete').click(); |
83 } | 83 } |
84 }); | 84 }); |
85 | 85 |
86 // Invoke. | 86 // Invoke. |
87 hostTableEntry_.element().querySelector('.delete-button').click(); | 87 hostTableEntry_.element().querySelector('.delete-button').click(); |
88 | 88 |
89 // Verify. | 89 // Verify. |
90 sinon.assert.calledWith(onDelete_, hostTableEntry_); | 90 sinon.assert.calledWith(onDelete_, hostTableEntry_); |
91 | 91 |
92 // Cleanup. | 92 // Cleanup. |
93 remoting.setMode.$testStub.restore(); | 93 $testStub(remoting.setMode).restore(); |
94 }); | 94 }); |
95 | 95 |
96 test( | 96 test( |
97 'Clicking on the cancel button in the confirm dialog cancels host deletion', | 97 'Clicking on the cancel button in the confirm dialog cancels host deletion', |
98 function() { | 98 function() { |
99 // Setup. | 99 // Setup. |
100 sinon.$setupStub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { | 100 sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) { |
101 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { | 101 if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) { |
102 document.getElementById('cancel-host-delete').click(); | 102 document.getElementById('cancel-host-delete').click(); |
103 } | 103 } |
104 }); | 104 }); |
105 | 105 |
106 // Invoke. | 106 // Invoke. |
107 hostTableEntry_.element().querySelector('.delete-button').click(); | 107 hostTableEntry_.element().querySelector('.delete-button').click(); |
108 | 108 |
109 // Verify. | 109 // Verify. |
110 sinon.assert.notCalled(onDelete_); | 110 sinon.assert.notCalled(onDelete_); |
111 | 111 |
112 // Cleanup. | 112 // Cleanup. |
113 remoting.setMode.$testStub.restore(); | 113 $testStub(remoting.setMode).restore(); |
114 }); | 114 }); |
115 | 115 |
116 test('Clicking on the rename button shows the input field.', function() { | 116 test('Clicking on the rename button shows the input field.', function() { |
117 // Invoke. | 117 // Invoke. |
118 hostTableEntry_.element().querySelector('.rename-button').click(); | 118 hostTableEntry_.element().querySelector('.rename-button').click(); |
119 | 119 |
120 // Verify. | 120 // Verify. |
121 var inputField = | 121 var inputField = |
122 hostTableEntry_.element().querySelector('.host-rename-input'); | 122 hostTableEntry_.element().querySelector('.host-rename-input'); |
123 | 123 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 }); | 161 }); |
162 | 162 |
163 test('HostTableEntry renders an offline host correctly.', function() { | 163 test('HostTableEntry renders an offline host correctly.', function() { |
164 setHost('LocalHost', 'OFFLINE', 'INITIALIZATION_FAILED'); | 164 setHost('LocalHost', 'OFFLINE', 'INITIALIZATION_FAILED'); |
165 var label = hostTableEntry_.element().querySelector('.host-name-label'); | 165 var label = hostTableEntry_.element().querySelector('.host-name-label'); |
166 QUnit.equal(label.innerText, 'OFFLINE'); | 166 QUnit.equal(label.innerText, 'OFFLINE'); |
167 QUnit.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED'); | 167 QUnit.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED'); |
168 }); | 168 }); |
169 | 169 |
170 test('HostTableEntry renders an out-of-date host correctly', function() { | 170 test('HostTableEntry renders an out-of-date host correctly', function() { |
171 sinon.$setupStub(remoting.Host, 'needsUpdate').returns(true); | 171 sinon.stub(remoting.Host, 'needsUpdate').returns(true); |
172 setHost('LocalHost', 'ONLINE'); | 172 setHost('LocalHost', 'ONLINE'); |
173 var warningOverlay = | 173 var warningOverlay = |
174 hostTableEntry_.element().querySelector('.warning-overlay'); | 174 hostTableEntry_.element().querySelector('.warning-overlay'); |
175 var label = hostTableEntry_.element().querySelector('.host-name-label'); | 175 var label = hostTableEntry_.element().querySelector('.host-name-label'); |
176 verifyVisible(warningOverlay, true, 'warning overlay'); | 176 verifyVisible(warningOverlay, true, 'warning overlay'); |
177 QUnit.equal(label.innerText, 'UPDATE_REQUIRED'); | 177 QUnit.equal(label.innerText, 'UPDATE_REQUIRED'); |
178 }); | 178 }); |
179 | 179 |
180 test('Clicking on an online host connects it', function() { | 180 test('Clicking on an online host connects it', function() { |
181 hostTableEntry_.element().querySelector('.host-name-label').click(); | 181 hostTableEntry_.element().querySelector('.host-name-label').click(); |
182 sinon.assert.calledWith(onConnect_, | 182 sinon.assert.calledWith(onConnect_, |
183 encodeURIComponent(hostTableEntry_.host.hostId)); | 183 encodeURIComponent(hostTableEntry_.host.hostId)); |
184 }); | 184 }); |
185 | 185 |
186 test('Clicking on an offline host should be a no-op', function() { | 186 test('Clicking on an offline host should be a no-op', function() { |
187 setHost('LocalHost', 'OFFLINE'); | 187 setHost('LocalHost', 'OFFLINE'); |
188 hostTableEntry_.element().querySelector('.host-name-label').click(); | 188 hostTableEntry_.element().querySelector('.host-name-label').click(); |
189 sinon.assert.notCalled(onConnect_); | 189 sinon.assert.notCalled(onConnect_); |
190 }); | 190 }); |
191 | 191 |
192 test('HostTableEntry handles host that is null', function() { | 192 test('HostTableEntry handles host that is null', function() { |
193 hostTableEntry_.setHost(null); | 193 hostTableEntry_.setHost(null); |
194 hostTableEntry_.element().querySelector('.host-name-label').click(); | 194 hostTableEntry_.element().querySelector('.host-name-label').click(); |
195 sinon.assert.notCalled(onConnect_); | 195 sinon.assert.notCalled(onConnect_); |
196 }); | 196 }); |
197 | 197 |
198 })(); | 198 })(); |
OLD | NEW |