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>
70 lines
2.9 KiB
JavaScript
70 lines
2.9 KiB
JavaScript
// Test content script - only for automated testing
|
|
// This script proves bidirectional communication between content script and background
|
|
|
|
// 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 Marionette test script
|
|
document.addEventListener('rentgen_test_request', async (event) => {
|
|
try {
|
|
// Mark that we received the event
|
|
document.body.setAttribute('data-rentgen-event-received', 'true');
|
|
|
|
// Extract test data from event
|
|
const testData = event.detail || {};
|
|
const timestamp = testData.timestamp || Date.now();
|
|
|
|
// 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: timestamp
|
|
});
|
|
|
|
// Store the response from background in DOM
|
|
// This provides the badge count (number of third-party domains)
|
|
if (response && response.success) {
|
|
document.body.setAttribute('data-rentgen-verified', 'true');
|
|
document.body.setAttribute('data-rentgen-badge-count', String(response.badgeCount));
|
|
document.body.setAttribute('data-rentgen-origin', response.origin);
|
|
document.body.setAttribute('data-rentgen-cluster-ids', JSON.stringify(response.clusterIds));
|
|
document.body.setAttribute('data-rentgen-background-timestamp', String(response.backgroundTimestamp));
|
|
|
|
// Also dispatch a custom event with the results
|
|
document.dispatchEvent(new CustomEvent('rentgen_test_complete', {
|
|
detail: {
|
|
success: true,
|
|
badgeCount: response.badgeCount,
|
|
origin: response.origin,
|
|
clusterIds: response.clusterIds,
|
|
backgroundTimestamp: response.backgroundTimestamp
|
|
}
|
|
}));
|
|
} else {
|
|
document.body.setAttribute('data-rentgen-verified', 'false');
|
|
document.body.setAttribute('data-rentgen-error', 'No response from background');
|
|
}
|
|
} catch (error) {
|
|
// Store error in DOM for debugging
|
|
document.body.setAttribute('data-rentgen-verified', 'false');
|
|
document.body.setAttribute('data-rentgen-error', String(error));
|
|
}
|
|
}); |