Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Web Inspector: When modifying sessionStorage, localStorage gets updated
https://bugs.webkit.org/show_bug.cgi?id=159181 <rdar://problem/27043447> Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-06-27 Reviewed by Timothy Hatcher. Source/WebInspectorUI: * UserInterface/Test/Test.js: (WebInspector.loaded): Add registration for StorageManager and StorageObserver. Source/WebKit2: * WebProcess/Storage/StorageAreaMap.cpp: (WebKit::StorageAreaMap::dispatchSessionStorageEvent): This should be dispatching storage events. LayoutTests: * inspector/storage/domStorage-events-expected.txt: Added. * inspector/storage/domStorage-events.html: Added. Add a new test for DOMStorage domain events. Ensures that sessionStorage and localStorage events are dispatched for the appropriate DOMStorageObject. Canonical link: https://commits.webkit.org/177280@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202529 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
171 additions
and 1 deletion.
- +13 −0 LayoutTests/ChangeLog
- +36 −0 LayoutTests/inspector/storage/domStorage-events-expected.txt
- +95 −0 LayoutTests/inspector/storage/domStorage-events.html
- +12 −0 Source/WebInspectorUI/ChangeLog
- +2 −0 Source/WebInspectorUI/UserInterface/Test/Test.js
- +12 −0 Source/WebKit2/ChangeLog
- +1 −1 Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,36 @@ | ||
Test for the DOMStorage events. | ||
|
||
|
||
== Running test suite: DOMStorage.Events | ||
-- Running test case: TestSessionStorage | ||
PASS: Should have a DOMStorageObject for sessionStorage. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemAdded | ||
PASS: Should add key 'foo'. | ||
PASS: Should have value 'value1'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemAdded | ||
PASS: Should add key 'x'. | ||
PASS: Should have value 'xvalue'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemUpdated | ||
PASS: Should update key 'x'. | ||
PASS: Should have oldValue 'value1'. | ||
PASS: Should have new value 'value2'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemRemoved | ||
PASS: Should remove key 'x'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemsCleared | ||
|
||
-- Running test case: TestLocalStorage | ||
PASS: Should have a DOMStorageObject for localStorage. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemAdded | ||
PASS: Should add key 'foo'. | ||
PASS: Should have value 'value1'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemAdded | ||
PASS: Should add key 'x'. | ||
PASS: Should have value 'xvalue'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemUpdated | ||
PASS: Should update key 'x'. | ||
PASS: Should have oldValue 'value1'. | ||
PASS: Should have new value 'value2'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemRemoved | ||
PASS: Should remove key 'x'. | ||
PASS: WebInspector.DOMStorageObject.Event.ItemsCleared | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../http/tests/inspector/resources/inspector-test.js"></script> | ||
<script> | ||
function clearStorages() { | ||
sessionStorage.clear(); | ||
localStorage.clear(); | ||
} | ||
|
||
function triggerActions(storage) { | ||
storage.setItem("foo", "value1"); | ||
storage.setItem("x", "xvalue"); | ||
storage.setItem("foo", "value2"); | ||
storage.removeItem("foo"); | ||
storage.clear(); | ||
} | ||
|
||
function test() | ||
{ | ||
function testStorageEvents(storageObject, callback) { | ||
let count = 0; | ||
storageObject.addEventListener(WebInspector.DOMStorageObject.Event.ItemAdded, (event) => { | ||
count++; | ||
|
||
if (count === 1) { | ||
InspectorTest.pass("WebInspector.DOMStorageObject.Event.ItemAdded"); | ||
InspectorTest.expectThat(event.data.key === "foo", "Should add key 'foo'."); | ||
InspectorTest.expectThat(event.data.value === "value1", "Should have value 'value1'."); | ||
return; | ||
} | ||
|
||
if (count === 2) { | ||
InspectorTest.pass("WebInspector.DOMStorageObject.Event.ItemAdded"); | ||
InspectorTest.expectThat(event.data.key === "x", "Should add key 'x'."); | ||
InspectorTest.expectThat(event.data.value === "xvalue", "Should have value 'xvalue'."); | ||
return; | ||
} | ||
|
||
InspectorTest.fail("Unexpected WebInspector.DOMStorageObject.Event.ItemAdded"); | ||
}); | ||
|
||
storageObject.singleFireEventListener(WebInspector.DOMStorageObject.Event.ItemRemoved, (event) => { | ||
InspectorTest.pass("WebInspector.DOMStorageObject.Event.ItemRemoved"); | ||
InspectorTest.expectThat(event.data.key === "foo", "Should remove key 'x'."); | ||
}); | ||
|
||
storageObject.singleFireEventListener(WebInspector.DOMStorageObject.Event.ItemUpdated, (event) => { | ||
InspectorTest.pass("WebInspector.DOMStorageObject.Event.ItemUpdated"); | ||
InspectorTest.expectThat(event.data.key === "foo", "Should update key 'x'."); | ||
InspectorTest.expectThat(event.data.oldValue === "value1", "Should have oldValue 'value1'."); | ||
InspectorTest.expectThat(event.data.value === "value2", "Should have new value 'value2'."); | ||
}); | ||
|
||
storageObject.singleFireEventListener(WebInspector.DOMStorageObject.Event.ItemsCleared, (event) => { | ||
InspectorTest.pass("WebInspector.DOMStorageObject.Event.ItemsCleared"); | ||
storageObject.removeEventListener(WebInspector.DOMStorageObject.Event.ItemAdded, null, null); | ||
callback(); | ||
}); | ||
} | ||
|
||
let suite = InspectorTest.createAsyncSuite("DOMStorage.Events"); | ||
|
||
suite.addTestCase({ | ||
name: "TestSessionStorage", | ||
description: "Test backend generated DOMStorage added, removed, updated, and cleared events for sessionStorage.", | ||
test: (resolve, reject) => { | ||
InspectorTest.evaluateInPage("triggerActions(sessionStorage)"); | ||
let sessionStorage = WebInspector.storageManager.domStorageObjects.find((x) => !x.isLocalStorage()); | ||
InspectorTest.expectThat(sessionStorage, "Should have a DOMStorageObject for sessionStorage."); | ||
testStorageEvents(sessionStorage, resolve); | ||
} | ||
}); | ||
|
||
suite.addTestCase({ | ||
name: "TestLocalStorage", | ||
description: "Test backend generated DOMStorage added, removed, updated, and cleared events for localStorage.", | ||
test: (resolve, reject) => { | ||
InspectorTest.evaluateInPage("triggerActions(localStorage)"); | ||
let localStorage = WebInspector.storageManager.domStorageObjects.find((x) => x.isLocalStorage()); | ||
InspectorTest.expectThat(localStorage, "Should have a DOMStorageObject for localStorage."); | ||
testStorageEvents(localStorage, resolve); | ||
} | ||
}); | ||
|
||
InspectorTest.evaluateInPage("clearStorages()", () => { | ||
suite.runTestCasesAndFinish(); | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body onload="runTest()"> | ||
<p>Test for the DOMStorage events.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters