OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/chrome/browser/ui/payments/region_data_loader.h" | 5 #import "ios/chrome/browser/ui/payments/region_data_loader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "components/autofill/core/browser/test_region_data_loader.h" | 13 #include "components/autofill/core/browser/test_region_data_loader.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
16 #include "third_party/ocmock/OCMock/OCMock.h" | 16 #include "third_party/ocmock/OCMock/OCMock.h" |
17 #include "third_party/ocmock/gtest_support.h" | 17 #include "third_party/ocmock/gtest_support.h" |
18 | 18 |
19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
20 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
21 #endif | 21 #endif |
22 | 22 |
23 namespace { | 23 namespace { |
24 const char kQuebec[] = "QC"; | 24 const char kQuebecCode[] = "QC"; |
25 const char kOntario[] = "ON"; | 25 const char kOntarioCode[] = "ON"; |
| 26 const char kQuebec[] = "Quebec"; |
| 27 const char kOntario[] = "Ontario"; |
26 } // namespace | 28 } // namespace |
27 | 29 |
28 class PaymentRequestRegionDataLoaderTest : public PlatformTest { | 30 class PaymentRequestRegionDataLoaderTest : public PlatformTest { |
29 protected: | 31 protected: |
30 PaymentRequestRegionDataLoaderTest() {} | 32 PaymentRequestRegionDataLoaderTest() {} |
31 ~PaymentRequestRegionDataLoaderTest() override {} | 33 ~PaymentRequestRegionDataLoaderTest() override {} |
32 | 34 |
33 autofill::TestRegionDataLoader autofill_region_data_loader_; | 35 autofill::TestRegionDataLoader autofill_region_data_loader_; |
34 }; | 36 }; |
35 | 37 |
36 // Tests that the two regions returned by the source are correctly returned. | 38 // Tests that the two regions returned by the source are correctly returned. |
37 TEST_F(PaymentRequestRegionDataLoaderTest, SourceSuccess) { | 39 TEST_F(PaymentRequestRegionDataLoaderTest, SourceSuccess) { |
38 // Mock the consumer. | 40 // Mock the consumer. |
39 id consumer = | 41 id consumer = |
40 [OCMockObject mockForProtocol:@protocol(RegionDataLoaderConsumer)]; | 42 [OCMockObject mockForProtocol:@protocol(RegionDataLoaderConsumer)]; |
41 [[consumer expect] regionDataLoaderDidSucceedWithRegions:@[ | 43 [[consumer expect] regionDataLoaderDidSucceedWithRegions:@{ |
42 base::SysUTF8ToNSString(kQuebec), base::SysUTF8ToNSString(kOntario) | 44 base::SysUTF8ToNSString(kQuebecCode) : base::SysUTF8ToNSString(kQuebec), |
43 ]]; | 45 base::SysUTF8ToNSString(kOntarioCode) : base::SysUTF8ToNSString(kOntario) |
| 46 }]; |
44 | 47 |
45 RegionDataLoader region_data_loader(consumer); | 48 RegionDataLoader region_data_loader(consumer); |
46 region_data_loader.LoadRegionData("some country", | 49 region_data_loader.LoadRegionData("some country", |
47 &autofill_region_data_loader_); | 50 &autofill_region_data_loader_); |
48 | 51 |
49 std::vector<std::pair<std::string, std::string>> regions; | 52 std::vector<std::pair<std::string, std::string>> regions; |
50 regions.push_back(std::make_pair(kQuebec, "Quebec")); | 53 regions.push_back(std::make_pair(kQuebecCode, kQuebec)); |
51 regions.push_back(std::make_pair(kOntario, "Ontario")); | 54 regions.push_back(std::make_pair(kOntarioCode, kOntario)); |
52 autofill_region_data_loader_.SendAsynchronousData(regions); | 55 autofill_region_data_loader_.SendAsynchronousData(regions); |
53 | 56 |
54 EXPECT_OCMOCK_VERIFY(consumer); | 57 EXPECT_OCMOCK_VERIFY(consumer); |
55 } | 58 } |
56 | 59 |
57 // Tests that the source emptiness/failure is properly handled. | 60 // Tests that the source emptiness/failure is properly handled. |
58 TEST_F(PaymentRequestRegionDataLoaderTest, SourceFailure) { | 61 TEST_F(PaymentRequestRegionDataLoaderTest, SourceFailure) { |
59 // Mock the consumer. | 62 // Mock the consumer. |
60 id consumer = | 63 id consumer = |
61 [OCMockObject mockForProtocol:@protocol(RegionDataLoaderConsumer)]; | 64 [OCMockObject mockForProtocol:@protocol(RegionDataLoaderConsumer)]; |
62 [[consumer expect] regionDataLoaderDidSucceedWithRegions:@[]]; | 65 [[consumer expect] regionDataLoaderDidSucceedWithRegions:@{}]; |
63 | 66 |
64 RegionDataLoader region_data_loader(consumer); | 67 RegionDataLoader region_data_loader(consumer); |
65 region_data_loader.LoadRegionData("some country", | 68 region_data_loader.LoadRegionData("some country", |
66 &autofill_region_data_loader_); | 69 &autofill_region_data_loader_); |
67 | 70 |
68 autofill_region_data_loader_.SendAsynchronousData( | 71 autofill_region_data_loader_.SendAsynchronousData( |
69 std::vector<std::pair<std::string, std::string>>()); | 72 std::vector<std::pair<std::string, std::string>>()); |
70 | 73 |
71 EXPECT_OCMOCK_VERIFY(consumer); | 74 EXPECT_OCMOCK_VERIFY(consumer); |
72 } | 75 } |
OLD | NEW |