| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 * Test fixture for print preview WebUI testing. | 6 * Test fixture for print preview WebUI testing. |
| 7 * @extends {testing.Test} | 7 * @extends {testing.Test} |
| 8 * @constructor | 8 * @constructor |
| 9 */ | 9 */ |
| 10 function PrintPreviewWebUITest() {} | 10 function PrintPreviewWebUITest() {} |
| 11 | 11 |
| 12 PrintPreviewWebUITest.prototype = { | 12 PrintPreviewWebUITest.prototype = { |
| 13 __proto__: testing.Test.prototype, | 13 __proto__: testing.Test.prototype, |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Browse to the sample page, cause print preview & call preLoad(). | 16 * Browse to the sample page, cause print preview & call preLoad(). |
| 17 * @type {string} | 17 * @type {string} |
| 18 * @override | 18 * @override |
| 19 */ | 19 */ |
| 20 browsePrintPreload: 'print_preview_hello_world_test.html', | 20 browsePrintPreload: 'print_preview_hello_world_test.html', |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Register a mock handler to ensure expectations are met and print preview | 23 * Register a mock handler to ensure expectations are met and print preview |
| 24 * behaves correctly. | 24 * behaves correctly. |
| 25 * @type {Function} | 25 * @type {Function} |
| 26 * @override | 26 * @override |
| 27 */ | 27 */ |
| 28 preLoad: function() { | 28 preLoad: function() { |
| 29 // TODO(scr) remove this after tests pass consistently. | 29 this.makeAndRegisterMockHandler(['getDefaultPrinter', |
| 30 console.info('preLoad'); | 30 'getPrinters', |
| 31 'getPreview', |
| 32 'print', |
| 33 'getPrinterCapabilities', |
| 34 'showSystemDialog', |
| 35 'morePrinters', |
| 36 'signIn', |
| 37 'addCloudPrinter', |
| 38 'manageCloudPrinters', |
| 39 'manageLocalPrinters', |
| 40 'closePrintPreviewTab', |
| 41 'hidePreview', |
| 42 'cancelPendingPrintRequest', |
| 43 'saveLastPrinter', |
| 44 ]); |
| 31 | 45 |
| 32 /** | 46 // Register stubs for methods expected to be called before tests |
| 33 * Create a handler class with empty methods to allow mocking to register | 47 // run. Specific expectations can be made in the tests themselves. |
| 34 * expectations and for registration of handlers with chrome.send. | 48 this.mockHandler.stubs().getDefaultPrinter(). |
| 35 * @constructor | |
| 36 */ | |
| 37 function MockPrintPreviewHandler() {} | |
| 38 | |
| 39 MockPrintPreviewHandler.prototype = { | |
| 40 getDefaultPrinter: function() {}, | |
| 41 getPrinters: function() {}, | |
| 42 getPreview: function(settings, draft_page_count, modifiable) {}, | |
| 43 print: function(settings) {}, | |
| 44 getPrinterCapabilities: function(printerName) {}, | |
| 45 showSystemDialog: function() {}, | |
| 46 morePrinters: function() {}, | |
| 47 signIn: function() {}, | |
| 48 addCloudPrinter: function() {}, | |
| 49 manageCloudPrinters: function() {}, | |
| 50 manageLocalPrinters: function() {}, | |
| 51 closePrintPreviewTab: function() {}, | |
| 52 hidePreview: function() {}, | |
| 53 cancelPendingPrintRequest: function() {}, | |
| 54 saveLastPrinter: function(name, cloud_print_data) {}, | |
| 55 }; | |
| 56 | |
| 57 // Create the actual mock and register stubs for methods expected to be | |
| 58 // called before tests run. Specific expectations can be made in the | |
| 59 // tests themselves. | |
| 60 var mockHandler = this.mockHandler = mock(MockPrintPreviewHandler); | |
| 61 mockHandler.stubs().getDefaultPrinter(). | |
| 62 will(callFunction(function() { | 49 will(callFunction(function() { |
| 63 setDefaultPrinter('FooDevice'); | 50 setDefaultPrinter('FooDevice'); |
| 64 })); | 51 })); |
| 65 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). | 52 this.mockHandler.stubs().getPrinterCapabilities(NOT_NULL). |
| 66 will(callFunction(function() { | 53 will(callFunction(function() { |
| 67 updateWithPrinterCapabilities({ | 54 updateWithPrinterCapabilities({ |
| 68 disableColorOption: true, | 55 disableColorOption: true, |
| 69 setColorAsDefault: true, | 56 setColorAsDefault: true, |
| 70 disableCopiesOption: true, | 57 disableCopiesOption: true, |
| 71 printerDefaultDuplexValue: copiesSettings.SIMPLEX, | 58 printerDefaultDuplexValue: copiesSettings.SIMPLEX, |
| 72 }); | 59 }); |
| 73 })); | 60 })); |
| 74 var savedArgs = new SaveMockArguments(); | 61 var savedArgs = new SaveMockArguments(); |
| 75 mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)). | 62 this.mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)). |
| 76 will(callFunctionWithSavedArgs(savedArgs, function(args) { | 63 will(callFunctionWithSavedArgs(savedArgs, function(args) { |
| 77 updatePrintPreview(1, JSON.parse(args[0]).requestID); | 64 updatePrintPreview(1, JSON.parse(args[0]).requestID); |
| 78 })); | 65 })); |
| 79 | 66 |
| 80 mockHandler.stubs().getPrinters(). | 67 this.mockHandler.stubs().getPrinters(). |
| 81 will(callFunction(function() { | 68 will(callFunction(function() { |
| 82 setPrinters([{ | 69 setPrinters([{ |
| 83 printerName: 'FooName', | 70 printerName: 'FooName', |
| 84 deviceName: 'FooDevice', | 71 deviceName: 'FooDevice', |
| 85 }, { | 72 }, { |
| 86 printerName: 'BarName', | 73 printerName: 'BarName', |
| 87 deviceName: 'BarDevice', | 74 deviceName: 'BarDevice', |
| 88 }, | 75 }, |
| 89 ]); | 76 ]); |
| 90 })); | 77 })); |
| 91 | 78 |
| 92 // Register mock as a handler of the chrome.send messages. | 79 this.makeAndRegisterMockGlobals(['updateWithPrinterCapabilities']); |
| 93 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler); | 80 this.mockGlobals.stubs().updateWithPrinterCapabilities( |
| 94 | |
| 95 /** | |
| 96 * Create a class to hold global functions to watch for. | |
| 97 * @constructor | |
| 98 */ | |
| 99 function MockGlobals() {} | |
| 100 | |
| 101 MockGlobals.prototype = { | |
| 102 updateWithPrinterCapabilities: function(settingInfo) {}, | |
| 103 }; | |
| 104 | |
| 105 var mockGlobals = this.mockGlobals = mock(MockGlobals); | |
| 106 mockGlobals.stubs().updateWithPrinterCapabilities( | |
| 107 savedArgs.match(ANYTHING)). | 81 savedArgs.match(ANYTHING)). |
| 108 will(callGlobalWithSavedArgs( | 82 will(callGlobalWithSavedArgs( |
| 109 savedArgs, 'updateWithPrinterCapabilities')); | 83 savedArgs, 'updateWithPrinterCapabilities')); |
| 110 | 84 |
| 111 // Register globals to mock out for us. | |
| 112 registerMockGlobals(mockGlobals, MockGlobals); | |
| 113 | |
| 114 // Override checkCompatiblePluginExists to return a value consistent with | 85 // Override checkCompatiblePluginExists to return a value consistent with |
| 115 // the state being tested and stub out the pdf viewer if it doesn't exist, | 86 // the state being tested and stub out the pdf viewer if it doesn't exist, |
| 116 // such as on non-official builds. When the plugin exists, use the real | 87 // such as on non-official builds. When the plugin exists, use the real |
| 117 // thing. | 88 // thing. |
| 118 var self = this; | 89 var self = this; |
| 119 window.addEventListener('DOMContentLoaded', function() { | 90 window.addEventListener('DOMContentLoaded', function() { |
| 120 if (!this.checkCompatiblePluginExists()) { | 91 if (!this.checkCompatiblePluginExists()) { |
| 121 // TODO(scr) remove this after tests pass consistently. | 92 // TODO(scr) remove this after tests pass consistently. |
| 122 console.info('no PDF Plugin; providing fake methods.'); | 93 console.info('no PDF Plugin; providing fake methods.'); |
| 123 this.createPDFPlugin = self.createPDFPlugin; | 94 this.createPDFPlugin = self.createPDFPlugin; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 413 |
| 443 // Test that error message is displayed when plugin doesn't exist. | 414 // Test that error message is displayed when plugin doesn't exist. |
| 444 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { | 415 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { |
| 445 var errorButton = $('error-button'); | 416 var errorButton = $('error-button'); |
| 446 assertNotEquals(null, errorButton); | 417 assertNotEquals(null, errorButton); |
| 447 expectFalse(errorButton.disabled); | 418 expectFalse(errorButton.disabled); |
| 448 var errorText = $('custom-message'); | 419 var errorText = $('custom-message'); |
| 449 assertNotEquals(null, errorText); | 420 assertNotEquals(null, errorText); |
| 450 expectFalse(errorText.hidden); | 421 expectFalse(errorText.hidden); |
| 451 }); | 422 }); |
| OLD | NEW |