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

Side by Side Diff: extensions/browser/api/document_scan/document_scan_api_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_api.h" 4 #include "extensions/browser/api/document_scan/document_scan_api.h"
James Cook 2015/02/05 19:02:59 nit: blank line above
babu 2015/02/05 21:34:02 Done.
5 5
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/browser/extensions/api/document_scan/mock_document_scan_interfa ce.h" 9 #include "extensions/browser/api/document_scan/mock_document_scan_interface.h"
10 #include "chrome/browser/extensions/extension_api_unittest.h" 10 #include "extensions/browser/api_test_utils.h"
11 #include "chrome/browser/extensions/extension_function_test_utils.h" 11 #include "extensions/browser/api_unittest.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.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 DocumentScanScanFunctionTest : public ExtensionApiUnittest { 21 class DocumentScanScanFunctionTest : public ApiUnitTest {
22 public: 22 public:
23 DocumentScanScanFunctionTest() 23 DocumentScanScanFunctionTest()
24 : function_(new DocumentScanScanFunction()), 24 : function_(new DocumentScanScanFunction()),
25 document_scan_interface_(new MockDocumentScanInterface()) {} 25 document_scan_interface_(new MockDocumentScanInterface()) {}
26 ~DocumentScanScanFunctionTest() override {} 26 ~DocumentScanScanFunctionTest() override {}
27 27
28 void SetUp() override { 28 void SetUp() override {
29 ExtensionApiUnittest::SetUp(); 29 ApiUnitTest::SetUp();
30 // Passes ownership. 30 // Passes ownership.
31 function_->document_scan_interface_.reset(document_scan_interface_); 31 function_->document_scan_interface_.reset(document_scan_interface_);
32 } 32 }
33 33
34 protected: 34 protected:
35 std::string RunFunctionAndReturnError(const std::string& args) { 35 std::string RunFunctionAndReturnError(const std::string& args) {
36 function_->set_extension(extension()); 36 function_->set_extension(extension());
37 std::string error = 37 std::string error = api_test_utils::RunFunctionAndReturnError(
38 extension_function_test_utils::RunFunctionAndReturnError( 38 function_, args, browser_context(), api_test_utils::NONE);
39 function_, args, browser(),
40 extension_function_test_utils::NONE);
41 return error; 39 return error;
42 } 40 }
43 41
44 DocumentScanScanFunction* function_; 42 DocumentScanScanFunction* function_;
45 MockDocumentScanInterface* document_scan_interface_; // Owned by function_. 43 MockDocumentScanInterface* document_scan_interface_; // Owned by function_.
46 }; 44 };
47 45
48 ACTION_P2(InvokeListScannersCallback, scanner_list, error) { 46 ACTION_P2(InvokeListScannersCallback, scanner_list, error) {
49 ::std::tr1::get<0>(args).Run(scanner_list, error); 47 ::std::tr1::get<0>(args).Run(scanner_list, error);
50 } 48 }
51 49
52 ACTION_P3(InvokeScanCallback, data, mime_type, error) { 50 ACTION_P3(InvokeScanCallback, data, mime_type, error) {
53 ::std::tr1::get<3>(args).Run(data, mime_type, error); 51 ::std::tr1::get<3>(args).Run(data, mime_type, error);
54 } 52 }
55 53
56 TEST_F(DocumentScanScanFunctionTest, GestureRequired) { 54 TEST_F(DocumentScanScanFunctionTest, GestureRequired) {
57 EXPECT_EQ("User gesture required to perform scan", 55 EXPECT_EQ("User gesture required to perform scan",
58 RunFunctionAndReturnError("[{}]")); 56 RunFunctionAndReturnError("[{}]"));
59 } 57 }
60 58
61 TEST_F(DocumentScanScanFunctionTest, NoScanners) { 59 TEST_F(DocumentScanScanFunctionTest, NoScanners) {
62 function_->set_user_gesture(true); 60 function_->set_user_gesture(true);
63 EXPECT_CALL(*document_scan_interface_, ListScanners(_)) 61 EXPECT_CALL(*document_scan_interface_, ListScanners(_))
64 .WillOnce(InvokeListScannersCallback( 62 .WillOnce(InvokeListScannersCallback(
65 std::vector<DocumentScanInterface::ScannerDescription>(), 63 std::vector<DocumentScanInterface::ScannerDescription>(), ""));
66 "")); 64 EXPECT_EQ("Scanner not available", RunFunctionAndReturnError("[{}]"));
67 EXPECT_EQ("Scanner not available",
68 RunFunctionAndReturnError("[{}]"));
69 } 65 }
70 66
71 TEST_F(DocumentScanScanFunctionTest, NoMatchingScanners) { 67 TEST_F(DocumentScanScanFunctionTest, NoMatchingScanners) {
72 function_->set_user_gesture(true); 68 function_->set_user_gesture(true);
73 std::vector<DocumentScanInterface::ScannerDescription> scanner_list; 69 std::vector<DocumentScanInterface::ScannerDescription> scanner_list;
74 DocumentScanInterface::ScannerDescription scanner; 70 DocumentScanInterface::ScannerDescription scanner;
75 scanner.image_mime_type = "img/fresco"; 71 scanner.image_mime_type = "img/fresco";
76 scanner_list.push_back(scanner); 72 scanner_list.push_back(scanner);
77 EXPECT_CALL(*document_scan_interface_, ListScanners(_)) 73 EXPECT_CALL(*document_scan_interface_, ListScanners(_))
78 .WillOnce(InvokeListScannersCallback(scanner_list, "")); 74 .WillOnce(InvokeListScannersCallback(scanner_list, ""));
(...skipping 23 matching lines...) Expand all
102 TEST_F(DocumentScanScanFunctionTest, Success) { 98 TEST_F(DocumentScanScanFunctionTest, Success) {
103 std::vector<DocumentScanInterface::ScannerDescription> scanner_list; 99 std::vector<DocumentScanInterface::ScannerDescription> scanner_list;
104 scanner_list.push_back(DocumentScanInterface::ScannerDescription()); 100 scanner_list.push_back(DocumentScanInterface::ScannerDescription());
105 EXPECT_CALL(*document_scan_interface_, ListScanners(_)) 101 EXPECT_CALL(*document_scan_interface_, ListScanners(_))
106 .WillOnce(InvokeListScannersCallback(scanner_list, "")); 102 .WillOnce(InvokeListScannersCallback(scanner_list, ""));
107 const char kScanData[] = "A beautiful picture"; 103 const char kScanData[] = "A beautiful picture";
108 const char kMimeType[] = "img/encaustic"; 104 const char kMimeType[] = "img/encaustic";
109 EXPECT_CALL(*document_scan_interface_, Scan(_, _, _, _)) 105 EXPECT_CALL(*document_scan_interface_, Scan(_, _, _, _))
110 .WillOnce(InvokeScanCallback(kScanData, kMimeType, "")); 106 .WillOnce(InvokeScanCallback(kScanData, kMimeType, ""));
111 function_->set_user_gesture(true); 107 function_->set_user_gesture(true);
112 scoped_ptr<base::DictionaryValue> result(RunFunctionAndReturnDictionary( 108 scoped_ptr<base::DictionaryValue> result(
113 function_, "[{}]")); 109 RunFunctionAndReturnDictionary(function_, "[{}]"));
114 ASSERT_NE(nullptr, result.get()); 110 ASSERT_NE(nullptr, result.get());
115 document_scan::ScanResults scan_results; 111 document_scan::ScanResults scan_results;
116 EXPECT_TRUE(document_scan::ScanResults::Populate(*result, &scan_results)); 112 EXPECT_TRUE(document_scan::ScanResults::Populate(*result, &scan_results));
117 EXPECT_THAT(scan_results.data_urls, testing::ElementsAre(kScanData)); 113 EXPECT_THAT(scan_results.data_urls, testing::ElementsAre(kScanData));
118 EXPECT_EQ(kMimeType, scan_results.mime_type); 114 EXPECT_EQ(kMimeType, scan_results.mime_type);
119 } 115 }
120 116
121 } // namespace api 117 } // namespace core_api
122 118
123 } // namespace extensions 119 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698