Commit d0308991 authored by Changhao Han's avatar Changhao Han Committed by Commit Bot

Set callback to nullptr after sending success

Change-Id: Iecbf7ff7d7a8f636b55d251cc105bac1e22f4b5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362921
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Auto-Submit: Changhao Han <changhaohan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800093}
parent b09a328a
...@@ -2616,6 +2616,7 @@ Response InspectorCSSAgent::trackComputedStyleUpdates( ...@@ -2616,6 +2616,7 @@ Response InspectorCSSAgent::trackComputedStyleUpdates(
if (computed_style_updated_callback_) { if (computed_style_updated_callback_) {
computed_style_updated_callback_->sendSuccess( computed_style_updated_callback_->sendSuccess(
BuildArrayForComputedStyleUpdatedNodes()); BuildArrayForComputedStyleUpdatedNodes());
computed_style_updated_callback_ = nullptr;
} }
computed_style_updated_node_ids_.clear(); computed_style_updated_node_ids_.clear();
return Response::Success(); return Response::Success();
......
...@@ -11,11 +11,6 @@ Updated nodes from the second session should not contain the first item: true ...@@ -11,11 +11,6 @@ Updated nodes from the second session should not contain the first item: true
Updated nodes from the second session should contain the second item: true Updated nodes from the second session should contain the second item: true
Updated nodes from the second session should contain the third item: true Updated nodes from the second session should contain the third item: true
Updated nodes from the second session should not contain the fourth item: true Updated nodes from the second session should not contain the fourth item: true
Sending a request before the previous one is resolved should fail with an error message:
{
code : -32000
message : A previous request has not been resolved yet.
}
Sending a request while no style is being tracked should fail with an error message: Sending a request while no style is being tracked should fail with an error message:
{ {
code : -32000 code : -32000
......
Test multiple CSS.takeComputedStyleUpdates commands at the same time.
Sending a request before the previous one is resolved should fail with an error message:
{
code : -32000
message : A previous request has not been resolved yet.
}
[
]
Updated nodes should contain the first item: true
Updated nodes should contain the second item: true
Updated nodes should not contain the third item: true
Updated nodes should not contain the fourth item: true
(async function (testRunner) {
const { page, session, dp } = await testRunner.startURL(
'resources/css-poll-style-updates.html',
'Test multiple CSS.takeComputedStyleUpdates commands at the same time.');
await dp.DOM.enable();
await dp.CSS.enable();
const CSSHelper = await testRunner.loadScript('../resources/css-helper.js');
const cssHelper = new CSSHelper(testRunner, dp);
const documentNodeId = await cssHelper.requestDocumentNodeId();
const nodeIds = await cssHelper.requestAllNodeIds(documentNodeId, '.item');
await dp.CSS.trackComputedStyleUpdates({
'propertiesToTrack': [
{
name: 'position',
value: 'relative',
},
{
name: 'position',
value: 'absolute',
}
],
});
// Test multiple requests at the same time
const multipleRequestsPromise = Promise.all([
dp.CSS.takeComputedStyleUpdates(),
dp.CSS.takeComputedStyleUpdates(),
]);
session.evaluate(
() =>
document.querySelector('.container').classList.add('change-2'));
// Only one request can be active at a time; other requests should fail.
const multipleRequestsResponse = await multipleRequestsPromise;
let errorResponse =
multipleRequestsResponse.find(result => Boolean(result.error));
testRunner.log(
'Sending a request before the previous one is resolved should fail with an error message:');
testRunner.log(errorResponse && errorResponse.error);
const pollBeforeDisablePromise = dp.CSS.takeComputedStyleUpdates();
await dp.CSS.trackComputedStyleUpdates({
'propertiesToTrack': [],
});
testRunner.log((await pollBeforeDisablePromise).result.nodeIds);
// Re-enable tracking and poll to see if the previous callback was correctly nullified
await dp.CSS.trackComputedStyleUpdates({
'propertiesToTrack': [
{
name: 'position',
value: 'relative',
},
{
name: 'position',
value: 'absolute',
}
],
});
session.evaluate(
() =>
document.querySelector('.container').classList.remove('change-2'));
const pollAfterReEnableResult = await dp.CSS.takeComputedStyleUpdates();
const respondedIds = pollAfterReEnableResult.result.nodeIds;
testRunner.log(
`Updated nodes should contain the first item: ${
respondedIds.includes(nodeIds[0])}`);
testRunner.log(
`Updated nodes should contain the second item: ${
respondedIds.includes(nodeIds[1])}`);
testRunner.log(
`Updated nodes should not contain the third item: ${
!respondedIds.includes(nodeIds[2])}`);
testRunner.log(
`Updated nodes should not contain the fourth item: ${
!respondedIds.includes(nodeIds[3])}`);
testRunner.completeTest();
});
...@@ -116,22 +116,6 @@ ...@@ -116,22 +116,6 @@
`Updated nodes from the second session should not contain the fourth item: ${ `Updated nodes from the second session should not contain the fourth item: ${
!secondSessionRespondedIds.includes(secondSessionNodeIds[3])}`); !secondSessionRespondedIds.includes(secondSessionNodeIds[3])}`);
const multipleRequestsPromise = Promise.all([
firstDP.CSS.takeComputedStyleUpdates(),
firstDP.CSS.takeComputedStyleUpdates(),
]);
firstSession.evaluate(
() =>
document.querySelector('.container').classList.remove('change-2'));
// Only one request can be active at a time; other requests should fail.
const multipleRequestsResponse = await multipleRequestsPromise;
let errorResponse =
multipleRequestsResponse.find(result => Boolean(result.error));
testRunner.log(
'Sending a request before the previous one is resolved should fail with an error message:');
testRunner.log(errorResponse && errorResponse.error);
await firstDP.CSS.trackComputedStyleUpdates({ await firstDP.CSS.trackComputedStyleUpdates({
'propertiesToTrack': [], 'propertiesToTrack': [],
}); });
......
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