mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-24 08:09:16 -05:00
dedup inspector client/channel test implementations (#262)
This commit is contained in:
parent
3dbf414752
commit
87fdcdc131
1 changed files with 104 additions and 162 deletions
|
@ -2261,139 +2261,30 @@ fn try_from_local() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspector_dispatch_protocol_message() {
|
||||
let _setup_guard = setup();
|
||||
let mut params = v8::Isolate::create_params();
|
||||
params.set_array_buffer_allocator(v8::new_default_allocator());
|
||||
let mut isolate = v8::Isolate::new(params);
|
||||
let mut locker = v8::Locker::new(&isolate);
|
||||
let scope = locker.enter();
|
||||
|
||||
use v8::inspector::*;
|
||||
|
||||
struct Client {
|
||||
base: V8InspectorClientBase,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
base: V8InspectorClientBase::new::<Self>(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl V8InspectorClientImpl for Client {
|
||||
fn base(&self) -> &V8InspectorClientBase {
|
||||
&self.base
|
||||
}
|
||||
fn base_mut(&mut self) -> &mut V8InspectorClientBase {
|
||||
&mut self.base
|
||||
}
|
||||
}
|
||||
|
||||
struct TestChannel {
|
||||
base: ChannelBase,
|
||||
send_response_count: usize,
|
||||
send_notification_count: usize,
|
||||
flush_protocol_notifications_count: usize,
|
||||
}
|
||||
|
||||
impl TestChannel {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base: ChannelBase::new::<Self>(),
|
||||
send_response_count: 0,
|
||||
send_notification_count: 0,
|
||||
flush_protocol_notifications_count: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelImpl for TestChannel {
|
||||
fn base(&self) -> &ChannelBase {
|
||||
&self.base
|
||||
}
|
||||
fn base_mut(&mut self) -> &mut ChannelBase {
|
||||
&mut self.base
|
||||
}
|
||||
fn send_response(
|
||||
&mut self,
|
||||
_call_id: i32,
|
||||
_message: v8::UniquePtr<StringBuffer>,
|
||||
) {
|
||||
self.send_response_count += 1;
|
||||
}
|
||||
fn send_notification(&mut self, _message: v8::UniquePtr<StringBuffer>) {
|
||||
self.send_notification_count += 1;
|
||||
}
|
||||
fn flush_protocol_notifications(&mut self) {
|
||||
self.flush_protocol_notifications_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut hs = v8::HandleScope::new(scope);
|
||||
let scope = hs.enter();
|
||||
let context = v8::Context::new(scope);
|
||||
let mut cs = v8::ContextScope::new(scope, context);
|
||||
let _scope = cs.enter();
|
||||
|
||||
let mut default_client = Client::new();
|
||||
let mut inspector = V8Inspector::create(&mut isolate, &mut default_client);
|
||||
let name = b"";
|
||||
let name_view = StringView::from(&name[..]);
|
||||
inspector.context_created(context, 1, &name_view);
|
||||
let mut channel = TestChannel::new();
|
||||
let state = b"{}";
|
||||
let state_view = StringView::from(&state[..]);
|
||||
let mut session = inspector.connect(1, &mut channel, &state_view);
|
||||
let message = String::from(
|
||||
r#"{"id":1,"method":"Network.enable","params":{"maxPostDataSize":65536}}"#,
|
||||
);
|
||||
let message = &message.into_bytes()[..];
|
||||
let string_view = StringView::from(message);
|
||||
session.dispatch_protocol_message(&string_view);
|
||||
assert_eq!(channel.send_response_count, 1);
|
||||
assert_eq!(channel.send_notification_count, 0);
|
||||
assert_eq!(channel.flush_protocol_notifications_count, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspector_schedule_pause_on_next_statement() {
|
||||
let _setup_guard = setup();
|
||||
let mut params = v8::Isolate::create_params();
|
||||
params.set_array_buffer_allocator(v8::new_default_allocator());
|
||||
let mut isolate = v8::Isolate::new(params);
|
||||
let mut locker = v8::Locker::new(&isolate);
|
||||
let scope = locker.enter();
|
||||
|
||||
use v8::inspector::*;
|
||||
|
||||
struct Client {
|
||||
base: V8InspectorClientBase,
|
||||
struct ClientCounter {
|
||||
base: v8::inspector::V8InspectorClientBase,
|
||||
count_run_message_loop_on_pause: usize,
|
||||
count_quit_message_loop_on_pause: usize,
|
||||
count_run_if_waiting_for_debugger: usize,
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
impl ClientCounter {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
base: V8InspectorClientBase::new::<Self>(),
|
||||
base: v8::inspector::V8InspectorClientBase::new::<Self>(),
|
||||
count_run_message_loop_on_pause: 0,
|
||||
count_quit_message_loop_on_pause: 0,
|
||||
count_run_if_waiting_for_debugger: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl V8InspectorClientImpl for Client {
|
||||
fn base(&self) -> &V8InspectorClientBase {
|
||||
impl v8::inspector::V8InspectorClientImpl for ClientCounter {
|
||||
fn base(&self) -> &v8::inspector::V8InspectorClientBase {
|
||||
&self.base
|
||||
}
|
||||
|
||||
fn base_mut(&mut self) -> &mut V8InspectorClientBase {
|
||||
fn base_mut(&mut self) -> &mut v8::inspector::V8InspectorClientBase {
|
||||
&mut self.base
|
||||
}
|
||||
|
||||
|
@ -2410,53 +2301,104 @@ fn inspector_schedule_pause_on_next_statement() {
|
|||
assert_eq!(context_group_id, 1);
|
||||
self.count_run_message_loop_on_pause += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TestChannel {
|
||||
base: ChannelBase,
|
||||
send_response_count: usize,
|
||||
send_notification_count: usize,
|
||||
flush_protocol_notifications_count: usize,
|
||||
}
|
||||
struct ChannelCounter {
|
||||
base: v8::inspector::ChannelBase,
|
||||
count_send_response: usize,
|
||||
count_send_notification: usize,
|
||||
count_flush_protocol_notifications: usize,
|
||||
}
|
||||
|
||||
impl TestChannel {
|
||||
impl ChannelCounter {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base: ChannelBase::new::<Self>(),
|
||||
send_response_count: 0,
|
||||
send_notification_count: 0,
|
||||
flush_protocol_notifications_count: 0,
|
||||
}
|
||||
base: v8::inspector::ChannelBase::new::<Self>(),
|
||||
count_send_response: 0,
|
||||
count_send_notification: 0,
|
||||
count_flush_protocol_notifications: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelImpl for TestChannel {
|
||||
fn base(&self) -> &ChannelBase {
|
||||
impl v8::inspector::ChannelImpl for ChannelCounter {
|
||||
fn base(&self) -> &v8::inspector::ChannelBase {
|
||||
&self.base
|
||||
}
|
||||
fn base_mut(&mut self) -> &mut ChannelBase {
|
||||
fn base_mut(&mut self) -> &mut v8::inspector::ChannelBase {
|
||||
&mut self.base
|
||||
}
|
||||
fn send_response(
|
||||
&mut self,
|
||||
call_id: i32,
|
||||
message: v8::UniquePtr<StringBuffer>,
|
||||
message: v8::UniquePtr<v8::inspector::StringBuffer>,
|
||||
) {
|
||||
println!(
|
||||
"send_response call_id {} message {}",
|
||||
call_id,
|
||||
message.unwrap().string()
|
||||
);
|
||||
self.send_response_count += 1;
|
||||
self.count_send_response += 1;
|
||||
}
|
||||
fn send_notification(&mut self, message: v8::UniquePtr<StringBuffer>) {
|
||||
fn send_notification(
|
||||
&mut self,
|
||||
message: v8::UniquePtr<v8::inspector::StringBuffer>,
|
||||
) {
|
||||
println!("send_notificatio message {}", message.unwrap().string());
|
||||
self.send_notification_count += 1;
|
||||
self.count_send_notification += 1;
|
||||
}
|
||||
fn flush_protocol_notifications(&mut self) {
|
||||
self.flush_protocol_notifications_count += 1;
|
||||
}
|
||||
self.count_flush_protocol_notifications += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspector_dispatch_protocol_message() {
|
||||
let _setup_guard = setup();
|
||||
let mut params = v8::Isolate::create_params();
|
||||
params.set_array_buffer_allocator(v8::new_default_allocator());
|
||||
let mut isolate = v8::Isolate::new(params);
|
||||
let mut locker = v8::Locker::new(&isolate);
|
||||
let scope = locker.enter();
|
||||
|
||||
use v8::inspector::*;
|
||||
|
||||
let mut hs = v8::HandleScope::new(scope);
|
||||
let scope = hs.enter();
|
||||
let context = v8::Context::new(scope);
|
||||
let mut cs = v8::ContextScope::new(scope, context);
|
||||
let _scope = cs.enter();
|
||||
|
||||
let mut default_client = ClientCounter::new();
|
||||
let mut inspector = V8Inspector::create(&mut isolate, &mut default_client);
|
||||
let name = b"";
|
||||
let name_view = StringView::from(&name[..]);
|
||||
inspector.context_created(context, 1, &name_view);
|
||||
let mut channel = ChannelCounter::new();
|
||||
let state = b"{}";
|
||||
let state_view = StringView::from(&state[..]);
|
||||
let mut session = inspector.connect(1, &mut channel, &state_view);
|
||||
let message = String::from(
|
||||
r#"{"id":1,"method":"Network.enable","params":{"maxPostDataSize":65536}}"#,
|
||||
);
|
||||
let message = &message.into_bytes()[..];
|
||||
let string_view = StringView::from(message);
|
||||
session.dispatch_protocol_message(&string_view);
|
||||
assert_eq!(channel.count_send_response, 1);
|
||||
assert_eq!(channel.count_send_notification, 0);
|
||||
assert_eq!(channel.count_flush_protocol_notifications, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspector_schedule_pause_on_next_statement() {
|
||||
let _setup_guard = setup();
|
||||
let mut params = v8::Isolate::create_params();
|
||||
params.set_array_buffer_allocator(v8::new_default_allocator());
|
||||
let mut isolate = v8::Isolate::new(params);
|
||||
let mut locker = v8::Locker::new(&isolate);
|
||||
let scope = locker.enter();
|
||||
|
||||
use v8::inspector::*;
|
||||
|
||||
let mut hs = v8::HandleScope::new(scope);
|
||||
let scope = hs.enter();
|
||||
|
@ -2464,9 +2406,9 @@ fn inspector_schedule_pause_on_next_statement() {
|
|||
let mut cs = v8::ContextScope::new(scope, context);
|
||||
let scope = cs.enter();
|
||||
|
||||
let mut client = Client::new();
|
||||
let mut client = ClientCounter::new();
|
||||
let mut inspector = V8Inspector::create(&mut isolate, &mut client);
|
||||
let mut channel = TestChannel::new();
|
||||
let mut channel = ChannelCounter::new();
|
||||
let state = b"{}";
|
||||
let state_view = StringView::from(&state[..]);
|
||||
let mut session = inspector.connect(1, &mut channel, &state_view);
|
||||
|
@ -2495,9 +2437,9 @@ fn inspector_schedule_pause_on_next_statement() {
|
|||
let detail = StringView::from(&detail[..]);
|
||||
session.schedule_pause_on_next_statement(&reason, &detail);
|
||||
|
||||
assert_eq!(channel.send_response_count, 1);
|
||||
assert_eq!(channel.send_notification_count, 0);
|
||||
assert_eq!(channel.flush_protocol_notifications_count, 0);
|
||||
assert_eq!(channel.count_send_response, 1);
|
||||
assert_eq!(channel.count_send_notification, 0);
|
||||
assert_eq!(channel.count_flush_protocol_notifications, 0);
|
||||
assert_eq!(client.count_run_message_loop_on_pause, 0);
|
||||
assert_eq!(client.count_quit_message_loop_on_pause, 0);
|
||||
assert_eq!(client.count_run_if_waiting_for_debugger, 0);
|
||||
|
@ -2505,9 +2447,9 @@ fn inspector_schedule_pause_on_next_statement() {
|
|||
let r = eval(scope, context, "1+2").unwrap();
|
||||
assert!(r.is_number());
|
||||
|
||||
assert_eq!(channel.send_response_count, 1);
|
||||
assert_eq!(channel.send_notification_count, 3);
|
||||
assert_eq!(channel.flush_protocol_notifications_count, 0);
|
||||
assert_eq!(channel.count_send_response, 1);
|
||||
assert_eq!(channel.count_send_notification, 3);
|
||||
assert_eq!(channel.count_flush_protocol_notifications, 0);
|
||||
assert_eq!(client.count_run_message_loop_on_pause, 1);
|
||||
assert_eq!(client.count_quit_message_loop_on_pause, 0);
|
||||
assert_eq!(client.count_run_if_waiting_for_debugger, 0);
|
||||
|
|
Loading…
Reference in a new issue