| OLD | NEW |
| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return true; | 324 return true; |
| 325 } | 325 } |
| 326 | 326 |
| 327 // Validates that set of printers reported by test apps via | 327 // Validates that set of printers reported by test apps via |
| 328 // chrome.printerProvider.onGetPritersRequested is the same as the set of | 328 // chrome.printerProvider.onGetPritersRequested is the same as the set of |
| 329 // printers in |expected_printers|. |expected_printers| contains list of | 329 // printers in |expected_printers|. |expected_printers| contains list of |
| 330 // 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 |
| 331 // in |expoected_printers| are unique. | 331 // in |expoected_printers| are unique. |
| 332 void ValidatePrinterListValue( | 332 void ValidatePrinterListValue( |
| 333 const base::ListValue& printers, | 333 const base::ListValue& printers, |
| 334 const std::vector<std::unique_ptr<base::Value>> expected_printers) { | 334 const std::vector<std::unique_ptr<base::Value>>& expected_printers) { |
| 335 ASSERT_EQ(expected_printers.size(), printers.GetSize()); | 335 ASSERT_EQ(expected_printers.size(), printers.GetSize()); |
| 336 for (const auto& printer_value : expected_printers) { | 336 for (const auto& printer_value : expected_printers) { |
| 337 EXPECT_TRUE(printers.Find(*printer_value.get()) != printers.end()) | 337 EXPECT_TRUE(printers.Find(*printer_value.get()) != printers.end()) |
| 338 << "Unable to find " << *printer_value.get() << " in " << printers; | 338 << "Unable to find " << *printer_value.get() << " in " << printers; |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 protected: | 342 protected: |
| 343 device::MockUsbService usb_service_; | 343 device::MockUsbService usb_service_; |
| 344 | 344 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 .Build()); | 501 .Build()); |
| 502 expected_printers.push_back( | 502 expected_printers.push_back( |
| 503 DictionaryBuilder() | 503 DictionaryBuilder() |
| 504 .Set("extensionId", extension_id) | 504 .Set("extensionId", extension_id) |
| 505 .Set("extensionName", "Test printer provider") | 505 .Set("extensionName", "Test printer provider") |
| 506 .Set("id", | 506 .Set("id", |
| 507 base::StringPrintf("%s:printerNoDesc", extension_id.c_str())) | 507 base::StringPrintf("%s:printerNoDesc", extension_id.c_str())) |
| 508 .Set("name", "Printer 2") | 508 .Set("name", "Printer 2") |
| 509 .Build()); | 509 .Build()); |
| 510 | 510 |
| 511 ValidatePrinterListValue(printers, std::move(expected_printers)); | 511 ValidatePrinterListValue(printers, expected_printers); |
| 512 } | 512 } |
| 513 | 513 |
| 514 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersAsyncSuccess) { | 514 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersAsyncSuccess) { |
| 515 ResultCatcher catcher; | 515 ResultCatcher catcher; |
| 516 | 516 |
| 517 std::string extension_id; | 517 std::string extension_id; |
| 518 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 518 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 519 "ASYNC_RESPONSE", &extension_id); | 519 "ASYNC_RESPONSE", &extension_id); |
| 520 ASSERT_FALSE(extension_id.empty()); | 520 ASSERT_FALSE(extension_id.empty()); |
| 521 | 521 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 532 std::vector<std::unique_ptr<base::Value>> expected_printers; | 532 std::vector<std::unique_ptr<base::Value>> expected_printers; |
| 533 expected_printers.push_back( | 533 expected_printers.push_back( |
| 534 DictionaryBuilder() | 534 DictionaryBuilder() |
| 535 .Set("description", "Test printer") | 535 .Set("description", "Test printer") |
| 536 .Set("extensionId", extension_id) | 536 .Set("extensionId", extension_id) |
| 537 .Set("extensionName", "Test printer provider") | 537 .Set("extensionName", "Test printer provider") |
| 538 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) | 538 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) |
| 539 .Set("name", "Printer 1") | 539 .Set("name", "Printer 1") |
| 540 .Build()); | 540 .Build()); |
| 541 | 541 |
| 542 ValidatePrinterListValue(printers, std::move(expected_printers)); | 542 ValidatePrinterListValue(printers, expected_printers); |
| 543 } | 543 } |
| 544 | 544 |
| 545 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersTwoExtensions) { | 545 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersTwoExtensions) { |
| 546 ResultCatcher catcher; | 546 ResultCatcher catcher; |
| 547 | 547 |
| 548 std::string extension_id_1; | 548 std::string extension_id_1; |
| 549 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 549 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 550 "OK", &extension_id_1); | 550 "OK", &extension_id_1); |
| 551 ASSERT_FALSE(extension_id_1.empty()); | 551 ASSERT_FALSE(extension_id_1.empty()); |
| 552 | 552 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 .Build()); | 594 .Build()); |
| 595 expected_printers.push_back( | 595 expected_printers.push_back( |
| 596 DictionaryBuilder() | 596 DictionaryBuilder() |
| 597 .Set("extensionId", extension_id_2) | 597 .Set("extensionId", extension_id_2) |
| 598 .Set("extensionName", "Test printer provider") | 598 .Set("extensionName", "Test printer provider") |
| 599 .Set("id", | 599 .Set("id", |
| 600 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) | 600 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 601 .Set("name", "Printer 2") | 601 .Set("name", "Printer 2") |
| 602 .Build()); | 602 .Build()); |
| 603 | 603 |
| 604 ValidatePrinterListValue(printers, std::move(expected_printers)); | 604 ValidatePrinterListValue(printers, expected_printers); |
| 605 } | 605 } |
| 606 | 606 |
| 607 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 607 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 608 GetPrintersTwoExtensionsBothUnloaded) { | 608 GetPrintersTwoExtensionsBothUnloaded) { |
| 609 ResultCatcher catcher; | 609 ResultCatcher catcher; |
| 610 | 610 |
| 611 std::string extension_id_1; | 611 std::string extension_id_1; |
| 612 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 612 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 613 "IGNORE_CALLBACK", &extension_id_1); | 613 "IGNORE_CALLBACK", &extension_id_1); |
| 614 ASSERT_FALSE(extension_id_1.empty()); | 614 ASSERT_FALSE(extension_id_1.empty()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 .Build()); | 673 .Build()); |
| 674 expected_printers.push_back( | 674 expected_printers.push_back( |
| 675 DictionaryBuilder() | 675 DictionaryBuilder() |
| 676 .Set("extensionId", extension_id_2) | 676 .Set("extensionId", extension_id_2) |
| 677 .Set("extensionName", "Test printer provider") | 677 .Set("extensionName", "Test printer provider") |
| 678 .Set("id", | 678 .Set("id", |
| 679 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) | 679 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 680 .Set("name", "Printer 2") | 680 .Set("name", "Printer 2") |
| 681 .Build()); | 681 .Build()); |
| 682 | 682 |
| 683 ValidatePrinterListValue(printers, std::move(expected_printers)); | 683 ValidatePrinterListValue(printers, expected_printers); |
| 684 } | 684 } |
| 685 | 685 |
| 686 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 686 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 687 GetPrintersTwoExtensionsOneWithNoListener) { | 687 GetPrintersTwoExtensionsOneWithNoListener) { |
| 688 ResultCatcher catcher; | 688 ResultCatcher catcher; |
| 689 | 689 |
| 690 std::string extension_id_1; | 690 std::string extension_id_1; |
| 691 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 691 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 692 "NO_LISTENER", &extension_id_1); | 692 "NO_LISTENER", &extension_id_1); |
| 693 ASSERT_FALSE(extension_id_1.empty()); | 693 ASSERT_FALSE(extension_id_1.empty()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 720 .Build()); | 720 .Build()); |
| 721 expected_printers.push_back( | 721 expected_printers.push_back( |
| 722 DictionaryBuilder() | 722 DictionaryBuilder() |
| 723 .Set("extensionId", extension_id_2) | 723 .Set("extensionId", extension_id_2) |
| 724 .Set("extensionName", "Test printer provider") | 724 .Set("extensionName", "Test printer provider") |
| 725 .Set("id", | 725 .Set("id", |
| 726 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) | 726 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 727 .Set("name", "Printer 2") | 727 .Set("name", "Printer 2") |
| 728 .Build()); | 728 .Build()); |
| 729 | 729 |
| 730 ValidatePrinterListValue(printers, std::move(expected_printers)); | 730 ValidatePrinterListValue(printers, expected_printers); |
| 731 } | 731 } |
| 732 | 732 |
| 733 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNoListener) { | 733 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNoListener) { |
| 734 ResultCatcher catcher; | 734 ResultCatcher catcher; |
| 735 | 735 |
| 736 std::string extension_id; | 736 std::string extension_id; |
| 737 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 737 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 738 "NO_LISTENER", &extension_id); | 738 "NO_LISTENER", &extension_id); |
| 739 ASSERT_FALSE(extension_id.empty()); | 739 ASSERT_FALSE(extension_id.empty()); |
| 740 | 740 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE"); | 851 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE"); |
| 852 } | 852 } |
| 853 | 853 |
| 854 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) { | 854 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) { |
| 855 RunUsbPrinterInfoRequestTest("NO_LISTENER"); | 855 RunUsbPrinterInfoRequestTest("NO_LISTENER"); |
| 856 } | 856 } |
| 857 | 857 |
| 858 } // namespace | 858 } // namespace |
| 859 | 859 |
| 860 } // namespace extensions | 860 } // namespace extensions |
| OLD | NEW |