Skip to content

Commit d620cdc

Browse files
committed
Let popup.html run standalone, for UI testing.
1 parent 7482a1a commit d620cdc

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/common.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ function setColorIsDarkMode(option, isDarkMode) {
219219
const value = isDarkMode ? "lightfg" : "darkfg";
220220
if (options[option] != value) {
221221
options[option] = value;
222-
chrome.storage.local.set({[option]: value});
222+
try {
223+
chrome.storage.local.set({[option]: value});
224+
} catch (e) {
225+
// This happens when testing popup.html standalone.
226+
console.error(e)
227+
}
223228
_watchOptionsFunc?.([option]);
224229
}
225230
}
@@ -261,4 +266,4 @@ function revertNAT64() {
261266
// our local Set is used for deduplication.
262267
_watchOptionsFunc?.([NAT64_KEY]);
263268
}
264-
}
269+
}

src/popup.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,29 @@ const ALL_URLS = "<all_urls>";
2424
const LONG_DOMAIN = 50;
2525

2626
const tabId = window.location.hash.substr(1);
27-
if (!isFinite(Number(tabId))) {
28-
throw "Bad tabId";
29-
}
3027

3128
let table = null;
3229

3330
window.onload = async function() {
3431
table = document.getElementById("addr_table");
3532
table.onmousedown = handleMouseDown;
36-
await beg();
3733
if (IS_MOBILE) {
3834
document.getElementById("mobile_footer").style.display = "flex";
3935
}
40-
connectToExtension();
36+
if (/^[0-9]+$/.test(tabId)) {
37+
await beg();
38+
connectToExtension();
39+
} else if (tabId) {
40+
throw new Error(`Bad tabId: ${tabId}`);
41+
} else {
42+
console.log("No tabId, using test table")
43+
const TEST_TUPLES = [
44+
["ipv6.example.com", "2001:db8::f00", "6", DFLAG_SSL],
45+
["ipv4.example.com", "192.0.2.9", "4", DFLAG_NOSSL],
46+
["cached.example.com", "2001:db8::f00", "6", DFLAG_SSL | DFLAG_NOSSL | AFLAG_CACHE],
47+
];
48+
pushAll(TEST_TUPLES, "646", REGULAR_COLOR, 0);
49+
}
4150
};
4251

4352
// Monitor for dark mode updates.

0 commit comments

Comments
 (0)