| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/dom_storage/local_storage_context_mojo.h" | 5 #include "content/browser/dom_storage/local_storage_context_mojo.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 std::vector<uint8_t>* value_out, | 55 std::vector<uint8_t>* value_out, |
| 56 bool success, | 56 bool success, |
| 57 const std::vector<uint8_t>& value) { | 57 const std::vector<uint8_t>& value) { |
| 58 *success_out = success; | 58 *success_out = success; |
| 59 *value_out = value; | 59 *value_out = value; |
| 60 callback.Run(); | 60 callback.Run(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void NoOpGet(bool success, const std::vector<uint8_t>& value) {} | 63 void NoOpGet(bool success, const std::vector<uint8_t>& value) {} |
| 64 | 64 |
| 65 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { | |
| 66 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); | |
| 67 return std::vector<uint8_t>(data, data + input.size() * sizeof(base::char16)); | |
| 68 } | |
| 69 | |
| 70 class TestLevelDBObserver : public mojom::LevelDBObserver { | 65 class TestLevelDBObserver : public mojom::LevelDBObserver { |
| 71 public: | 66 public: |
| 72 struct Observation { | 67 struct Observation { |
| 73 enum { kAdd, kChange, kDelete, kDeleteAll } type; | 68 enum { kAdd, kChange, kDelete, kDeleteAll } type; |
| 74 std::string key; | 69 std::string key; |
| 75 std::string old_value; | 70 std::string old_value; |
| 76 std::string new_value; | 71 std::string new_value; |
| 77 std::string source; | 72 std::string source; |
| 78 }; | 73 }; |
| 79 | 74 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // Opening origin1 and accessing its data should migrate its storage. | 590 // Opening origin1 and accessing its data should migrate its storage. |
| 596 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper)); | 591 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper)); |
| 597 wrapper->Get(std::vector<uint8_t>(), base::Bind(&NoOpGet)); | 592 wrapper->Get(std::vector<uint8_t>(), base::Bind(&NoOpGet)); |
| 598 base::RunLoop().RunUntilIdle(); | 593 base::RunLoop().RunUntilIdle(); |
| 599 EXPECT_FALSE(mock_data().empty()); | 594 EXPECT_FALSE(mock_data().empty()); |
| 600 | 595 |
| 601 base::RunLoop run_loop; | 596 base::RunLoop run_loop; |
| 602 bool success = false; | 597 bool success = false; |
| 603 std::vector<uint8_t> result; | 598 std::vector<uint8_t> result; |
| 604 wrapper->Get( | 599 wrapper->Get( |
| 605 String16ToUint8Vector(key), | 600 LocalStorageContextMojo::MigrateString(key), |
| 606 base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result)); | 601 base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result)); |
| 607 run_loop.Run(); | 602 run_loop.Run(); |
| 608 EXPECT_TRUE(success); | 603 EXPECT_TRUE(success); |
| 609 EXPECT_EQ(String16ToUint8Vector(value), result); | 604 EXPECT_EQ(LocalStorageContextMojo::MigrateString(value), result); |
| 610 | 605 |
| 611 // Origin1 should no longer exist in old storage. | 606 // Origin1 should no longer exist in old storage. |
| 612 area = local->OpenStorageArea(origin1.GetURL()); | 607 area = local->OpenStorageArea(origin1.GetURL()); |
| 613 ASSERT_EQ(0u, area->Length()); | 608 ASSERT_EQ(0u, area->Length()); |
| 614 local->CloseStorageArea(area); | 609 local->CloseStorageArea(area); |
| 615 } | 610 } |
| 616 | 611 |
| 617 namespace { | 612 namespace { |
| 618 | 613 |
| 619 class ServiceTestClient : public service_manager::test::ServiceTestClient, | 614 class ServiceTestClient : public service_manager::test::ServiceTestClient, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 base::RunLoop().RunUntilIdle(); | 837 base::RunLoop().RunUntilIdle(); |
| 843 | 838 |
| 844 // Data should have been preserved now. | 839 // Data should have been preserved now. |
| 845 context = base::MakeUnique<LocalStorageContextMojo>( | 840 context = base::MakeUnique<LocalStorageContextMojo>( |
| 846 connector(), nullptr, base::FilePath(), test_path); | 841 connector(), nullptr, base::FilePath(), test_path); |
| 847 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 842 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 848 EXPECT_EQ(value, result); | 843 EXPECT_EQ(value, result); |
| 849 } | 844 } |
| 850 | 845 |
| 851 } // namespace content | 846 } // namespace content |
| OLD | NEW |