| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @implements {settings.CupsPrintersBrowserProxy} | 7 * @implements {settings.CupsPrintersBrowserProxy} |
| 8 * @extends {settings.TestBrowserProxy} | 8 * @extends {settings.TestBrowserProxy} |
| 9 */ | 9 */ |
| 10 var TestCupsPrintersBrowserProxy = function() { | 10 var TestCupsPrintersBrowserProxy = function() { |
| 11 settings.TestBrowserProxy.call(this, [ | 11 settings.TestBrowserProxy.call(this, [ |
| 12 'getCupsPrintersList', | 12 'getCupsPrintersList', |
| 13 'getCupsPrinterManufacturersList', | 13 'getCupsPrinterManufacturersList', |
| 14 'getCupsPrinterModelsList' | 14 'getCupsPrinterModelsList', |
| 15 'startDiscoveringPrinters', |
| 16 'stopDiscoveringPrinters', |
| 15 ]); | 17 ]); |
| 16 }; | 18 }; |
| 17 | 19 |
| 18 TestCupsPrintersBrowserProxy.prototype = { | 20 TestCupsPrintersBrowserProxy.prototype = { |
| 19 __proto__: settings.TestBrowserProxy.prototype, | 21 __proto__: settings.TestBrowserProxy.prototype, |
| 20 | 22 |
| 21 printerList: [], | 23 printerList: [], |
| 22 manufacturers: [], | 24 manufacturers: [], |
| 23 models: [], | 25 models: [], |
| 24 | 26 |
| 25 /** @override */ | 27 /** @override */ |
| 26 getCupsPrintersList: function() { | 28 getCupsPrintersList: function() { |
| 27 this.methodCalled('getCupsPrintersList'); | 29 this.methodCalled('getCupsPrintersList'); |
| 28 return Promise.resolve(this.printerList); | 30 return Promise.resolve(this.printerList); |
| 29 }, | 31 }, |
| 30 | 32 |
| 31 /** @override */ | 33 /** @override */ |
| 32 getCupsPrinterManufacturersList: function() { | 34 getCupsPrinterManufacturersList: function() { |
| 33 this.methodCalled('getCupsPrinterManufacturersList'); | 35 this.methodCalled('getCupsPrinterManufacturersList'); |
| 34 return Promise.resolve(this.manufacturers); | 36 return Promise.resolve(this.manufacturers); |
| 35 }, | 37 }, |
| 36 | 38 |
| 37 /** @override */ | 39 /** @override */ |
| 38 getCupsPrinterModelsList: function(manufacturer) { | 40 getCupsPrinterModelsList: function(manufacturer) { |
| 39 this.methodCalled('getCupsPrinterModelsList', manufacturer); | 41 this.methodCalled('getCupsPrinterModelsList', manufacturer); |
| 40 return Promise.resolve(this.models); | 42 return Promise.resolve(this.models); |
| 41 }, | 43 }, |
| 44 |
| 45 /** @override */ |
| 46 startDiscoveringPrinters: function() { |
| 47 this.methodCalled('startDiscoveringPrinters'); |
| 48 }, |
| 49 |
| 50 /** @override */ |
| 51 stopDiscoveringPrinters: function() { |
| 52 this.methodCalled('stopDiscoveringPrinters'); |
| 53 }, |
| 42 }; | 54 }; |
| 43 | 55 |
| 44 suite('CupsAddPrinterDialogTests', function() { | 56 suite('CupsAddPrinterDialogTests', function() { |
| 45 function fillDialog(addDialog) { | 57 function fillAddManuallyDialog(addDialog) { |
| 46 var name = addDialog.$$('#printerNameInput'); | 58 var name = addDialog.$$('#printerNameInput'); |
| 47 var address = addDialog.$$('#printerAddressInput'); | 59 var address = addDialog.$$('#printerAddressInput'); |
| 48 | 60 |
| 49 assertTrue(!!name); | 61 assertTrue(!!name); |
| 50 name.value = 'Test Printer'; | 62 name.value = 'Test Printer'; |
| 51 | 63 |
| 52 assertTrue(!!address); | 64 assertTrue(!!address); |
| 53 address.value = '127.0.0.1'; | 65 address.value = '127.0.0.1'; |
| 54 } | 66 } |
| 55 | 67 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 75 Polymer.dom.flush(); | 87 Polymer.dom.flush(); |
| 76 }); | 88 }); |
| 77 | 89 |
| 78 teardown(function() { | 90 teardown(function() { |
| 79 page.remove(); | 91 page.remove(); |
| 80 dialog = null; | 92 dialog = null; |
| 81 page = null; | 93 page = null; |
| 82 }); | 94 }); |
| 83 | 95 |
| 84 /** | 96 /** |
| 85 * Test that the manual add dialog is showing. | 97 * Test that the discovery dialog is showing when a user initially asks |
| 98 * to add a printer. |
| 86 */ | 99 */ |
| 87 test('ManualAddShowing', function() { | 100 test('DiscoveryShowing', function() { |
| 88 assertFalse(!!dialog.$$('add-printer-manufacturer-model-dialog')); | 101 assertFalse(!!dialog.$$('add-printer-manufacturer-model-dialog')); |
| 89 assertFalse(!!dialog.$$('add-printer-configuring-dialog')); | 102 assertFalse(!!dialog.$$('add-printer-configuring-dialog')); |
| 90 assertTrue(!!dialog.$$('add-printer-manually-dialog')); | 103 assertFalse(!!dialog.$$('add-printer-manually-dialog')); |
| 104 assertTrue(!!dialog.$$('add-printer-discovery-dialog')); |
| 91 }); | 105 }); |
| 92 | 106 |
| 93 /** | 107 /** |
| 94 * Test that clicking on Add opens the model select page. | 108 * Test that clicking on Add opens the model select page. |
| 95 */ | 109 */ |
| 96 test('ValidAddOpensModelSelection', function() { | 110 test('ValidAddOpensModelSelection', function() { |
| 111 // Starts in discovery dialog, select add manually button. |
| 112 var discoveryDialog = dialog.$$('add-printer-discovery-dialog'); |
| 113 assertTrue(!!discoveryDialog); |
| 114 MockInteractions.tap(discoveryDialog.$$('.secondary-button')); |
| 115 Polymer.dom.flush(); |
| 116 |
| 117 // Now we should be in the manually add dialog. |
| 97 var addDialog = dialog.$$('add-printer-manually-dialog'); | 118 var addDialog = dialog.$$('add-printer-manually-dialog'); |
| 98 assertTrue(!!addDialog); | 119 assertTrue(!!addDialog); |
| 99 | 120 |
| 100 fillDialog(addDialog); | 121 fillAddManuallyDialog(addDialog); |
| 101 | 122 |
| 102 MockInteractions.tap(addDialog.$$('.action-button')); | 123 MockInteractions.tap(addDialog.$$('.action-button')); |
| 103 Polymer.dom.flush(); | 124 Polymer.dom.flush(); |
| 104 | 125 |
| 105 // showing model selection | 126 // showing model selection |
| 106 assertFalse(!!dialog.$$('add-printer-configuring-dialog')); | 127 assertFalse(!!dialog.$$('add-printer-configuring-dialog')); |
| 107 assertTrue(!!dialog.$$('add-printer-manufacturer-model-dialog')); | 128 assertTrue(!!dialog.$$('add-printer-manufacturer-model-dialog')); |
| 108 }); | 129 }); |
| 109 | 130 |
| 110 /** | 131 /** |
| 111 * Test that getModels isn't called with a blank query. | 132 * Test that getModels isn't called with a blank query. |
| 112 */ | 133 */ |
| 113 test('NoBlankQueries', function() { | 134 test('NoBlankQueries', function() { |
| 135 var discoveryDialog = dialog.$$('add-printer-discovery-dialog'); |
| 136 assertTrue(!!discoveryDialog); |
| 137 MockInteractions.tap(discoveryDialog.$$('.secondary-button')); |
| 138 Polymer.dom.flush(); |
| 139 |
| 114 var addDialog = dialog.$$('add-printer-manually-dialog'); | 140 var addDialog = dialog.$$('add-printer-manually-dialog'); |
| 115 assertTrue(!!addDialog); | 141 assertTrue(!!addDialog); |
| 116 fillDialog(addDialog); | 142 fillAddManuallyDialog(addDialog); |
| 117 | 143 |
| 118 cupsPrintersBrowserProxy.whenCalled('getCupsPrinterModelsList') | 144 cupsPrintersBrowserProxy.whenCalled('getCupsPrinterModelsList') |
| 119 .then(function(manufacturer) { assertGT(0, manufacturer.length); }); | 145 .then(function(manufacturer) { assertGT(0, manufacturer.length); }); |
| 120 | 146 |
| 121 cupsPrintersBrowserProxy.manufacturers = | 147 cupsPrintersBrowserProxy.manufacturers = |
| 122 ['ManufacturerA', 'ManufacturerB', 'Chromites']; | 148 ['ManufacturerA', 'ManufacturerB', 'Chromites']; |
| 123 MockInteractions.tap(addDialog.$$('.action-button')); | 149 MockInteractions.tap(addDialog.$$('.action-button')); |
| 124 Polymer.dom.flush(); | 150 Polymer.dom.flush(); |
| 125 | 151 |
| 126 var modelDialog = dialog.$$('add-printer-manufacturer-model-dialog'); | 152 var modelDialog = dialog.$$('add-printer-manufacturer-model-dialog'); |
| 127 assertTrue(!!modelDialog); | 153 assertTrue(!!modelDialog); |
| 128 | 154 |
| 129 return cupsPrintersBrowserProxy.whenCalled( | 155 return cupsPrintersBrowserProxy.whenCalled( |
| 130 'getCupsPrinterManufacturersList'); | 156 'getCupsPrinterManufacturersList'); |
| 131 }); | 157 }); |
| 132 }); | 158 }); |
| OLD | NEW |