#include "browser/browser_app.hpp" #include "core/arena.hpp" #include "core/json.hpp" #include "core/memory_governor.hpp" #include "docs/doc_viewer.hpp" #include "ext/extension_runtime.hpp" #include "gfx/astra3d.hpp" #include "gfx/font_engine.hpp" #include "gfx/image_decoder.hpp" #include "gfx/rasterizer.hpp" #include "gfx/svg_engine.hpp" #include "ipc/ipc_channel.hpp" #include "ipc/sandbox.hpp" #include "js/astra_js.hpp" #include "media/media_engine.hpp" #include "net/http2_client.hpp" #include "net/http_cache.hpp" #include "net/http_client.hpp" #include "net/websocket_client.hpp" #include "privacy/security_policy.hpp" #include "privacy/shield.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace astra; namespace { int g_tests_passed = 0; int g_tests_failed = 0; void expect(bool cond, const std::string& label) { if (cond) { ++g_tests_passed; std::cout << " [PASS] " << label << "\n"; } else { ++g_tests_failed; std::cerr << " [FAIL] " << label << "\n"; } } int run_full_test_suite() { std::cout << "=== Astra Browser Core v9 — Full Subsystem Verification Suite ===\n\n"; // 1. SlabArena + OS Reclamation { SlabArena arena(64 * 1024); for (int i = 0; i < 4000; ++i) (void)arena.create(i); size_t before = arena.bytes_used(); arena.reset(true); expect(before >= 16000 && arena.bytes_used() == 0 && arena.slab_count() == 0, "SlabArena allocates cleanly and releases OS slabs via munmap/madvise"); } // 2. JSON Parser { JsonValue v; std::string err; bool ok = JsonValue::parse(R"({"name":"Astra","mv":3,"perms":["storage","declarativeNetRequest"],"active":true})", v, &err); expect(ok && v.get_string("name") == "Astra" && v.get_number("mv") == 3 && v.get_bool("active") && v.get("perms")->as_array().size() == 2, "RFC 8259 JSON parser parses Manifest V3 structures"); } // 3. AstraShield Privacy Engine { AstraShield shield; auto d1 = shield.inspect_request("http://example.com/article?id=42&utm_source=ads&fbclid=xyz999", "example.com", true); expect(!d1.blocked && d1.upgraded_to_https && d1.params_stripped == 2 && d1.sanitized_url == "https://example.com/article?id=42", "AstraShield upgrades HTTP->HTTPS and strips utm_source/fbclid params"); auto d2 = shield.inspect_request("https://stats.doubleclick.net/pixel.js", "example.com", false); expect(d2.blocked && d2.category == TrackerCategory::Advertising, "AstraShield suffix-trie blocks subdomain trackers (stats.doubleclick.net)"); shield.store_cookie("site-a.com", "https://cdn.widget.net", "uid=ALPHA; Secure; HttpOnly"); std::string on_a = shield.cookie_header_for("site-a.com", "https://cdn.widget.net", true); std::string on_b = shield.cookie_header_for("site-b.com", "https://cdn.widget.net", true); expect(on_a == "uid=ALPHA" && on_b.empty(), "Total Cookie Protection isolates third-party cookies across top-level sites"); } // 4. Bounded RAM+Disk HttpCache { HttpCache cache("/tmp/astra_test_cache", 2048); cache.store({"https://astra.test/a", "text/css", "\"e1\"", std::string(1000, 'A'), 0, 600}); cache.store({"https://astra.test/b", "text/css", "\"e2\"", std::string(1000, 'B'), 0, 600}); cache.store({"https://astra.test/c", "text/css", "\"e3\"", std::string(1000, 'C'), 0, 600}); CachedResource hit; bool found_c = cache.lookup("https://astra.test/c", hit); expect(found_c && hit.body.size() == 1000 && cache.stats().evictions >= 1 && cache.stats().current_bytes <= 2048, "HttpCache stores to RAM+Disk and enforces bounded LRU byte eviction"); } // 5. Native PNG Encoder + Native PNG Decoder roundtrip (all zero external build deps) { Framebuffer fb(64, 48); fb.fill_rect(0, 0, 64, 48, 0xFF112233u); fb.fill_rect(10, 10, 20, 20, 0xFF38BDF8u); bool saved = fb.save_png("/tmp/astra_roundtrip_test.png"); DecodedImage dec = ImageDecoder::decode_file("/tmp/astra_roundtrip_test.png"); expect(saved && dec.valid && dec.width == 64 && dec.height == 48 && dec.argb[15 * 64 + 15] == 0xFF38BDF8u && dec.argb[0] == 0xFF112233u, "AstraImage native PNG decoder roundtrips exact ARGB32 pixels cleanly"); } // 6. HTML5 + CSS3 + Layout + HitRegions + Binary DisplayList v2 { SlabArena arena; std::string html = "Astra v2" "" "
Open 3D
"; HtmlDocument doc = HtmlDocument::parse(arena, html); CssStylesheet sheet; sheet.parse(doc.collect_stylesheets()); LayoutFrame* root = LayoutEngine::build_layout(arena, doc, sheet, 1024, 600); DisplayList dl = LayoutEngine::build_display_list(root, 1024, 600); auto blob = dl.serialize(); DisplayList rt; bool dec_ok = DisplayList::deserialize(blob, rt); expect(dec_ok && rt.items.size() == dl.items.size() && rt.hit_regions.size() == 2, "HTML5 -> CSS3 -> Layout -> ASD2 Binary DisplayList + HitRegions roundtrip"); } // 7. AstraJS v2: Bytecode VM (functions, loops, arrays, objects, Mark-and-Sweep GC, Microtasks, Timers, DOM Events) { SlabArena arena; HtmlDocument doc = HtmlDocument::parse( arena, "

0

"); AstraJsEngine vm; std::map store; vm.bind_storage([&](const std::string& k) { return store[k]; }, [&](const std::string& k, const std::string& v) { store[k] = v; }); std::string script = "function fib(n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); }\n" "let sum = 0;\n" "let arr = [10, 20, 30];\n" "arr.push(40);\n" "for (let i = 0; i < arr.length; i = i + 1) { sum = sum + arr[i]; }\n" "let f8 = fib(8);\n" "let order = \"\";\n" "setTimeout(function() { order = order + \"T\"; }, 10);\n" "queueMicrotask(function() { order = order + \"M\"; });\n" "let garbage = { a: [1, 2, 3], b: { c: 9 } };\n" "garbage = null;\n" "let clicks = 0;\n" "let btn = document.querySelector(\"#inc\");\n" "btn.addEventListener(\"click\", function() {\n" " clicks = clicks + 1;\n" " document.querySelector(\"#t\").textContent = \"Clicks:\" + clicks + \" Fib8:\" + f8 + \" Sum:\" + sum;\n" "});\n" "console.log(\"fib8=\", f8, \"sum=\", sum);\n"; auto rep = vm.execute(script, doc); size_t freed = vm.gc_collect(); auto click1 = vm.dispatch_event(doc.query_selector("#inc"), "click", doc); auto click2 = vm.dispatch_event(doc.query_selector("#inc"), "click", doc); (void)click1; (void)click2; std::string order = vm.globals().count("order") ? vm.globals().at("order").to_string() : ""; std::string dom_txt = doc.query_selector("#t")->text_content(); expect(rep.ok && rep.bytecode_size > 40 && rep.microtasks_run == 1 && rep.timers_run == 1 && order == "MT" && freed >= 3 && dom_txt == "Clicks:2 Fib8:21 Sum:100", "AstraJS v2 Bytecode VM executes recursion, loops, arrays, GC sweep, Microtask->Timer order, and DOM click events"); } // 8. Astra3D v2 Smooth Shader Engine { Framebuffer fb(320, 200); Camera3D cam; cam.smooth_shading = true; cam.wireframe = false; auto st = Astra3D::render_scene_into(fb.pixels(), 320, 0, 0, 320, 200, "planet", 0.5f, cam); expect(st.vertices > 600 && st.triangles_rasterized > 400, "Astra3D v2 smooth-normal planetary shader engine rasterizes high-detail geometry"); } // 9. Native PDF Viewer { std::string pdf = "%PDF-1.4\n" "1 0 obj << /Title (Astra Spec) /Author (Astra Team) >> endobj\n" "2 0 obj << /Length 44 >> stream\n" "BT /F1 12 Tf 72 720 Td (Astra Native PDF Works!) Tj ET\n" "endstream endobj\n%%EOF\n"; ParsedDocument d = DocViewer::parse_pdf_bytes(pdf); expect(d.ok && d.title == "Astra Spec" && d.page_count == 1 && d.pages[0].find("Astra Native PDF Works!") != std::string::npos, "AstraDocs parses real PDF header, metadata, and BT/ET/Tj text streams natively"); } // 10. AstraMedia v2 Bounded Playback Session (multi-frame MP4 decode) { MediaPlaybackSession sess; std::string mp4 = "astra/examples/astra_demo.mp4"; if (!std::ifstream(mp4)) mp4 = "examples/astra_demo.mp4"; bool opened = sess.open(mp4); bool batched = opened && sess.decode_batch(0, 6); DecodedVideoFrame f0, f1; bool got2 = batched && sess.next_frame(f0) && sess.next_frame(f1); expect(got2 && f0.frame_index == 0 && f1.frame_index == 1 && sess.buffered_bytes() <= MediaPlaybackSession::kMaxBufferBytes, "AstraMedia v2 decodes multi-frame H.264 MP4 sequence within 16 MiB ring buffer cap"); } // 11. Multi-Process IPC + Strict TLS + Subresource Loader + Interactive Click/Scroll { std::error_code ec; std::filesystem::remove_all("/tmp/astra_http_cache", ec); BrowserApp app(2ULL * 1024 * 1024 * 1024); bool started = app.start_workers(); expect(started && app.content_pid() > 0 && app.media_pid() > 0, "Multi-process architecture spawns isolated Content and RDD Media workers over AF_UNIX IPC"); uint32_t tab1 = app.new_tab("astra://home"); auto nav = app.navigate(tab1, "astra://home"); expect(nav.ok && nav.rendered_via_ipc && nav.display_items > 10 && nav.hit_regions >= 2, "Content Process renders page into ASD2 DisplayList + HitRegions over IPC"); // Test live strict-verified HTTPS + HttpCache hit on second fetch auto https1 = app.navigate(tab1, "https://example.com"); auto https2 = app.navigate(tab1, "https://example.com"); expect(https1.ok && https1.tls_verified && !https1.from_cache && https2.ok && https2.from_cache, "AstraNet enforces strict TLS certificate+hostname verification and hits HttpCache on repeat load"); auto mem = app.memory_snapshot(); expect(mem.total_rss_bytes > 0 && mem.total_rss_bytes < 256ULL * 1024 * 1024 && mem.processes.size() >= 3, "MemoryGovernor tracks real Linux /proc RSS across Main + Content + RDD workers"); // 12. AstraFont Native TrueType Vector Typography + UTF-8 + Bounded LRU Cache { auto& fe = FontEngine::instance(); float w_en = fe.measure_text("Astra Browser", 18.0f, true, false); float w_es = fe.measure_text("Navegación rápida — España", 16.0f, false, false); float w_mono = fe.measure_text("0xFF38BDF8", 13.0f, false, true); expect(fe.freetype_active() && w_en > 80.0f && w_es > 120.0f && w_mono > 50.0f && fe.cached_glyph_count() >= 15 && fe.cache_bytes() <= FontEngine::kMaxCacheBytes, "AstraFont loads libfreetype.so.6 via dlopen, renders UTF-8 TrueType glyphs within 4 MiB LRU cap"); } // 13. AstraImage v2 Native Pure-C++20 Baseline DCT JPEG Decoder { std::string jpg = "astra/examples/astra_nebula.jpg"; if (!std::ifstream(jpg)) jpg = "examples/astra_nebula.jpg"; DecodedImage jimg = ImageDecoder::decode_file(jpg); bool non_uniform = false; if (jimg.valid && jimg.argb.size() > 100) { uint32_t first = jimg.argb[0]; for (size_t i = 1; i < jimg.argb.size(); i += 97) { if (jimg.argb[i] != first) { non_uniform = true; break; } } } expect(jimg.valid && jimg.format == "JPEG" && jimg.width >= 300 && jimg.height >= 180 && non_uniform, "AstraImage v2 pure-C++20 Baseline DCT JPEG decoder decodes real YCbCr JPEG images natively"); } // 14. CSS Grid Multi-Column + Multi-Row Layout Engine { SlabArena ga; HtmlDocument gdoc = HtmlDocument::parse( ga, "
" "
1
2
3
" "
4
5
6
" "
"); CssStylesheet gsheet; gsheet.parse(gdoc.collect_stylesheets()); LayoutFrame* groot = LayoutEngine::build_layout(ga, gdoc, gsheet, 960.0f, 600.0f); LayoutFrame* grid = (groot && !groot->children.empty()) ? groot->children[0] : nullptr; bool ok_grid = grid && grid->children.size() == 6 && grid->children[0]->border_box.x < grid->children[1]->border_box.x && grid->children[1]->border_box.x < grid->children[2]->border_box.x && std::abs(grid->children[0]->border_box.y - grid->children[2]->border_box.y) < 1.0f && grid->children[3]->border_box.y > grid->children[0]->border_box.y + 60.0f; expect(ok_grid, "CSS Grid (display: grid + repeat(3, 1fr) + gap) computes multi-column/multi-row geometry accurately"); } // 15. Interactive Focus, Keyboard Typing & AstraJS v3 input/submit Events { const std::string fpath = "/tmp/astra_input_test.html"; { std::ofstream f(fpath); f << "" << "" << "

idle

" << ""; } app.new_tab("file://" + fpath); const Tab* tptr = app.active_tab(); int hit_x = 80, hit_y = Framebuffer::kChromeHeight + 40; if (tptr) { for (const auto& hr : tptr->cached_display_list.hit_regions) { if (hr.kind == HitRegionKind::Input) { hit_x = static_cast(hr.rect.x + 20); hit_y = Framebuffer::kChromeHeight + static_cast(hr.rect.y + 16); } } } auto cr = app.click_at(hit_x, hit_y); bool typed = app.type_text("astra v3"); std::string mid_txt = app.active_tab()->live_doc->query_selector("#out")->text_content(); bool submitted = app.press_enter(); std::string end_txt = app.active_tab()->live_doc->query_selector("#out")->text_content(); expect(cr.handled && cr.action == "focus_input" && typed && submitted && mid_txt == "typing:astra v3" && end_txt == "submitted:ASTRA V3", "Interactive focus, keyboard typing, and Enter dispatch real input/submit events in AstraJS v3"); } // 16. AstraJS v3 Web APIs: fetch() via AstraShield + HttpCache, JSON.parse/stringify, localStorage { const std::string apath = "/tmp/astra_webapi_test.html"; { std::ofstream f(apath); f << "

init

"; } app.new_tab("file://" + apath); std::string res_txt = app.active_tab()->live_doc->query_selector("#res")->text_content(); expect(res_txt.find("AstraV3|fast|true|200|") == 0 && res_txt.find("\"v\":3") != std::string::npos, "AstraJS v3 executes fetch() (with AstraShield blocking + live HTTPS), JSON.parse/stringify, and localStorage"); } // 17. Interactive Browser Chrome v4: Editable Omnibox, History Back/Forward, [+] New Tab, [x] Close Tab { uint32_t t_home = app.new_tab("astra://home"); (void)t_home; size_t tabs_before = app.tabs().size(); auto c_omni = app.click_at(320, 60); // Click Omnibox bool typed_url = app.type_text("astra://3d"); bool nav_enter = app.press_enter(); std::string after_enter = app.active_tab()->url; auto c_back = app.click_at(28, 60); // Click Back [<] std::string after_back = app.active_tab()->url; auto c_fwd = app.click_at(62, 60); // Click Forward [>] std::string after_fwd = app.active_tab()->url; // Click [+] button after visible tabs size_t vis = std::min(app.tabs().size(), 5); int plus_x = 92 + static_cast(vis) * 213 + 12; auto c_new = app.click_at(plus_x, 20); size_t tabs_after_new = app.tabs().size(); bool closed = app.close_tab(app.active_tab_id()); size_t tabs_after_close = app.tabs().size(); expect(c_omni.action == "focus_omnibox" && typed_url && nav_enter && after_enter == "astra://3d" && c_back.action == "back" && after_back == "astra://home" && c_fwd.action == "forward" && after_fwd == "astra://3d" && c_new.action == "new_tab" && tabs_after_new == tabs_before + 1 && closed && tabs_after_close == tabs_before, "Chrome v4 interactive Omnibox, Back/Forward history stack, [+] new tab, and tab closing work end-to-end"); } // 18. CSS Positioning (absolute/fixed), z-index Paint Ordering, box-shadow DropShadow, opacity & ASD3 Roundtrip { SlabArena pa; HtmlDocument pdoc = HtmlDocument::parse( pa, "" "
" "
Overlay
" ""); CssStylesheet psheet; psheet.parse(pdoc.collect_stylesheets()); LayoutFrame* proot = LayoutEngine::build_layout(pa, pdoc, psheet, 1280.0f, 636.0f); DisplayList pdl = LayoutEngine::build_display_list(proot, 1280, 636); auto blob = pdl.serialize(); DisplayList rt; bool rt_ok = DisplayList::deserialize(blob, rt); bool has_shadow = false, has_fixed = false, z_ordered = true; for (size_t i = 0; i < rt.items.size(); ++i) { if (rt.items[i].type == DisplayItemType::DropShadow) has_shadow = true; if (rt.items[i].fixed_viewport && rt.items[i].z_index == 50) has_fixed = true; if (i > 0 && rt.items[i].z_index < rt.items[i - 1].z_index) z_ordered = false; } // Fixed button at top:16, right:20 -> x in [1060, 1260], y in [16, 48] MUST still hit when scroll_y = 500! const HitRegion* fixed_hit = rt.hit_test(1120.0f, 24.0f, 500.0f); expect(rt_ok && has_shadow && has_fixed && z_ordered && fixed_hit && fixed_hit->fixed_viewport && fixed_hit->target == "#pin", "CSS position:absolute/fixed, z-index layering, box-shadow DropShadow, opacity & ASD3 roundtrip work cleanly"); } // 19. AstraNet v3: TLS 1.3 / ALPN Inspection + Bounded 4-Thread Parallel Subresource Fetcher { std::error_code ec; std::filesystem::remove_all("/tmp/astra_netv3_cache", ec); AstraShield sh; HttpCache hc("/tmp/astra_netv3_cache", 4 * 1024 * 1024); HttpClient net(sh, &hc); auto single = net.get("https://example.com", "example.com", true); auto batch = net.fetch_batch({ "https://example.com/", "https://doubleclick.net/track.js", "https://example.com/?b=2" }, "example.com", 4); expect(single.status_code == 200 && single.tls_verified && !single.tls_version.empty() && batch.size() == 3 && batch[0].status_code == 200 && batch[1].blocked_by_privacy && batch[2].status_code == 200, "AstraNet v3 negotiates TLS 1.3 + ALPN and executes bounded 4-thread parallel fetch_batch safely"); } // 20. AstraJS v4: Real Promise Microtask Chaining (.then/.catch/.finally/Promise.all) + Disk-Persisted localStorage { std::error_code ec; std::filesystem::remove_all("/tmp/astra_origin_storage", ec); const std::string ppath = "/tmp/astra_promise_test.html"; { std::ofstream f(ppath); f << "

init

"; } app.new_tab("file://" + ppath); std::string run1 = app.active_tab()->live_doc->query_selector("#pout")->text_content(); app.reload_active_tab(); std::string run2 = app.active_tab()->live_doc->query_selector("#pout")->text_content(); expect(run1 == "S_C:boom_P42_F_T|v1" && run2 == "S_C:boom_P42_F_T|v1_2", "AstraJS v4 executes Promise .then/.catch/.finally microtasks before timers and persists per-origin localStorage to disk"); } // 21. Multi-Extension MV3 Simultaneous Isolation (2 Extensions + Combined DNR + chrome.storage.local) { BrowserApp mapp(512ULL * 1024 * 1024); std::string e1 = "astra/examples/astra-privacy-guard"; if (!std::ifstream(e1 + "/manifest.json")) e1 = "examples/astra-privacy-guard"; std::string e2 = "astra/examples/astra-reader-boost"; if (!std::ifstream(e2 + "/manifest.json")) e2 = "examples/astra-reader-boost"; bool ok1 = mapp.load_extension(e1); bool ok2 = mapp.load_extension(e2); auto dnr1 = mapp.extensions().evaluate_dnr("https://tracker.evil-ads.test/banner", "example.com"); auto dnr2 = mapp.extensions().evaluate_dnr("https://popup-annoyance.test/modal.js", "example.com"); const std::string mhtml = "/tmp/astra_multi_ext.html"; { std::ofstream f(mhtml); f << "
none
"; } mapp.new_tab("file://" + mhtml); std::string slot_txt = mapp.active_tab()->live_doc->query_selector("#ext-boost-slot")->text_content(); expect(ok1 && ok2 && mapp.extensions().extensions().size() == 2 && dnr1.block && dnr2.block && slot_txt == "MV3 ReaderBoost: enabled", "Multi-Extension MV3 runtime loads 2 extensions simultaneously with combined DNR + chrome.storage.local"); } // 22. AstraMedia v3: Native WAV Audio Probe + Bounded PCM Decode (Non-Zero RMS) & Video Scrubber Seek { std::string wav = "astra/examples/astra_chime.wav"; if (!std::ifstream(wav)) wav = "examples/astra_chime.wav"; auto ainfo = MediaEngine::probe_container(wav); DecodedAudioBuffer abuf; bool decoded = MediaEngine::decode_audio_pcm(wav, 1.0, abuf); expect(ainfo.valid && ainfo.has_audio && ainfo.audio_sample_rate == 44100 && decoded && abuf.valid && abuf.pcm_s16.size() > 10000 && abuf.rms_level > 0.04, "AstraMedia v3 probes WAV audio container and decodes bounded PCM s16le waveform with real non-zero RMS"); } // 23. AstraNet v4: Native HTTP/2 (RFC 7540 Framing + RFC 7541 HPACK + Huffman) & Live TLS 1.3 ALPN { Http2Frame hdr_f; hdr_f.type = Http2FrameType::Headers; hdr_f.flags = 0x05; hdr_f.stream_id = 1; hdr_f.payload = {0x88}; // :status 200 (HPACK static index 8) auto packed = Http2Client::pack_frame(hdr_f); Http2Frame unpacked; size_t consumed = 0; bool f_ok = Http2Client::unpack_frame(packed.data(), packed.size(), unpacked, consumed) && unpacked.type == Http2FrameType::Headers && unpacked.stream_id == 1; // Huffman decode test: "www.example.com" = f1 e3 c2 e5 f2 3a 6b a0 ab 90 f4 ff (RFC 7541 C.4.1) const uint8_t huff_in[] = {0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90, 0xf4, 0xff}; std::string huff_out; bool huff_ok = HpackCodec::huffman_decode(huff_in, sizeof(huff_in), huff_out); HpackCodec hdec; std::vector> hlist; bool hpack_ok = hdec.decode_headers(unpacked.payload.data(), unpacked.payload.size(), hlist) && !hlist.empty() && hlist[0].first == ":status" && hlist[0].second == "200"; // Live HTTPS test (negotiates h2 or http/1.1 cleanly) AstraShield h2sh; HttpClient h2net(h2sh, nullptr); auto live_r = h2net.get("https://example.com", "example.com", true); auto live_r2 = h2net.get("https://example.com/", "example.com", true); expect(f_ok && huff_ok && huff_out == "www.example.com" && hpack_ok && live_r.status_code == 200 && live_r.tls_verified && live_r2.status_code == 200 && (h2net.http2_requests() >= 1 || h2net.keepalive_reuses() >= 1), "AstraNet v4 HTTP/2 RFC 7540 framing + RFC 7541 HPACK/Huffman + live TLS 1.3 ALPN/pool work end-to-end"); } // 24. AstraJS v5: async/await, Arrow Functions (=>), and Shared Mutable Lexical Closures { SlabArena ja; HtmlDocument jdoc = HtmlDocument::parse(ja, "
init
"); AstraJsEngine jvm; std::string js = "const makeCounter = (start) => {\n" " let n = start;\n" " return () => { n = n + 1; return n; };\n" "};\n" "const c1 = makeCounter(10);\n" "const c2 = makeCounter(100);\n" "const v1 = c1();\n" "const v2 = c1();\n" "const v3 = c2();\n" "async function compute() {\n" " const a = await Promise.resolve(v1 + v2);\n" " const b = await Promise.resolve(v3);\n" " document.querySelector(\"#out\").textContent = a + \":\" + b + \":\" + c1();\n" "}\n" "compute();\n"; auto rep = jvm.execute(js, jdoc); std::string got = jdoc.query_selector("#out")->text_content(); expect(rep.ok && got == "23:101:13", "AstraJS v5 executes async/await, arrow functions (=>), and independent mutable lexical closures"); } // 25. AstraJS v5 Dynamic DOM: innerHTML fragment parser, classList, setAttribute/removeAttribute { SlabArena da; HtmlDocument ddoc = HtmlDocument::parse(da, "
"); AstraJsEngine dvm; std::string js = "let b = document.querySelector(\"#box\");\n" "b.classList.add(\"active\");\n" "let hasA = b.classList.contains(\"active\");\n" "b.classList.toggle(\"card\");\n" "b.removeAttribute(\"data-x\");\n" "b.setAttribute(\"data-ok\", \"yes\");\n" "b.innerHTML = \"Hello Astra5\";\n" "let inner = b.innerHTML;\n" "let txt = document.querySelector(\"#child\").textContent;\n" "let summary = hasA + \"|\" + b.className + \"|\" + b.getAttribute(\"data-x\") + \"|\" + b.getAttribute(\"data-ok\") + \"|\" + txt;\n"; auto rep = dvm.execute(js, ddoc); std::string sum = dvm.globals().count("summary") ? dvm.globals().at("summary").to_string() : ""; std::string in_h = dvm.globals().count("inner") ? dvm.globals().at("inner").to_string() : ""; expect(rep.ok && sum == "true|active||yes|Hello Astra5" && in_h.find("Astra5") != std::string::npos, "AstraJS v5 dynamic DOM supports innerHTML getter/setter, classList, and removeAttribute cleanly"); } // 26. CSS @media Responsive Queries + WebRender Per-Item overflow:hidden Clipping (ASD4) { SlabArena ma; HtmlDocument mdoc = HtmlDocument::parse( ma, "
"); CssStylesheet msheet; msheet.parse(mdoc.collect_stylesheets()); LayoutFrame* wide_root = LayoutEngine::build_layout(ma, mdoc, msheet, 1280.0f, 600.0f); LayoutFrame* narrow_root = LayoutEngine::build_layout(ma, mdoc, msheet, 600.0f, 600.0f); uint32_t wide_bg = wide_root->children[0]->style.background.to_argb(); uint32_t narrow_bg = narrow_root->children[0]->style.background.to_argb(); DisplayList dl = LayoutEngine::build_display_list(wide_root, 1280, 600); auto blob = dl.serialize(); DisplayList rt; bool rt_ok = DisplayList::deserialize(blob, rt); bool has_clipped_child = false; for (const auto& it : rt.items) { if (it.has_clip && it.rect.h >= 120.0f && it.clip_rect.h <= 62.0f) has_clipped_child = true; } // Verify Framebuffer actually clips pixels outside clip_rect Framebuffer cfb(200, 200); cfb.composite_display_list(rt, 0, 0.0f); // At y=30 (inside 60px clipped box) -> red #ef4444; at y=100 (below 60px) -> clear_color_argb! uint32_t inside_px = cfb.pixels()[30 * 200 + 50]; uint32_t below_px = cfb.pixels()[100 * 200 + 50]; expect(wide_bg == 0xFF111827u && narrow_bg == 0xFF0284C7u && rt_ok && has_clipped_child && inside_px == 0xFFEF4444u && below_px == rt.clear_color_argb, "CSS @media queries adapt to viewport width and WebRender ASD4 overflow:hidden clips pixels strictly"); } // 27. Native Download Manager + FIPS 180-4 SHA-256 + astra://downloads Ledger { std::error_code ec; std::filesystem::remove_all("/tmp/astra_downloads_test", ec); std::string sha_abc = BrowserApp::compute_sha256_hex("abc"); std::string data_file = "astra/examples/astra_data.json"; if (!std::ifstream(data_file)) data_file = "examples/astra_data.json"; auto rec = app.download_url("file://" + data_file, "/tmp/astra_downloads_test"); uint32_t dtab = app.new_tab("astra://downloads"); const Tab* dt = app.active_tab(); bool has_sha_in_page = dt && dt->raw_html.find(rec.sha256_hex) != std::string::npos; expect(sha_abc == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" && rec.ok && rec.bytes > 20 && std::filesystem::exists(rec.saved_path) && dtab > 0 && has_sha_in_page, "Native Download Manager saves files with exact FIPS 180-4 SHA-256 checksum and renders astra://downloads"); } // 28. AstraMedia v4: PCM Waveform Peak Analyzer + Dynamic Linux ALSA Audio Probe { std::string wav = "astra/examples/astra_chime.wav"; if (!std::ifstream(wav)) wav = "examples/astra_chime.wav"; DecodedAudioBuffer abuf; bool dec = MediaEngine::decode_audio_pcm(wav, 1.0, abuf); auto peaks = MediaEngine::compute_waveform_peaks(abuf, 40); float max_peak = 0.0f; for (float p : peaks) max_peak = std::max(max_peak, p); auto alsa_rep = MediaEngine::play_audio_alsa(abuf); bool safe_status = (alsa_rep.status == "played" || alsa_rep.status == "headless_no_soundcard" || alsa_rep.status == "alsa_not_installed"); expect(dec && peaks.size() == 40 && max_peak > 0.25f && safe_status, "AstraMedia v4 computes 40-bar PCM waveform peaks and probes Linux ALSA output via dlopen safely"); } // 29. AstraNet v5: True HTTP/2 Multi-Stream Multiplexing over a Single TLS 1.3 Socket { std::error_code ec; std::filesystem::remove_all("/tmp/astra_h2mux_test_cache", ec); AstraShield msh; HttpCache mhc("/tmp/astra_h2mux_test_cache", 4 * 1024 * 1024); HttpClient mnet(msh, &mhc); auto batch = mnet.fetch_batch({ "https://example.com/", "https://example.com/?mux=2", "https://example.com/?mux=3" }, "example.com", 4); expect(batch.size() == 3 && batch[0].status_code == 200 && batch[1].status_code == 200 && batch[2].status_code == 200 && batch[0].multiplexed_h2 && batch[1].multiplexed_h2 && batch[2].multiplexed_h2 && mnet.http2_multiplexed_streams() >= 3, "AstraNet v5 multiplexes 3 concurrent HTTP/2 streams over a single TLS 1.3 ALPN h2 connection"); } // 30. AstraJS v6: try/catch/throw Multi-Frame Stack Unwinding + ES6 for..of (Array & String) { SlabArena ea; HtmlDocument edoc = HtmlDocument::parse(ea, "
"); AstraJsEngine evm; std::string js = "function deepThrow(x) { throw \"err:\" + x; }\n" "function mid(x) { return deepThrow(x); }\n" "let caught = \"none\";\n" "let afterTry = false;\n" "try { mid(42); } catch (e) { caught = e; } finally { afterTry = true; }\n" "let sum = 0;\n" "for (let n of [3, 5, 7, 10]) { sum = sum + n; }\n" "let chars = \"\";\n" "for (let ch of \"ASTRA\") { chars = chars + ch + \"-\"; }\n"; auto rep = evm.execute(js, edoc); std::string caught = evm.globals().count("caught") ? evm.globals().at("caught").to_string() : ""; double sum = evm.globals().count("sum") ? evm.globals().at("sum").to_number() : 0.0; std::string chars = evm.globals().count("chars") ? evm.globals().at("chars").to_string() : ""; bool fin = evm.globals().count("afterTry") && evm.globals().at("afterTry").truthy(); expect(rep.ok && caught == "err:42" && fin && sum == 25.0 && chars == "A-S-T-R-A-", "AstraJS v6 unwinds try/catch/finally/throw across call frames and iterates Arrays & Strings via for..of"); } // 31. AstraJS v6: Native HTML5 2D API + requestAnimationFrame Queue { SlabArena ca; HtmlDocument cdoc = HtmlDocument::parse( ca, "

0

"); AstraJsEngine cvm; std::string js = "let cv = document.querySelector(\"#c1\");\n" "let ctx = cv.getContext(\"2d\");\n" "ctx.fillStyle = \"#0f172a\"; ctx.fillRect(0, 0, 120, 80);\n" "ctx.fillStyle = \"#ef4444\"; ctx.fillRect(10, 10, 30, 30);\n" "ctx.fillStyle = \"#3b82f6\"; ctx.beginPath(); ctx.arc(75, 35, 14, 0, Math.PI * 2); ctx.fill();\n" "ctx.strokeStyle = \"#38bdf8\"; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(5, 70); ctx.lineTo(115, 70); ctx.stroke();\n" "ctx.font = \"bold 12px monospace\"; ctx.fillStyle = \"#ffffff\"; ctx.fillText(\"OK\", 8, 62);\n" "let frame = 0;\n" "function tick(ts) {\n" " frame = frame + 1;\n" " ctx.fillStyle = \"#22c55e\";\n" " ctx.fillRect(10 + frame * 15, 50, 10, 10);\n" " document.querySelector(\"#st\").textContent = \"frame:\" + frame;\n" " requestAnimationFrame(tick);\n" "}\n" "requestAnimationFrame(tick);\n"; auto rep0 = cvm.execute(js, cdoc); bool queued = (cvm.pending_raf_count() == 1); auto rep1 = cvm.run_animation_frame(16.67, cdoc); auto rep2 = cvm.run_animation_frame(33.34, cdoc); const CanvasSurface* surf = cvm.find_canvas("c1"); uint32_t red_px = (surf && surf->argb.size() == 120u * 80u) ? surf->argb[20 * 120 + 20] : 0; uint32_t blue_px = (surf && surf->argb.size() == 120u * 80u) ? surf->argb[35 * 120 + 75] : 0; uint32_t green_px = (surf && surf->argb.size() == 120u * 80u) ? surf->argb[55 * 120 + 45] : 0; std::string st_txt = cdoc.query_selector("#st")->text_content(); expect(rep0.ok && queued && rep1.raf_run == 1 && rep2.raf_run == 1 && surf && surf->width == 120 && surf->height == 80 && red_px == 0xFFEF4444u && blue_px == 0xFF3B82F6u && green_px == 0xFF22C55Eu && st_txt == "frame:2", "AstraJS v6 renders native HTML5 2D shapes/text and steps requestAnimationFrame callbacks cleanly"); } // 32. CSS Box Sizing Level 3: box-sizing: border-box vs content-box Geometry { SlabArena ba; HtmlDocument bdoc = HtmlDocument::parse( ba, "
"); CssStylesheet bsheet; bsheet.parse(bdoc.collect_stylesheets()); LayoutFrame* broot = LayoutEngine::build_layout(ba, bdoc, bsheet, 800.0f, 600.0f); bool ok_bs = broot && broot->children.size() == 2 && std::abs(broot->children[0]->border_box.w - 240.0f) < 0.5f && std::abs(broot->children[0]->border_box.h - 100.0f) < 0.5f && std::abs(broot->children[0]->content_box.w - 192.0f) < 0.5f && std::abs(broot->children[0]->content_box.h - 52.0f) < 0.5f && std::abs(broot->children[1]->border_box.w - 288.0f) < 0.5f && std::abs(broot->children[1]->border_box.h - 148.0f) < 0.5f && std::abs(broot->children[1]->content_box.w - 240.0f) < 0.5f && std::abs(broot->children[1]->content_box.h - 100.0f) < 0.5f; expect(ok_bs, "CSS box-sizing: border-box vs content-box computes exact border_box and content_box dimensions"); } // 33. CSS linear-gradient(...) + ASD5 DisplayList Roundtrip + Per-Pixel Gradient Interpolation { SlabArena ga; HtmlDocument gdoc = HtmlDocument::parse( ga, "
"); CssStylesheet gsheet; gsheet.parse(gdoc.collect_stylesheets()); LayoutFrame* groot = LayoutEngine::build_layout(ga, gdoc, gsheet, 400.0f, 200.0f); DisplayList gdl = LayoutEngine::build_display_list(groot, 400, 200); auto blob = gdl.serialize(); size_t moff = 0; uint32_t magic = 0; bool is_asd5 = read_u32(blob, moff, magic) && magic == 0x41534435u; DisplayList rt; bool rt_ok = DisplayList::deserialize(blob, rt); bool has_grad = false; for (const auto& it : rt.items) { if (it.type == DisplayItemType::FillGradient && it.color_argb == 0xFFEF4444u && it.color2_argb == 0xFF3B82F6u && std::abs(it.angle_deg - 90.0f) < 0.5f) { has_grad = true; } } Framebuffer gfb(220, 80); gfb.composite_display_list(rt, 0, 0.0f); uint32_t left_px = gfb.pixels()[30 * 220 + 5]; uint32_t mid_px = gfb.pixels()[30 * 220 + 100]; uint32_t right_px = gfb.pixels()[30 * 220 + 195]; auto r_ch = [](uint32_t c) { return (c >> 16) & 0xFFu; }; auto b_ch = [](uint32_t c) { return c & 0xFFu; }; bool grad_interp = (r_ch(left_px) > 220 && b_ch(left_px) < 85 && r_ch(mid_px) > 120 && b_ch(mid_px) > 120 && b_ch(right_px) > 220 && r_ch(right_px) < 85); expect(is_asd5 && rt_ok && has_grad && grad_interp, "CSS linear-gradient(90deg) roundtrips in ASD5 DisplayList and rasterizes smooth per-pixel RGB interpolation"); } // 34. AstraNet v6: RFC 6455 WebSocket SHA-1/Base64 Handshake + Real Loopback Echo Server + JS new WebSocket() { // Canonical RFC 6455 Section 1.3 vector std::string canonical_accept = WebSocketClient::compute_accept_key("dGhlIHNhbXBsZSBub25jZQ=="); bool rfc_vector_ok = (canonical_accept == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="); int listen_fd = ::socket(AF_INET, SOCK_STREAM, 0); int opt = 1; if (listen_fd >= 0) setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = 0; // ephemeral port bool bound = (listen_fd >= 0 && ::bind(listen_fd, reinterpret_cast(&addr), sizeof(addr)) == 0 && ::listen(listen_fd, 4) == 0); socklen_t alen = sizeof(addr); uint16_t port = 0; if (bound && ::getsockname(listen_fd, reinterpret_cast(&addr), &alen) == 0) { port = ntohs(addr.sin_port); } bool srv_saw_masked_frame = false; std::thread srv_thread([&]() { if (!bound) return; int cfd = ::accept(listen_fd, nullptr, nullptr); if (cfd < 0) return; std::string req; char buf[1024]; while (req.find("\r\n\r\n") == std::string::npos && req.size() < 4096) { ssize_t n = ::recv(cfd, buf, sizeof(buf), 0); if (n <= 0) break; req.append(buf, static_cast(n)); } std::string ws_key; size_t kp = req.find("Sec-WebSocket-Key:"); if (kp != std::string::npos) { size_t vs = kp + 18; while (vs < req.size() && req[vs] == ' ') ++vs; size_t ve = req.find("\r\n", vs); if (ve != std::string::npos) ws_key = req.substr(vs, ve - vs); } std::string accept_val = WebSocketClient::compute_accept_key(ws_key); std::string resp = "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Accept: " + accept_val + "\r\n\r\n"; (void)::send(cfd, resp.data(), resp.size(), MSG_NOSIGNAL); // Serve up to 3 masked client frames (Text -> Echo Text, Ping -> Pong, Close -> exit) for (int iter = 0; iter < 4; ++iter) { uint8_t fh[2]; if (::recv(cfd, fh, 2, MSG_WAITALL) != 2) break; uint8_t op = fh[0] & 0x0Fu; bool masked = (fh[1] & 0x80u) != 0; size_t plen = fh[1] & 0x7Fu; if (plen >= 126) break; uint8_t mask[4] = {0, 0, 0, 0}; if (masked && ::recv(cfd, mask, 4, MSG_WAITALL) != 4) break; std::string pl(plen, '\0'); if (plen > 0 && ::recv(cfd, pl.data(), plen, MSG_WAITALL) != static_cast(plen)) break; if (masked) { srv_saw_masked_frame = true; for (size_t i = 0; i < plen; ++i) pl[i] = static_cast(static_cast(pl[i]) ^ mask[i & 3u]); } if (op == 0x8) break; // Close std::vector out; if (op == 0x1) { // Text -> echo prefixed std::string reply = "echo:" + pl; out.push_back(0x81u); out.push_back(static_cast(reply.size())); out.insert(out.end(), reply.begin(), reply.end()); } else if (op == 0x9) { // Ping -> Pong out.push_back(0x8Au); out.push_back(static_cast(pl.size())); out.insert(out.end(), pl.begin(), pl.end()); } if (!out.empty()) (void)::send(cfd, out.data(), out.size(), MSG_NOSIGNAL); } ::close(cfd); }); SlabArena wsa; HtmlDocument wsdoc = HtmlDocument::parse(wsa, "

