1 // Copyright 2014 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.
5 #include "extensions/browser/api/document_scan/document_scan_interface_chromeos.h"
10 #include "base/bind.h"
11 #include "chromeos/dbus/mock_lorgnette_manager_client.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
17 namespace extensions
{
21 // Tests of networking_private_crypto support for Networking Private API.
22 class DocumentScanInterfaceChromeosTest
: public testing::Test
{
24 DocumentScanInterfaceChromeosTest()
25 : client_(new chromeos::MockLorgnetteManagerClient()) {}
26 ~DocumentScanInterfaceChromeosTest() override
{}
28 void SetUp() override
{
29 scan_interface_
.lorgnette_manager_client_
= client_
.get();
32 MOCK_METHOD2(OnListScannersResultReceived
,
33 void(const std::vector
<
34 DocumentScanInterface::ScannerDescription
>& scanners
,
35 const std::string
& error
));
37 MOCK_METHOD3(OnScanCompleted
,
38 void(const std::string
& scanned_image
,
39 const std::string
& mime_type
,
40 const std::string
& error
));
43 DocumentScanInterfaceChromeos scan_interface_
;
44 scoped_ptr
<chromeos::MockLorgnetteManagerClient
> client_
;
47 ACTION_P2(InvokeListScannersCallback
, scanner_list
, error
) {
48 ::std::tr1::get
<0>(args
).Run(scanner_list
, error
);
51 ACTION_P2(InvokeScanCallback
, succeeded
, image_data
) {
52 ::std::tr1::get
<2>(args
).Run(succeeded
, image_data
);
55 MATCHER_P5(IsScannerDescription
, name
, manufacturer
, model
, type
, mime
, "") {
56 return arg
.name
== name
&& arg
.manufacturer
== manufacturer
&&
57 arg
.model
== model
&& arg
.scanner_type
== type
&&
58 arg
.image_mime_type
== mime
;
61 MATCHER_P2(IsScannerProperties
, mode
, resolution
, "") {
62 return arg
.mode
== mode
&& arg
.resolution_dpi
== resolution
;
65 TEST_F(DocumentScanInterfaceChromeosTest
, ListScanners
) {
66 chromeos::LorgnetteManagerClient::ScannerTable scanners
;
67 const char kScannerName
[] = "Monet";
68 chromeos::LorgnetteManagerClient::ScannerTableEntry entry
;
69 const char kScannerManufacturer
[] = "Jacques-Louis David";
70 entry
[lorgnette::kScannerPropertyManufacturer
] = kScannerManufacturer
;
71 const char kScannerModel
[] = "Le Havre";
72 entry
[lorgnette::kScannerPropertyModel
] = kScannerModel
;
73 const char kScannerType
[] = "Impressionism";
74 entry
[lorgnette::kScannerPropertyType
] = kScannerType
;
75 scanners
[kScannerName
] = entry
;
76 EXPECT_CALL(*client_
, ListScanners(_
))
77 .WillOnce(InvokeListScannersCallback(true, scanners
));
78 EXPECT_CALL(*this, OnListScannersResultReceived(
79 testing::ElementsAre(IsScannerDescription(
80 kScannerName
, kScannerManufacturer
, kScannerModel
,
81 kScannerType
, "image/png")),
83 scan_interface_
.ListScanners(base::Bind(
84 &DocumentScanInterfaceChromeosTest::OnListScannersResultReceived
,
85 base::Unretained(this)));
88 TEST_F(DocumentScanInterfaceChromeosTest
, ScanFailure
) {
89 const char kScannerName
[] = "Monet";
90 const int kResolution
= 4096;
91 EXPECT_CALL(*client_
, ScanImageToString(
94 lorgnette::kScanPropertyModeColor
, kResolution
),
95 _
)).WillOnce(InvokeScanCallback(false, ""));
96 EXPECT_CALL(*this, OnScanCompleted("data:image/png;base64,", "image/png",
97 "Image scan failed"));
99 kScannerName
, DocumentScanInterface::kScanModeColor
, kResolution
,
100 base::Bind(&DocumentScanInterfaceChromeosTest::OnScanCompleted
,
101 base::Unretained(this)));
104 TEST_F(DocumentScanInterfaceChromeosTest
, ScanSuccess
) {
105 const char kScannerName
[] = "Monet";
106 const int kResolution
= 4096;
111 IsScannerProperties(lorgnette::kScanPropertyModeColor
, kResolution
),
112 _
)).WillOnce(InvokeScanCallback(true, std::string("PrettyPicture")));
114 // Data URL plus base64 representation of "PrettyPicture".
115 const char kExpectedImageData
[] =
116 "data:image/png;base64,UHJldHR5UGljdHVyZQ==";
118 EXPECT_CALL(*this, OnScanCompleted(kExpectedImageData
, "image/png", ""));
119 scan_interface_
.Scan(
120 kScannerName
, DocumentScanInterface::kScanModeColor
, kResolution
,
121 base::Bind(&DocumentScanInterfaceChromeosTest::OnScanCompleted
,
122 base::Unretained(this)));
125 } // namespace core_api
127 } // namespace extensions