Skip to content

Commit b823a4b

Browse files
committed
refactor: update servo configuration, rename NullEngine to ScaffoldEngine, and add input tracing.
1 parent 7cf6bf3 commit b823a4b

8 files changed

Lines changed: 99 additions & 27 deletions

src/app/input.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,18 @@ impl BrazenApp {
317317
};
318318
if !suppress_engine_input {
319319
if pressed {
320+
if input_logging {
321+
tracing::trace!(target: "brazen::input", key = %key_name, ?modifiers, repeat = repeat, "forwarding KeyDown to engine");
322+
}
320323
self.engine.handle_input(InputEvent::KeyDown {
321324
key: key_name,
322325
modifiers,
323326
repeat,
324327
});
325328
} else {
329+
if input_logging {
330+
tracing::trace!(target: "brazen::input", key = %key_name, ?modifiers, "forwarding KeyUp to engine");
331+
}
326332
self.engine.handle_input(InputEvent::KeyUp {
327333
key: key_name,
328334
modifiers,
@@ -334,12 +340,15 @@ impl BrazenApp {
334340
if suppress_engine_input {
335341
continue;
336342
}
343+
if input_logging {
344+
tracing::trace!(target: "brazen::input", text = %text, "text input event received");
345+
}
337346

338347
// SUPPRESS single-character text input to avoid "double typing".
339348
// Servo's KeyboardEvent (KeyDown) already handles printable characters.
340349
if text.chars().count() == 1 {
341350
if input_logging {
342-
tracing::trace!(target: "brazen::input", text = %text, "suppressing single-char text input to avoid duplication");
351+
tracing::trace!(target: "brazen::input", text = %text, "suppressing single-char text input to avoid duplication in engine");
343352
}
344353
continue;
345354
}

src/app/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ use super::*;
132132
) {
133133
callback(Ok(()));
134134
}
135+
136+
fn select_all(&mut self) {}
135137
}
136138

137139
#[test]
@@ -202,6 +204,12 @@ use super::*;
202204
dom_snapshot: None,
203205
network_log: VecDeque::new(),
204206
extracted_entities: Vec::new(),
207+
terminal_history: Vec::new(),
208+
terminal_input: String::new(),
209+
terminal_busy: false,
210+
observe_dom: false,
211+
control_terminal: false,
212+
use_mcp_tools: false,
205213
};
206214

207215
let mut ready_engine = MockEngine {

src/servo_upstream.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ use crate::servo_resources::{
1313
};
1414
use dpi::PhysicalSize;
1515
use libservo::{
16-
Code, CompositionEvent, CompositionState, DeviceIntPoint, DeviceIntRect, DeviceIntSize,
17-
DevicePoint, EventLoopWaker, ImeEvent, InputEvent, Key, KeyState, KeyboardEvent, LoadStatus,
18-
Location, Modifiers, MouseButton, MouseButtonAction, MouseButtonEvent, MouseLeftViewportEvent,
19-
MouseMoveEvent, NamedKey, Opts, RenderingContext, Servo, ServoBuilder, ServoDelegate,
20-
SoftwareRenderingContext, WebView, WebViewBuilder, WebViewDelegate, WebViewPoint, WheelDelta,
16+
CompositionState, Key, KeyState, Location, Modifiers, NamedKey, Opts, Servo, ServoBuilder,
17+
ServoDelegate, WebView, WebViewBuilder, WebViewDelegate, prefs,
18+
Code, CompositionEvent, DeviceIntPoint, DeviceIntRect, DeviceIntSize,
19+
DevicePoint, EventLoopWaker, ImeEvent, InputEvent, KeyboardEvent, LoadStatus,
20+
MouseButton, MouseButtonAction, MouseButtonEvent, MouseLeftViewportEvent,
21+
MouseMoveEvent, WebViewPoint, WheelDelta,
2122
WheelEvent, WheelMode, WebResourceLoad, WebResourceResponse,
23+
RenderingContext, SoftwareRenderingContext,
2224
};
2325
use libservo::clipboard_delegate::{ClipboardDelegate, StringRequest};
2426
use tracing_log::LogTracer;
@@ -377,20 +379,16 @@ impl ServoUpstreamRuntime {
377379
if let Some(cache_dir) = &config.cache_path {
378380
std::fs::create_dir_all(cache_dir).ok();
379381
}
380-
let opts = Opts {
381-
ignore_certificate_errors: config.ignore_certificate_errors,
382-
certificate_path: resolved_certificate_path
383-
.as_ref()
384-
.map(|path| path.display().to_string()),
385-
config_dir: config
386-
.storage_path
387-
.as_ref()
388-
.and_then(|p| p.parent().map(|p| p.to_path_buf())),
389-
user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Brazen/0.1.0".to_string(),
390-
cache_dir: config.cache_path.clone(),
391-
cookie_file: config.cookies_path.clone(),
392-
..Opts::default()
393-
};
382+
let mut opts = libservo::Opts::default();
383+
opts.ignore_certificate_errors = config.ignore_certificate_errors;
384+
opts.certificate_path = resolved_certificate_path.as_ref().map(|p| p.display().to_string());
385+
opts.config_dir = config.storage_path.as_ref().and_then(|p| p.parent().map(|p| p.to_path_buf()));
386+
387+
// Set preferences
388+
let mut preferences = prefs::get().clone();
389+
preferences.user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36".to_string();
390+
prefs::set(preferences);
391+
394392
let frame_ready = Arc::new(AtomicBool::new(true));
395393
let rendering_context = Rc::new(
396394
SoftwareRenderingContext::new(PhysicalSize::new(width, height))
@@ -663,6 +661,15 @@ impl ServoUpstreamRuntime {
663661
}
664662

665663
pub fn handle_keyboard(&self, key: &str, pressed: bool, modifiers: KeyModifiers, repeat: bool) {
664+
tracing::trace!(
665+
target: "brazen::servo::input",
666+
key = %key,
667+
pressed = pressed,
668+
modifiers = ?modifiers,
669+
repeat = repeat,
670+
"keyboard event received in upstream runtime"
671+
);
672+
666673
let state = if pressed {
667674
KeyState::Down
668675
} else {

tests/bootstrap.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use brazen::commands::{AppCommand, CommandOutcome, dispatch_command};
22
use brazen::config::{BrazenConfig, LoggingConfig, default_config_toml};
3-
use brazen::engine::{BrowserEngine, BrowserTab, EngineEvent, EngineStatus, NullEngine};
3+
use brazen::engine::{BrowserEngine, BrowserTab, EngineEvent, EngineStatus, ScaffoldEngine};
44
use brazen::logging::{LoggingPlan, init_tracing};
55
use brazen::permissions::{Capability, PermissionDecision};
66
use brazen::platform_paths::PlatformPaths;
@@ -17,7 +17,7 @@ impl EngineFactory for TestFactory {
1717
_mount_manager: brazen::mounts::MountManager,
1818
_session: std::sync::Arc<std::sync::RwLock<brazen::session::SessionSnapshot>>,
1919
) -> Box<dyn BrowserEngine> {
20-
Box::new(NullEngine::new())
20+
Box::new(ScaffoldEngine::new())
2121
}
2222
}
2323

@@ -305,11 +305,20 @@ fn command_dispatch_routes_navigation_and_panel_state() {
305305
visit_counts: std::collections::HashMap::new(),
306306
visit_total: 0,
307307
revisit_total: 0,
308+
dom_snapshot: None,
309+
network_log: std::collections::VecDeque::new(),
310+
extracted_entities: Vec::new(),
311+
terminal_history: Vec::new(),
312+
terminal_input: String::new(),
313+
terminal_busy: false,
314+
observe_dom: false,
315+
control_terminal: false,
316+
use_mcp_tools: false,
308317
pending_window_screenshot: std::sync::Arc::new(std::sync::Mutex::new(None)),
309318
mount_manager: brazen::mounts::MountManager::new(),
310319
runtime_paths,
311320
};
312-
let mut engine = NullEngine::new();
321+
let mut engine = ScaffoldEngine::new();
313322

314323
let outcome = dispatch_command(
315324
&mut shell,
@@ -408,11 +417,20 @@ fn command_dispatch_rejects_invalid_urls() {
408417
visit_counts: std::collections::HashMap::new(),
409418
visit_total: 0,
410419
revisit_total: 0,
420+
dom_snapshot: None,
421+
network_log: std::collections::VecDeque::new(),
422+
extracted_entities: Vec::new(),
423+
terminal_history: Vec::new(),
424+
terminal_input: String::new(),
425+
terminal_busy: false,
426+
observe_dom: false,
427+
control_terminal: false,
428+
use_mcp_tools: false,
411429
pending_window_screenshot: std::sync::Arc::new(std::sync::Mutex::new(None)),
412430
mount_manager: brazen::mounts::MountManager::new(),
413431
runtime_paths,
414432
};
415-
let mut engine = NullEngine::new();
433+
let mut engine = ScaffoldEngine::new();
416434

417435
let outcome = dispatch_command(
418436
&mut shell,
@@ -468,7 +486,7 @@ bind = "http://127.0.0.1:9999"
468486

469487
#[test]
470488
fn null_engine_emits_navigation_event() {
471-
let mut engine = NullEngine::new();
489+
let mut engine = ScaffoldEngine::new();
472490
engine.navigate("https://example.com");
473491
let events = engine.take_events();
474492
assert!(events.iter().any(|event| {

tests/servo_rendering_about_blank.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ mod tests {
1616
resources_dir: None,
1717
certificate_path: None,
1818
ignore_certificate_errors: false,
19+
cookies_path: None,
20+
storage_path: None,
21+
cache_path: None,
1922
};
2023
let (tx, _) = std::sync::mpsc::channel();
2124
let mount_manager = MountManager::new();

tests/servo_rendering_data_url.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ mod tests {
1919
resources_dir: None,
2020
certificate_path: None,
2121
ignore_certificate_errors: false,
22+
cookies_path: None,
23+
storage_path: None,
24+
cache_path: None,
2225
};
2326
let (tx, _) = std::sync::mpsc::channel();
2427
let mount_manager = MountManager::new();

tests/servo_runtime.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@ mod tests {
66

77
#[test]
88
fn servo_embedder_renders_frame_after_surface_attach() {
9-
let config = ServoEmbedderConfig::from_engine_config(&EngineConfig::default());
10-
let mut embedder = ServoEmbedder::new(config);
9+
let config = ServoEmbedderConfig::from_brazen_config(&brazen::config::BrazenConfig::default());
10+
let mount_manager = brazen::mounts::MountManager::new();
11+
let session = std::sync::Arc::new(std::sync::RwLock::new(brazen::session::SessionSnapshot::new("test".to_string(), "now".to_string())));
12+
let paths = brazen::platform_paths::RuntimePaths {
13+
config_path: "brazen.toml".into(),
14+
data_dir: "data".into(),
15+
logs_dir: "logs".into(),
16+
profiles_dir: "profiles".into(),
17+
cache_dir: "cache".into(),
18+
downloads_dir: "downloads".into(),
19+
crash_dumps_dir: "crash-dumps".into(),
20+
active_profile_dir: "profiles/default".into(),
21+
session_path: "profiles/default/session.json".into(),
22+
audit_log_path: "logs/audit.jsonl".into(),
23+
};
24+
let mut embedder = ServoEmbedder::new(config, mount_manager, session, paths);
1125
embedder.init().unwrap();
1226
embedder.attach_surface(
1327
brazen::engine::RenderSurfaceHandle {

tests/test_observability.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl BrowserEngine for MockEngine {
4949
fn go_back(&mut self) {}
5050
fn go_forward(&mut self) {}
5151
fn attach_surface(&mut self, _handle: RenderSurfaceHandle) {}
52+
fn select_all(&mut self) {}
5253
}
5354

5455
fn create_mock_shell_state() -> ShellState {
@@ -119,6 +120,15 @@ fn create_mock_shell_state() -> ShellState {
119120
audit_log_path: root.join("audit.log"),
120121
},
121122
pending_window_screenshot: Arc::new(std::sync::Mutex::new(None)),
123+
dom_snapshot: None,
124+
network_log: std::collections::VecDeque::new(),
125+
extracted_entities: Vec::new(),
126+
terminal_history: Vec::new(),
127+
terminal_input: String::new(),
128+
terminal_busy: false,
129+
observe_dom: false,
130+
control_terminal: false,
131+
use_mcp_tools: false,
122132
}
123133
}
124134

0 commit comments

Comments
 (0)