Initial commit

This commit is contained in:
Aditya Gupta
2026-06-29 19:29:19 +05:30
committed by GitHub
commit aabb8986aa
292 changed files with 17976 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
describe('Webextension Content Runtime Script', () => {
before(function () {
// Chrome doesn't allow content scripts on the extension pages
if ((browser.capabilities as WebdriverIO.Capabilities).browserName === 'chrome') {
this.skip();
}
});
it('should create all runtime elements on the page', async function () {
// Open the popup
const extensionPath = await browser.getExtensionPath();
const popupUrl = `${extensionPath}/popup/index.html`;
// if Popup file not found, skip the test
try {
await browser.url(popupUrl);
} catch {
console.error('Popup file not found');
this.skip();
}
await expect(browser).toHaveTitle('Popup');
// Trigger inject button on popup
const contentScriptsButton = await $('button*=Content Scripts').getElement();
await contentScriptsButton.click();
// Check if id exists on the page
const runtimeExampleElement = await $('#CEB-extension-runtime-example').getElement();
const runtimeAllElement = await $('#CEB-extension-runtime-all').getElement();
await expect(runtimeExampleElement).toBeExisting();
await expect(runtimeAllElement).toBeExisting();
});
});

View File

@@ -0,0 +1,21 @@
describe('Content UI Injection', () => {
it('should locate the injected content UI (all and example) div on example.com`', async () => {
await browser.url('https://example.com');
const contentAllDiv = await $('#CEB-extension-all').getElement();
await expect(contentAllDiv).toBeDisplayed();
const contentExampleDiv = await $('#CEB-extension-example').getElement();
await expect(contentExampleDiv).toBeDisplayed();
});
it('should locate the injected content UI all div and not locate example div on google.com', async () => {
await browser.url('https://www.google.com');
const contentAllDiv = await $('#CEB-extension-all').getElement();
await expect(contentAllDiv).toBeDisplayed();
const contentExampleDiv = await $('#CEB-extension-example').getElement();
await expect(contentExampleDiv).not.toBeDisplayed();
});
});

View File

@@ -0,0 +1,33 @@
describe('Webextension Content Script', () => {
it('should log "example content script loaded" in console on example.com', async () => {
await browser.sessionSubscribe({ events: ['log.entryAdded'] });
const logs: (string | null)[] = [];
browser.on('log.entryAdded', logEntry => {
logs.push(logEntry.text);
});
await browser.url('https://example.com');
const EXPECTED_LOG_MESSAGE = '[CEB] Example content script loaded';
await browser.waitUntil(() => logs.includes(EXPECTED_LOG_MESSAGE));
expect(logs).toContain(EXPECTED_LOG_MESSAGE);
});
it('should log "all content script loaded" in console on any page', async () => {
await browser.sessionSubscribe({ events: ['log.entryAdded'] });
const logs: (string | null)[] = [];
browser.on('log.entryAdded', logEntry => {
logs.push(logEntry.text);
});
await browser.url('https://www.google.com');
const EXPECTED_LOG_MESSAGE = '[CEB] All content script loaded';
await browser.waitUntil(() => logs.includes(EXPECTED_LOG_MESSAGE));
expect(logs).toContain(EXPECTED_LOG_MESSAGE);
});
});

View File

@@ -0,0 +1,12 @@
import { canSwitchTheme } from '../helpers/theme.js';
describe('Webextension DevTools Panel', () => {
it('should make DevTools panel available', async () => {
const extensionPath = await browser.getExtensionPath();
const devtoolsPanelUrl = `${extensionPath}/devtools-panel/index.html`;
await browser.url(devtoolsPanelUrl);
await expect(browser).toHaveTitle('Devtools Panel');
await canSwitchTheme();
});
});

View File

@@ -0,0 +1,15 @@
import { canSwitchTheme } from '../helpers/theme.js';
describe('Webextension New Tab', () => {
it('should open the extension page when a new tab is opened', async () => {
const extensionPath = await browser.getExtensionPath();
const newTabUrl =
process.env.CLI_CEB_FIREFOX === 'true' ? `${extensionPath}/new-tab/index.html` : 'chrome://newtab';
await browser.url(newTabUrl);
const appDiv = await $('.App').getElement();
await expect(appDiv).toBeExisting();
await canSwitchTheme();
});
});

View File

@@ -0,0 +1,13 @@
import { canSwitchTheme } from '../helpers/theme.js';
describe('Webextension Options Page', () => {
it('should make options page accessible', async () => {
const extensionPath = await browser.getExtensionPath();
const optionsUrl = `${extensionPath}/options/index.html`;
await browser.url(optionsUrl);
await expect(browser).toHaveTitle('Options');
await canSwitchTheme();
});
});

View File

@@ -0,0 +1,12 @@
import { canSwitchTheme } from '../helpers/theme.js';
describe('Webextension Popup', () => {
it('should open the popup successfully', async () => {
const extensionPath = await browser.getExtensionPath();
const popupUrl = `${extensionPath}/popup/index.html`;
await browser.url(popupUrl);
await expect(browser).toHaveTitle('Popup');
await canSwitchTheme();
});
});

View File

@@ -0,0 +1,12 @@
import { canSwitchTheme } from '../helpers/theme.js';
describe('Webextension Side Panel', () => {
it('should make side panel accessible', async () => {
const extensionPath = await browser.getExtensionPath();
const sidePanelUrl = `${extensionPath}/side-panel/index.html`;
await browser.url(sidePanelUrl);
await expect(browser).toHaveTitle('Side Panel');
await canSwitchTheme();
});
});

View File

@@ -0,0 +1,7 @@
describe('The example page can be loaded', () => {
it('should be able to go to example page', async () => {
await browser.url('https://www.example.com');
await expect(browser).toHaveTitle('Example Domain');
});
});