forked from icd/rentgen
Changed test from artificial computation ((17*2)+3=37) to real-world functionality testing: counting third-party domains shown in badge. Test flow: 1. Visit news.ycombinator.com → verify badge = 0 (no trackers) 2. Visit pudelek.pl → verify badge > 0 (has trackers) Changes: - background.ts: handler returns badgeCount from getClustersForOrigin() - test-content-script.js: sends origin, stores badgeCount in DOM - test-lib.js: testBadgeCount() replaces testBackgroundComputation() - test_verify.py: tests two real sites instead of math computation This tests actual Rentgen functionality: third-party domain detection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
// Test library for Marionette-based extension verification
|
|
// This JavaScript code runs in the browser context via Marionette
|
|
|
|
/**
|
|
* Inject test content script into the page
|
|
* @returns {Promise<boolean>} - True if injection successful
|
|
*/
|
|
async function injectTestContentScript() {
|
|
// Read the content script file
|
|
const response = await fetch(browser.runtime.getURL('lib/tests/test-content-script.js'));
|
|
const scriptCode = await response.text();
|
|
|
|
// Inject it into the page
|
|
const script = document.createElement('script');
|
|
script.textContent = scriptCode;
|
|
document.documentElement.appendChild(script);
|
|
script.remove();
|
|
|
|
// Wait a bit for script to initialize
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
return document.body.getAttribute('data-rentgen-injected') === 'true';
|
|
}
|
|
|
|
/**
|
|
* Test that background script returns badge count correctly
|
|
* Tests real Rentgen functionality: counting third-party domains
|
|
* @returns {Promise<number|null>} - Badge count (number of third-party domains) or null on failure
|
|
*/
|
|
async function testBadgeCount() {
|
|
// Inject content script first
|
|
const injected = await injectTestContentScript();
|
|
if (!injected) {
|
|
return -1; // Content script not loaded
|
|
}
|
|
|
|
// Dispatch test request to content script
|
|
document.dispatchEvent(new CustomEvent('rentgen_test_request', {
|
|
detail: { timestamp: Date.now() }
|
|
}));
|
|
|
|
// Wait for background response with badge count
|
|
return new Promise((resolve) => {
|
|
let attempts = 0;
|
|
const checkInterval = setInterval(() => {
|
|
attempts++;
|
|
const badgeCount = document.body.getAttribute('data-rentgen-badge-count');
|
|
|
|
if (badgeCount !== null) {
|
|
clearInterval(checkInterval);
|
|
resolve(parseInt(badgeCount));
|
|
} else if (attempts > 50) {
|
|
clearInterval(checkInterval);
|
|
resolve(null);
|
|
}
|
|
}, 100);
|
|
});
|
|
}
|