OLD | NEW |
1 <script> | 1 <script> |
2 function noop(x) { | 2 function noop(x) { |
3 } | 3 } |
4 | 4 |
5 function doGC() { | 5 function doGC() { |
6 if (window.GCController) { | 6 if (window.GCController) { |
7 window.GCController.collectAll(); | 7 window.GCController.collectAll(); |
8 } | 8 } |
9 } | 9 } |
| 10 var countOrig; |
| 11 var countAfterCreate; |
| 12 var countAfterGC; |
10 | 13 |
11 function runtest() { | 14 function finishTest() { |
12 if (window.testRunner) | |
13 testRunner.dumpAsText(); | |
14 | |
15 | |
16 var output = document.getElementById("output"); | |
17 output.innerHTML = ""; | |
18 | |
19 // Test that objects are deleted after their JS references are released. | |
20 var countOrig = plug.testObjectCount; | |
21 o1 = plug.testCreateTestObject(); | |
22 o2 = plug.testCreateTestObject(); | |
23 o3 = plug.testCreateTestObject(); | |
24 var countAfterCreate = plug.testObjectCount; | |
25 o1 = o2 = o3 = null; | |
26 doGC(); | 15 doGC(); |
27 var countAfterGC = plug.testObjectCount; | 16 var countAfterGC2 = plug.testObjectCount; |
28 | 17 |
29 output.innerHTML += "--- num test objects:<br>"; | 18 output.innerHTML += "--- num test objects:<br>"; |
30 output.innerHTML += "countAfterCreate == countOrig + 3? " | 19 output.innerHTML += "countAfterCreate == countOrig + 3? " |
31 + ((countAfterCreate == countOrig + 3) ? "PASS" : "FAIL") | 20 + ((countAfterCreate == countOrig + 3) ? "PASS" : "FAIL") |
32 + "<br>"; | 21 + "<br>"; |
33 output.innerHTML += "countOrig == countAfterGC? " | 22 output.innerHTML += "countOrig == countAfterGC? " |
34 + ((countOrig == countAfterGC) ? "PASS" : "FAIL") | 23 + ((countOrig == countAfterGC) ? "PASS" : "FAIL") |
35 + "<br>"; | 24 + "<br>"; |
| 25 output.innerHTML += "countOrig == countAfterGC2? " |
| 26 + ((countOrig == countAfterGC2) ? "PASS" : "FAIL") |
| 27 + "<br>"; |
36 output.innerHTML += "<br>"; | 28 output.innerHTML += "<br>"; |
37 | 29 |
38 // Test that the object refcount returns to normal after JS references | 30 var success = (countAfterGC == countOrig) && (countAfterGC2 == countOrig); |
39 // are released. | 31 output.innerHTML += (success ? "SUCCESS" : "FAILURE"); |
40 var testObj = plug.testObject; | 32 |
41 var refOrig = testObj.refCount; | 33 if (window.testRunner) |
42 var o1 = plug.testObject; | 34 testRunner.notifyDone(); |
43 var o2 = plug.testObject; | 35 } |
44 var o3 = plug.testObject; | 36 |
45 var refAfterGet = testObj.refCount; | 37 function step2() { |
46 o1 = o2 = o3 = null; | |
47 doGC(); | 38 doGC(); |
48 var refAfterGetGC = testObj.refCount; | 39 countAfterGC = plug.testObjectCount; |
49 | 40 |
50 // Test that calling NPN_Invoke with our object as a parameter returns | 41 var testObj = plug.testCreateTestObject(); |
51 // our refcount to normal (may require a GC). | 42 // The following will refcount testObj by passing it to the plugin and again |
| 43 // by the plugin calling noop, and we will verify in finishTest that the |
| 44 // refcounts are properly released, by verifying the plugin object was |
| 45 // properly deleted. |
52 plug.testPassTestObject("noop", testObj); | 46 plug.testPassTestObject("noop", testObj); |
53 plug.testPassTestObject("noop", testObj); | 47 plug.testPassTestObject("noop", testObj); |
54 plug.testPassTestObject("noop", testObj); | 48 plug.testPassTestObject("noop", testObj); |
| 49 |
55 doGC(); | 50 doGC(); |
56 var refAfterPass = testObj.refCount; | 51 // PPAPI requires the main loop to run to fully release references. See |
| 52 // PPB_Var_Deprecated_Proxy::OnMsgReleaseObject. |
| 53 setTimeout(finishTest, 0); |
| 54 } |
57 | 55 |
58 output.innerHTML += "--- refcount on plug.testObject:<br>"; | 56 function runtest() { |
59 output.innerHTML += "originally: " + refOrig + "<br>"; | 57 if (window.testRunner) { |
60 output.innerHTML += "after GC: " + refAfterGetGC + "<br>"; | 58 testRunner.dumpAsText(); |
61 output.innerHTML += "after passing: " + refAfterPass + "<br>"; | 59 testRunner.waitUntilDone(); |
| 60 } |
62 | 61 |
63 var success = (countAfterGC == countOrig) && (refAfterPass == refOrig); | 62 var output = document.getElementById("output"); |
64 output.innerHTML += (success ? "SUCCESS" : "FAILURE"); | 63 output.innerHTML = ""; |
| 64 |
| 65 // Test that objects are deleted after their JS references are released. |
| 66 countOrig = plug.testObjectCount; |
| 67 o1 = plug.testCreateTestObject(); |
| 68 o2 = plug.testCreateTestObject(); |
| 69 o3 = plug.testCreateTestObject(); |
| 70 countAfterCreate = plug.testObjectCount; |
| 71 o1 = o2 = o3 = null; |
| 72 doGC(); |
| 73 // PPAPI requires the main loop to run to fully release references. See |
| 74 // PPB_Var_Deprecated_Proxy::OnMsgReleaseObject. |
| 75 setTimeout(step2, 0); |
65 } | 76 } |
66 </script> | 77 </script> |
67 | 78 |
68 <body onload="runtest()"> | 79 <body onload="runtest()"> |
69 | 80 |
70 Test that we can get an NPObject returned through a method on | 81 Test that we can get an NPObject returned through a method on |
71 an NPAPI Object.<P> | 82 an NPAPI Object.<P> |
72 | 83 |
73 Prints "SUCCESS" on success, "FAILURE" on failure. | 84 Prints "SUCCESS" on success, "FAILURE" on failure. |
74 | 85 |
75 <embed name="plug" type="application/x-webkit-test-netscape"> | 86 <embed name="plug" type="application/x-blink-deprecated-test-plugin"> |
76 | 87 |
77 <div id=output>FAILURE</div> | 88 <div id=output>FAILURE</div> |
78 | 89 |
79 </body> | 90 </body> |
80 | 91 |
OLD | NEW |