| 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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 return success; | 719 return success; |
| 720 } | 720 } |
| 721 | 721 |
| 722 private: | 722 private: |
| 723 TestBrowserThreadBundle thread_bundle_; | 723 TestBrowserThreadBundle thread_bundle_; |
| 724 base::ScopedTempDir temp_path_; | 724 base::ScopedTempDir temp_path_; |
| 725 | 725 |
| 726 DISALLOW_COPY_AND_ASSIGN(LocalStorageContextMojoTestWithService); | 726 DISALLOW_COPY_AND_ASSIGN(LocalStorageContextMojoTestWithService); |
| 727 }; | 727 }; |
| 728 | 728 |
| 729 // Enable when http://crbug.com/677194 is fixed and ServiceTest works | 729 TEST_F(LocalStorageContextMojoTestWithService, InMemory) { |
| 730 // correctly on Android. | |
| 731 #if defined(OS_ANDROID) | |
| 732 #define MAYBE_InMemory DISABLED_InMemory | |
| 733 #else | |
| 734 #define MAYBE_InMemory InMemory | |
| 735 #endif | |
| 736 TEST_F(LocalStorageContextMojoTestWithService, MAYBE_InMemory) { | |
| 737 auto context = base::MakeUnique<LocalStorageContextMojo>( | 730 auto context = base::MakeUnique<LocalStorageContextMojo>( |
| 738 connector(), nullptr, base::FilePath(), base::FilePath()); | 731 connector(), nullptr, base::FilePath(), base::FilePath()); |
| 739 auto key = StdStringToUint8Vector("key"); | 732 auto key = StdStringToUint8Vector("key"); |
| 740 auto value = StdStringToUint8Vector("value"); | 733 auto value = StdStringToUint8Vector("value"); |
| 741 | 734 |
| 742 mojom::LevelDBWrapperPtr wrapper; | 735 mojom::LevelDBWrapperPtr wrapper; |
| 743 context->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), | 736 context->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), |
| 744 MakeRequest(&wrapper)); | 737 MakeRequest(&wrapper)); |
| 745 | 738 |
| 746 DoTestPut(context.get(), key, value); | 739 DoTestPut(context.get(), key, value); |
| 747 std::vector<uint8_t> result; | 740 std::vector<uint8_t> result; |
| 748 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 741 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 749 EXPECT_EQ(value, result); | 742 EXPECT_EQ(value, result); |
| 750 | 743 |
| 751 context.reset(); | 744 context.reset(); |
| 752 base::RunLoop().RunUntilIdle(); | 745 base::RunLoop().RunUntilIdle(); |
| 753 | 746 |
| 754 // Should not have created any files. | 747 // Should not have created any files. |
| 755 EXPECT_TRUE(FirstEntryInDir().empty()); | 748 EXPECT_TRUE(FirstEntryInDir().empty()); |
| 756 | 749 |
| 757 // Re-opening should get fresh data. | 750 // Re-opening should get fresh data. |
| 758 context = base::MakeUnique<LocalStorageContextMojo>( | 751 context = base::MakeUnique<LocalStorageContextMojo>( |
| 759 connector(), nullptr, base::FilePath(), base::FilePath()); | 752 connector(), nullptr, base::FilePath(), base::FilePath()); |
| 760 EXPECT_FALSE(DoTestGet(context.get(), key, &result)); | 753 EXPECT_FALSE(DoTestGet(context.get(), key, &result)); |
| 761 } | 754 } |
| 762 | 755 |
| 763 // Enable when http://crbug.com/677194 is fixed and ServiceTest works | 756 TEST_F(LocalStorageContextMojoTestWithService, InMemoryInvalidPath) { |
| 764 // correctly on Android. | |
| 765 #if defined(OS_ANDROID) | |
| 766 #define MAYBE_InMemoryInvalidPath DISABLED_InMemoryInvalidPath | |
| 767 #else | |
| 768 #define MAYBE_InMemoryInvalidPath InMemoryInvalidPath | |
| 769 #endif | |
| 770 TEST_F(LocalStorageContextMojoTestWithService, MAYBE_InMemoryInvalidPath) { | |
| 771 auto context = base::MakeUnique<LocalStorageContextMojo>( | 757 auto context = base::MakeUnique<LocalStorageContextMojo>( |
| 772 connector(), nullptr, base::FilePath(), | 758 connector(), nullptr, base::FilePath(), |
| 773 base::FilePath(FILE_PATH_LITERAL("../../"))); | 759 base::FilePath(FILE_PATH_LITERAL("../../"))); |
| 774 auto key = StdStringToUint8Vector("key"); | 760 auto key = StdStringToUint8Vector("key"); |
| 775 auto value = StdStringToUint8Vector("value"); | 761 auto value = StdStringToUint8Vector("value"); |
| 776 | 762 |
| 777 mojom::LevelDBWrapperPtr wrapper; | 763 mojom::LevelDBWrapperPtr wrapper; |
| 778 context->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), | 764 context->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), |
| 779 MakeRequest(&wrapper)); | 765 MakeRequest(&wrapper)); |
| 780 | 766 |
| 781 DoTestPut(context.get(), key, value); | 767 DoTestPut(context.get(), key, value); |
| 782 std::vector<uint8_t> result; | 768 std::vector<uint8_t> result; |
| 783 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 769 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 784 EXPECT_EQ(value, result); | 770 EXPECT_EQ(value, result); |
| 785 | 771 |
| 786 context.reset(); | 772 context.reset(); |
| 787 base::RunLoop().RunUntilIdle(); | 773 base::RunLoop().RunUntilIdle(); |
| 788 | 774 |
| 789 // Should not have created any files. | 775 // Should not have created any files. |
| 790 EXPECT_TRUE(FirstEntryInDir().empty()); | 776 EXPECT_TRUE(FirstEntryInDir().empty()); |
| 791 } | 777 } |
| 792 | 778 |
| 793 // Enable when http://crbug.com/677194 is fixed and ServiceTest works | 779 TEST_F(LocalStorageContextMojoTestWithService, OnDisk) { |
| 794 // correctly on Android. | |
| 795 #if defined(OS_ANDROID) | |
| 796 #define MAYBE_OnDisk DISABLED_OnDisk | |
| 797 #else | |
| 798 #define MAYBE_OnDisk OnDisk | |
| 799 #endif | |
| 800 TEST_F(LocalStorageContextMojoTestWithService, MAYBE_OnDisk) { | |
| 801 base::FilePath test_path(FILE_PATH_LITERAL("test_path")); | 780 base::FilePath test_path(FILE_PATH_LITERAL("test_path")); |
| 802 auto context = base::MakeUnique<LocalStorageContextMojo>( | 781 auto context = base::MakeUnique<LocalStorageContextMojo>( |
| 803 connector(), nullptr, base::FilePath(), test_path); | 782 connector(), nullptr, base::FilePath(), test_path); |
| 804 auto key = StdStringToUint8Vector("key"); | 783 auto key = StdStringToUint8Vector("key"); |
| 805 auto value = StdStringToUint8Vector("value"); | 784 auto value = StdStringToUint8Vector("value"); |
| 806 | 785 |
| 807 DoTestPut(context.get(), key, value); | 786 DoTestPut(context.get(), key, value); |
| 808 std::vector<uint8_t> result; | 787 std::vector<uint8_t> result; |
| 809 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 788 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 810 EXPECT_EQ(value, result); | 789 EXPECT_EQ(value, result); |
| 811 | 790 |
| 812 context.reset(); | 791 context.reset(); |
| 813 base::RunLoop().RunUntilIdle(); | 792 base::RunLoop().RunUntilIdle(); |
| 814 | 793 |
| 815 // Should have created files. | 794 // Should have created files. |
| 816 EXPECT_EQ(test_path, FirstEntryInDir().BaseName()); | 795 EXPECT_EQ(test_path, FirstEntryInDir().BaseName()); |
| 817 | 796 |
| 818 // Should be able to re-open. | 797 // Should be able to re-open. |
| 819 context = base::MakeUnique<LocalStorageContextMojo>( | 798 context = base::MakeUnique<LocalStorageContextMojo>( |
| 820 connector(), nullptr, base::FilePath(), test_path); | 799 connector(), nullptr, base::FilePath(), test_path); |
| 821 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 800 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 822 EXPECT_EQ(value, result); | 801 EXPECT_EQ(value, result); |
| 823 } | 802 } |
| 824 | 803 |
| 825 // Enable when http://crbug.com/677194 is fixed and ServiceTest works | 804 TEST_F(LocalStorageContextMojoTestWithService, InvalidVersionOnDisk) { |
| 826 // correctly on Android. | |
| 827 #if defined(OS_ANDROID) | |
| 828 #define MAYBE_InvalidVersionOnDisk DISABLED_InvalidVersionOnDisk | |
| 829 #else | |
| 830 #define MAYBE_InvalidVersionOnDisk InvalidVersionOnDisk | |
| 831 #endif | |
| 832 TEST_F(LocalStorageContextMojoTestWithService, MAYBE_InvalidVersionOnDisk) { | |
| 833 base::FilePath test_path(FILE_PATH_LITERAL("test_path")); | 805 base::FilePath test_path(FILE_PATH_LITERAL("test_path")); |
| 834 | 806 |
| 835 // Create context and add some data to it. | 807 // Create context and add some data to it. |
| 836 auto context = base::MakeUnique<LocalStorageContextMojo>( | 808 auto context = base::MakeUnique<LocalStorageContextMojo>( |
| 837 connector(), nullptr, base::FilePath(), test_path); | 809 connector(), nullptr, base::FilePath(), test_path); |
| 838 auto key = StdStringToUint8Vector("key"); | 810 auto key = StdStringToUint8Vector("key"); |
| 839 auto value = StdStringToUint8Vector("value"); | 811 auto value = StdStringToUint8Vector("value"); |
| 840 | 812 |
| 841 DoTestPut(context.get(), key, value); | 813 DoTestPut(context.get(), key, value); |
| 842 std::vector<uint8_t> result; | 814 std::vector<uint8_t> result; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 871 base::RunLoop().RunUntilIdle(); | 843 base::RunLoop().RunUntilIdle(); |
| 872 | 844 |
| 873 // Data should have been preserved now. | 845 // Data should have been preserved now. |
| 874 context = base::MakeUnique<LocalStorageContextMojo>( | 846 context = base::MakeUnique<LocalStorageContextMojo>( |
| 875 connector(), nullptr, base::FilePath(), test_path); | 847 connector(), nullptr, base::FilePath(), test_path); |
| 876 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 848 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 877 EXPECT_EQ(value, result); | 849 EXPECT_EQ(value, result); |
| 878 } | 850 } |
| 879 | 851 |
| 880 } // namespace content | 852 } // namespace content |
| OLD | NEW |