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

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

Issue 7645007: WebUI Testing: async support - global mocking, deferred runs, continued run. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Create an enum to describe when testDone should be called. Created 9 years, 4 months 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() {}
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 // TODO(scr) remove this after tests pass consistently.
30 console.info('PreLoad'); 30 console.info('preLoad');
31 31
32 /** 32 /**
33 * Create a handler class with empty methods to allow mocking to register 33 * Create a handler class with empty methods to allow mocking to register
34 * expectations and for registration of handlers with chrome.send. 34 * expectations and for registration of handlers with chrome.send.
35 * @constructor
35 **/ 36 **/
36 function MockPrintPreviewHandler() {} 37 function MockPrintPreviewHandler() {}
37 38
38 MockPrintPreviewHandler.prototype = { 39 MockPrintPreviewHandler.prototype = {
39 getDefaultPrinter: function() {}, 40 getDefaultPrinter: function() {},
40 getPrinters: function() {}, 41 getPrinters: function() {},
41 getPreview: function(settings) {}, 42 getPreview: function(settings) {},
42 print: function(settings) {}, 43 print: function(settings) {},
43 getPrinterCapabilities: function(printerName) {}, 44 getPrinterCapabilities: function(printerName) {},
44 showSystemDialog: function() {}, 45 showSystemDialog: function() {},
(...skipping 17 matching lines...) Expand all
62 setDefaultPrinter('FooDevice'); 63 setDefaultPrinter('FooDevice');
63 })); 64 }));
64 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). 65 mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
65 will(callFunction(function() { 66 will(callFunction(function() {
66 updateWithPrinterCapabilities({ 67 updateWithPrinterCapabilities({
67 disableColorOption: true, 68 disableColorOption: true,
68 setColorAsDefault: true, 69 setColorAsDefault: true,
69 disableCopiesOption: true, 70 disableCopiesOption: true,
70 }); 71 });
71 })); 72 }));
72 mockHandler.stubs().getPreview(NOT_NULL). 73 var savedArgs = new SaveMockArguments();
73 will(callFunction(function() { 74 mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)).
74 updatePrintPreview('title', true, 1, 1); 75 will(callFunctionWithSavedArgs(savedArgs, function(options) {
76 updatePrintPreview('title', true, 1, JSON.parse(options).requestID);
75 })); 77 }));
76 78
77 mockHandler.stubs().getPrinters(). 79 mockHandler.stubs().getPrinters().
78 will(callFunction(function() { 80 will(callFunction(function() {
79 setUseCloudPrint(false, ""); 81 setUseCloudPrint(false, "");
mmenke 2011/08/23 15:26:29 nit: Single quotes.
Sheridan Rawlins 2011/08/24 02:33:53 Done.
80 setPrinters([{ 82 setPrinters([{
81 printerName: 'FooName', 83 printerName: 'FooName',
82 deviceName: 'FooDevice', 84 deviceName: 'FooDevice',
83 }, { 85 }, {
84 printerName: 'BarName', 86 printerName: 'BarName',
85 deviceName: 'BarDevice', 87 deviceName: 'BarDevice',
86 }, 88 },
87 ]); 89 ]);
88 })); 90 }));
89 91
90 // Register mock as a handler of the chrome.send messages. 92 // Register mock as a handler of the chrome.send messages.
91 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler); 93 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler);
92 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)).
108 will(callGlobalWithSavedArgs(
109 savedArgs, 'updateWithPrinterCapabilities'));
110
111 // Register globals to mock out for us.
112 registerMockGlobals(mockGlobals, MockGlobals);
113
93 // Override checkCompatiblePluginExists to return a value consistent with 114 // Override checkCompatiblePluginExists to return a value consistent with
94 // the state being tested and stub out the pdf viewer if it doesn't exist, 115 // the state being tested and stub out the pdf viewer if it doesn't exist,
95 // such as on non-official builds. When the plugin exists, use the real 116 // such as on non-official builds. When the plugin exists, use the real
96 // thing. 117 // thing.
97 var self = this; 118 var self = this;
98 window.addEventListener('DOMContentLoaded', function() { 119 window.addEventListener('DOMContentLoaded', function() {
99 if (!this.checkCompatiblePluginExists()) { 120 if (!this.checkCompatiblePluginExists()) {
100 // TODO(scr) remove this after tests pass consistently. 121 // TODO(scr) remove this after tests pass consistently.
101 console.info('no PDF Plugin; providing fake methods.'); 122 console.info('no PDF Plugin; providing fake methods.');
102 this.createPDFPlugin = self.createPDFPlugin; 123 this.createPDFPlugin = self.createPDFPlugin;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 disableLandscapeOption: false, 331 disableLandscapeOption: false,
311 }); 332 });
312 })); 333 }));
313 334
314 updateControlsWithSelectedPrinterCapabilities(); 335 updateControlsWithSelectedPrinterCapabilities();
315 expectFalse(colorSettings.colorRadioButton.checked); 336 expectFalse(colorSettings.colorRadioButton.checked);
316 expectTrue(colorSettings.bwRadioButton.checked); 337 expectTrue(colorSettings.bwRadioButton.checked);
317 }); 338 });
318 339
319 // Test that changing the selected printer updates the preview. 340 // Test that changing the selected printer updates the preview.
320 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', 341 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
321 function() { 342 var savedArgs = new SaveMockArguments();
322 var matchAnythingSave = new SaveArgumentsMatcher(ANYTHING); 343 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
344 will(callFunctionWithSavedArgs(savedArgs, function(options) {
345 updatePrintPreview('title', true, 2,
346 JSON.parse(options).requestID);
347 }));
323 348
324 this.mockHandler.expects(once()).getPreview(matchAnythingSave). 349 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
325 will(callFunction(function() { 350 savedArgs.match(ANYTHING)).
326 updatePrintPreview('title', true, 2, 351 will(callGlobalWithSavedArgs(
327 matchAnythingSave.argument.requestID); 352 savedArgs, 'updateWithPrinterCapabilities'));
328 }));
329 353
330 var printerList = $('printer-list'); 354 var printerList = $('printer-list');
331 assertNotEquals(null, printerList, 'printerList'); 355 assertNotEquals(null, printerList, 'printerList');
332 assertGE(printerList.options.length, printerListMinLength); 356 assertGE(printerList.options.length, printerListMinLength);
333 expectEquals(fooIndex, printerList.selectedIndex, 357 expectEquals(fooIndex, printerList.selectedIndex,
334 'fooIndex=' + fooIndex); 358 'fooIndex=' + fooIndex);
335 var oldLastPreviewRequestID = lastPreviewRequestID; 359 var oldLastPreviewRequestID = lastPreviewRequestID;
336 ++printerList.selectedIndex; 360 ++printerList.selectedIndex;
337 updateControlsWithSelectedPrinterCapabilities(); 361 updateControlsWithSelectedPrinterCapabilities();
338 expectNotEquals(oldLastPreviewRequestID, lastPreviewRequestID); 362 expectNotEquals(oldLastPreviewRequestID, lastPreviewRequestID);
(...skipping 28 matching lines...) Expand all
367 391
368 // Test that error message is displayed when plugin doesn't exist. 392 // Test that error message is displayed when plugin doesn't exist.
369 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { 393 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() {
370 var errorButton = $('error-button'); 394 var errorButton = $('error-button');
371 assertNotEquals(null, errorButton); 395 assertNotEquals(null, errorButton);
372 expectFalse(errorButton.disabled); 396 expectFalse(errorButton.disabled);
373 var errorText = $('error-text'); 397 var errorText = $('error-text');
374 assertNotEquals(null, errorText); 398 assertNotEquals(null, errorText);
375 expectFalse(errorText.classList.contains('hidden')); 399 expectFalse(errorText.classList.contains('hidden'));
376 }); 400 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698