1 // Copyright 2014 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.
5 #include "third_party/libaddressinput/chromium/storage_test_runner.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h"
16 using ::i18n::addressinput::Storage
;
18 StorageTestRunner::StorageTestRunner(Storage
* storage
)
24 StorageTestRunner::~StorageTestRunner() {}
26 void StorageTestRunner::RunAllTests() {
27 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData());
28 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut());
29 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData());
32 void StorageTestRunner::ClearValues() {
38 scoped_ptr
<Storage::Callback
> StorageTestRunner::BuildCallback() {
39 return scoped_ptr
<Storage::Callback
>(::i18n::addressinput::BuildCallback(
40 this, &StorageTestRunner::OnDataReady
));
43 void StorageTestRunner::OnDataReady(bool success
,
44 const std::string
& key
,
46 assert(!success
|| data
!= NULL
);
55 void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
57 scoped_ptr
<Storage::Callback
> callback(BuildCallback());
58 storage_
->Get("key", *callback
);
60 EXPECT_FALSE(success_
);
61 EXPECT_EQ("key", key_
);
62 EXPECT_TRUE(data_
.empty());
65 void StorageTestRunner::GetReturnsWhatWasPut() {
67 storage_
->Put("key", new std::string("value"));
68 scoped_ptr
<Storage::Callback
> callback(BuildCallback());
69 storage_
->Get("key", *callback
);
71 EXPECT_TRUE(success_
);
72 EXPECT_EQ("key", key_
);
73 EXPECT_EQ("value", data_
);
76 void StorageTestRunner::SecondPutOverwritesData() {
78 storage_
->Put("key", new std::string("bad-value"));
79 storage_
->Put("key", new std::string("good-value"));
80 scoped_ptr
<Storage::Callback
> callback(BuildCallback());
81 storage_
->Get("key", *callback
);
83 EXPECT_TRUE(success_
);
84 EXPECT_EQ("key", key_
);
85 EXPECT_EQ("good-value", data_
);
88 } // namespace autofill