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

Side by Side Diff: extensions/browser/api/printer_provider/printer_provider_apitest.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 ResultCatcher catcher; 290 ResultCatcher catcher;
291 scoped_refptr<device::UsbDevice> device = 291 scoped_refptr<device::UsbDevice> device =
292 new device::MockUsbDevice(0, 0, "Google", "USB Printer", ""); 292 new device::MockUsbDevice(0, 0, "Google", "USB Printer", "");
293 usb_service_.AddDevice(device); 293 usb_service_.AddDevice(device);
294 294
295 std::string extension_id; 295 std::string extension_id;
296 InitializePrinterProviderTestApp("api_test/printer_provider/usb_printers", 296 InitializePrinterProviderTestApp("api_test/printer_provider/usb_printers",
297 test_param, &extension_id); 297 test_param, &extension_id);
298 ASSERT_FALSE(extension_id.empty()); 298 ASSERT_FALSE(extension_id.empty());
299 299
300 scoped_ptr<base::Value> expected_printer_info(new base::DictionaryValue()); 300 std::unique_ptr<base::Value> expected_printer_info(
301 new base::DictionaryValue());
301 base::RunLoop run_loop; 302 base::RunLoop run_loop;
302 StartGetUsbPrinterInfoRequest( 303 StartGetUsbPrinterInfoRequest(
303 extension_id, device, 304 extension_id, device,
304 base::Bind(&ExpectValueAndRunCallback, expected_printer_info.get(), 305 base::Bind(&ExpectValueAndRunCallback, expected_printer_info.get(),
305 run_loop.QuitClosure())); 306 run_loop.QuitClosure()));
306 run_loop.Run(); 307 run_loop.Run();
307 308
308 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 309 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
309 } 310 }
310 311
(...skipping 12 matching lines...) Expand all
323 return true; 324 return true;
324 } 325 }
325 326
326 // Validates that set of printers reported by test apps via 327 // Validates that set of printers reported by test apps via
327 // chrome.printerProvider.onGetPritersRequested is the same as the set of 328 // chrome.printerProvider.onGetPritersRequested is the same as the set of
328 // printers in |expected_printers|. |expected_printers| contains list of 329 // printers in |expected_printers|. |expected_printers| contains list of
329 // printer objects formatted as a JSON string. It is assumed that the values 330 // printer objects formatted as a JSON string. It is assumed that the values
330 // in |expoected_printers| are unique. 331 // in |expoected_printers| are unique.
331 void ValidatePrinterListValue( 332 void ValidatePrinterListValue(
332 const base::ListValue& printers, 333 const base::ListValue& printers,
333 const std::vector<scoped_ptr<base::Value>> expected_printers) { 334 const std::vector<std::unique_ptr<base::Value>> expected_printers) {
334 ASSERT_EQ(expected_printers.size(), printers.GetSize()); 335 ASSERT_EQ(expected_printers.size(), printers.GetSize());
335 for (const auto& printer_value : expected_printers) { 336 for (const auto& printer_value : expected_printers) {
336 EXPECT_TRUE(printers.Find(*printer_value.get()) != printers.end()) 337 EXPECT_TRUE(printers.Find(*printer_value.get()) != printers.end())
337 << "Unable to find " << *printer_value.get() << " in " << printers; 338 << "Unable to find " << *printer_value.get() << " in " << printers;
338 } 339 }
339 } 340 }
340 341
341 protected: 342 protected:
342 device::MockUsbService usb_service_; 343 device::MockUsbService usb_service_;
343 344
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 base::RunLoop run_loop; 483 base::RunLoop run_loop;
483 base::ListValue printers; 484 base::ListValue printers;
484 485
485 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, 486 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone,
486 &printers, run_loop.QuitClosure())); 487 &printers, run_loop.QuitClosure()));
487 488
488 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 489 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
489 490
490 run_loop.Run(); 491 run_loop.Run();
491 492
492 std::vector<scoped_ptr<base::Value>> expected_printers; 493 std::vector<std::unique_ptr<base::Value>> expected_printers;
493 expected_printers.push_back( 494 expected_printers.push_back(
494 DictionaryBuilder() 495 DictionaryBuilder()
495 .Set("description", "Test printer") 496 .Set("description", "Test printer")
496 .Set("extensionId", extension_id) 497 .Set("extensionId", extension_id)
497 .Set("extensionName", "Test printer provider") 498 .Set("extensionName", "Test printer provider")
498 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) 499 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str()))
499 .Set("name", "Printer 1") 500 .Set("name", "Printer 1")
500 .Build()); 501 .Build());
501 expected_printers.push_back( 502 expected_printers.push_back(
502 DictionaryBuilder() 503 DictionaryBuilder()
(...skipping 18 matching lines...) Expand all
521 base::RunLoop run_loop; 522 base::RunLoop run_loop;
522 base::ListValue printers; 523 base::ListValue printers;
523 524
524 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, 525 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone,
525 &printers, run_loop.QuitClosure())); 526 &printers, run_loop.QuitClosure()));
526 527
527 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 528 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
528 529
529 run_loop.Run(); 530 run_loop.Run();
530 531
531 std::vector<scoped_ptr<base::Value>> expected_printers; 532 std::vector<std::unique_ptr<base::Value>> expected_printers;
532 expected_printers.push_back( 533 expected_printers.push_back(
533 DictionaryBuilder() 534 DictionaryBuilder()
534 .Set("description", "Test printer") 535 .Set("description", "Test printer")
535 .Set("extensionId", extension_id) 536 .Set("extensionId", extension_id)
536 .Set("extensionName", "Test printer provider") 537 .Set("extensionName", "Test printer provider")
537 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) 538 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str()))
538 .Set("name", "Printer 1") 539 .Set("name", "Printer 1")
539 .Build()); 540 .Build());
540 541
541 ValidatePrinterListValue(printers, std::move(expected_printers)); 542 ValidatePrinterListValue(printers, std::move(expected_printers));
(...skipping 17 matching lines...) Expand all
559 base::ListValue printers; 560 base::ListValue printers;
560 561
561 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, 562 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone,
562 &printers, run_loop.QuitClosure())); 563 &printers, run_loop.QuitClosure()));
563 564
564 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 565 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
565 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 566 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
566 567
567 run_loop.Run(); 568 run_loop.Run();
568 569
569 std::vector<scoped_ptr<base::Value>> expected_printers; 570 std::vector<std::unique_ptr<base::Value>> expected_printers;
570 expected_printers.push_back( 571 expected_printers.push_back(
571 DictionaryBuilder() 572 DictionaryBuilder()
572 .Set("description", "Test printer") 573 .Set("description", "Test printer")
573 .Set("extensionId", extension_id_1) 574 .Set("extensionId", extension_id_1)
574 .Set("extensionName", "Test printer provider") 575 .Set("extensionName", "Test printer provider")
575 .Set("id", base::StringPrintf("%s:printer1", extension_id_1.c_str())) 576 .Set("id", base::StringPrintf("%s:printer1", extension_id_1.c_str()))
576 .Set("name", "Printer 1") 577 .Set("name", "Printer 1")
577 .Build()); 578 .Build());
578 expected_printers.push_back( 579 expected_printers.push_back(
579 DictionaryBuilder() 580 DictionaryBuilder()
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 base::ListValue printers; 655 base::ListValue printers;
655 656
656 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, 657 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone,
657 &printers, run_loop.QuitClosure())); 658 &printers, run_loop.QuitClosure()));
658 659
659 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 660 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
660 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 661 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
661 662
662 run_loop.Run(); 663 run_loop.Run();
663 664
664 std::vector<scoped_ptr<base::Value>> expected_printers; 665 std::vector<std::unique_ptr<base::Value>> expected_printers;
665 expected_printers.push_back( 666 expected_printers.push_back(
666 DictionaryBuilder() 667 DictionaryBuilder()
667 .Set("description", "Test printer") 668 .Set("description", "Test printer")
668 .Set("extensionId", extension_id_2) 669 .Set("extensionId", extension_id_2)
669 .Set("extensionName", "Test printer provider") 670 .Set("extensionName", "Test printer provider")
670 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str())) 671 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str()))
671 .Set("name", "Printer 1") 672 .Set("name", "Printer 1")
672 .Build()); 673 .Build());
673 expected_printers.push_back( 674 expected_printers.push_back(
674 DictionaryBuilder() 675 DictionaryBuilder()
(...skipping 26 matching lines...) Expand all
701 base::ListValue printers; 702 base::ListValue printers;
702 703
703 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, 704 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone,
704 &printers, run_loop.QuitClosure())); 705 &printers, run_loop.QuitClosure()));
705 706
706 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 707 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
707 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 708 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
708 709
709 run_loop.Run(); 710 run_loop.Run();
710 711
711 std::vector<scoped_ptr<base::Value>> expected_printers; 712 std::vector<std::unique_ptr<base::Value>> expected_printers;
712 expected_printers.push_back( 713 expected_printers.push_back(
713 DictionaryBuilder() 714 DictionaryBuilder()
714 .Set("description", "Test printer") 715 .Set("description", "Test printer")
715 .Set("extensionId", extension_id_2) 716 .Set("extensionId", extension_id_2)
716 .Set("extensionName", "Test printer provider") 717 .Set("extensionName", "Test printer provider")
717 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str())) 718 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str()))
718 .Set("name", "Printer 1") 719 .Set("name", "Printer 1")
719 .Build()); 720 .Build());
720 expected_printers.push_back( 721 expected_printers.push_back(
721 DictionaryBuilder() 722 DictionaryBuilder()
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 scoped_refptr<device::UsbDevice> device = 820 scoped_refptr<device::UsbDevice> device =
820 new device::MockUsbDevice(0, 0, "Google", "USB Printer", ""); 821 new device::MockUsbDevice(0, 0, "Google", "USB Printer", "");
821 usb_service_.AddDevice(device); 822 usb_service_.AddDevice(device);
822 823
823 std::string extension_id; 824 std::string extension_id;
824 InitializePrinterProviderTestApp("api_test/printer_provider/usb_printers", 825 InitializePrinterProviderTestApp("api_test/printer_provider/usb_printers",
825 "OK", &extension_id); 826 "OK", &extension_id);
826 ASSERT_FALSE(extension_id.empty()); 827 ASSERT_FALSE(extension_id.empty());
827 828
828 UsbGuidMap* guid_map = UsbGuidMap::Get(browser_context()); 829 UsbGuidMap* guid_map = UsbGuidMap::Get(browser_context());
829 scoped_ptr<base::Value> expected_printer_info( 830 std::unique_ptr<base::Value> expected_printer_info(
830 DictionaryBuilder() 831 DictionaryBuilder()
831 .Set("description", "This printer is a USB device.") 832 .Set("description", "This printer is a USB device.")
832 .Set("extensionId", extension_id) 833 .Set("extensionId", extension_id)
833 .Set("extensionName", "Test USB printer provider") 834 .Set("extensionName", "Test USB printer provider")
834 .Set("id", 835 .Set("id",
835 base::StringPrintf("%s:usbDevice-%u", extension_id.c_str(), 836 base::StringPrintf("%s:usbDevice-%u", extension_id.c_str(),
836 guid_map->GetIdFromGuid(device->guid()))) 837 guid_map->GetIdFromGuid(device->guid())))
837 .Set("name", "Test Printer") 838 .Set("name", "Test Printer")
838 .Build()); 839 .Build());
839 base::RunLoop run_loop; 840 base::RunLoop run_loop;
(...skipping 10 matching lines...) Expand all
850 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE"); 851 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE");
851 } 852 }
852 853
853 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) { 854 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) {
854 RunUsbPrinterInfoRequestTest("NO_LISTENER"); 855 RunUsbPrinterInfoRequestTest("NO_LISTENER");
855 } 856 }
856 857
857 } // namespace 858 } // namespace
858 859
859 } // namespace extensions 860 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698