summaryrefslogtreecommitdiff
path: root/chromium/components/autofill/core/browser/address_normalization_manager_unittest.cc
blob: e7f89b09415acd7649456ce92a0d691b0cb6382f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/address_normalization_manager.h"

#include <memory>

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "components/autofill/core/browser/test_address_normalizer.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace autofill {

class AddressNormalizationManagerTest : public testing::Test {
 protected:
  AddressNormalizationManagerTest() {}

  void Initialize(const std::string& app_locale) {
    manager_ = std::make_unique<AddressNormalizationManager>(
        &address_normalizer_, app_locale);
  }

  void Finalize() {
    manager_->FinalizeWithCompletionCallback(
        base::BindOnce(&AddressNormalizationManagerTest::CompletionCallback,
                       base::Unretained(this)));
  }

  void CompletionCallback() { completion_callback_called_ = true; }

  TestAddressNormalizer address_normalizer_;
  std::unique_ptr<AddressNormalizationManager> manager_;
  bool completion_callback_called_ = false;
};

TEST_F(AddressNormalizationManagerTest, SynchronousResult) {
  Initialize("en-US");

  AutofillProfile profile_to_normalize;
  manager_->NormalizeAddressUntilFinalized(&profile_to_normalize);

  EXPECT_FALSE(completion_callback_called_);
  Finalize();
  EXPECT_TRUE(completion_callback_called_);
}

TEST_F(AddressNormalizationManagerTest, AsynchronousResult) {
  Initialize("en-US");
  address_normalizer_.DelayNormalization();

  AutofillProfile profile_to_normalize;
  manager_->NormalizeAddressUntilFinalized(&profile_to_normalize);

  EXPECT_FALSE(completion_callback_called_);
  Finalize();
  EXPECT_FALSE(completion_callback_called_);
  address_normalizer_.CompleteAddressNormalization();
  EXPECT_TRUE(completion_callback_called_);
}

}  // namespace autofill