Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var testPassed = false; | 5 var testPassed = false; |
| 6 var resultString = ""; | 6 var resultString = ""; |
| 7 var asyncCounter = 0; | |
| 8 var javascriptDone = false; | 7 var javascriptDone = false; |
| 9 var vrDisplayPromiseDone = false; | 8 var initializationSteps = {"load": false}; |
|
mthiesse
2017/05/30 15:30:46
nit: Unnecessary quotes around 'load'.
bsheedy
2017/05/30 18:15:36
Done.
| |
| 10 | 9 |
| 11 function finishJavaScriptStep() { | 10 function finishJavaScriptStep() { |
| 12 javascriptDone = true; | 11 javascriptDone = true; |
| 13 } | 12 } |
| 14 | 13 |
| 14 // Used to check when JavaScript is in an acceptable state to start testing | |
| 15 // after a page load, as Chromium thinking that the page has finished loading | |
|
tiborg
2017/05/30 14:41:23
Nit: I think we use the name Chrome to refer to th
bsheedy
2017/05/30 18:15:36
Done.
| |
| 16 // is not always sufficient. By default waits until the load event is fired. | |
| 17 function isInitializationComplete() { | |
| 18 for (var step in initializationSteps) { | |
| 19 if (!initializationSteps[step]) { | |
| 20 return false; | |
| 21 } | |
| 22 } | |
| 23 return true; | |
| 24 } | |
| 25 | |
| 26 window.addEventListener("load", | |
| 27 () => {initializationSteps["load"] = true;}, false); | |
| 28 | |
| 15 function checkResultsForFailures(tests, harness_status) { | 29 function checkResultsForFailures(tests, harness_status) { |
| 16 testPassed = true; | 30 testPassed = true; |
| 17 if (harness_status["status"] != 0) { | 31 if (harness_status["status"] != 0) { |
| 18 testPassed = false; | 32 testPassed = false; |
| 19 resultString += "Harness failed due to " + | 33 resultString += "Harness failed due to " + |
| 20 (harness_status["status"] == 1 ? "error" : "timeout") | 34 (harness_status["status"] == 1 ? "error" : "timeout") |
| 21 + ". "; | 35 + ". "; |
| 22 } | 36 } |
| 23 for (var test in tests) { | 37 for (var test in tests) { |
| 24 let passed = (tests[test]["status"] == 0); | 38 let passed = (tests[test]["status"] == 0); |
| 25 if (!passed) { | 39 if (!passed) { |
| 26 testPassed = false; | 40 testPassed = false; |
| 27 resultString += "FAIL "; | 41 resultString += "FAIL "; |
| 28 } else { | 42 } else { |
| 29 resultString += "PASS "; | 43 resultString += "PASS "; |
| 30 } | 44 } |
| 31 resultString += tests[test]["name"] + | 45 resultString += tests[test]["name"] + |
| 32 (passed ? "" : (": " + tests[test]["message"])) + | 46 (passed ? "" : (": " + tests[test]["message"])) + |
| 33 ". "; | 47 ". "; |
| 34 } | 48 } |
| 35 } | 49 } |
| 36 | 50 |
| 37 add_completion_callback( (tests, harness_status) => { | 51 // Only interact with testharness.js if it was actually included on the page |
| 38 checkResultsForFailures(tests, harness_status); | 52 // before this file |
| 39 console.debug("Test result: " + (testPassed ? "Pass" : "Fail")); | 53 if (typeof add_completion_callback !== "undefined") { |
| 40 console.debug("Test result string: " + resultString); | 54 add_completion_callback( (tests, harness_status) => { |
| 41 finishJavaScriptStep(); | 55 checkResultsForFailures(tests, harness_status); |
| 42 }); | 56 console.debug("Test result: " + (testPassed ? "Pass" : "Fail")); |
| 57 console.debug("Test result string: " + resultString); | |
| 58 finishJavaScriptStep(); | |
| 59 }); | |
| 60 } | |
| OLD | NEW |