@@ -38,13 +38,14 @@ impl From<SendTabPayload> for crate::SendTabPayload {
3838}
3939
4040impl SendTabPayload {
41- pub fn single_tab ( title : & str , url : & str ) -> ( Self , telemetry:: SentCommand ) {
41+ pub fn single_tab ( title : & str , url : & str , private : bool ) -> ( Self , telemetry:: SentCommand ) {
4242 let sent_telemetry: telemetry:: SentCommand = telemetry:: SentCommand :: for_send_tab ( ) ;
4343 (
4444 SendTabPayload {
4545 entries : vec ! [ TabHistoryEntry {
4646 title: title. to_string( ) ,
4747 url: url. to_string( ) ,
48+ private,
4849 } ] ,
4950 flow_id : sent_telemetry. flow_id . clone ( ) ,
5051 stream_id : sent_telemetry. stream_id . clone ( ) ,
@@ -58,13 +59,16 @@ impl SendTabPayload {
5859pub struct TabHistoryEntry {
5960 pub title : String ,
6061 pub url : String ,
62+ #[ serde( default ) ]
63+ pub private : bool ,
6164}
6265
6366impl From < TabHistoryEntry > for crate :: TabHistoryEntry {
6467 fn from ( e : TabHistoryEntry ) -> Self {
6568 crate :: TabHistoryEntry {
6669 title : e. title ,
6770 url : e. url ,
71+ is_private : e. private ,
6872 }
6973 }
7074}
@@ -82,15 +86,35 @@ mod tests {
8286
8387 #[ test]
8488 fn test_payload ( ) {
85- let ( payload, telem) = SendTabPayload :: single_tab ( "title" , "http://example.com" ) ;
89+ let ( payload, telem) = SendTabPayload :: single_tab ( "title" , "http://example.com" , true ) ;
8690 let json = serde_json:: to_string ( & payload) . expect ( "should work" ) ;
8791 assert_eq ! ( telem. flow_id. len( ) , 12 ) ;
8892 assert_eq ! ( telem. stream_id. len( ) , 12 ) ;
8993 assert_ne ! ( telem. flow_id, telem. stream_id) ;
9094 let p2: SendTabPayload = serde_json:: from_str ( & json) . expect ( "should work" ) ;
9195 // no 'PartialEq' derived so check each field individually...
9296 assert_eq ! ( payload. entries[ 0 ] . url, "http://example.com" . to_string( ) ) ;
97+ assert ! ( payload. entries[ 0 ] . private) ;
9398 assert_eq ! ( payload. flow_id, p2. flow_id) ;
9499 assert_eq ! ( payload. stream_id, p2. stream_id) ;
95100 }
101+
102+ #[ test]
103+ fn test_raw_payload ( ) {
104+ let json = r#"{"title": "new title", "url": "https://example99.com", "private": true}"# ;
105+ let p: TabHistoryEntry = serde_json:: from_str ( json) . expect ( "should work" ) ;
106+ assert_eq ! ( p. title, "new title" ) ;
107+ assert_eq ! ( p. url, "https://example99.com" ) ;
108+ assert ! ( p. private) ;
109+ }
110+
111+ #[ test]
112+ fn test_raw_payload_without_private ( ) {
113+ // no "private" field
114+ let json = r#"{"title": "the title", "url": "https://example.com"}"# ;
115+ let p: TabHistoryEntry = serde_json:: from_str ( json) . expect ( "should work" ) ;
116+ assert_eq ! ( p. title, "the title" ) ;
117+ assert_eq ! ( p. url, "https://example.com" ) ;
118+ assert ! ( !p. private) ;
119+ }
96120}
0 commit comments