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