Skip to content

Commit

Permalink
[IndexedDB Storage Partition] (17) Migrate third party storage to non…
Browse files Browse the repository at this point in the history
…-origin buckets

This CL allows the storage of third-party default buckets in the correct
location. This is an experimental feature and wpt testing is needed next.

This CL is a part of a series:
(1) Tentative WPT
(2) Add to third-party-storage-partitioning virtual suite
(3) Add WPT to check for persistence
(4) Rename IndexedDBBucketState(Handle)
(5) Store BucketLocator to IndexedDBCallbacks and DatabaseImpl
(6) Store BucketLocator to CursorImpl and TransactionImpl
(7) Store BucketLocator to IndexedDBDatabase
(8) Store BucketLocator to IndexedDBBackingStore and IndexedDBCursor
(9) Store BucketLocator to IndexedDBBucketState and IndexedDBFactoryImpl
(10) Store BucketLocator to IndexedDBContextImpl
(11) Cleanup inside IndexedDB
(12) Propagate BucketLocator to IndexedDBObserver
(13) Propagate BucketLocator to IndexedDBControl
(14) Move mojom to privileged folder
(15) Split base data path out
(16) QuotaManager::GetBucketById
(17) Migrate third party storage to non-origin buckets
(18) WPT Tests

Bug: 1218100
Change-Id: Ia970774c044e0c92084c7c45031624b524494b7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3633516
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Quick-Run: Ari Chivukula <arichiv@chromium.org>
Commit-Queue: Ari Chivukula <arichiv@chromium.org>
Auto-Submit: Ari Chivukula <arichiv@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001876}
  • Loading branch information
arichiv authored and Chromium LUCI CQ committed May 11, 2022
1 parent eba86ee commit 1b94009
Show file tree
Hide file tree
Showing 11 changed files with 856 additions and 132 deletions.
123 changes: 122 additions & 1 deletion content/browser/indexed_db/indexed_db_backing_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_clock.h"
Expand All @@ -51,6 +52,7 @@
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/indexeddb/web_idb_types.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
Expand Down Expand Up @@ -473,6 +475,27 @@ class IndexedDBBackingStoreTest : public testing::Test {
IndexedDBValue value2_;
};

class IndexedDBBackingStoreTestForThirdPartyStoragePartitioning
: public testing::WithParamInterface<bool>,
public IndexedDBBackingStoreTest {
public:
IndexedDBBackingStoreTestForThirdPartyStoragePartitioning() {
scoped_feature_list_.InitWithFeatureState(
blink::features::kThirdPartyStoragePartitioning,
IsThirdPartyStoragePartitioningEnabled());
}

bool IsThirdPartyStoragePartitioningEnabled() { return GetParam(); }

private:
base::test::ScopedFeatureList scoped_feature_list_;
};

INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
testing::Bool());

enum class ExternalObjectTestType {
kOnlyBlobs,
kOnlyFileSystemAccessHandles,
Expand Down Expand Up @@ -1631,7 +1654,8 @@ TEST_F(IndexedDBBackingStoreTest, GetDatabaseNames) {
EXPECT_EQ(db1_name, names[0]);
}

TEST_F(IndexedDBBackingStoreTest, ReadCorruptionInfo) {
TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
ReadCorruptionInfoForOpaqueStorageKey) {
auto filesystem_proxy = std::make_unique<storage::FilesystemProxy>(
storage::FilesystemProxy::UNRESTRICTED, base::FilePath());
storage::BucketLocator bucket_locator;
Expand All @@ -1641,10 +1665,17 @@ TEST_F(IndexedDBBackingStoreTest, ReadCorruptionInfo) {
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(),
base::FilePath(), bucket_locator)
.empty());
}

TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
ReadCorruptionInfoForFirstPartyStorageKey) {
auto filesystem_proxy = std::make_unique<storage::FilesystemProxy>(
storage::FilesystemProxy::UNRESTRICTED, base::FilePath());
storage::BucketLocator bucket_locator;
const base::FilePath path_base = temp_dir_.GetPath();
bucket_locator.storage_key =
blink::StorageKey::CreateFromStringForTesting("http://www.google.com/");
bucket_locator.id = storage::BucketId::FromUnsafeValue(1);
ASSERT_FALSE(path_base.empty());
ASSERT_TRUE(PathIsWritable(path_base));

Expand Down Expand Up @@ -1719,6 +1750,96 @@ TEST_F(IndexedDBBackingStoreTest, ReadCorruptionInfo) {
EXPECT_EQ("foo", message);
}

TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
ReadCorruptionInfoForThirdPartyStorageKey) {
auto filesystem_proxy = std::make_unique<storage::FilesystemProxy>(
storage::FilesystemProxy::UNRESTRICTED, base::FilePath());
storage::BucketLocator bucket_locator;
const base::FilePath path_base = temp_dir_.GetPath();
bucket_locator.storage_key =
blink::StorageKey(url::Origin::Create(GURL("http://www.google.com/")),
url::Origin::Create(GURL("http://www.youtube.com/")));
bucket_locator.id = storage::BucketId::FromUnsafeValue(1);
ASSERT_FALSE(path_base.empty());
ASSERT_TRUE(PathIsWritable(path_base));

// File not found.
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());

