From 5f15ab1c379fcd254785a398775fe12ceefdbe60 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 29 Dec 2020 02:35:03 -0800 Subject: improve test reliability; try clear scriptsForTab (doesn't work yet) --- extension/background.js | 3 +-- test.c | 43 ------------------------------------------- test/Makefile | 5 +++++ test/test | Bin 0 -> 49784 bytes test/test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 45 deletions(-) delete mode 100755 test.c create mode 100644 test/Makefile create mode 100755 test/test create mode 100755 test/test.c diff --git a/extension/background.js b/extension/background.js index ab15933..4de9b67 100644 --- a/extension/background.js +++ b/extension/background.js @@ -84,14 +84,13 @@ const BrowserState = { scriptsForTab: {} }; chrome.debugger.onEvent.addListener((source, method, params) => { console.log(source, method, params); - if (method === "Page.") { + if (method === "Page.frameStartedLoading") { // we're gonna assume we're always plugged into both Page and Debugger. BrowserState.scriptsForTab[source.tabId] = []; } else if (method === "Debugger.scriptParsed") { BrowserState.scriptsForTab[source.tabId] = BrowserState.scriptsForTab[source.tabId] || []; BrowserState.scriptsForTab[source.tabId].push(params); - // FIXME: clear these out when page changes in tab (how?) } }); })(); diff --git a/test.c b/test.c deleted file mode 100755 index 76b353d..0000000 --- a/test.c +++ /dev/null @@ -1,43 +0,0 @@ -//usr/bin/env cc -o test "$0" && ./test; exit - -// (run this file directly with `./test.c` in most shells; if that -// doesn't work, run it with `sh test.c`) - -#include -#include - -#include -#include -#include - -int file_contents_equal(char* path, char* contents) { - // hehe: https://twitter.com/ianh_/status/1340450349065244675 - setenv("path", path, 1); - setenv("contents", contents, 1); - return system("[ \"$contents\" == \"$(cat \"$path\")\" ]") == 0; -} - -char* expand(char* phrase) { // expand path with wildcard - wordexp_t result; assert(wordexp(phrase, &result, 0) == 0); - return result.we_wordv[0]; -} - -// integration tests -int main() { - assert(system("node extension/background.js --unhandled-rejections=strict") == 0); // run quick local JS tests - - // reload the extension so we know it's the latest code. - system("echo reload > fs/mnt/runtime/reload"); // this may error, but it should still have effect - // FIXME: race here - sleep(4); - - // FIXME: synthesize some kind of web page - assert(system("echo about:blank > fs/mnt/tabs/create") == 0); - // FIXME: race here - assert(file_contents_equal("fs/mnt/tabs/last-focused/url.txt", "about:blank")); - assert(system("echo remove > fs/mnt/tabs/last-focused/control") == 0); - - assert(file_contents_equal(expand("fs/mnt/extensions/TabFS*/enabled"), "true")); - - assert(1); printf("Done!\n"); -} diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..060a265 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,5 @@ +run-test: test + ./test + +test: test.c + cc -o $@ $^ diff --git a/test/test b/test/test new file mode 100755 index 0000000..36de26f Binary files /dev/null and b/test/test differ diff --git a/test/test.c b/test/test.c new file mode 100755 index 0000000..f715b44 --- /dev/null +++ b/test/test.c @@ -0,0 +1,44 @@ +//usr/bin/env cc -o test "$0" && ./test; exit + +// (run this file directly with `./test.c` in most shells; if that +// doesn't work, run it with `sh test.c`) + +#include +#include +#include + +#include +#include +#include + +int file_contents_equal(char* path, char* contents) { + // hehe: https://twitter.com/ianh_/status/1340450349065244675 + setenv("path", path, 1); + setenv("contents", contents, 1); + return system("[ \"$contents\" == \"$(cat \"$path\")\" ]") == 0; +} + +char* expand(char* phrase) { // expand path with wildcard + wordexp_t result; assert(wordexp(phrase, &result, 0) == 0); + return result.we_wordv[0]; +} + +// integration tests +int main() { + assert(system("node ../extension/background.js --unhandled-rejections=strict") == 0); // run quick local JS tests + + // reload the extension so we know it's the latest code. + system("echo reload > ../fs/mnt/runtime/reload 2>/dev/null"); // this may error, but it should still have effect + // spin until the extension reloads. + struct stat st; while (stat("../fs/mnt/tabs", &st) != 0) {} + + assert(file_contents_equal(expand("../fs/mnt/extensions/TabFS*/enabled"), "true")); + + // FIXME: synthesize some kind of web page + assert(system("echo about:blank > ../fs/mnt/tabs/create") == 0); + // FIXME: race here + assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank")); + assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0); + + assert(1); printf("Done!\n"); +} -- cgit v1.2.3