license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
Lei Zhang | 9fae89c | 2018-09-26 03:29:48 | [diff] [blame] | 5 | #ifndef PRINTING_PRINTING_TEST_H_ |
| 6 | #define PRINTING_PRINTING_TEST_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
| 8 | #include <windows.h> |
| 9 | #include <winspool.h> |
| 10 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 11 | #include <string> |
| 12 | |
Lei Zhang | 9fae89c | 2018-09-26 03:29:48 | [diff] [blame] | 13 | #include "base/stl_util.h" |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 14 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | // Disable the whole test case when executing on a computer that has no printer |
| 16 | // installed. |
[email protected] | c4c89cd | 2012-04-09 21:18:21 | [diff] [blame] | 17 | // Note: Parent should be testing::Test or InProcessBrowserTest. |
Lei Zhang | 01a1d3c0 | 2019-05-21 04:59:10 | [diff] [blame] | 18 | template <typename Parent> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | class PrintingTest : public Parent { |
| 20 | public: |
Lei Zhang | 01a1d3c0 | 2019-05-21 04:59:10 | [diff] [blame] | 21 | static bool IsTestCaseDisabled() { return GetDefaultPrinter().empty(); } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | static std::wstring GetDefaultPrinter() { |
| 23 | wchar_t printer_name[MAX_PATH]; |
Lei Zhang | 9fae89c | 2018-09-26 03:29:48 | [diff] [blame] | 24 | DWORD size = base::size(printer_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | BOOL result = ::GetDefaultPrinter(printer_name, &size); |
| 26 | if (result == 0) { |
| 27 | if (GetLastError() == ERROR_FILE_NOT_FOUND) { |
| 28 | printf("There is no printer installed, printing can't be tested!\n"); |
| 29 | return std::wstring(); |
| 30 | } |
| 31 | printf("INTERNAL PRINTER ERROR!\n"); |
| 32 | return std::wstring(); |
| 33 | } |
| 34 | return printer_name; |
| 35 | } |
| 36 | }; |
| 37 | |
Lei Zhang | 9fae89c | 2018-09-26 03:29:48 | [diff] [blame] | 38 | #endif // PRINTING_PRINTING_TEST_H_ |