Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: extensions/browser/api/document_scan/document_scan_interface_chromeos_unittest.cc

Issue 899523004: Move chrome.documentScan API to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated DEPS Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "chrome/browser/extensions/api/document_scan/document_scan_interface_ch romeos.h" 4
5 #include "extensions/browser/api/document_scan/document_scan_interface_chromeos. h"
5 6
6 #include <string> 7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "chromeos/dbus/mock_lorgnette_manager_client.h" 11 #include "chromeos/dbus/mock_lorgnette_manager_client.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "third_party/cros_system_api/dbus/service_constants.h"
13 14
14 using testing::_; 15 using testing::_;
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 namespace api { 19 namespace core_api {
19 20
20 // Tests of networking_private_crypto support for Networking Private API. 21 // Tests of networking_private_crypto support for Networking Private API.
21 class DocumentScanInterfaceChromeosTest : public testing::Test { 22 class DocumentScanInterfaceChromeosTest : public testing::Test {
22 public: 23 public:
23 DocumentScanInterfaceChromeosTest() 24 DocumentScanInterfaceChromeosTest()
24 : client_(new chromeos::MockLorgnetteManagerClient()) {} 25 : client_(new chromeos::MockLorgnetteManagerClient()) {}
25 ~DocumentScanInterfaceChromeosTest() override {} 26 ~DocumentScanInterfaceChromeosTest() override {}
26 27
27 void SetUp() override { 28 void SetUp() override {
28 scan_interface_.lorgnette_manager_client_ = client_.get(); 29 scan_interface_.lorgnette_manager_client_ = client_.get();
29 } 30 }
30 31
31 MOCK_METHOD2( 32 MOCK_METHOD2(OnListScannersResultReceived,
32 OnListScannersResultReceived, 33 void(const std::vector<
33 void(const std::vector<DocumentScanInterface::ScannerDescription>& 34 DocumentScanInterface::ScannerDescription>& scanners,
34 scanners, 35 const std::string& error));
35 const std::string& error));
36 36
37 MOCK_METHOD3(OnScanCompleted, void(const std::string& scanned_image, 37 MOCK_METHOD3(OnScanCompleted,
38 const std::string& mime_type, 38 void(const std::string& scanned_image,
39 const std::string& error)); 39 const std::string& mime_type,
40 const std::string& error));
40 41
41 protected: 42 protected:
42 DocumentScanInterfaceChromeos scan_interface_; 43 DocumentScanInterfaceChromeos scan_interface_;
43 scoped_ptr<chromeos::MockLorgnetteManagerClient> client_; 44 scoped_ptr<chromeos::MockLorgnetteManagerClient> client_;
44 }; 45 };
45 46
46 ACTION_P2(InvokeListScannersCallback, scanner_list, error) { 47 ACTION_P2(InvokeListScannersCallback, scanner_list, error) {
47 ::std::tr1::get<0>(args).Run(scanner_list, error); 48 ::std::tr1::get<0>(args).Run(scanner_list, error);
48 } 49 }
49 50
50 ACTION_P2(InvokeScanCallback, succeeded, image_data) { 51 ACTION_P2(InvokeScanCallback, succeeded, image_data) {
51 ::std::tr1::get<2>(args).Run(succeeded, image_data); 52 ::std::tr1::get<2>(args).Run(succeeded, image_data);
52 } 53 }
53 54
54 MATCHER_P5(IsScannerDescription, name, manufacturer, model, type, mime, "") { 55 MATCHER_P5(IsScannerDescription, name, manufacturer, model, type, mime, "") {
55 return 56 return arg.name == name && arg.manufacturer == manufacturer &&
56 arg.name == name && 57 arg.model == model && arg.scanner_type == type &&
57 arg.manufacturer == manufacturer && 58 arg.image_mime_type == mime;
58 arg.model == model &&
59 arg.scanner_type == type &&
60 arg.image_mime_type == mime;
61 } 59 }
62 60
63 MATCHER_P2(IsScannerProperties, mode, resolution, "") { 61 MATCHER_P2(IsScannerProperties, mode, resolution, "") {
64 return arg.mode == mode && arg.resolution_dpi == resolution; 62 return arg.mode == mode && arg.resolution_dpi == resolution;
65 } 63 }
66 64
67 TEST_F(DocumentScanInterfaceChromeosTest, ListScanners) { 65 TEST_F(DocumentScanInterfaceChromeosTest, ListScanners) {
68 chromeos::LorgnetteManagerClient::ScannerTable scanners; 66 chromeos::LorgnetteManagerClient::ScannerTable scanners;
69 const char kScannerName[] = "Monet"; 67 const char kScannerName[] = "Monet";
70 chromeos::LorgnetteManagerClient::ScannerTableEntry entry; 68 chromeos::LorgnetteManagerClient::ScannerTableEntry entry;
71 const char kScannerManufacturer[] = "Jacques-Louis David"; 69 const char kScannerManufacturer[] = "Jacques-Louis David";
72 entry[lorgnette::kScannerPropertyManufacturer] = kScannerManufacturer; 70 entry[lorgnette::kScannerPropertyManufacturer] = kScannerManufacturer;
73 const char kScannerModel[] = "Le Havre"; 71 const char kScannerModel[] = "Le Havre";
74 entry[lorgnette::kScannerPropertyModel] = kScannerModel; 72 entry[lorgnette::kScannerPropertyModel] = kScannerModel;
75 const char kScannerType[] = "Impressionism"; 73 const char kScannerType[] = "Impressionism";
76 entry[lorgnette::kScannerPropertyType] = kScannerType; 74 entry[lorgnette::kScannerPropertyType] = kScannerType;
77 scanners[kScannerName] = entry; 75 scanners[kScannerName] = entry;
78 EXPECT_CALL(*client_, ListScanners(_)) 76 EXPECT_CALL(*client_, ListScanners(_))
79 .WillOnce(InvokeListScannersCallback(true, scanners)); 77 .WillOnce(InvokeListScannersCallback(true, scanners));
80 EXPECT_CALL(*this, OnListScannersResultReceived( 78 EXPECT_CALL(*this, OnListScannersResultReceived(
81 testing::ElementsAre( 79 testing::ElementsAre(IsScannerDescription(
82 IsScannerDescription(kScannerName, 80 kScannerName, kScannerManufacturer, kScannerModel,
83 kScannerManufacturer, 81 kScannerType, "image/png")),
84 kScannerModel, 82 ""));
85 kScannerType,
86 "image/png")), ""));
87 scan_interface_.ListScanners(base::Bind( 83 scan_interface_.ListScanners(base::Bind(
88 &DocumentScanInterfaceChromeosTest::OnListScannersResultReceived, 84 &DocumentScanInterfaceChromeosTest::OnListScannersResultReceived,
89 base::Unretained(this))); 85 base::Unretained(this)));
90 } 86 }
91 87
92 TEST_F(DocumentScanInterfaceChromeosTest, ScanFailure) { 88 TEST_F(DocumentScanInterfaceChromeosTest, ScanFailure) {
93 const char kScannerName[] = "Monet"; 89 const char kScannerName[] = "Monet";
94 const int kResolution = 4096; 90 const int kResolution = 4096;
95 EXPECT_CALL(*client_, ScanImageToString( 91 EXPECT_CALL(*client_, ScanImageToString(
96 kScannerName, 92 kScannerName,
97 IsScannerProperties( 93 IsScannerProperties(
98 lorgnette::kScanPropertyModeColor, 94 lorgnette::kScanPropertyModeColor, kResolution),
99 kResolution),
100 _)).WillOnce(InvokeScanCallback(false, "")); 95 _)).WillOnce(InvokeScanCallback(false, ""));
101 EXPECT_CALL(*this, OnScanCompleted("data:image/png;base64,", 96 EXPECT_CALL(*this, OnScanCompleted("data:image/png;base64,", "image/png",
102 "image/png",
103 "Image scan failed")); 97 "Image scan failed"));
104 scan_interface_.Scan( 98 scan_interface_.Scan(
105 kScannerName, 99 kScannerName, DocumentScanInterface::kScanModeColor, kResolution,
106 DocumentScanInterface::kScanModeColor, 100 base::Bind(&DocumentScanInterfaceChromeosTest::OnScanCompleted,
107 kResolution, 101 base::Unretained(this)));
108 base::Bind(
109 &DocumentScanInterfaceChromeosTest::OnScanCompleted,
110 base::Unretained(this)));
111 } 102 }
112 103
113 TEST_F(DocumentScanInterfaceChromeosTest, ScanSuccess) { 104 TEST_F(DocumentScanInterfaceChromeosTest, ScanSuccess) {
114 const char kScannerName[] = "Monet"; 105 const char kScannerName[] = "Monet";
115 const int kResolution = 4096; 106 const int kResolution = 4096;
116 EXPECT_CALL(*client_, 107 EXPECT_CALL(
117 ScanImageToString( 108 *client_,
118 kScannerName, 109 ScanImageToString(
119 IsScannerProperties( 110 kScannerName,
120 lorgnette::kScanPropertyModeColor, 111 IsScannerProperties(lorgnette::kScanPropertyModeColor, kResolution),
121 kResolution), 112 _)).WillOnce(InvokeScanCallback(true, std::string("PrettyPicture")));
122 _))
123 .WillOnce(InvokeScanCallback(true, std::string("PrettyPicture")));
124 113
125 // Data URL plus base64 representation of "PrettyPicture". 114 // Data URL plus base64 representation of "PrettyPicture".
126 const char kExpectedImageData[] = 115 const char kExpectedImageData[] =
127 "data:image/png;base64,UHJldHR5UGljdHVyZQ=="; 116 "data:image/png;base64,UHJldHR5UGljdHVyZQ==";
128 117
129 EXPECT_CALL(*this, OnScanCompleted(kExpectedImageData, "image/png", "")); 118 EXPECT_CALL(*this, OnScanCompleted(kExpectedImageData, "image/png", ""));
130 scan_interface_.Scan( 119 scan_interface_.Scan(
131 kScannerName, 120 kScannerName, DocumentScanInterface::kScanModeColor, kResolution,
132 DocumentScanInterface::kScanModeColor, 121 base::Bind(&DocumentScanInterfaceChromeosTest::OnScanCompleted,
133 kResolution, 122 base::Unretained(this)));
134 base::Bind(
135 &DocumentScanInterfaceChromeosTest::OnScanCompleted,
136 base::Unretained(this)));
137 } 123 }
138 124
139 } // namespace api 125 } // namespace core_api
140 126
141 } // namespace extensions 127 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698