summaryrefslogtreecommitdiff
path: root/chromium/printing/print_settings_conversion_unittest.cc
blob: 2039a55ce7c5a7f57f1ae6f12c0b6d4e8e3a03d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "printing/print_settings_conversion.h"

#include "base/json/json_reader.h"
#include "base/values.h"
#include "printing/print_settings.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace printing {

namespace {

const char kPrinterSettings[] = R"({
  "headerFooterEnabled": true,
  "title": "Test Doc",
  "url": "http://localhost/",
  "shouldPrintBackgrounds": false,
  "shouldPrintSelectionOnly": false,
  "mediaSize": {
    "height_microns": 297000,
    "width_microns": 210000
  },
  "marginsType": 0,
  "pageRange": [{
    "from": 1,
    "to": 1
  }],
  "collate": false,
  "copies": 1,
  "color": 2,
  "duplex": 0,
  "landscape": false,
  "deviceName": "printer",
  "scaleFactor": 100,
  "rasterizePDF": false,
  "pagesPerSheet": 1,
  "dpiHorizontal": 300,
  "dpiVertical": 300,
  "previewModifiable": true,
  "sendUserInfo": true,
  "username": "username@domain.net",
  "pinValue": "0000"
})";

}  // namespace

TEST(PrintSettingsConversionTest, ConversionTest) {
  base::Optional<base::Value> value = base::JSONReader::Read(kPrinterSettings);
  ASSERT_TRUE(value.has_value());
  PrintSettings settings;
  bool success = PrintSettingsFromJobSettings(value.value(), &settings);
  ASSERT_TRUE(success);
#if defined(OS_CHROMEOS)
  EXPECT_TRUE(settings.send_user_info());
  EXPECT_EQ("username@domain.net", settings.username());
  EXPECT_EQ("0000", settings.pin_value());
#endif
}

#if defined(OS_CHROMEOS)
TEST(PrintSettingsConversionTest, ConversionTest_DontSendUsername) {
  base::Optional<base::Value> value = base::JSONReader::Read(kPrinterSettings);
  ASSERT_TRUE(value.has_value());
  value->SetKey(kSettingSendUserInfo, base::Value(false));
  PrintSettings settings;
  bool success = PrintSettingsFromJobSettings(value.value(), &settings);
  ASSERT_TRUE(success);
  EXPECT_FALSE(settings.send_user_info());
  EXPECT_EQ("", settings.username());
}
#endif

}  // namespace printing