init

"); AstraJsEngine wsvm; std::string ws_script = "let sock = new WebSocket(\"ws://127.0.0.1:" + std::to_string(port) + "/stream\");\n" "let stateOpen = sock.readyState;\n" "let cbMsg = \"\";\n" "let closedFlag = false;\n" "sock.onmessage = (ev) => { cbMsg = ev.data; };\n" "sock.onclose = () => { closedFlag = true; };\n" "let sent = sock.send(\"AstraV7\");\n" "let r1 = sock.recv(2000);\n" "sock.ping(\"hb\");\n" "let pong = sock.recv(2000);\n" "sock.close();\n" "let stateClosed = sock.readyState;\n" "document.querySelector(\"#wsout\").textContent = stateOpen + \"|\" + sent + \"|\" + r1 + \"|\" + cbMsg + \"|\" + pong + \"|\" + closedFlag + \"|\" + stateClosed;\n"; auto wsrep = wsvm.execute(ws_script, wsdoc); if (srv_thread.joinable()) srv_thread.join(); if (listen_fd >= 0) ::close(listen_fd); std::string wsout = wsdoc.query_selector("#wsout")->text_content(); expect(rfc_vector_ok && bound && wsrep.ok && srv_saw_masked_frame && wsout == "1|true|echo:AstraV7|echo:AstraV7|hb|true|3", "AstraNet v6 RFC 6455 WebSocket handshake, masked framing, ping/pong & JS new WebSocket() work end-to-end"); } // 35. CSS3 Custom Properties (--*/var()), :root Inheritance, Fallback & Direct-Child Combinator (>) { SlabArena va; HtmlDocument vdoc = HtmlDocument::parse( va, "" "
Direct
" "
Nested
" "
Scoped
" ""); CssStylesheet vsheet; vsheet.parse(vdoc.collect_stylesheets()); LayoutFrame* vroot = LayoutEngine::build_layout(va, vdoc, vsheet, 800.0f, 400.0f); const LayoutFrame* f_direct = nullptr; const LayoutFrame* f_nested = nullptr; const LayoutFrame* f_scoped = nullptr; std::function find_frames = [&](const LayoutFrame* f) { if (!f) return; if (f->node) { std::string id = f->node->get_attr("id"); if (id == "direct") f_direct = f; else if (id == "nested") f_nested = f; else if (id == "scoped") f_scoped = f; } for (const LayoutFrame* c : f->children) find_frames(c); }; find_frames(vroot); bool ok_vars = f_direct && f_nested && f_scoped && f_direct->style.color.to_argb() == 0xFF38BDF8u && f_direct->style.background.to_argb() == 0xFF1E293Bu && std::abs(f_direct->style.padding.left - 18.0f) < 0.5f && f_nested->style.color.to_argb() != 0xFF38BDF8u && f_scoped->style.color.to_argb() == 0xFF10B981u; expect(ok_vars, "CSS3 :root variables (--*/var() with fallback), scoped cascade, and direct-child combinator (>) resolve accurately"); } // 36. CSS3 Flexbox justify-content (space-between/center), align-items:center, text-align & min/max-width { SlabArena fa; HtmlDocument fdoc = HtmlDocument::parse( fa, "" "
A
B
" "
Centered
" ""); CssStylesheet fsheet; fsheet.parse(fdoc.collect_stylesheets()); LayoutFrame* froot = LayoutEngine::build_layout(fa, fdoc, fsheet, 800.0f, 400.0f); bool ok_flex = froot && froot->children.size() == 2 && froot->children[0]->children.size() == 2 && std::abs(froot->children[0]->children[0]->border_box.x - 0.0f) < 1.0f && std::abs(froot->children[0]->children[1]->border_box.x - 500.0f) < 1.0f && std::abs(froot->children[0]->children[0]->border_box.y - 30.0f) < 1.5f && std::abs(froot->children[1]->border_box.w - 260.0f) < 1.0f && froot->children[1]->style.text_align == TextAlign::Center; expect(ok_flex, "CSS3 Flexbox justify-content:space-between, align-items:center, text-align & min/max-width compute exact geometry"); } // 37. AstraJS v7: ES6 class / constructor / this / new Instantiation & Template Literals (`...${expr}...`) { SlabArena cla; HtmlDocument cldoc = HtmlDocument::parse(cla, "

