blob: 0839204488d3e75102ae5c0e6d9c75baba16c5a1 [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
Lei Zhang9fae89c2018-09-26 03:29:485#ifndef PRINTING_PRINTING_TEST_H_
6#define PRINTING_PRINTING_TEST_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <windows.h>
9#include <winspool.h>
10
[email protected]51e8d9352010-10-06 22:21:1711#include <string>
12
Lei Zhang9fae89c2018-09-26 03:29:4813#include "base/stl_util.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]c4c89cd2012-04-09 21:18:2117// Note: Parent should be testing::Test or InProcessBrowserTest.
Lei Zhang01a1d3c02019-05-21 04:59:1018template <typename Parent>
initial.commit09911bf2008-07-26 23:55:2919class PrintingTest : public Parent {
20 public:
Lei Zhang01a1d3c02019-05-21 04:59:1021 static bool IsTestCaseDisabled() { return GetDefaultPrinter().empty(); }
initial.commit09911bf2008-07-26 23:55:2922 static std::wstring GetDefaultPrinter() {
23 wchar_t printer_name[MAX_PATH];
Lei Zhang9fae89c2018-09-26 03:29:4824 DWORD size = base::size(printer_name);
initial.commit09911bf2008-07-26 23:55:2925 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 Zhang9fae89c2018-09-26 03:29:4838#endif // PRINTING_PRINTING_TEST_H_