Chromium Code Reviews| 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 (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 }, | |
| 35 'getPrinters': function() { | |
| 36 }, | |
| 37 'getPreview': function(settings) { | |
| 38 }, | |
| 39 'print': function(settings) { | |
| 40 }, | |
| 41 'getPrinterCapabilities': function(printerName) { | |
| 42 }, | |
| 43 'showSystemDialog': function() { | |
| 44 }, | |
| 45 'managePrinters': function() { | |
| 46 }, | |
| 47 'closePrintPreviewTab': function() { | |
| 48 }, | |
| 49 'hidePreview': function() { | |
| 50 }, | |
| 51 }; | |
| 52 | |
| 53 // Create the actual mock and register stubs for methods expected to be | |
| 54 // called before our tests run. Specific expectations can be made in the | |
| 55 // tests themselves. | |
| 56 var mockHandler = this.mockHandler = mock(MockPrintPreviewHandler); | |
| 57 mockHandler.stubs().getDefaultPrinter(). | |
| 58 will(callFunction( | |
| 59 function() { | |
| 60 setDefaultPrinter('FooDevice'); | |
| 61 })); | |
| 62 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). | |
| 63 will(callFunction( | |
| 64 function() { | |
| 65 updateWithPrinterCapabilities({ | |
| 66 'disableColorOption': true, | |
|
Evan Stade
2011/07/08 23:04:46
indent is wrong, see http://google-styleguide.goog
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
| 67 'setColorAsDefault': true, | |
| 68 'disableCopiesOption': true | |
| 69 }); | |
| 70 })); | |
| 71 mockHandler.stubs().getPreview(NOT_NULL). | |
| 72 will(callFunction( | |
| 73 function() { | |
|
Evan Stade
2011/07/08 23:04:46
put `function() {` on the line above (throughout f
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
| 74 updatePrintPreview(1, 'title', true); | |
| 75 })); | |
| 76 | |
| 77 mockHandler.stubs().getPrinters(). | |
| 78 will(callFunction( | |
| 79 function() { | |
| 80 setPrinters([ | |
| 81 { | |
|
Evan Stade
2011/07/08 23:04:46
merge L80-81
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
| 82 'printerName': 'FooName', | |
|
Evan Stade
2011/07/08 23:04:46
indent wrong again
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
| 83 'deviceName': 'FooDevice', | |
| 84 }, | |
|
Evan Stade
2011/07/08 23:04:46
merge L84-85
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
| 85 { | |
| 86 'printerName': 'BarName', | |
| 87 'deviceName': 'BarDevice', | |
| 88 }, | |
| 89 ]); | |
| 90 })); | |
| 91 | |
| 92 // Register our mock as a handler of the chrome.send messages. | |
| 93 registerMockMessageCallbacks(mockHandler, MockPrintPreviewHandler); | |
| 94 }, | |
| 95 }; | |
| 96 | |
| 97 GEN('#include "base/command_line.h"'); | |
| 98 GEN('#include "base/path_service.h"'); | |
| 99 GEN('#include "base/stringprintf.h"'); | |
| 100 GEN('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); | |
| 101 GEN('#include "chrome/common/chrome_paths.h"'); | |
| 102 GEN('#include "chrome/common/chrome_switches.h"'); | |
| 103 GEN('#include "googleurl/src/gurl.h"'); | |
| 104 GEN('#include "testing/gtest/include/gtest/gtest.h"'); | |
| 105 GEN(''); | |
| 106 GEN('class PrintPreviewWebUITest'); | |
| 107 GEN(' : public WebUIBrowserTest {'); | |
| 108 GEN(' protected:'); | |
| 109 GEN(' // WebUIBrowserTest:'); | |
| 110 GEN(' virtual void SetUpOnMainThread() OVERRIDE {'); | |
| 111 GEN(' WebUIBrowserTest::SetUpOnMainThread();'); | |
| 112 GEN(' if (!HasPDFLib())'); | |
| 113 GEN(' ' + | |
| 114 'skipTest(base::StringPrintf("%s:%d: No PDF Lib.", __FILE__, __LINE__));'); | |
| 115 GEN(' }'); | |
| 116 GEN(''); | |
| 117 GEN(' virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {'); | |
| 118 GEN(' WebUIBrowserTest::SetUpCommandLine(command_line);'); | |
| 119 GEN('#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) || \\'); | |
| 120 GEN(' defined(OS_MACOSX)'); | |
| 121 GEN(' // Don\'t enable the flag for chrome builds, which should be on by ' + | |
| 122 'default.'); | |
| 123 GEN(' command_line->AppendSwitch(switches::kEnablePrintPreview);'); | |
| 124 GEN('#else'); | |
| 125 GEN(' ASSERT_TRUE(switches::IsPrintPreviewEnabled());'); | |
| 126 GEN('#endif'); | |
| 127 GEN(' }'); | |
| 128 GEN(''); | |
| 129 GEN(' bool HasPDFLib() const {'); | |
| 130 GEN(' FilePath pdf;'); | |
| 131 GEN(' return PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) &&'); | |
| 132 GEN(' file_util::PathExists(pdf);'); | |
| 133 GEN(' }'); | |
| 134 GEN('};'); | |
| 135 GEN(''); | |
| 136 | |
| 137 TEST_F('PrintPreviewWebUITest', 'FLAKY_TestPrinterList', function() { | |
| 138 var printerList = $('printer-list'); | |
| 139 assertTrue(!!printerList, 'printerList'); | |
| 140 assertTrue(printerList.options.length >= 2, 'printer-list has at least 2'); | |
| 141 expectEquals('FooName', printerList.options[0].text, '0 text is FooName'); | |
| 142 expectEquals('FooDevice', printerList.options[0].value, | |
| 79 '0 value is FooDevice'); | 143 '0 value is FooDevice'); |
| 80 expectEquals('BarName', printer_list.options[1].text, '1 text is BarName'); | 144 expectEquals('BarName', printerList.options[1].text, '1 text is BarName'); |
| 81 expectEquals('BarDevice', printer_list.options[1].value, | 145 expectEquals('BarDevice', printerList.options[1].value, |
| 82 '1 value is BarDevice'); | 146 '1 value is BarDevice'); |
| 83 } | 147 }); |
| 84 | |
| 85 var test_fixture = 'PrintPreviewWebUITest'; | |
| 86 var test_add_library = false; | |
| OLD | NEW |