3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script type=
"text/javascript">
8 var responsesReceived
= 0;
10 function finishWhenDone(agentName
, action
, errorString
)
12 if (action
=== "enable")
13 InspectorTest
.addResult("");
15 InspectorTest
.addResult(agentName
+ "." + action
+ " finished with error " + errorString
);
17 InspectorTest
.addResult(agentName
+ "." + action
+ " finished successfully");
20 if (responsesReceived
=== requestsSent
)
21 InspectorTest
.completeTest();
24 var targets
= WebInspector
.targetManager
.targets();
25 targets
.forEach(function(target
) {
26 var agentNames
= Object
.keys(target
._agentsMap
).filter(function(agentName
) {
27 var agent
= target
._agentsMap
[agentName
];
28 return agent
["enable"] && agent
["disable"] && agentName
!== "ServiceWorker" && agentName
!== "Security"; // async wrt others.
31 function disableAgent(agentName
)
34 var agent
= target
._agentsMap
[agentName
];
35 if (agent
._promisified
) {
36 agent
.disable(finishWhenDone
.bind(null, agentName
, "disable"))
37 .catch(finishWhenDone
.bind(null, agentName
, "disable"));
39 agent
.disable(finishWhenDone
.bind(null, agentName
, "disable"));
43 function enableAgent(agentName
)
46 var agent
= target
._agentsMap
[agentName
];
47 if (agent
._promisified
) {
48 agent
.enable(finishWhenDone
.bind(null, agentName
, "enable"))
49 .catch(finishWhenDone
.bind(null, agentName
, "enable"));
51 agent
.enable(finishWhenDone
.bind(null, agentName
, "enable"));
55 agentNames
.forEach(disableAgent
);
57 agentNames
.forEach(function(agentName
) {
58 enableAgent(agentName
);
59 disableAgent(agentName
);
66 <body onload=
"runTest()">
67 <p>Test that each agent could be enabled/disabled separately.
</p>