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

Side by Side Diff: chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc

Issue 2931843003: Print Preview: Change getPrinterCapabilities to cr.sendWithPromise (Closed)
Patch Set: Address comments Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 4
5 #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const base::ListValue& printers, 196 const base::ListValue& printers,
197 bool is_done) { 197 bool is_done) {
198 ++(*call_count); 198 ++(*call_count);
199 printers_out->reset(printers.DeepCopy()); 199 printers_out->reset(printers.DeepCopy());
200 *is_done_out = is_done; 200 *is_done_out = is_done;
201 } 201 }
202 202
203 // Used as a callback to StartGetCapability in tests. 203 // Used as a callback to StartGetCapability in tests.
204 // Increases |*call_count| and records values returned by StartGetCapability. 204 // Increases |*call_count| and records values returned by StartGetCapability.
205 void RecordCapability(size_t* call_count, 205 void RecordCapability(size_t* call_count,
206 std::string* destination_id_out,
207 std::unique_ptr<base::DictionaryValue>* capability_out, 206 std::unique_ptr<base::DictionaryValue>* capability_out,
208 const std::string& destination_id,
209 const base::DictionaryValue& capability) { 207 const base::DictionaryValue& capability) {
210 ++(*call_count); 208 ++(*call_count);
211 *destination_id_out = destination_id;
212 capability_out->reset(capability.DeepCopy()); 209 capability_out->reset(capability.DeepCopy());
213 } 210 }
214 211
215 // Used as a callback to StartPrint in tests. 212 // Used as a callback to StartPrint in tests.
216 // Increases |*call_count| and records values returned by StartPrint. 213 // Increases |*call_count| and records values returned by StartPrint.
217 void RecordPrintResult(size_t* call_count, 214 void RecordPrintResult(size_t* call_count,
218 bool* success_out, 215 bool* success_out,
219 std::string* status_out, 216 std::string* status_out,
220 bool success, 217 bool success,
221 const std::string& status) { 218 const std::string& status) {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 fake_api->TriggerNextGetPrintersCallback(base::ListValue(), true); 599 fake_api->TriggerNextGetPrintersCallback(base::ListValue(), true);
603 600
604 EXPECT_EQ(2u, call_count); 601 EXPECT_EQ(2u, call_count);
605 EXPECT_TRUE(is_done); 602 EXPECT_TRUE(is_done);
606 EXPECT_TRUE(printers.get()); 603 EXPECT_TRUE(printers.get());
607 EXPECT_EQ(0u, printers->GetSize()); // RecordPrinterList resets |printers|. 604 EXPECT_EQ(0u, printers->GetSize()); // RecordPrinterList resets |printers|.
608 } 605 }
609 606
610 TEST_F(ExtensionPrinterHandlerTest, GetCapability) { 607 TEST_F(ExtensionPrinterHandlerTest, GetCapability) {
611 size_t call_count = 0; 608 size_t call_count = 0;
612 std::string destination_id;
613 std::unique_ptr<base::DictionaryValue> capability; 609 std::unique_ptr<base::DictionaryValue> capability;
614 610
615 extension_printer_handler_->StartGetCapability( 611 extension_printer_handler_->StartGetCapability(
616 kPrinterId, 612 kPrinterId, base::Bind(&RecordCapability, &call_count, &capability));
617 base::Bind(&RecordCapability, &call_count, &destination_id, &capability));
618 613
619 EXPECT_EQ(0u, call_count); 614 EXPECT_EQ(0u, call_count);
620 615
621 FakePrinterProviderAPI* fake_api = GetPrinterProviderAPI(); 616 FakePrinterProviderAPI* fake_api = GetPrinterProviderAPI();
622 ASSERT_TRUE(fake_api); 617 ASSERT_TRUE(fake_api);
623 ASSERT_EQ(1u, fake_api->pending_get_capability_count()); 618 ASSERT_EQ(1u, fake_api->pending_get_capability_count());
624 619
625 std::string error; 620 std::string error;
626 std::unique_ptr<base::DictionaryValue> original_capability( 621 std::unique_ptr<base::DictionaryValue> original_capability(
627 GetJSONAsDictionaryValue(kPWGRasterOnlyPrinterSimpleDescription, &error)); 622 GetJSONAsDictionaryValue(kPWGRasterOnlyPrinterSimpleDescription, &error));
628 ASSERT_TRUE(original_capability) 623 ASSERT_TRUE(original_capability)
629 << "Error deserializing capability: " << error; 624 << "Error deserializing capability: " << error;
630 625
631 fake_api->TriggerNextGetCapabilityCallback(*original_capability); 626 fake_api->TriggerNextGetCapabilityCallback(*original_capability);
632 627
633 EXPECT_EQ(1u, call_count); 628 EXPECT_EQ(1u, call_count);
634 EXPECT_EQ(kPrinterId, destination_id);
635 ASSERT_TRUE(capability.get()); 629 ASSERT_TRUE(capability.get());
636 EXPECT_TRUE(capability->Equals(original_capability.get())) 630 EXPECT_TRUE(capability->Equals(original_capability.get()))
637 << *capability << ", expected: " << *original_capability; 631 << *capability << ", expected: " << *original_capability;
638 } 632 }
639 633
640 TEST_F(ExtensionPrinterHandlerTest, GetCapability_Reset) { 634 TEST_F(ExtensionPrinterHandlerTest, GetCapability_Reset) {
641 size_t call_count = 0; 635 size_t call_count = 0;
642 std::string destination_id;
643 std::unique_ptr<base::DictionaryValue> capability; 636 std::unique_ptr<base::DictionaryValue> capability;
644 637
645 extension_printer_handler_->StartGetCapability( 638 extension_printer_handler_->StartGetCapability(
646 kPrinterId, 639 kPrinterId, base::Bind(&RecordCapability, &call_count, &capability));
647 base::Bind(&RecordCapability, &call_count, &destination_id, &capability));
648 640
649 EXPECT_EQ(0u, call_count); 641 EXPECT_EQ(0u, call_count);
650 642
651 FakePrinterProviderAPI* fake_api = GetPrinterProviderAPI(); 643 FakePrinterProviderAPI* fake_api = GetPrinterProviderAPI();
652 ASSERT_TRUE(fake_api); 644 ASSERT_TRUE(fake_api);
653 ASSERT_EQ(1u, fake_api->pending_get_capability_count()); 645 ASSERT_EQ(1u, fake_api->pending_get_capability_count());
654 646
655 extension_printer_handler_->Reset(); 647 extension_printer_handler_->Reset();
656 648
657 std::string error; 649 std::string error;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 DictionaryBuilder() 1001 DictionaryBuilder()
1010 .Set("id", "printer1") 1002 .Set("id", "printer1")
1011 .Set("name", "Printer 1") 1003 .Set("name", "Printer 1")
1012 .Build()); 1004 .Build());
1013 1005
1014 fake_api->TriggerNextUsbPrinterInfoCallback(*original_printer_info); 1006 fake_api->TriggerNextUsbPrinterInfoCallback(*original_printer_info);
1015 1007
1016 EXPECT_EQ(0u, call_count); 1008 EXPECT_EQ(0u, call_count);
1017 EXPECT_FALSE(printer_info.get()); 1009 EXPECT_FALSE(printer_info.get());
1018 } 1010 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698