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

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

Issue 7237030: Added options browser_tests using the generator and js handler framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent & commenting capitalization. Created 9 years, 5 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 (function() { 5 /**
6 function MockHandler() { 6 * TestFixture for print preview WebUI testing.
7 this.__proto__ = MockHandler.prototype; 7 * @extends {testing.Test}
8 }; 8 * @constructor
9 **/
10 function PrintPreviewWebUITest() {}
9 11
10 MockHandler.prototype = { 12 PrintPreviewWebUITest.prototype = {
11 'getDefaultPrinter': function() { 13 __proto__: testing.Test.prototype,
12 console.log('getDefaultPrinter');
13 setDefaultPrinter('FooDevice');
14 },
15 'getPrinters': function() {
16 console.log('getPrinters');
17 setPrinters([
18 {
19 'printerName': 'FooName',
20 'deviceName': 'FooDevice',
21 },
22 {
23 'printerName': 'BarName',
24 'deviceName': 'BarDevice',
25 },
26 ]);
27 },
28 'getPreview': function(settings) {
29 console.log('getPreview(' + settings + ')');
30 updatePrintPreview(1, 'title', true);
31 },
32 'print': function(settings) {
33 console.log('print(' + settings + ')');
34 },
35 'getPrinterCapabilities': function(printer_name) {
36 console.log('getPrinterCapabilities(' + printer_name + ')');
37 updateWithPrinterCapabilities({
38 'disableColorOption': true,
39 'setColorAsDefault': true,
40 'disableCopiesOption': true
41 });
42 },
43 'showSystemDialog': function() {
44 console.log('showSystemDialog');
45 },
46 'managePrinters': function() {
47 console.log('managePrinters');
48 },
49 'closePrintPreviewTab': function() {
50 console.log('closePrintPreviewTab');
51 },
52 'hidePreview': function() {
53 console.log('hidePreview');
54 },
55 };
56 14
57 function registerCallbacks() { 15 /**
58 console.log('registeringCallbacks'); 16 * Browse to the sample page, cause print preview & call our PreLoad().
59 var mock_handler = new MockHandler(); 17 **/
60 for (func in MockHandler.prototype) { 18 browsePrintPreload: 'print_preview_hello_world_test.html',
61 if (typeof(mock_handler[func]) == 'function')
62 registerMessageCallback(func,
63 mock_handler,
64 mock_handler[func]);
65 }
66 };
67 19
68 if ('window' in this && 'registerMessageCallback' in window) 20 /**
69 registerCallbacks(); 21 * Register a mock handler to ensure expectations are met and print preview
70 })(); 22 * behaves correctly.
23 **/
24 PreLoad: function() {
71 25
72 // Tests. 26 /**
73 function FLAKY_TestPrinterList() { 27 * Create a handler class with empty methods to allow mocking to register
74 var printer_list = $('printer-list'); 28 * expectations and for registration of handlers with chrome.send.
75 assertTrue(!!printer_list, 'printer_list'); 29 **/
76 assertTrue(printer_list.options.length >= 2, 'printer-list has at least 2'); 30 function MockPrintPreviewHandler() {}
77 expectEquals('FooName', printer_list.options[0].text, '0 text is FooName'); 31
78 expectEquals('FooDevice', printer_list.options[0].value, 32 MockPrintPreviewHandler.prototype = {
33 getDefaultPrinter: function() {},
34 getPrinters: function() {},
35 getPreview: function(settings) {},
36 print: function(settings) {},
37 getPrinterCapabilities: function(printerName) {},
38 showSystemDialog: function() {},
39 managePrinters: function() {},
40 closePrintPreviewTab: function() {},
41 hidePreview: function() {},
42 };
43
44 // Create the actual mock and register stubs for methods expected to be
45 // called before our tests run. Specific expectations can be made in the
46 // tests themselves.
47 var mockHandler = this.mockHandler = mock(MockPrintPreviewHandler);
48 mockHandler.stubs().getDefaultPrinter().
49 will(callFunction(function() {
50 setDefaultPrinter('FooDevice');
51 }));
52 mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
53 will(callFunction(function() {
54 updateWithPrinterCapabilities({
55 disableColorOption: true,
56 setColorAsDefault: true,
57 disableCopiesOption: true,
58 });
59 }));
60 mockHandler.stubs().getPreview(NOT_NULL).
61 will(callFunction(function() {
62 updatePrintPreview(1, 'title', true);
63 }));
64
65 mockHandler.stubs().getPrinters().
66 will(callFunction(function() {
67 setPrinters([{
68 printerName: 'FooName',
69 deviceName: 'FooDevice',
70 }, {
71 printerName: 'BarName',
72 deviceName: 'BarDevice',
73 },
74 ]);
75 }));
76
77 // Register our mock as a handler of the chrome.send messages.
78 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler);
79 },
80 testGenPreamble: function(testFixture, testName) {
81 GEN(' if (!HasPDFLib()) {');
82 GEN(' LOG(WARNING)');
83 GEN(' << "Skipping test ' + testFixture + '.' + testName + '"');
84 GEN(' << ": No PDF Lib.";');
85 GEN(' SUCCEED();');
86 GEN(' return;');
87 GEN(' }');
88 },
89 typedefCppFixture: null,
90 };
91
92 GEN('#include "base/command_line.h"');
93 GEN('#include "base/path_service.h"');
94 GEN('#include "base/stringprintf.h"');
95 GEN('#include "chrome/browser/ui/webui/web_ui_browsertest.h"');
96 GEN('#include "chrome/common/chrome_paths.h"');
97 GEN('#include "chrome/common/chrome_switches.h"');
98 GEN('');
99 GEN('class PrintPreviewWebUITest');
100 GEN(' : public WebUIBrowserTest {');
101 GEN(' protected:');
102 GEN(' // WebUIBrowserTest override.');
103 GEN(' virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {');
104 GEN(' WebUIBrowserTest::SetUpCommandLine(command_line);');
105 GEN('#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) || \\');
106 GEN(' defined(OS_MACOSX)');
107 GEN(' // Don\'t enable the flag for chrome builds, which should be on by ' +
108 'default.');
109 GEN(' command_line->AppendSwitch(switches::kEnablePrintPreview);');
110 GEN('#else');
111 GEN(' ASSERT_TRUE(switches::IsPrintPreviewEnabled());');
112 GEN('#endif');
113 GEN(' }');
114 GEN('');
115 GEN(' bool HasPDFLib() const {');
116 GEN(' FilePath pdf;');
117 GEN(' return PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&');
118 GEN(' file_util::PathExists(pdf);');
119 GEN(' }');
120 GEN('};');
121 GEN('');
122
123 TEST_F('PrintPreviewWebUITest', 'FLAKY_TestPrinterList', function() {
124 var printerList = $('printer-list');
125 assertTrue(!!printerList, 'printerList');
126 assertTrue(printerList.options.length >= 2, 'printer-list has at least 2');
127 expectEquals('FooName', printerList.options[0].text, '0 text is FooName');
128 expectEquals('FooDevice', printerList.options[0].value,
79 '0 value is FooDevice'); 129 '0 value is FooDevice');
80 expectEquals('BarName', printer_list.options[1].text, '1 text is BarName'); 130 expectEquals('BarName', printerList.options[1].text, '1 text is BarName');
81 expectEquals('BarDevice', printer_list.options[1].value, 131 expectEquals('BarDevice', printerList.options[1].value,
82 '1 value is BarDevice'); 132 '1 value is BarDevice');
83 } 133 });
84
85 var test_fixture = 'PrintPreviewWebUITest';
86 var test_add_library = false;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698