| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/value_store/value_store_unittest.h" | 5 #include "chrome/browser/value_store/value_store_unittest.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| 11 using content::BrowserThread; | 11 using content::BrowserThread; |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // To save typing ValueStore::DEFAULTS everywhere. | 15 // To save typing ValueStore::DEFAULTS everywhere. |
| 16 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; | 16 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; |
| 17 | 17 |
| 18 // Gets the pretty-printed JSON for a value. | 18 // Gets the pretty-printed JSON for a value. |
| 19 std::string GetJSON(const Value& value) { | 19 std::string GetJSON(const Value& value) { |
| 20 std::string json; | 20 std::string json; |
| 21 base::JSONWriter::WriteWithOptions(&value, | 21 base::JSONWriter::WriteWithOptions(&value, |
| 22 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 22 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 23 &json); | 23 &json); |
| 24 return json; | 24 return json; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Pretty-prints a set of strings. | |
| 28 std::string ToString(const std::set<std::string>& strings) { | |
| 29 std::string string("{"); | |
| 30 for (std::set<std::string>::const_iterator it = strings.begin(); | |
| 31 it != strings.end(); ++it) { | |
| 32 if (it != strings.begin()) { | |
| 33 string.append(", "); | |
| 34 } | |
| 35 string.append(*it); | |
| 36 } | |
| 37 string.append("}"); | |
| 38 return string; | |
| 39 } | |
| 40 | |
| 41 } // namespace | 27 } // namespace |
| 42 | 28 |
| 43 // Compares two possibly NULL values for equality, filling |error| with an | 29 // Compares two possibly NULL values for equality, filling |error| with an |
| 44 // appropriate error message if they're different. | 30 // appropriate error message if they're different. |
| 45 bool ValuesEqual( | 31 bool ValuesEqual( |
| 46 const Value* expected, const Value* actual, std::string* error) { | 32 const Value* expected, const Value* actual, std::string* error) { |
| 47 if (expected == actual) { | 33 if (expected == actual) { |
| 48 return true; | 34 return true; |
| 49 } | 35 } |
| 50 if (expected && !actual) { | 36 if (expected && !actual) { |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 471 } |
| 486 { | 472 { |
| 487 ValueStoreChangeList changes; | 473 ValueStoreChangeList changes; |
| 488 changes.push_back(ValueStoreChange(key3_, val3_->DeepCopy(), NULL)); | 474 changes.push_back(ValueStoreChange(key3_, val3_->DeepCopy(), NULL)); |
| 489 changes.push_back( | 475 changes.push_back( |
| 490 ValueStoreChange("qwerty", val3_->DeepCopy(), NULL)); | 476 ValueStoreChange("qwerty", val3_->DeepCopy(), NULL)); |
| 491 EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Clear()); | 477 EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Clear()); |
| 492 EXPECT_PRED_FORMAT2(ChangesEq, ValueStoreChangeList(), storage_->Clear()); | 478 EXPECT_PRED_FORMAT2(ChangesEq, ValueStoreChangeList(), storage_->Clear()); |
| 493 } | 479 } |
| 494 } | 480 } |
| OLD | NEW |