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

Side by Side Diff: content/browser/dom_storage/local_storage_context_mojo_unittest.cc

Issue 2625873004: Delete and try to recreate localstorage database on invalid schema version. (Closed)
Patch Set: fix windows build Created 3 years, 11 months 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 unified diff | Download patch
OLDNEW
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 "components/filesystem/public/interfaces/file_system.mojom.h" 10 #include "components/filesystem/public/interfaces/file_system.mojom.h"
11 #include "components/leveldb/public/cpp/util.h" 11 #include "components/leveldb/public/cpp/util.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/local_storage_usage_info.h" 13 #include "content/public/browser/local_storage_usage_info.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/test/mock_leveldb_database.h" 15 #include "content/test/mock_leveldb_database.h"
16 #include "mojo/public/cpp/bindings/associated_binding.h" 16 #include "mojo/public/cpp/bindings/associated_binding.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/binding_set.h" 18 #include "mojo/public/cpp/bindings/binding_set.h"
19 #include "services/file/file_service.h" 19 #include "services/file/file_service.h"
20 #include "services/file/public/interfaces/constants.mojom.h" 20 #include "services/file/public/interfaces/constants.mojom.h"
21 #include "services/file/user_id_map.h" 21 #include "services/file/user_id_map.h"
22 #include "services/service_manager/public/cpp/interface_factory.h" 22 #include "services/service_manager/public/cpp/interface_factory.h"
23 #include "services/service_manager/public/cpp/interface_registry.h" 23 #include "services/service_manager/public/cpp/interface_registry.h"
24 #include "services/service_manager/public/cpp/service_context.h" 24 #include "services/service_manager/public/cpp/service_context.h"
25 #include "services/service_manager/public/cpp/service_test.h" 25 #include "services/service_manager/public/cpp/service_test.h"
26 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 26 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/leveldatabase/env_chromium.h"
29 #include "third_party/leveldatabase/src/include/leveldb/db.h"
28 30
29 using leveldb::StdStringToUint8Vector; 31 using leveldb::StdStringToUint8Vector;
30 using leveldb::Uint8VectorToStdString; 32 using leveldb::Uint8VectorToStdString;
31 33
32 namespace content { 34 namespace content {
33 35
34 namespace { 36 namespace {
35 37
36 void NoOpSuccess(bool success) {} 38 void NoOpSuccess(bool success) {}
37 39
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 727
726 // Should have created files. 728 // Should have created files.
727 EXPECT_EQ(test_path, FirstEntryInDir().BaseName()); 729 EXPECT_EQ(test_path, FirstEntryInDir().BaseName());
728 730
729 // Should be able to re-open. 731 // Should be able to re-open.
730 context.reset(new LocalStorageContextMojo(connector(), test_path)); 732 context.reset(new LocalStorageContextMojo(connector(), test_path));
731 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); 733 EXPECT_TRUE(DoTestGet(context.get(), key, &result));
732 EXPECT_EQ(value, result); 734 EXPECT_EQ(value, result);
733 } 735 }
734 736
737 // Enable when http://crbug.com/677194 is fixed and ServiceTest works
738 // correctly on Android.
739 #if defined(OS_ANDROID)
740 #define MAYBE_InvalidVersionOnDisk DISABLED_InvalidVersionOnDisk
741 #else
742 #define MAYBE_InvalidVersionOnDisk InvalidVersionOnDisk
743 #endif
744 TEST_F(LocalStorageContextMojoTestWithService, MAYBE_InvalidVersionOnDisk) {
745 base::FilePath test_path(FILE_PATH_LITERAL("test_path"));
746
747 // Create context and add some data to it.
748 auto context =
749 base::MakeUnique<LocalStorageContextMojo>(connector(), test_path);
750 auto key = StdStringToUint8Vector("key");
751 auto value = StdStringToUint8Vector("value");
752
753 DoTestPut(context.get(), key, value);
754 std::vector<uint8_t> result;
755 EXPECT_TRUE(DoTestGet(context.get(), key, &result));
756 EXPECT_EQ(value, result);
757
758 context.reset();
759 base::RunLoop().RunUntilIdle();
760
761 {
762 // Mess up version number in database.
763 leveldb_env::ChromiumEnv env;
764 leveldb::DB* db = nullptr;
765 leveldb::Options options;
766 options.env = &env;
767 base::FilePath db_path =
768 temp_path().Append(test_path).Append(FILE_PATH_LITERAL("leveldb"));
769 ASSERT_TRUE(leveldb::DB::Open(options, db_path.AsUTF8Unsafe(), &db).ok());
770 std::unique_ptr<leveldb::DB> db_owner(db);
771 ASSERT_TRUE(db->Put(leveldb::WriteOptions(), "VERSION", "argh").ok());
772 }
773
774 // Make sure data is gone.
775 context = base::MakeUnique<LocalStorageContextMojo>(connector(), test_path);
776 EXPECT_FALSE(DoTestGet(context.get(), key, &result));
777
778 // Write data again.
779 DoTestPut(context.get(), key, value);
780
781 context.reset();
782 base::RunLoop().RunUntilIdle();
783
784 // Data should have been preserved now.
785 context = base::MakeUnique<LocalStorageContextMojo>(connector(), test_path);
786 EXPECT_TRUE(DoTestGet(context.get(), key, &result));
787 EXPECT_EQ(value, result);
788 }
789
735 } // namespace content 790 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698