base::FilePath info_path =
path_base.AppendASCII("http_www.google.com_0.indexeddb.leveldb")
.AppendASCII("corruption_info.json");
if (IsThirdPartyStoragePartitioningEnabled()) {
info_path = path_base.AppendASCII("1")
.AppendASCII("IndexedDB")
.AppendASCII("indexeddb.leveldb")
.AppendASCII("corruption_info.json");
}
ASSERT_TRUE(CreateDirectory(info_path.DirName()));

// Empty file.
std::string dummy_data;
ASSERT_TRUE(base::WriteFile(info_path, dummy_data));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// File size > 4 KB.
dummy_data.resize(5000, 'c');
ASSERT_TRUE(base::WriteFile(info_path, dummy_data));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// Random string.
ASSERT_TRUE(base::WriteFile(info_path, "foo bar"));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// Not a dictionary.
ASSERT_TRUE(base::WriteFile(info_path, "[]"));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// Empty dictionary.
ASSERT_TRUE(base::WriteFile(info_path, "{}"));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// Dictionary, no message key.
ASSERT_TRUE(base::WriteFile(info_path, "{\"foo\":\"bar\"}"));
EXPECT_TRUE(indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator)
.empty());
EXPECT_FALSE(PathExists(info_path));

// Dictionary, message key.
ASSERT_TRUE(base::WriteFile(info_path, "{\"message\":\"bar\"}"));
std::string message = indexed_db::ReadCorruptionInfo(
filesystem_proxy.get(), path_base, bucket_locator);
EXPECT_FALSE(message.empty());
EXPECT_FALSE(PathExists(info_path));
EXPECT_EQ("bar", message);

// Dictionary, message key and more.
ASSERT_TRUE(base::WriteFile(info_path, "{\"message\":\"foo\",\"bar\":5}"));
message = indexed_db::ReadCorruptionInfo(filesystem_proxy.get(), path_base,
bucket_locator);
EXPECT_FALSE(message.empty());
EXPECT_FALSE(PathExists(info_path));
EXPECT_EQ("foo", message);
}

// There was a wrong migration from schema 2 to 3, which always delete IDB
// blobs and doesn't actually write the new schema version. This tests the
// upgrade path where the database doesn't have blob entries, so it' safe to
Expand Down
29 changes: 16 additions & 13 deletions content/browser/indexed_db/indexed_db_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ namespace content {

// This browser test is aimed towards exercising the IndexedDB bindings and
// the actual implementation that lives in the browser side.
class IndexedDBBrowserTest : public ContentBrowserTest,
public ::testing::WithParamInterface<const char*> {
class IndexedDBBrowserTest : public ContentBrowserTest {
public:
IndexedDBBrowserTest() = default;

Expand Down Expand Up @@ -1026,7 +1025,21 @@ std::unique_ptr<net::test_server::HttpResponse> StaticFileRequestHandler(
// See TODO in CorruptDBRequestHandler. Windows does not support nested
// message loops on the IO thread, so run this test on other platforms.
#if !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(IndexedDBBrowserTest, OperationOnCorruptedOpenDatabase) {
class IndexedDBBrowserTestWithCorruption
: public IndexedDBBrowserTest,
public ::testing::WithParamInterface<const char*> {};

INSTANTIATE_TEST_SUITE_P(/* no prefix */,
IndexedDBBrowserTestWithCorruption,
::testing::Values("failGetBlobJournal",
"get",
"getAll",
"iterate",
"failTransactionCommit",
"clearObjectStore"));

IN_PROC_BROWSER_TEST_P(IndexedDBBrowserTestWithCorruption,
OperationOnCorruptedOpenDatabase) {
ASSERT_TRUE(embedded_test_server()->Started() ||
embedded_test_server()->InitializeAndListen());
const blink::StorageKey storage_key = blink::StorageKey(
Expand Down Expand Up @@ -1062,16 +1075,6 @@ IN_PROC_BROWSER_TEST_P(IndexedDBBrowserTest, OperationOnCorruptedOpenDatabase) {
std::string(s_corrupt_db_test_prefix) + "corrupted_open_db_recovery.html";
SimpleTest(embedded_test_server()->GetURL(test_file));
}

// Only instantiate on platforms that run the parameterized test.
INSTANTIATE_TEST_SUITE_P(IndexedDBBrowserTestInstantiation,
IndexedDBBrowserTest,
::testing::Values("failGetBlobJournal",
"get",
"getAll",
"iterate",
"failTransactionCommit",
"clearObjectStore"));
#endif // !BUILDFLAG(IS_WIN)

// TODO: http://crbug.com/510520, flaky on all platforms
Expand Down

0 comments on commit 1b94009

Please sign in to comment.