Web Inspector: Keep Web Inspector window alive across process swaps (PSON) (Local...
[WebKit-https.git] / LayoutTests / inspector / unit-tests / target-manager.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6 let worker;
7
8 function createWorker() {
9     worker = new Worker("../worker/resources/worker-1.js");
10 }
11
12 function terminateWorker() {
13     worker.terminate();
14 }
15
16 function test()
17 {
18     function dumpTargets() {
19         for (let target of WI.targets)
20             InspectorTest.log(`Target - ${String(target.type)} - ${target.displayName}`);
21     }
22
23     let suite = InspectorTest.createAsyncSuite("TargetManager");
24
25     suite.addTestCase({
26         name: "TargetManager.MainTarget",
27         description: "We should always have the main target.",
28         async test() {
29             InspectorTest.assert(WI.targets === WI.targetManager.targets);
30             InspectorTest.expectEqual(WI.targets.length, 1, "Targets list should always start out with the main target.");
31             InspectorTest.expectEqual([...WI.targets][0], WI.mainTarget, "Target list should always contain the main target.");
32             InspectorTest.expectNotNull(WI.mainTarget.executionContext, "Main target should have an ExecutionContext.");
33             InspectorTest.expectEqual(WI.mainTarget.RuntimeAgent, WI.pageTarget.RuntimeAgent, "Main target should have the page target's RuntimeAgent.");
34             dumpTargets();
35         }
36     });
37
38     suite.addTestCase({
39         name: "TargetManager.WorkerTarget.Create",
40         description: "Creating a Worker should create a new Worker Target.",
41         async test() {
42             InspectorTest.evaluateInPage("createWorker()");
43             let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetAdded);
44             let target = event.data.target;
45             InspectorTest.assert(target instanceof WI.Target);
46             InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Added Target should have Worker type.");
47             InspectorTest.expectNotNull(target.executionContext, "Added Target should have an ExecutionContext.");
48             InspectorTest.expectNotNull(target.RuntimeAgent, "Added Target should have a RuntimeAgent.");
49             InspectorTest.expectNotEqual(target.RuntimeAgent, RuntimeAgent, "Added Target RuntimeAgent should not be the global RuntimeAgent.");
50             dumpTargets();
51         }
52     });
53
54     suite.addTestCase({
55         name: "TargetManager.WorkerTarget.Remove",
56         description: "Creating a Worker should create a new Worker Target.",
57         async test() {
58             InspectorTest.evaluateInPage("terminateWorker()");
59             let event = await WI.targetManager.awaitEvent(WI.TargetManager.Event.TargetRemoved);
60             let target = event.data.target;
61             InspectorTest.assert(target instanceof WI.Target);
62             InspectorTest.expectEqual(target.type, WI.Target.Type.Worker, "Removed Target should have Worker type.");
63             dumpTargets();
64         }
65     });
66
67     suite.runTestCasesAndFinish();
68 }
69 </script>
70 </head>
71 <body onload="runTest()">
72 <p>Test for TargetManager and other global WI.Target objects.</p>
73 </body>
74 </html>