Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / libaddressinput / chromium / storage_test_runner.cc
blob453f0f292895382f94d166a35aea210b17e2b160
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"
7 #include <cassert>
8 #include <cstddef>
9 #include <string>
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h"
14 namespace autofill {
16 using ::i18n::addressinput::Storage;
18 StorageTestRunner::StorageTestRunner(Storage* storage)
19 : storage_(storage),
20 success_(false),
21 key_(),
22 data_() {}
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() {
33 success_ = false;
34 key_.clear();
35 data_.clear();
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,
45 std::string* data) {
46 assert(!success || data != NULL);
47 success_ = success;
48 key_ = key;
49 if (data != NULL) {
50 data_ = *data;
51 delete data;
55 void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
56 ClearValues();
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() {
66 ClearValues();
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() {
77 ClearValues();
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