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 #include "components/payments/core/subkey_requester.h" | 5 #include "components/payments/core/subkey_requester.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 const char kLocale[] = "OZ"; | 27 const char kLocale[] = "OZ"; |
28 const int kInvalidSize = -1; | 28 const int kInvalidSize = -1; |
29 const int kCorrectSize = 2; // for subkeys = Do, Re | 29 const int kCorrectSize = 2; // for subkeys = Do, Re |
30 const int kEmptySize = 0; | 30 const int kEmptySize = 0; |
31 | 31 |
32 class SubKeyReceiver : public base::RefCountedThreadSafe<SubKeyReceiver> { | 32 class SubKeyReceiver : public base::RefCountedThreadSafe<SubKeyReceiver> { |
33 public: | 33 public: |
34 SubKeyReceiver() : subkeys_size_(kInvalidSize) {} | 34 SubKeyReceiver() : subkeys_size_(kInvalidSize) {} |
35 | 35 |
36 void OnSubKeysReceived(const std::vector<std::string>& subkeys) { | 36 void OnSubKeysReceived(const std::vector<std::string>& subkeys_codes, |
37 subkeys_size_ = subkeys.size(); | 37 const std::vector<std::string>& subkeys_names) { |
| 38 subkeys_size_ = subkeys_codes.size(); |
38 } | 39 } |
39 | 40 |
40 int subkeys_size() const { return subkeys_size_; } | 41 int subkeys_size() const { return subkeys_size_; } |
41 | 42 |
42 private: | 43 private: |
43 friend class base::RefCountedThreadSafe<SubKeyReceiver>; | 44 friend class base::RefCountedThreadSafe<SubKeyReceiver>; |
44 ~SubKeyReceiver() {} | 45 ~SubKeyReceiver() {} |
45 | 46 |
46 int subkeys_size_; | 47 int subkeys_size_; |
47 | 48 |
48 DISALLOW_COPY_AND_ASSIGN(SubKeyReceiver); | 49 DISALLOW_COPY_AND_ASSIGN(SubKeyReceiver); |
49 }; | 50 }; |
50 | 51 |
51 // Used to load region rules for this test. | 52 // Used to load region rules for this test. |
52 class ChromiumTestdataSource : public TestdataSource { | 53 class ChromiumTestdataSource : public TestdataSource { |
53 public: | 54 public: |
54 ChromiumTestdataSource() : TestdataSource(true) {} | 55 ChromiumTestdataSource() : TestdataSource(true) {} |
55 | 56 |
56 ~ChromiumTestdataSource() override {} | 57 ~ChromiumTestdataSource() override {} |
57 | 58 |
58 // For this test, only load the rules for the kLocale. | 59 // For this test, only load the rules for the kLocale. |
59 void Get(const std::string& key, const Callback& data_ready) const override { | 60 void Get(const std::string& key, const Callback& data_ready) const override { |
60 data_ready( | 61 data_ready( |
61 true, key, | 62 true, key, |
62 new std::string( | 63 new std::string( |
63 "{\"data/OZ\": " | 64 "{\"data/OZ\": " |
64 "{\"id\":\"data/OZ\",\"key\":\"OZ\",\"name\":\"Oz \", " | 65 "{\"id\":\"data/OZ\",\"key\":\"OZ\",\"name\":\"Oz \", " |
65 "\"lang\":\"en\",\"languages\":\"en\",\"sub_keys\":\"DO~Re\"}}")); | 66 "\"lang\":\"en\",\"sub_keys\":\"DO~RE\", \"sub_names\":\"Do~Re\"}," |
| 67 "\"data/OZ/DO\": " |
| 68 "{\"id\":\"data/OZ/DO\",\"key\":\"DO\",\"name\":\"Do \", " |
| 69 "\"lang\":\"en\"}," |
| 70 "\"data/OZ/RE\": " |
| 71 "{\"id\":\"data/OZ/RE\",\"key\":\"RE\",\"name\":\"Ro \", " |
| 72 "\"lang\":\"en\"}}")); |
66 } | 73 } |
67 | 74 |
68 private: | 75 private: |
69 DISALLOW_COPY_AND_ASSIGN(ChromiumTestdataSource); | 76 DISALLOW_COPY_AND_ASSIGN(ChromiumTestdataSource); |
70 }; | 77 }; |
71 | 78 |
72 // A test subclass of the SubKeyRequesterImpl. Used to simulate rules not | 79 // A test subclass of the SubKeyRequesterImpl. Used to simulate rules not |
73 // being loaded. | 80 // being loaded. |
74 class TestSubKeyRequester : public SubKeyRequester { | 81 class TestSubKeyRequester : public SubKeyRequester { |
75 public: | 82 public: |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 192 |
186 // Even if the rules are not loaded before the call to | 193 // Even if the rules are not loaded before the call to |
187 // StartRegionSubKeysRequest, they should get loaded in the call. Since our | 194 // StartRegionSubKeysRequest, they should get loaded in the call. Since our |
188 // test source is synchronous, the request will happen synchronously | 195 // test source is synchronous, the request will happen synchronously |
189 // too. | 196 // too. |
190 EXPECT_TRUE(requester_->AreRulesLoadedForRegion(kLocale)); | 197 EXPECT_TRUE(requester_->AreRulesLoadedForRegion(kLocale)); |
191 EXPECT_EQ(subkey_receiver_->subkeys_size(), kCorrectSize); | 198 EXPECT_EQ(subkey_receiver_->subkeys_size(), kCorrectSize); |
192 } | 199 } |
193 | 200 |
194 } // namespace payments | 201 } // namespace payments |
OLD | NEW |