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

Side by Side Diff: components/payments/core/address_normalization_manager_unittest.cc

Issue 2889983002: Adds the AddressNormalizationManager and tests. (Closed)
Patch Set: . Created 3 years, 7 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
« no previous file with comments | « components/payments/core/address_normalization_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "components/payments/core/address_normalization_manager.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/memory/ptr_util.h"
10 #include "components/payments/core/test_address_normalizer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace payments {
14
15 class AddressNormalizationManagerTest : public testing::Test {
16 protected:
17 AddressNormalizationManagerTest() {}
18
19 void Initialize(const std::string& country_code) {
20 std::unique_ptr<TestAddressNormalizer> address_normalizer =
21 base::MakeUnique<TestAddressNormalizer>();
22 address_normalizer_ = address_normalizer.get();
23 manager_ = base::MakeUnique<AddressNormalizationManager>(
24 std::move(address_normalizer), country_code);
25 }
26
27 void Finalize() {
28 manager_->FinalizeWithCompletionCallback(
29 base::BindOnce(&AddressNormalizationManagerTest::CompletionCallback,
30 base::Unretained(this)));
31 }
32
33 void CompletionCallback() { completion_callback_called_ = true; }
34
35 std::unique_ptr<AddressNormalizationManager> manager_;
36 TestAddressNormalizer* address_normalizer_ = nullptr; // Weak.
37 bool completion_callback_called_ = false;
38 };
39
40 TEST_F(AddressNormalizationManagerTest, SynchronousResult) {
41 Initialize("US");
42
43 autofill::AutofillProfile profile_to_normalize;
44 manager_->StartNormalizingAddress(&profile_to_normalize);
45
46 EXPECT_FALSE(completion_callback_called_);
47 Finalize();
48 EXPECT_TRUE(completion_callback_called_);
49 }
50
51 TEST_F(AddressNormalizationManagerTest, AsynchronousResult) {
52 Initialize("US");
53 address_normalizer_->DelayNormalization();
54
55 autofill::AutofillProfile profile_to_normalize;
56 manager_->StartNormalizingAddress(&profile_to_normalize);
57
58 EXPECT_FALSE(completion_callback_called_);
59 Finalize();
60 EXPECT_FALSE(completion_callback_called_);
61 address_normalizer_->CompleteAddressNormalization();
62 EXPECT_TRUE(completion_callback_called_);
63 }
64
65 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/address_normalization_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698