haikuwebkit/LayoutTests/storage/websql/transaction-database-expand...

69 lines
1.7 KiB
HTML
Raw Permalink Normal View History

WebSQL: User cannot grant quota increase if the JS provides an expected usage value that is too low https://bugs.webkit.org/show_bug.cgi?id=189801 <rdar://problem/43592498> Reviewed by Youenn Fablet. Source/WebCore: User was unable to grant a quota increase for WebSQL if the JS provided an expected usage value that is too low. This is because WebKit was passing this provided expectedUsage value to the client for the purpose of quota increase, even when this expectedUsage value does not make any sense (i.e. it is lower than the current database size). As a result, the client would grant a quota that is equal to the previous quota and the JS would not be able to insert any data. In order to address the issue, when the current quota is exceeded and Database::didExceedQuota() is called, we now make sure that the expectedUsage value is greater than the current quota. If it is not, we provide `current quota + 5MB` as expected usage to the client. This way, the client will grant a quota that is actually increased (provided that the user accepts). Test: storage/websql/transaction-database-expand-quota.html * Modules/webdatabase/Database.cpp: (WebCore::Database::setEstimatedSize): (WebCore::Database::didExceedQuota): * Modules/webdatabase/Database.h: LayoutTests: Add layout test coverage. * storage/websql/transaction-database-expand-quota-expected.txt: Added. * storage/websql/transaction-database-expand-quota.html: Added. Canonical link: https://commits.webkit.org/204806@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236348 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-21 19:59:40 +00:00
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body onload="runTest()">
<script>
description("Check that a quota increase is granted, even if the provided expected size is too low.");
jsTestIsAsync = true;
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.clearAllDatabases();
testRunner.dumpDatabaseCallbacks();
testRunner.databaseDefaultQuota = 0.1 * 1024 * 1024;
WebSQL: User cannot grant quota increase if the JS provides an expected usage value that is too low https://bugs.webkit.org/show_bug.cgi?id=189801 <rdar://problem/43592498> Reviewed by Youenn Fablet. Source/WebCore: User was unable to grant a quota increase for WebSQL if the JS provided an expected usage value that is too low. This is because WebKit was passing this provided expectedUsage value to the client for the purpose of quota increase, even when this expectedUsage value does not make any sense (i.e. it is lower than the current database size). As a result, the client would grant a quota that is equal to the previous quota and the JS would not be able to insert any data. In order to address the issue, when the current quota is exceeded and Database::didExceedQuota() is called, we now make sure that the expectedUsage value is greater than the current quota. If it is not, we provide `current quota + 5MB` as expected usage to the client. This way, the client will grant a quota that is actually increased (provided that the user accepts). Test: storage/websql/transaction-database-expand-quota.html * Modules/webdatabase/Database.cpp: (WebCore::Database::setEstimatedSize): (WebCore::Database::didExceedQuota): * Modules/webdatabase/Database.h: LayoutTests: Add layout test coverage. * storage/websql/transaction-database-expand-quota-expected.txt: Added. * storage/websql/transaction-database-expand-quota.html: Added. Canonical link: https://commits.webkit.org/204806@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236348 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-21 19:59:40 +00:00
testRunner.databaseMaxQuota = 50 * 1024 * 1024;
}
let db;
const dataSize = 0.5 * 1024 * 1024; // 0.5 MB.
WebSQL: User cannot grant quota increase if the JS provides an expected usage value that is too low https://bugs.webkit.org/show_bug.cgi?id=189801 <rdar://problem/43592498> Reviewed by Youenn Fablet. Source/WebCore: User was unable to grant a quota increase for WebSQL if the JS provided an expected usage value that is too low. This is because WebKit was passing this provided expectedUsage value to the client for the purpose of quota increase, even when this expectedUsage value does not make any sense (i.e. it is lower than the current database size). As a result, the client would grant a quota that is equal to the previous quota and the JS would not be able to insert any data. In order to address the issue, when the current quota is exceeded and Database::didExceedQuota() is called, we now make sure that the expectedUsage value is greater than the current quota. If it is not, we provide `current quota + 5MB` as expected usage to the client. This way, the client will grant a quota that is actually increased (provided that the user accepts). Test: storage/websql/transaction-database-expand-quota.html * Modules/webdatabase/Database.cpp: (WebCore::Database::setEstimatedSize): (WebCore::Database::didExceedQuota): * Modules/webdatabase/Database.h: LayoutTests: Add layout test coverage. * storage/websql/transaction-database-expand-quota-expected.txt: Added. * storage/websql/transaction-database-expand-quota.html: Added. Canonical link: https://commits.webkit.org/204806@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236348 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-21 19:59:40 +00:00
let largeData = "";
for (let i = 0; i < dataSize; i++)
largeData += "x";
let isFirstAttempt = true;
function writeData()
{
db.transaction((tx) => {
let id = 1;
tx.executeSql('INSERT INTO foo (id, text) VALUES (?, ?)', [id, largeData]);
}, (error) => {
if (isFirstAttempt && error.code == SQLError.QUOTA_ERR) {
isFirstAttempt = false;
setTimeout(writeData, 0);
return;
}
testFailed("Failed to write data: " + error.code + ": " + error.message);
finishJSTest();
}, () => {
testPassed("Successfully wrote data");
finishJSTest();
});
}
function runTest() {
try {
db = openDatabase('ExpandedQuotaTransaction', '', '', 0.2 * 1024 * 1024);
WebSQL: User cannot grant quota increase if the JS provides an expected usage value that is too low https://bugs.webkit.org/show_bug.cgi?id=189801 <rdar://problem/43592498> Reviewed by Youenn Fablet. Source/WebCore: User was unable to grant a quota increase for WebSQL if the JS provided an expected usage value that is too low. This is because WebKit was passing this provided expectedUsage value to the client for the purpose of quota increase, even when this expectedUsage value does not make any sense (i.e. it is lower than the current database size). As a result, the client would grant a quota that is equal to the previous quota and the JS would not be able to insert any data. In order to address the issue, when the current quota is exceeded and Database::didExceedQuota() is called, we now make sure that the expectedUsage value is greater than the current quota. If it is not, we provide `current quota + 5MB` as expected usage to the client. This way, the client will grant a quota that is actually increased (provided that the user accepts). Test: storage/websql/transaction-database-expand-quota.html * Modules/webdatabase/Database.cpp: (WebCore::Database::setEstimatedSize): (WebCore::Database::didExceedQuota): * Modules/webdatabase/Database.h: LayoutTests: Add layout test coverage. * storage/websql/transaction-database-expand-quota-expected.txt: Added. * storage/websql/transaction-database-expand-quota.html: Added. Canonical link: https://commits.webkit.org/204806@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236348 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-21 19:59:40 +00:00
} catch (err) {
testFailed("Failed to open the database");
finishJSTest();
return;
}
db.transaction((tx) => {
tx.executeSql('CREATE TABLE foo (id unique, text)');
}, (error) => {
testFailed("Failed to create table: " + error.code + ": " + error.message);
finishJSTest();
}, () => {
writeData();
});
}
onload = runTest;
</script>
</body>
</html>