Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GEN('#include "base/feature_list.h"'); | 5 GEN('#include "base/feature_list.h"'); |
| 6 GEN('#include "chrome/common/chrome_features.h"'); | 6 GEN('#include "chrome/common/chrome_features.h"'); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Test fixture for print preview WebUI testing. | 9 * Test fixture for print preview WebUI testing. |
| 10 * @constructor | 10 * @constructor |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 * @device - The device whose capabilities should be dispatched. | 144 * @device - The device whose capabilities should be dispatched. |
| 145 */ | 145 */ |
| 146 setCapabilities: function(device) { | 146 setCapabilities: function(device) { |
| 147 var capsSetEvent = | 147 var capsSetEvent = |
| 148 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 148 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
| 149 capsSetEvent.settingsInfo = device; | 149 capsSetEvent.settingsInfo = device; |
| 150 this.nativeLayer_.dispatchEvent(capsSetEvent); | 150 this.nativeLayer_.dispatchEvent(capsSetEvent); |
| 151 }, | 151 }, |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will | |
| 155 * happen in the same thread. | |
| 156 */ | |
| 157 invalidSettings: function() { | |
|
dpapad
2017/04/28 17:13:30
Nit: |invalidSettings| sounds more like a data var
rbpotter
2017/04/29 00:07:11
Done.
| |
| 158 var invalidSettingsEvent = | |
| 159 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | |
| 160 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); | |
| 161 }, | |
| 162 | |
| 163 | |
| 164 /** | |
| 154 * Even though animation duration and delay is set to zero, it is necessary to | 165 * Even though animation duration and delay is set to zero, it is necessary to |
| 155 * wait until the animation has finished. | 166 * wait until the animation has finished. |
| 156 */ | 167 */ |
| 157 waitForAnimationToEnd: function(elementId) { | 168 waitForAnimationToEnd: function(elementId) { |
| 158 // add a listener for the animation end event | 169 // add a listener for the animation end event |
| 159 document.addEventListener('animationend', function f(e) { | 170 document.addEventListener('animationend', function f(e) { |
| 160 if (e.target.id == elementId) { | 171 if (e.target.id == elementId) { |
| 161 document.removeEventListener(f, 'animationend'); | 172 document.removeEventListener(f, 'animationend'); |
| 162 testDone(); | 173 testDone(); |
| 163 } | 174 } |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 // increments by 1 for each startGetPreview call it makes. It should only | 1360 // increments by 1 for each startGetPreview call it makes. It should only |
| 1350 // make one such call during initialization or there will be a race; see | 1361 // make one such call during initialization or there will be a race; see |
| 1351 // crbug.com/666595 | 1362 // crbug.com/666595 |
| 1352 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1363 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
| 1353 -1); | 1364 -1); |
| 1354 this.setInitialSettings(); | 1365 this.setInitialSettings(); |
| 1355 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1366 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
| 1356 0); | 1367 0); |
| 1357 testDone(); | 1368 testDone(); |
| 1358 }); | 1369 }); |
| 1370 | |
| 1371 // Test that invalid settings errors disable the print preview and display | |
| 1372 // an error and that the preview dialog can be recovered by selecting a | |
| 1373 // new destination. | |
| 1374 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { | |
| 1375 // Setup | |
| 1376 this.setInitialSettings(); | |
| 1377 this.setLocalDestinations(); | |
| 1378 expectEquals('ready', printPreview.uiState_); | |
|
dpapad
2017/04/28 17:13:30
Is there a way to avoid referring to a private var
rbpotter
2017/04/29 00:07:11
Done.
| |
| 1379 | |
| 1380 // There will be an error message in the preview area since the plugin is | |
| 1381 // not running. However, it should not be the invalid settings error. | |
| 1382 var previewAreaEl = $('preview-area'); | |
| 1383 var customMessageEl = | |
| 1384 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | |
| 1385 expectEquals(false, customMessageEl.hidden); | |
| 1386 var expectedMessageStart = 'The selected printer is not available or not ' + | |
| 1387 'installed correctly.' | |
| 1388 expectEquals(-1, customMessageEl.textContent.search(expectedMessageStart)); | |
| 1389 | |
| 1390 // Manually enable the print button to verify it is disabled. | |
| 1391 var printHeader = $('print-header'); | |
| 1392 var printButton = printHeader.querySelector('button.print'); | |
| 1393 checkElementDisplayed(printButton, true); | |
| 1394 printButton.disabled = false; | |
| 1395 expectEquals(false, printButton.disabled); | |
| 1396 | |
| 1397 // Report invalid settings error. | |
| 1398 this.invalidSettings(); | |
| 1399 | |
| 1400 // Should be in an error state, print button disabled, invalid custom error | |
| 1401 // message shown. | |
| 1402 expectEquals('error', printPreview.uiState_); | |
| 1403 expectEquals(false, customMessageEl.hidden); | |
| 1404 expectEquals(true, | |
| 1405 customMessageEl.textContent.search(expectedMessageStart) > -1); | |
| 1406 expectEquals(true, printButton.disabled); | |
| 1407 | |
| 1408 // Select a new destination | |
| 1409 var barDestination; | |
| 1410 var destinations = printPreview.destinationStore_.destinations(); | |
| 1411 for (var destination, i = 0; destination = destinations[i]; i++) { | |
| 1412 if (destination.id == 'BarDevice') { | |
| 1413 barDestination = destination; | |
| 1414 break; | |
| 1415 } | |
| 1416 } | |
| 1417 printPreview.destinationStore_.selectDestination(barDestination); | |
| 1418 | |
| 1419 // Should now have recovered. Error message does not change and the button | |
| 1420 // will not be re-enabled since the preview never actually loads. | |
| 1421 expectEquals('ready', printPreview.uiState_); | |
| 1422 testDone(); | |
| 1423 }); | |
| OLD | NEW |