init

"); AstraJsEngine clvm; std::string js = "class EngineNode {\n" " constructor(name, threads) {\n" " this.name = name;\n" " this.threads = threads;\n" " }\n" " summary(ver) {\n" " return `${this.name}:v${ver}(${this.threads * 2}q)`;\n" " }\n" "}\n" "const n1 = new EngineNode(\"AstraNet\", 4);\n" "const n2 = new EngineNode(\"AstraJS\", 2);\n" "const tag = `${n1.summary(7)} | ${n2.summary(7)}`;\n" "document.querySelector(\"#cl\").textContent = tag;\n"; auto rep = clvm.execute(js, cldoc); std::string got = cldoc.query_selector("#cl")->text_content(); expect(rep.ok && got == "AstraNet:v7(8q) | AstraJS:v7(4q)", "AstraJS v7 compiles and executes ES6 class/constructor/this/new and template literal interpolation cleanly"); } // 38. AstraJS v7: Dynamic element.style.* Inline CSS Proxy -> Layout Engine Reflection { SlabArena sa; HtmlDocument sdoc = HtmlDocument::parse( sa, "
Dynamic
"); AstraJsEngine svm; std::string js = "const el = document.querySelector(\"#dyn\");\n" "el.style.backgroundColor = \"#0ea5e9\";\n" "el.style.borderRadius = \"14px\";\n" "el.style.width = \"320px\";\n" "el.style.color = \"#ffffff\";\n" "const readBack = el.style.backgroundColor + \"|\" + el.style.width;\n"; auto rep = svm.execute(js, sdoc); std::string rb = svm.globals().count("readBack") ? svm.globals().at("readBack").to_string() : ""; CssStylesheet ssheet; LayoutFrame* sroot = LayoutEngine::build_layout(sa, sdoc, ssheet, 800.0f, 300.0f); bool ok_style = rep.ok && rb == "#0ea5e9|320px" && sroot && !sroot->children.empty() && sroot->children[0]->style.background.to_argb() == 0xFF0EA5E9u && sroot->children[0]->style.color.to_argb() == 0xFFFFFFFFu && std::abs(sroot->children[0]->style.border_radius - 14.0f) < 0.5f && std::abs(sroot->children[0]->border_box.w - 320.0f) < 1.0f; expect(ok_style, "AstraJS v7 element.style.* camelCase proxy mutates inline CSS and reflects directly in LayoutEngine"); } // 39. AstraSVG v1: Native Inline Vector Parser, 2x2 AA Rasterizer & DisplayList ASD5 Pipeline { const std::string svg_xml = "" "" "" "" ""; SvgSurface surf = SvgEngine::render_svg(svg_xml, 120, 120); uint32_t center_px = surf.valid ? surf.argb[60 * 120 + 60] : 0; uint32_t bg_px = surf.valid ? surf.argb[20 * 120 + 20] : 0; uint32_t corner_px = surf.valid ? surf.argb[0] : 0xFFFFFFFFu; bool direct_ok = surf.valid && surf.width == 120 && surf.height == 120 && center_px == 0xFF10B981u && bg_px == 0xFF0F172Au && (corner_px >> 24) == 0; SlabArena svga; HtmlDocument svgdoc = HtmlDocument::parse( svga, "" + svg_xml + ""); CssStylesheet svgsheet; LayoutFrame* svgroot = LayoutEngine::build_layout(svga, svgdoc, svgsheet, 320.0f, 200.0f); DisplayList dl = LayoutEngine::build_display_list(svgroot, 320, 200); auto blob = dl.serialize(); DisplayList dl2; bool deser_ok = DisplayList::deserialize(blob, dl2); bool has_svg_item = false; for (const auto& it : dl2.items) { if (it.type == DisplayItemType::EmbedSvg && it.text.find(", , and Bezier through DisplayList ASD5 into Framebuffer"); } // 40. AstraJS v8: ES6 Destructuring, Default Params, Array Spread, Object Shorthand & Functional Stdlib { SlabArena j8a; HtmlDocument j8doc = HtmlDocument::parse(j8a, "

init

"); AstraJsEngine j8vm; std::string js = "const cfg = { engine: \"Astra\", ver: 8, threads: 4 };\n" "const { engine, ver: version } = cfg;\n" "const nums = [1, 2, 3, 4, 5];\n" "const [first, second] = nums;\n" "const spread = [0, ...nums, 6];\n" "function scale(x, factor = 10) { return x * factor; }\n" "const evens = spread.filter((n) => n % 2 === 0 && n > 0);\n" "const sum = evens.reduce((acc, n) => acc + n, 0);\n" "const found = spread.find((n) => n > 4);\n" "const sliced = spread.slice(1, 4).join(\"-\");\n" "const rev = [\"a\", \"b\", \"c\"].reverse().join(\"\");\n" "const shortObj = { engine, version };\n" "const merged = Object.assign({}, shortObj, { ok: true });\n" "const keysCount = Object.keys(merged).length;\n" "const label = \"astra-core\".replace(\"core\", \"v8\");\n" "const strChecks = label.startsWith(\"astra\") && label.endsWith(\"v8\") && (\"x\".repeat(3) === \"xxx\");\n" "document.querySelector(\"#j8\").textContent = `${engine}:${version}|${first}+${second}|sum=${sum}|find=${found}|sl=${sliced}|rev=${rev}|sc=${scale(3)}|k=${keysCount}|${label}|${strChecks}`;\n"; auto rep = j8vm.execute(js, j8doc); std::string got = j8doc.query_selector("#j8")->text_content(); expect(rep.ok && got == "Astra:8|1+2|sum=12|find=5|sl=1-2-3|rev=cba|sc=30|k=3|astra-v8|true", "AstraJS v8 executes ES6 destructuring, default params, array spread, shorthand objects, Object.* & Array/String stdlib"); } // 41. AstraNet v7 + JS fetch(): General REST Methods (POST/PUT/DELETE) & Custom Request Headers { int listen_fd = ::socket(AF_INET, SOCK_STREAM, 0); int opt = 1; if (listen_fd >= 0) ::setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = 0; bool bound = (listen_fd >= 0 && ::bind(listen_fd, reinterpret_cast(&addr), sizeof(addr)) == 0 && ::listen(listen_fd, 8) == 0); socklen_t alen = sizeof(addr); uint16_t port = 0; if (bound && ::getsockname(listen_fd, reinterpret_cast(&addr), &alen) == 0) { port = ntohs(addr.sin_port); } std::thread srv([&]() { if (!bound) return; // Handle 3 HTTP requests: JS fetch POST, HttpClient PUT, HttpClient DELETE for (int i = 0; i < 3; ++i) { int cfd = ::accept(listen_fd, nullptr, nullptr); if (cfd < 0) break; std::string raw; char buf[2048]; size_t header_end = std::string::npos; size_t content_len = 0; while (raw.size() < 16384) { ssize_t n = ::recv(cfd, buf, sizeof(buf), 0); if (n <= 0) break; raw.append(buf, static_cast(n)); if (header_end == std::string::npos) { header_end = raw.find("\r\n\r\n"); if (header_end != std::string::npos) { std::string low = raw.substr(0, header_end); for (char& c : low) c = static_cast(std::tolower(static_cast(c))); size_t clp = low.find("content-length:"); if (clp != std::string::npos) { content_len = static_cast(std::strtoull(low.c_str() + clp + 15, nullptr, 10)); } } } if (header_end != std::string::npos && raw.size() >= header_end + 4 + content_len) break; } std::string method = raw.substr(0, raw.find(' ')); std::string body = (header_end != std::string::npos) ? raw.substr(header_end + 4) : ""; std::string sess_hdr; size_t hp = raw.find("X-Astra-Session:"); if (hp != std::string::npos) { size_t vs = hp + 16; while (vs < raw.size() && raw[vs] == ' ') ++vs; size_t ve = raw.find("\r\n", vs); if (ve != std::string::npos) sess_hdr = raw.substr(vs, ve - vs); } std::string json = "{\"method\":\"" + method + "\",\"session\":\"" + sess_hdr + "\",\"body\":\"" + body + "\"}"; std::string resp = "HTTP/1.1 200 OK\r\n" "Content-Type: application/json\r\n" "Connection: close\r\n" "Content-Length: " + std::to_string(json.size()) + "\r\n\r\n" + json; (void)::send(cfd, resp.data(), resp.size(), MSG_NOSIGNAL); ::close(cfd); } }); std::string endpoint = "http://127.0.0.1:" + std::to_string(port) + "/api/items"; std::string page_path = "/tmp/astra_v8_rest_test.html"; { std::ofstream pf(page_path); pf << "

init

"; } uint32_t rest_tid = app.new_tab("file://" + page_path); (void)rest_tid; std::string rest_out; for (const auto& t : app.tabs()) { if (t.id == rest_tid && t.live_doc) { const DomNode* p = t.live_doc->query_selector("#rest"); if (p) rest_out = p->text_content(); } } AstraShield rest_shield; HttpClient raw_http(rest_shield); auto put_resp = raw_http.request("PUT", endpoint, "upd=1", {{"X-Astra-Session", "v8-put"}}, "text/plain"); auto del_resp = raw_http.request("DELETE", endpoint, "", {{"X-Astra-Session", "v8-del"}}, "text/plain"); if (srv.joinable()) srv.join(); if (listen_fd >= 0) ::close(listen_fd); bool ok_rest = bound && rest_out == "200|POST|v8-alpha|hello-v8" && put_resp.status_code == 200 && put_resp.body.find("\"method\":\"PUT\"") != std::string::npos && put_resp.body.find("\"session\":\"v8-put\"") != std::string::npos && del_resp.status_code == 200 && del_resp.body.find("\"method\":\"DELETE\"") != std::string::npos && del_resp.body.find("\"session\":\"v8-del\"") != std::string::npos; expect(ok_rest, "AstraNet v7 & JS fetch() deliver POST/PUT/DELETE methods, custom headers & request bodies end-to-end"); } // 42. CSS3 Level 8: :first-child/:last-child/:focus, flex-wrap:wrap, border-left & transform:translate() { SlabArena c8a; HtmlDocument c8doc = HtmlDocument::parse( c8a, "" "
" "
One
" "
Two
" "
Three
" "
"); CssStylesheet c8sheet; c8sheet.parse(c8doc.collect_stylesheets()); LayoutFrame* c8root = LayoutEngine::build_layout(c8a, c8doc, c8sheet, 400.0f, 300.0f); bool ok_c8 = false; if (c8root && !c8root->children.empty() && c8root->children[0]->children.size() == 3) { const LayoutFrame* f0 = c8root->children[0]->children[0]; const LayoutFrame* f1 = c8root->children[0]->children[1]; const LayoutFrame* f2 = c8root->children[0]->children[2]; // Row 1: f0 (x=0, y=0) + f1 (x=120, y=0) = 230px <= 250px. // Row 2: f2 wraps to y=50px, then transform:translate(15px, 10px) -> x=15px, y=60px. DisplayList c8dl = LayoutEngine::build_display_list(c8root, 400, 300); bool has_accent_bar = false; for (const auto& it : c8dl.items) { if (it.type == DisplayItemType::FillRect && it.color_argb == 0xFF38BDF8u && std::abs(it.rect.w - 4.0f) < 0.5f) { has_accent_bar = true; } } ok_c8 = f0->style.background.to_argb() == 0xFF0284C7u && f1->style.background.to_argb() == 0xFF1E293Bu && f2->style.background.to_argb() == 0xFF065F46u && std::abs(f0->border_box.x - 0.0f) < 1.0f && std::abs(f1->border_box.x - 120.0f) < 1.0f && std::abs(f2->border_box.x - 15.0f) < 1.0f && std::abs(f2->border_box.y - 60.0f) < 1.5f && has_accent_bar; } expect(ok_c8, "CSS3 Level 8 resolves :first-child/:last-child, flex-wrap multi-row layout, border-left accent & transform:translate()"); } // 43. End-to-End Session 8 Showcase (astra_session8.html): Inline SVG + Flex-Wrap + ES6 JS + Render { std::string showcase_path = "astra/examples/astra_session8.html"; if (!std::filesystem::exists(showcase_path)) showcase_path = "examples/astra_session8.html"; uint32_t s8_tid = app.new_tab("file://" + showcase_path); bool has_svg = false; std::string js_summary; for (const auto& t : app.tabs()) { if (t.id == s8_tid) { for (const auto& it : t.cached_display_list.items) { if (it.type == DisplayItemType::EmbedSvg) has_svg = true; } if (t.live_doc) { if (const DomNode* el = t.live_doc->query_selector("#s8-js-out")) { js_summary = el->text_content(); } } } } expect(has_svg && js_summary.find("v8") != std::string::npos && js_summary.find("48") != std::string::npos, "End-to-end astra_session8.html renders inline , flex-wrap CSS3 & ES6 AstraJS v8 pipeline"); } // 44. Hito A — Real Web Layout v9: + colspan, float/clear, inline-block, calc(), :nth-child, ::before/::after, " ""); CssStylesheet s9; s9.parse(d9.collect_stylesheets()); LayoutFrame* r9 = LayoutEngine::build_layout(a9, d9, s9, 800.0f, 600.0f); DisplayList dl9 = LayoutEngine::build_display_list(r9, 800, 600); bool ok_float_x = false, ok_calc_w = false, ok_clear_y = false; bool ok_inline_block = false, ok_table_cols = false, ok_nth_even = false; bool ok_before = false, ok_after = false, ok_iframe = false; if (r9 && r9->children.size() >= 4) { const LayoutFrame* f_side = r9->children[0]; const LayoutFrame* f_main = r9->children[1]; const LayoutFrame* f_after = r9->children[2]; ok_float_x = (f_side->border_box.x >= 595.0f && f_side->border_box.w >= 195.0f); ok_calc_w = (std::abs(f_main->border_box.w - 600.0f) < 2.0f); ok_clear_y = (f_after->border_box.y >= f_side->border_box.y + f_side->border_box.h - 1.0f); // Check inline-block siblings side-by-side and table columns const LayoutFrame* ib1 = nullptr; const LayoutFrame* ib2 = nullptr; const LayoutFrame* tbl = nullptr; for (const LayoutFrame* ch : f_main->children) { if (ch->style.display == DisplayType::InlineBlock) { if (!ib1) ib1 = ch; else if (!ib2) ib2 = ch; } if (ch->node && ch->node->tag == "table") tbl = ch; } if (ib1 && ib2) { ok_inline_block = (ib2->border_box.x > ib1->border_box.x + 50.0f && std::abs(ib1->border_box.y - ib2->border_box.y) < 2.0f); } if (tbl) { std::vector rows; std::function gather_rows = [&](const LayoutFrame* n) { if (!n) return; if (n->style.display == DisplayType::TableRow) rows.push_back(n); for (const LayoutFrame* c : n->children) gather_rows(c); }; gather_rows(tbl); if (rows.size() == 3 && rows[1]->children.size() == 2 && rows[2]->children.size() == 1) { const LayoutFrame* c0 = rows[1]->children[0]; const LayoutFrame* c1 = rows[1]->children[1]; const LayoutFrame* span2 = rows[2]->children[0]; ok_table_cols = (c1->border_box.x > c0->border_box.x + 80.0f) && (span2->border_box.w > c0->border_box.w * 1.5f); ok_nth_even = (rows[1]->style.background.to_argb() == 0xFF132038u); } } } for (const auto& it : dl9.items) { if (it.type == DisplayItemType::DrawText) { if (it.text.find("PRE") != std::string::npos) ok_before = true; if (it.text.find("POST") != std::string::npos) ok_after = true; if (it.text.find("NestedDoc") != std::string::npos) ok_iframe = true; } } bool all44 = ok_float_x && ok_calc_w && ok_clear_y && ok_inline_block && ok_table_cols && ok_nth_even && ok_before && ok_after && ok_iframe; if (!all44) { std::cerr << " [diag44] float=" << ok_float_x << " calc=" << ok_calc_w << " clear=" << ok_clear_y << " ib=" << ok_inline_block << " tbl=" << ok_table_cols << " nth=" << ok_nth_even << " bef=" << ok_before << " aft=" << ok_after << " ifr=" << ok_iframe << "\n"; } expect(all44, "Hito A: CSS3 Layout v9 handles
+colspan, float/clear, inline-block, calc(), :nth-child, ::before/::after &