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

Side by Side Diff: chrome/test/data/webui/print_preview.js

Issue 8503003: Seed test for SyncUI: sign in successfully with mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made some utility methods to make mockHandler and mockGlobals generation simpler. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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() {}
(...skipping 11 matching lines...) Expand all
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 // TODO(scr) remove this after tests pass consistently.
30 console.info('preLoad'); 30 console.info('preLoad');
31 31
32 /** 32 this.makeAndRegisterMockHandler(['getDefaultPrinter',
33 * Create a handler class with empty methods to allow mocking to register 33 'getPrinters',
34 * expectations and for registration of handlers with chrome.send. 34 'getPreview',
35 * @constructor 35 'print',
36 */ 36 'getPrinterCapabilities',
37 function MockPrintPreviewHandler() {} 37 'showSystemDialog',
38 'morePrinters',
39 'signIn',
40 'addCloudPrinter',
41 'manageCloudPrinters',
42 'manageLocalPrinters',
43 'closePrintPreviewTab',
44 'hidePreview',
45 'cancelPendingPrintRequest',
46 'saveLastPrinter',
47 ]);
38 48
39 MockPrintPreviewHandler.prototype = { 49 // Register stubs for methods expected to be called before tests
40 getDefaultPrinter: function() {}, 50 // run. Specific expectations can be made in the tests themselves.
41 getPrinters: function() {}, 51 var mockHandler = this.mockHandler;
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(). 52 mockHandler.stubs().getDefaultPrinter().
62 will(callFunction(function() { 53 will(callFunction(function() {
63 setDefaultPrinter('FooDevice'); 54 setDefaultPrinter('FooDevice');
64 })); 55 }));
65 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). 56 mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
66 will(callFunction(function() { 57 will(callFunction(function() {
67 updateWithPrinterCapabilities({ 58 updateWithPrinterCapabilities({
68 disableColorOption: true, 59 disableColorOption: true,
69 setColorAsDefault: true, 60 setColorAsDefault: true,
70 disableCopiesOption: true, 61 disableCopiesOption: true,
(...skipping 11 matching lines...) Expand all
82 setPrinters([{ 73 setPrinters([{
83 printerName: 'FooName', 74 printerName: 'FooName',
84 deviceName: 'FooDevice', 75 deviceName: 'FooDevice',
85 }, { 76 }, {
86 printerName: 'BarName', 77 printerName: 'BarName',
87 deviceName: 'BarDevice', 78 deviceName: 'BarDevice',
88 }, 79 },
89 ]); 80 ]);
90 })); 81 }));
91 82
92 // Register mock as a handler of the chrome.send messages. 83 this.makeAndRegisterMockGlobals(['updateWithPrinterCapabilities']);
93 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler); 84 var mockGlobals = this.mockGlobals;
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( 85 mockGlobals.stubs().updateWithPrinterCapabilities(
107 savedArgs.match(ANYTHING)). 86 savedArgs.match(ANYTHING)).
108 will(callGlobalWithSavedArgs( 87 will(callGlobalWithSavedArgs(
109 savedArgs, 'updateWithPrinterCapabilities')); 88 savedArgs, 'updateWithPrinterCapabilities'));
110 89
111 // Register globals to mock out for us.
112 registerMockGlobals(mockGlobals, MockGlobals);
113
114 // Override checkCompatiblePluginExists to return a value consistent with 90 // Override checkCompatiblePluginExists to return a value consistent with
115 // the state being tested and stub out the pdf viewer if it doesn't exist, 91 // 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 92 // such as on non-official builds. When the plugin exists, use the real
117 // thing. 93 // thing.
118 var self = this; 94 var self = this;
119 window.addEventListener('DOMContentLoaded', function() { 95 window.addEventListener('DOMContentLoaded', function() {
120 if (!this.checkCompatiblePluginExists()) { 96 if (!this.checkCompatiblePluginExists()) {
121 // TODO(scr) remove this after tests pass consistently. 97 // TODO(scr) remove this after tests pass consistently.
122 console.info('no PDF Plugin; providing fake methods.'); 98 console.info('no PDF Plugin; providing fake methods.');
123 this.createPDFPlugin = self.createPDFPlugin; 99 this.createPDFPlugin = self.createPDFPlugin;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 418
443 // Test that error message is displayed when plugin doesn't exist. 419 // Test that error message is displayed when plugin doesn't exist.
444 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { 420 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() {
445 var errorButton = $('error-button'); 421 var errorButton = $('error-button');
446 assertNotEquals(null, errorButton); 422 assertNotEquals(null, errorButton);
447 expectFalse(errorButton.disabled); 423 expectFalse(errorButton.disabled);
448 var errorText = $('custom-message'); 424 var errorText = $('custom-message');
449 assertNotEquals(null, errorText); 425 assertNotEquals(null, errorText);
450 expectFalse(errorText.hidden); 426 expectFalse(errorText.hidden);
451 }); 427 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698