Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: content/browser/dom_storage/local_storage_context_mojo_unittest.cc

Issue 2607493003: Store a version number in the localstorage database. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/dom_storage/local_storage_context_mojo.cc ('k') | content/browser/leveldb_wrapper_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/dom_storage/local_storage_context_mojo_unittest.cc
diff --git a/content/browser/dom_storage/local_storage_context_mojo_unittest.cc b/content/browser/dom_storage/local_storage_context_mojo_unittest.cc
index df2242f243dea0c27460f2e40f8c3d3f1768cdff..81f6b5707a4316460a759bf8caf2cecd1b7341a9 100644
--- a/content/browser/dom_storage/local_storage_context_mojo_unittest.cc
+++ b/content/browser/dom_storage/local_storage_context_mojo_unittest.cc
@@ -20,29 +20,45 @@ namespace {
void NoOpSuccess(bool success) {}
+void GetCallback(const base::Closure& callback,
+ bool* success_out,
+ std::vector<uint8_t>* value_out,
+ bool success,
+ const std::vector<uint8_t>& value) {
+ *success_out = success;
+ *value_out = value;
+ callback.Run();
+}
+
} // namespace
class LocalStorageContextMojoTest : public testing::Test {
public:
- LocalStorageContextMojoTest()
- : db_(&mock_data_),
- db_binding_(&db_),
- context_(nullptr, base::FilePath()) {
- context_.SetDatabaseForTesting(db_binding_.CreateInterfacePtrAndBind());
+ LocalStorageContextMojoTest() : db_(&mock_data_), db_binding_(&db_) {}
+
+ LocalStorageContextMojo* context() {
+ if (!context_) {
+ context_ =
+ base::MakeUnique<LocalStorageContextMojo>(nullptr, base::FilePath());
+ context_->SetDatabaseForTesting(db_binding_.CreateInterfacePtrAndBind());
+ }
+ return context_.get();
}
-
- LocalStorageContextMojo* context() { return &context_; }
const std::map<std::vector<uint8_t>, std::vector<uint8_t>>& mock_data() {
return mock_data_;
}
+ void set_mock_data(const std::string& key, const std::string& value) {
+ mock_data_[StdStringToUint8Vector(key)] = StdStringToUint8Vector(value);
+ }
+
private:
TestBrowserThreadBundle thread_bundle_;
std::map<std::vector<uint8_t>, std::vector<uint8_t>> mock_data_;
MockLevelDBDatabase db_;
mojo::Binding<leveldb::mojom::LevelDBDatabase> db_binding_;
- LocalStorageContextMojo context_;
+ std::unique_ptr<LocalStorageContextMojo> context_;
};
TEST_F(LocalStorageContextMojoTest, Basic) {
@@ -56,8 +72,8 @@ TEST_F(LocalStorageContextMojoTest, Basic) {
wrapper.reset();
base::RunLoop().RunUntilIdle();
- ASSERT_EQ(1u, mock_data().size());
- EXPECT_EQ(value, mock_data().begin()->second);
+ ASSERT_EQ(2u, mock_data().size());
+ EXPECT_EQ(value, mock_data().rbegin()->second);
}
TEST_F(LocalStorageContextMojoTest, OriginsAreIndependent) {
@@ -77,8 +93,45 @@ TEST_F(LocalStorageContextMojoTest, OriginsAreIndependent) {
wrapper.reset();
base::RunLoop().RunUntilIdle();
- ASSERT_EQ(2u, mock_data().size());
- EXPECT_EQ(value, mock_data().begin()->second);
+ ASSERT_EQ(3u, mock_data().size());
+ EXPECT_EQ(value, mock_data().rbegin()->second);
+}
+
+TEST_F(LocalStorageContextMojoTest, ValidVersion) {
+ set_mock_data("VERSION", "1");
+ set_mock_data(std::string("_http://foobar.com") + '\x00' + "key", "value");
+
+ mojom::LevelDBWrapperPtr wrapper;
+ context()->OpenLocalStorage(url::Origin(GURL("http://foobar.com")),
+ MakeRequest(&wrapper));
+
+ base::RunLoop run_loop;
+ bool success = false;
+ std::vector<uint8_t> result;
+ wrapper->Get(
+ StdStringToUint8Vector("key"),
+ base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result));
+ run_loop.Run();
+ EXPECT_TRUE(success);
+ EXPECT_EQ(StdStringToUint8Vector("value"), result);
+}
+
+TEST_F(LocalStorageContextMojoTest, InvalidVersion) {
+ set_mock_data("VERSION", "foobar");
+ set_mock_data(std::string("_http://foobar.com") + '\x00' + "key", "value");
+
+ mojom::LevelDBWrapperPtr wrapper;
+ context()->OpenLocalStorage(url::Origin(GURL("http://foobar.com")),
+ MakeRequest(&wrapper));
+
+ base::RunLoop run_loop;
+ bool success = false;
+ std::vector<uint8_t> result;
+ wrapper->Get(
+ StdStringToUint8Vector("key"),
+ base::Bind(&GetCallback, run_loop.QuitClosure(), &success, &result));
+ run_loop.Run();
+ EXPECT_FALSE(success);
}
} // namespace content
« no previous file with comments | « content/browser/dom_storage/local_storage_context_mojo.cc ('k') | content/browser/leveldb_wrapper_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698