LCOV - code coverage report
Current view: top level - pkg/playground - preloaded.js Coverage Total Hit
Test: cockpit Lines: 65.5 % 29 19
Test Date: 2026-06-16 14:09:37

            Line data    Source code
       1              : // SPDX-License-Identifier: LGPL-2.1-or-later
       2          120 : import cockpit from "cockpit";
       3              : 
       4              : // This is the basic structure of a preloaded page.  It has a two
       5              : // phase initialization: phase 1 while it is still invisible, and
       6              : // phase 2 when it becomes visible.
       7              : //
       8              : // Elements on the page (including the body) are made visible only
       9              : // once the page itself is visible.  Otherwise layout might go wrong
      10              : // and not recover automatically.
      11              : 
      12          120 : function init_1() {
      13          120 :     return (cockpit.spawn(["hostname"])
      14          120 :             .then(data => {
      15          120 :                 document.getElementById("host").innerText = data.trim();
      16          120 :             }));
      17          120 : }
      18              : 
      19            0 : function init_2() {
      20            0 :     return (cockpit.file("/etc/os-release").read()
      21            0 :             .then(data => {
      22            0 :                 document.getElementById("release").innerText = data;
      23            0 :             }));
      24            0 : }
      25              : 
      26            0 : function navigate() {
      27            0 :     document.getElementById("path").innerText = cockpit.location.path.join("/");
      28            0 :     document.body.removeAttribute("hidden");
      29            0 : }
      30              : 
      31          120 : function maybe_phase_2() {
      32          120 :     cockpit.removeEventListener("visibilitychange", maybe_phase_2);
      33          120 :     if (cockpit.hidden) {
      34          120 :         cockpit.addEventListener("visibilitychange", maybe_phase_2);
      35           19 :     } else {
      36           19 :         init_2().then(navigate);
      37           19 :     }
      38          120 : }
      39              : 
      40          120 : function init() {
      41          120 :     init_1().then(maybe_phase_2);
      42          120 : }
      43              : 
      44          120 : document.addEventListener("DOMContentLoaded", init);
        

Generated by: LCOV version 2.0-1