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/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "components/leveldb/public/cpp/util.h" | 8 #include "components/leveldb/public/cpp/util.h" |
9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
10 #include "content/test/mock_leveldb_database.h" | 10 #include "content/test/mock_leveldb_database.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 auto key = StdStringToUint8Vector("key"); | 65 auto key = StdStringToUint8Vector("key"); |
66 auto value = StdStringToUint8Vector("value"); | 66 auto value = StdStringToUint8Vector("value"); |
67 | 67 |
68 mojom::LevelDBWrapperPtr wrapper; | 68 mojom::LevelDBWrapperPtr wrapper; |
69 context()->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), | 69 context()->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), |
70 MakeRequest(&wrapper)); | 70 MakeRequest(&wrapper)); |
71 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess)); | 71 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess)); |
72 wrapper.reset(); | 72 wrapper.reset(); |
73 | 73 |
74 base::RunLoop().RunUntilIdle(); | 74 base::RunLoop().RunUntilIdle(); |
| 75 |
75 ASSERT_EQ(2u, mock_data().size()); | 76 ASSERT_EQ(2u, mock_data().size()); |
76 EXPECT_EQ(value, mock_data().rbegin()->second); | 77 EXPECT_EQ(value, mock_data().rbegin()->second); |
77 } | 78 } |
78 | 79 |
79 TEST_F(LocalStorageContextMojoTest, OriginsAreIndependent) { | 80 TEST_F(LocalStorageContextMojoTest, OriginsAreIndependent) { |
80 url::Origin origin1(GURL("http://foobar.com:123")); | 81 url::Origin origin1(GURL("http://foobar.com:123")); |
81 url::Origin origin2(GURL("http://foobar.com:1234")); | 82 url::Origin origin2(GURL("http://foobar.com:1234")); |
82 auto key1 = StdStringToUint8Vector("4key"); | 83 auto key1 = StdStringToUint8Vector("4key"); |
83 auto key2 = StdStringToUint8Vector("key"); | 84 auto key2 = StdStringToUint8Vector("key"); |
84 auto value = StdStringToUint8Vector("value"); | 85 auto value = StdStringToUint8Vector("value"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 base::RunLoop run_loop; | 128 base::RunLoop run_loop; |
128 bool success = false; | 129 bool success = false; |
129 std::vector<uint8_t> result; | 130 std::vector<uint8_t> result; |
130 wrapper->Get( | 131 wrapper->Get( |
131 StdStringToUint8Vector("key"), | 132 StdStringToUint8Vector("key"), |
132 base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result)); | 133 base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result)); |
133 run_loop.Run(); | 134 run_loop.Run(); |
134 EXPECT_FALSE(success); | 135 EXPECT_FALSE(success); |
135 } | 136 } |
136 | 137 |
| 138 TEST_F(LocalStorageContextMojoTest, VersionOnlyWrittenOnCommit) { |
| 139 mojom::LevelDBWrapperPtr wrapper; |
| 140 context()->OpenLocalStorage(url::Origin(GURL("http://foobar.com")), |
| 141 MakeRequest(&wrapper)); |
| 142 |
| 143 base::RunLoop run_loop; |
| 144 bool success = false; |
| 145 std::vector<uint8_t> result; |
| 146 wrapper->Get( |
| 147 StdStringToUint8Vector("key"), |
| 148 base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result)); |
| 149 run_loop.Run(); |
| 150 EXPECT_FALSE(success); |
| 151 wrapper.reset(); |
| 152 |
| 153 base::RunLoop().RunUntilIdle(); |
| 154 EXPECT_TRUE(mock_data().empty()); |
| 155 } |
| 156 |
137 } // namespace content | 157 } // namespace content |
OLD | NEW |