Skip to content

Commit add0736

Browse files
tweak
1 parent 908c439 commit add0736

File tree

1 file changed

+63
-82
lines changed

1 file changed

+63
-82
lines changed

tests/os.html

+63-82
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
t0,
5959
pad = 25,
6060
isTimeOut = false,
61-
isThrowError = false
61+
isThrowError = false,
62+
useNew
6263

6364
let notNormal = sb +" not normal"+ sc +" [now you <b><u>really</u></b> stand out]",
6465
goodResult = sg +"result: "+ sc,
@@ -69,10 +70,12 @@
6970
2: goodResult +"update your browser" +"<br><br><div class='indent faint'>this PoC requires FF89+ to be fully effective</div>",
7071
3: badResult +"timed out:"+ notNormal,
7172
4: badResult,
72-
4: goodResult,
73+
5: goodResult,
74+
6: badResult +"mixed chrome:// test results",
75+
7: "pending",
7376
}
7477

75-
const get_old_OS = () => new Promise(resolve => {
78+
const get_thisOS = () => new Promise(resolve => {
7679
// FF89-123
7780
// 1280128: FF51+ win/mac | 1701257: FF89+ linux, therefore undefined = android
7881
function exit() {
@@ -81,83 +84,51 @@
8184
}
8285
setTimeout(() => resolve("timed out"), 100)
8386

87+
if (useNew) {thisOS = 0} // count instead
8488
if (!isTimeOut) {
8589
// FF121+: 1855861
90+
// FF124+: 1874232
91+
// new: chrome://browser/content/extension-popup-panel.css
92+
// fallback: chrome://browser/content/extension.css
93+
// both these are desktop only
94+
8695
const get_event = (css, item) => new Promise(resolve => {
8796
css.onload = function() {
97+
if (useNew) {
98+
//desktop vs android
99+
thisOS++
100+
} else {
88101
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()
95102
}
96-
css.onerror = function() {
97103
count++
98104
document.head.removeChild(css)
99-
aDebug.push(s3 + (item +": ").padStart(pad) + sc + red_cross +" not detected")
100-
if (count == 3) {exit()}
105+
aDebug.push(s3 + (item +": ").padStart(pad) + sc + green_tick +" detected")
106+
if (count == maxCount) {exit()}
107+
//exit(true) // comment out: test all three for debugging
101108
return resolve()
102109
}
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-
}
146110
css.onerror = function() {
147111
count++
148112
document.head.removeChild(css)
149113
aDebug.push(s3 + (item +": ").padStart(pad) + sc + red_cross +" not detected")
150-
if (count == 2) {exit()}
114+
if (count == maxCount) {exit()}
151115
return resolve()
152116
}
153117
})
154118

155-
let count = 0
119+
let count = 0, maxCount
156120
try {
121+
let path = "chrome://browser/content/extension-", suffix = "-panel.css"
122+
let list = ["win", "mac","linux"]
123+
if (useNew) {
124+
list = ['extension-popup-panel','extension']
125+
path = "chrome://browser/content/", suffix = ".css"
126+
aDebug.push(s13 + "124+ chrome:// test: ".padStart(pad) + sc + path +"*.css")
127+
} else {
128+
aDebug.push(s13 + "89-123 chrome:// test: ".padStart(pad) + sc +"browser/content/extension-*"+ suffix)
129+
}
157130
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']
131+
maxCount = list.length
161132
list.forEach(function(item) {
162133
let css = document.createElement("link")
163134
css.type = "text/css"
@@ -172,31 +143,26 @@
172143
return resolve("error")
173144
}
174145
}
175-
176146
})
177147

178148
function run() {
179149
t0 = performance.now()
180150
dom.os.innerHTML = ""
181151
dom.debug.innerHTML = ""
152+
let notation = ""
182153

183154
function exit(type) {
184155
dom.perf = Math.round((performance.now() - t0)) + " ms"
185156
dom.debug.innerHTML = aDebug.join("<br>")
186-
if (type < 6) {
187-
dom.os.innerHTML = oMessages[type]
188-
} else {
189-
dom.os.innerHTML = "pending"
190-
}
157+
if (type < 8) {dom.os.innerHTML = oMessages[type]} else {dom.os.innerHTML = "pending"}
191158
}
192-
193159
if (!isFF) {
194160
exit(1)
195161
} else if (isVer < 89) {
196162
exit(2)
197-
} else if (isVer < 124) {
163+
} else {
198164
Promise.all([
199-
get_old_OS()
165+
get_thisOS()
200166
]).then(function(res){
201167
let result = res[0]
202168
if (result == "timed out") {
@@ -205,20 +171,34 @@
205171
} else if (result == "error") {
206172
exit(4)
207173
} 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)
174+
if (useNew) {
175+
// logis: must be 0 or 2, not 1, so I can pickup on changes
176+
if (thisOS == 0) {
177+
thisOS = "android"
178+
notation = green_tick +" none detected"
179+
} else if (thisOS == 2) {
180+
thisOS = "desktop"
181+
notation = green_tick +" both detected"
182+
} else {
183+
notation = red_cross +" mixed results"
184+
thisOS = undefined
185+
}
186+
aDebug.push(s13 + "desktop test: ".padStart(pad) + sc + notation)
187+
}
188+
// thisOS s/be (no errors or timeouts)
189+
// old: android, linux, mac, windows
190+
// new: android or desktop or undefined
191+
if (thisOS == undefined) {
192+
exit(6) // something changed upstream: address it
193+
} else if (thisOS !== "desktop") {
194+
oMessages[5] = goodResult + thisOS
195+
exit(5) // bingo!
196+
} else {
197+
oMessages[7] = "pending: "+ thisOS
198+
// desktop needws more digging
199+
exit(7)
200+
}
219201
}
220-
exit()
221-
222202
})
223203
}
224204
}
@@ -234,6 +214,7 @@
234214
]).then(function(){
235215
aDebug.push(s13 + "gecko test: ".padStart(pad) + sc + isFF)
236216
if (isFF) {
217+
useNew = isVer > 123
237218
let isVerOpen = (isVer == isVerMax +"")
238219
aDebug.push(s13 + "version test: ".padStart(pad) + sc + isVer + (isVerOpen ? "+" : (isVer == 52 ? " or lower" : "")))
239220
}

0 commit comments

Comments
 (0)