Commit ac90937b authored by Mike Jackson's avatar Mike Jackson Committed by Commit Bot

DevTools: Ensure unhandled exception doesn't prevent clearing of indexeddb data

In the event there are multiple targets on page, clearing the storage via the applications
tab can result in:
  console.assert(this._databaseNamesBySecurityOrigin[securityOrigin]);
firing in Resources.IndexedDBModel.clearForOrigin because only the top
level security origin is passed to each target, and the security origins might
not match.

Repro steps:

1) Load http://nparashuram.com/trialtool/#example=/IndexedDB/trialtool/index.html&selected=#saveData
2) Run the following examples: "Pre Requisities", "Open Database", "Create Object Store", "Add Data"
3) Load the devtools, and clear all site data from the application tab

Change-Id: Iccad7f70c61eb6593058280f971849f139f473a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716445
Commit-Queue: Mike Jackson <mjackson@microsoft.com>
Reviewed-by: default avatarErik Luo <luoe@chromium.org>
Reviewed-by: default avatarJeff Fisher <jeffish@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#690782}
parent bf19b777
...@@ -160,7 +160,7 @@ Resources.IndexedDBModel = class extends SDK.SDKModel { ...@@ -160,7 +160,7 @@ Resources.IndexedDBModel = class extends SDK.SDKModel {
* @param {string} origin * @param {string} origin
*/ */
clearForOrigin(origin) { clearForOrigin(origin) {
if (!this._enabled) if (!this._enabled || !this._databaseNamesBySecurityOrigin[origin])
return; return;
this._removeOrigin(origin); this._removeOrigin(origin);
......
Validate IndexeddbModel clearForOrigin
Create IndexedDB in main frame
Database Length: 1
Database Entries:
Security Origin:http://127.0.0.1:8000, Database Name:Database-main-frame
**done**
Removing bogus security origin...
Database Length: 1
Database Entries:
Security Origin:http://127.0.0.1:8000, Database Name:Database-main-frame
**done**
Removing http://127.0.0.1:8000 security origin...
Database Length: 0
Database Entries:
**done**
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(`Validate IndexeddbModel clearForOrigin\n`);
await TestRunner.loadModule('application_test_runner');
// Note: every test that uses a storage API must manually clean-up state from previous tests.
await ApplicationTestRunner.resetState();
await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('resources');
const model = TestRunner.mainTarget.model(Resources.IndexedDBModel);
const view = UI.panels.resources;
function createIndexedDBInMainFrame(callback) {
var mainFrameId = TestRunner.resourceTreeModel.mainFrame.id;
ApplicationTestRunner.createDatabase(mainFrameId, 'Database-main-frame', () => {
var event = model.addEventListener(Resources.IndexedDBModel.Events.DatabaseAdded, () => {
Common.EventTarget.removeEventListeners([event]);
callback();
});
model.refreshDatabaseNames();
});
}
function dumpDatabases() {
const databases = model.databases();
TestRunner.addResult('Database Length: ' + databases.length);
TestRunner.addResult('Database Entries:');
for (let j = 0; j < databases.length; ++j)
TestRunner.addResult(` Security Origin:${databases[j].securityOrigin}, Database Name:${databases[j].name}`);
TestRunner.addResult('**done**\n');
}
TestRunner.addResult('Create IndexedDB in main frame');
await new Promise(createIndexedDBInMainFrame);
await TestRunner.addSnifferPromise(UI.panels.resources._sidebar.indexedDBListTreeElement, '_indexedDBLoadedForTest');
dumpDatabases();
TestRunner.addResult('Removing bogus security origin...');
model.clearForOrigin('http://bogus-security-origin.com');
dumpDatabases();
TestRunner.addResult('Removing http://127.0.0.1:8000 security origin...');
model.clearForOrigin('http://127.0.0.1:8000');
dumpDatabases();
TestRunner.completeTest();
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment