1
0
forked from icd/rentgen
rentgen/tests/inner-test-content-script.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

49 lines
1.8 KiB
JavaScript

// Test content script - RUNS INSIDE THE BROWSER EXTENSION
// Only loaded during automated testing (ENABLE_TESTS=true)
// This script proves bidirectional communication between content script and background
// Browser API polyfill for Chrome/Chromium compatibility
if (typeof browser === 'undefined') {
var browser = chrome;
}
// Set initial DOM marker to prove content script is injected
(function() {
function setMarker() {
if (document.body) {
document.body.setAttribute('data-rentgen-injected', 'true');
} else {
// Wait for DOM ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
document.body.setAttribute('data-rentgen-injected', 'true');
});
}
}
}
setMarker();
})();
// Listen for test request from test script (test-lib.js)
document.addEventListener('DEBUG_rentgen_test_request', async (event) => {
try {
// Send message to background script to get badge count for this origin
// This tests real Rentgen functionality: counting third-party domains
const response = await browser.runtime.sendMessage({
type: 'RENTGEN_TEST_VERIFICATION',
origin: window.location.origin,
url: window.location.href,
title: document.title,
timestamp: event.detail?.timestamp || Date.now()
});
// Store the badge count in DOM for the test script to read
if (response && response.success) {
document.body.setAttribute('data-rentgen-badge-count', String(response.badgeCount));
}
} catch (error) {
// If there's an error, the test will timeout waiting for badge count
console.error('Test verification error:', error);
}
});