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

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

Powered by Google App Engine
This is Rietveld 408576698