blob: 9bd43d121cd28ec612fb1b8296ac3347842e3c11 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
5#ifndef CHROME_BROWSER_PRINTING_PRINTING_TEST_H__
6#define CHROME_BROWSER_PRINTING_PRINTING_TEST_H__
7
8#include <windows.h>
9#include <winspool.h>
10
[email protected]51e8d9352010-10-06 22:21:1711#include <string>
12
avi126e93c2015-12-21 21:48:1613#include "base/macros.h"
[email protected]51e8d9352010-10-06 22:21:1714
initial.commit09911bf2008-07-26 23:55:2915// Disable the whole test case when executing on a computer that has no printer
16// installed.
[email protected]c4c89cd782012-04-09 21:18:2117// Note: Parent should be testing::Test or InProcessBrowserTest.
initial.commit09911bf2008-07-26 23:55:2918template<typename Parent>
19class PrintingTest : public Parent {
20 public:
21 static bool IsTestCaseDisabled() {
22 return GetDefaultPrinter().empty();
23 }
24 static std::wstring GetDefaultPrinter() {
25 wchar_t printer_name[MAX_PATH];
26 DWORD size = arraysize(printer_name);
27 BOOL result = ::GetDefaultPrinter(printer_name, &size);
28 if (result == 0) {
29 if (GetLastError() == ERROR_FILE_NOT_FOUND) {
30 printf("There is no printer installed, printing can't be tested!\n");
31 return std::wstring();
32 }
33 printf("INTERNAL PRINTER ERROR!\n");
34 return std::wstring();
35 }
36 return printer_name;
37 }
38};
39
40#endif // CHROME_BROWSER_PRINTING_PRINTING_TEST_H__