|
| 1 | +<!DOCTYPE html> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 3 | +<head> |
| 4 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 | + <meta name="viewport" content="width=500"> |
| 6 | + <title>os</title> |
| 7 | + <link rel="stylesheet" type="text/css" href="testindex.css"> |
| 8 | + <script src="testglobals.js"></script> |
| 9 | + <script src="testgeneric.js"></script> |
| 10 | + <!-- custom --> |
| 11 | + <style> |
| 12 | + table {width: 480px;} |
| 13 | + hr {color: var(--test3);} |
| 14 | + #tb3 td {padding-left: 0px;} |
| 15 | + </style> |
| 16 | +</head> |
| 17 | + |
| 18 | +<body> |
| 19 | + |
| 20 | + <table> |
| 21 | + <tr><td><h2>TorZillaPrint</h2></td></tr> |
| 22 | + <tr><td class="blurb"><a class="return" href="../index.html#devices">return to TZP index</a></td></tr> |
| 23 | + </table> |
| 24 | + |
| 25 | + <!-- app lang --> |
| 26 | + <table id="tb3"> |
| 27 | + <thead><tr><th> |
| 28 | + <div class="nav-title">os |
| 29 | + <div class="nav-up"><span class="c perf" id="perf"></span></div> |
| 30 | + </div> |
| 31 | + </th></tr></thead> |
| 32 | + <tr><td class="intro"> |
| 33 | + <span class="no_color">gecko (FF89+) only: testing os detection logic</span> |
| 34 | + </td></tr> |
| 35 | + <tr><td><hr><br></td></tr> |
| 36 | + <tr><td style="text-align: left;"> |
| 37 | + <div>OS |
| 38 | + <p class="c mono spaces no_color" id="os"> </p><br> |
| 39 | + </div> |
| 40 | + <div>DEBUG |
| 41 | + <p class="c mono spaces no_color" id="debug"> </p> |
| 42 | + </div> |
| 43 | + </td></tr> |
| 44 | + </table> |
| 45 | + <br> |
| 46 | + |
| 47 | +<script> |
| 48 | +'use strict'; |
| 49 | +// https://bugzilla.mozilla.org/show_bug.cgi?id=1363508 |
| 50 | + |
| 51 | +s3 = s3.trim() |
| 52 | +s13 = s13.trim() |
| 53 | +sb = sb.trim() |
| 54 | +sg = sg.trim() |
| 55 | + |
| 56 | +let aDebug = [], |
| 57 | + thisOS = undefined, |
| 58 | + t0, |
| 59 | + pad = 25, |
| 60 | + isTimeOut = false, |
| 61 | + isThrowError = false |
| 62 | + |
| 63 | +let notNormal = sb +" not normal"+ sc +" [now you <b><u>really</u></b> stand out]", |
| 64 | + goodResult = sg +"result: "+ sc, |
| 65 | + badResult = sb +"result: "+ sc |
| 66 | + |
| 67 | +let oMessages = { |
| 68 | + 1: goodResult +"you are not gecko", |
| 69 | + 2: goodResult +"update your browser" +"<br><br><div class='indent faint'>this PoC requires FF89+ to be fully effective</div>", |
| 70 | + 3: badResult +"timed out:"+ notNormal, |
| 71 | + 4: badResult, |
| 72 | + 4: goodResult, |
| 73 | +} |
| 74 | + |
| 75 | +const get_old_OS = () => new Promise(resolve => { |
| 76 | + // FF89-123 |
| 77 | + // 1280128: FF51+ win/mac | 1701257: FF89+ linux, therefore undefined = android |
| 78 | + function exit() { |
| 79 | + if (thisOS === undefined) {thisOS = "android"} |
| 80 | + return resolve() |
| 81 | + } |
| 82 | + setTimeout(() => resolve("timed out"), 100) |
| 83 | + |
| 84 | + if (!isTimeOut) { |
| 85 | + // FF121+: 1855861 |
| 86 | + const get_event = (css, item) => new Promise(resolve => { |
| 87 | + css.onload = function() { |
| 88 | + thisOS = item == "win" ? "windows" : item |
| 89 | + count++ |
| 90 | + document.head.removeChild(css) |
| 91 | + aDebug.push(s3 + (item +": ").padStart(pad) + sc + green_tick +" detected") |
| 92 | + if (count == 3) {exit()} |
| 93 | + //exit(true) // comment out: test all three for debugging |
| 94 | + return resolve() |
| 95 | + } |
| 96 | + css.onerror = function() { |
| 97 | + count++ |
| 98 | + document.head.removeChild(css) |
| 99 | + aDebug.push(s3 + (item +": ").padStart(pad) + sc + red_cross +" not detected") |
| 100 | + if (count == 3) {exit()} |
| 101 | + return resolve() |
| 102 | + } |
| 103 | + }) |
| 104 | + |
| 105 | + let count = 0 |
| 106 | + try { |
| 107 | + let path = "chrome://browser/content/extension-", suffix = "-panel.css" |
| 108 | + aDebug.push(s13 + "chrome:// test: ".padStart(pad) + sc +"browser/content/extension-*"+ suffix) |
| 109 | + if (isThrowError) {foo++} |
| 110 | + let list = ["win", "mac","linux"] |
| 111 | + list.forEach(function(item) { |
| 112 | + let css = document.createElement("link") |
| 113 | + css.type = "text/css" |
| 114 | + css.rel = "stylesheet" |
| 115 | + css.href = path + item + suffix |
| 116 | + document.head.appendChild(css) |
| 117 | + get_event(css, item) |
| 118 | + }) |
| 119 | + } catch(e) { |
| 120 | + oMessages[4] = badResult + "error:" + notNormal + "<br><br><div class='indent faint'>"+ e +"</div>" |
| 121 | + aDebug.push(sb + ("error: ").padStart(pad) + sc + e.name) |
| 122 | + return resolve("error") |
| 123 | + } |
| 124 | + } |
| 125 | +}) |
| 126 | + |
| 127 | +const get_desktop = () => new Promise(resolve => { |
| 128 | + function exit() { |
| 129 | + return resolve() |
| 130 | + } |
| 131 | + setTimeout(() => resolve("timed out"), 100) |
| 132 | + |
| 133 | + if (!isTimeOut) { |
| 134 | + // FF124+: 1874232 |
| 135 | + // added: chrome://browser/content/extension-popup-panel.css |
| 136 | + // also: chrome://browser/content/extension.css is apparently desktop only? |
| 137 | + |
| 138 | + const get_event = (css, item) => new Promise(resolve => { |
| 139 | + css.onload = function() { |
| 140 | + count++ |
| 141 | + document.head.removeChild(css) |
| 142 | + aDebug.push(s3 + (item +": ").padStart(pad) + sc + green_tick +" detected") |
| 143 | + if (count == 2) {exit()} |
| 144 | + return resolve() |
| 145 | + } |
| 146 | + css.onerror = function() { |
| 147 | + count++ |
| 148 | + document.head.removeChild(css) |
| 149 | + aDebug.push(s3 + (item +": ").padStart(pad) + sc + red_cross +" not detected") |
| 150 | + if (count == 2) {exit()} |
| 151 | + return resolve() |
| 152 | + } |
| 153 | + }) |
| 154 | + |
| 155 | + let count = 0 |
| 156 | + try { |
| 157 | + if (isThrowError) {foo++} |
| 158 | + let path = "chrome://browser/content/", suffix = ".css" |
| 159 | + aDebug.push(s13 + "chrome:// test: ".padStart(pad) + sc + path +"*.css") |
| 160 | + let list = ['extension-popup-panel','extension'] |
| 161 | + list.forEach(function(item) { |
| 162 | + let css = document.createElement("link") |
| 163 | + css.type = "text/css" |
| 164 | + css.rel = "stylesheet" |
| 165 | + css.href = path + item + suffix |
| 166 | + document.head.appendChild(css) |
| 167 | + get_event(css, item) |
| 168 | + }) |
| 169 | + } catch(e) { |
| 170 | + oMessages[4] = badResult + "error:" + notNormal + "<br><br><div class='indent faint'>"+ e +"</div>" |
| 171 | + aDebug.push(sb + ("error: ").padStart(pad) + sc + e.name) |
| 172 | + return resolve("error") |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | +}) |
| 177 | + |
| 178 | +function run() { |
| 179 | + t0 = performance.now() |
| 180 | + dom.os.innerHTML = "" |
| 181 | + dom.debug.innerHTML = "" |
| 182 | + |
| 183 | + function exit(type) { |
| 184 | + dom.perf = Math.round((performance.now() - t0)) + " ms" |
| 185 | + dom.debug.innerHTML = aDebug.join("<br>") |
| 186 | + if (type < 6) { |
| 187 | + dom.os.innerHTML = oMessages[type] |
| 188 | + } else { |
| 189 | + dom.os.innerHTML = "pending" |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + if (!isFF) { |
| 194 | + exit(1) |
| 195 | + } else if (isVer < 89) { |
| 196 | + exit(2) |
| 197 | + } else if (isVer < 124) { |
| 198 | + Promise.all([ |
| 199 | + get_old_OS() |
| 200 | + ]).then(function(res){ |
| 201 | + let result = res[0] |
| 202 | + if (result == "timed out") { |
| 203 | + aDebug.push(sb + ("timed out: ").padStart(pad) + sc) |
| 204 | + exit(3) |
| 205 | + } else if (result == "error") { |
| 206 | + exit(4) |
| 207 | + } else { |
| 208 | + oMessages[5] = goodResult + thisOS |
| 209 | + exit(5) |
| 210 | + } |
| 211 | + }) |
| 212 | + } else { |
| 213 | + Promise.all([ |
| 214 | + get_desktop() |
| 215 | + ]).then(function(res){ |
| 216 | + let result = res[0] |
| 217 | + if (result == "timed out") { |
| 218 | + aDebug.push(sb + ("timed out: ").padStart(pad) + sc) |
| 219 | + } |
| 220 | + exit() |
| 221 | + |
| 222 | + }) |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +setTimeout(function() { |
| 227 | + // do not call the global get_isOS |
| 228 | + // don't even use isOS |
| 229 | + Promise.all([ |
| 230 | + get_globals() |
| 231 | + ]).then(function(){ |
| 232 | + Promise.all([ |
| 233 | + get_isVer() |
| 234 | + ]).then(function(){ |
| 235 | + aDebug.push(s13 + "gecko test: ".padStart(pad) + sc + isFF) |
| 236 | + if (isFF) { |
| 237 | + let isVerOpen = (isVer == isVerMax +"") |
| 238 | + aDebug.push(s13 + "version test: ".padStart(pad) + sc + isVer + (isVerOpen ? "+" : (isVer == 52 ? " or lower" : ""))) |
| 239 | + } |
| 240 | + run() |
| 241 | + }) |
| 242 | + }) |
| 243 | +}, 25) |
| 244 | + |
| 245 | +</script> |
| 246 | +</body> |
| 247 | +</html> |
0 commit comments