Test Suite
Tests all sdk methods to make sure they are operational
Code Snippet
1// ==========================================
2// 1. CONSOLE SDK
3// ==========================================
4console.log("🚀 Starting the Ultimate Mega SDK Integration Test...");
5console.warn("Please do not interact with the page while the test runs.");
6console.error("This is a simulated error log to test console.error.");
7
8// ==========================================
9// 2. SELECTION (Global Context)
10// ==========================================
11console.log("Context Data:", {
12 text: selection.text,
13 url: selection.pageUrl,
14 title: selection.pageTitle
15});
16
17// ==========================================
18// 3. NOTIFY SDK
19// ==========================================
20await notify.show("Starting Ultimate Mega SDK Test...", "info");
21await new Promise(r => setTimeout(r, 500));
22await notify.show("Testing all methods sequentially...", "warning");
23await new Promise(r => setTimeout(r, 500));
24
25// ==========================================
26// 4. SPINNER SDK
27// ==========================================
28await spinner.show("Testing Storage SDK...");
29
30// ==========================================
31// 5. STORAGE SDK
32// ==========================================
33await storage.set("mega_test_key", { count: 1 });
34let storageResult = await storage.get("mega_test_key");
35await storage.update("mega_test_key", (val) => ({ count: val.count + 1 }));
36const updatedStorage = await storage.get("mega_test_key");
37const allKeys = await storage.keys();
38await storage.delete("mega_test_key");
39console.log("Storage Test:", (updatedStorage.count === 2 && allKeys.includes("mega_test_key")) ? "✅" : "❌");
40
41// ==========================================
42// 6. CLIPBOARD SDK
43// ==========================================
44await spinner.update("Testing Clipboard SDK...");
45const originalClipboard = await clipboard.read().catch(() => "");
46await clipboard.write("tee_test_string");
47const clipboardResult = await clipboard.read();
48await clipboard.write(originalClipboard);
49console.log("Clipboard Test:", clipboardResult === "tee_test_string" ? "✅" : "❌");
50
51// ==========================================
52// 7. HTTP SDK
53// ==========================================
54await spinner.update("Testing HTTP SDK...");
55const httpResult = await http.fetch("https://jsonplaceholder.typicode.com/todos/1", { method: "GET" });
56console.log("HTTP Test:", httpResult?.id === 1 ? "✅" : "❌");
57
58// ==========================================
59// 8. AI SDK
60// ==========================================
61await spinner.update("Testing AI SDK (Prompt, Chat, JSON)...");
62const aiPromptRes = await ai.prompt("What is 2+2? Reply with ONLY the number.", "You are a calculator.");
63const aiChatRes = await ai.chat([
64 { role: "system", content: "You are a pirate." },
65 { role: "user", content: "Say the word 'Ahoy' and nothing else." }
66]);
67const aiJsonRes = await ai.json("Extract the name from: John Smith", "Output JSON with a 'name' field");
68console.log("AI Test (Prompt):", aiPromptRes ? "✅" : "❌");
69console.log("AI Test (Chat):", aiChatRes ? "✅" : "❌");
70console.log("AI Test (JSON):", (typeof aiJsonRes === 'string' ? JSON.parse(aiJsonRes).name : aiJsonRes.name) ? "✅" : "❌");
71
72// ==========================================
73// 9. NOTES SDK
74// ==========================================
75await spinner.update("Testing Notes SDK...");
76const newNote = await notes.create({ title: "Mega Test Note", content: "Temporary note." });
77let fetchedNote = await notes.get(newNote.id);
78await notes.update(newNote.id, { content: "Updated note content." });
79const allNotes = await notes.list();
80await notes.delete(newNote.id);
81console.log("Notes Test:", (fetchedNote?.id === newNote.id && allNotes.length > 0) ? "✅" : "❌");
82
83// ==========================================
84// 10. PAGE SDK
85// ==========================================
86await spinner.update("Testing Page SDK...");
87const hasFocus = await page.hasFocus();
88const pageText = await page.getText();
89const pageSelection = await page.getSelection();
90const metadata = await page.getMetadata();
91
92await page.scrollTo(0, 100);
93await new Promise(r => setTimeout(r, 500));
94await page.scrollTo(0, 0);
95
96// CSS Injection Test
97const cssId = await page.injectCSS("body { border: 5px solid red !important; }");
98await new Promise(r => setTimeout(r, 500));
99await page.removeCSS(cssId);
100
101// Text Node Patching & Highlighting
102await page.highlightSelection("rgba(200, 255, 0, 0.3)");
103const textNodes = await page.getVisibleTextNodes({ limit: 1 });
104if (textNodes && textNodes.length > 0) {
105 await page.patchTextNodes([{ id: textNodes[0].id, text: "TEE WAS HERE!" }]);
106}
107
108const screenshot = await page.screenshot();
109// Skip mutate/click/fill/extract as they require specific DOM structures that might not exist on the current page.
110
111console.log("Page SDK Base Tests:", (pageText && screenshot) ? "✅" : "❌");
112
113// ==========================================
114// 11. BROWSER SDK
115// ==========================================
116await spinner.update("Testing Browser SDK...");
117
118// Tabs
119const activeTabs = await browser.tabs.query({ active: true, currentWindow: true });
120const currentTab = await browser.tabs.getCurrent();
121const newTab = await browser.tabs.create({ url: "https://example.com", active: false });
122await browser.tabs.update(newTab.id, { muted: true });
123await browser.tabs.remove(newTab.id);
124
125// Bookmarks & History (May return empty depending on browser state, just testing they don't crash)
126const tree = await browser.bookmarks.getTree();
127const newBookmark = await browser.bookmarks.create({ title: "Tee Test", url: "https://example.com" });
128await browser.bookmarks.remove(newBookmark.id).catch(() => {}); // cleanup if supported
129const history = await browser.history.search({ text: "google", maxResults: 1 });
130
131console.log("Browser SDK Tests:", activeTabs.length > 0 ? "✅" : "❌");
132
133// ==========================================
134// 12. INPUT SDK
135// ==========================================
136await spinner.hide();
137
138const selectedOption = await input.select("Choose a difficulty level:", ["Easy", "Medium", "Hard", "Ultimate Mega"]);
139console.log("Input SDK (Select):", selectedOption);
140
141const userInput = await input.text("Enter your name to generate the final report:", "Developer");
142console.log("Input SDK (Text):", userInput);
143
144const userConfirmed = await input.confirm("Would you like to render the final results widget?");
145console.log("Input SDK (Confirm):", userConfirmed);
146
147if (!userConfirmed) {
148 await notify.show("Test aborted by user.", "error");
149 return;
150}
151
152// ==========================================
153// 13. POPUP SDK (Toasts)
154// ==========================================
155await popup.show("Generating Widget UI...");
156await new Promise(r => setTimeout(r, 1000));
157await popup.html("<b>Applying themes...</b>");
158await new Promise(r => setTimeout(r, 1000));
159await popup.success("Widget Ready!");
160await popup.error("Just kidding, this is a simulated error toast to test popup.error.");
161
162// ==========================================
163// 14. WIDGET SDK
164// ==========================================
165await widget.show([
166 { type: "text", text: "Ultimate Mega Test Results", size: "xl", weight: "bold", color: "accent" },
167 { type: "text", text: `Triggered by: ${userInput} on ${selection.pageTitle}`, size: "sm", color: "muted" },
168 { type: "divider" },
169
170 { type: "input", id: "test-input", placeholder: "Type here to test widget events..." },
171 { type: "text", id: "event-logger", text: "Waiting for input...", size: "sm", color: "warning" },
172
173 { type: "divider" },
174 { type: "button", id: "btn-finish", text: "Acknowledge & Close", variant: "primary" }
175], "center", { theme: "dark" });
176
177// Test widget.on (Live event listeners)
178widget.on("test-input", "change", async (data) => {
179 console.log("Widget Input Changed:", data);
180 const currentValue = await widget.getValue("test-input");
181 await widget.update([
182 { type: "text", text: "Ultimate Mega Test Results", size: "xl", weight: "bold", color: "accent" },
183 { type: "text", text: `Triggered by: ${userInput} on ${selection.pageTitle}`, size: "sm", color: "muted" },
184 { type: "divider" },
185 { type: "input", id: "test-input", placeholder: "Type here to test widget events...", value: currentValue },
186 { type: "text", id: "event-logger", text: `You typed: ${currentValue}`, size: "sm", color: "success" },
187 { type: "divider" },
188 { type: "button", id: "btn-finish", text: "Acknowledge & Close", variant: "primary" }
189 ]);
190});
191
192// Wait for the user to click the finish button
193await widget.waitForEvent("btn-finish", "click");
194
195// Cleanup
196await widget.hide();
197await popup.success("All systems operational!");
198Submitted on 7/12/2026