1
0
forked from icd/rentgen
rentgen/tests/test-lib.js
Jacek Wielemborek b1154c4d62 test: add Selenium WebDriver integration tests
- Add Selenium WebDriver for browser extension testing
- Simplify test content script (only essential DOM attributes)
- Rename test-content-script.js → inner-test-content-script.js for clarity
- Add DEBUG_ prefix to test event name (DEBUG_rentgen_test_request)
- Auto-restore manifest.json after tests (git checkout)
- Include tests in run-checks.sh script
- Update Dockerfile to use Selenium instead of Marionette
- Ignore tests directory in web-ext lint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 11:04:16 +00:00

56 lines
1.9 KiB
JavaScript

// Test library for Marionette-based extension verification
// This JavaScript code runs in the browser context via Marionette
/**
* Check if test content script is loaded
* The content script is automatically injected by manifest.json when ENABLE_TESTS=true
* @returns {Promise<boolean>} - True if content script is loaded
*/
async function waitForTestContentScript() {
// Wait for content script to set the marker
let attempts = 0;
while (attempts < 50) {
if (document.body && document.body.getAttribute('data-rentgen-injected') === 'true') {
return true;
}
await new Promise(resolve => setTimeout(resolve, 100));
attempts++;
}
return false;
}
/**
* 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() {
// Wait for content script to be loaded
const loaded = await waitForTestContentScript();
if (!loaded) {
return -1; // Content script not loaded
}
// Dispatch test request to content script
document.dispatchEvent(new CustomEvent('DEBUG_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);
});
}