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

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

Issue 2889983002: Adds the AddressNormalizationManager and tests. (Closed)
Patch Set: Cleanup. 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
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(const AddressNormalizationManager&) {
34 completion_callback_called_ = true;
35 }
36
37 std::unique_ptr<AddressNormalizationManager> manager_;
38 TestAddressNormalizer* address_normalizer_ = nullptr; // Weak.
39 bool completion_callback_called_ = false;
40 };
41
42 TEST_F(AddressNormalizationManagerTest, SynchronousResult) {
43 Initialize("US");
44
45 autofill::AutofillProfile profile_to_normalize;
46 manager_->StartNormalizingAddress(&profile_to_normalize);
47
48 EXPECT_FALSE(completion_callback_called_);
49 Finalize();
50 EXPECT_TRUE(completion_callback_called_);
51 }
52
53 TEST_F(AddressNormalizationManagerTest, AsynchronousResult) {
54 Initialize("US");
55 address_normalizer_->DelayNormalization();
56
57 autofill::AutofillProfile profile_to_normalize;
58 manager_->StartNormalizingAddress(&profile_to_normalize);
59
60 EXPECT_FALSE(completion_callback_called_);
61 Finalize();
62 EXPECT_FALSE(completion_callback_called_);
63 address_normalizer_->CompleteAddressNormalization();
64 EXPECT_TRUE(completion_callback_called_);
65 }
66
67 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698