mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
confirmation dialog on proxy close (close #23)
This commit is contained in:
parent
8a8273e972
commit
d2e61e315c
2 changed files with 21 additions and 0 deletions
|
@ -44,6 +44,8 @@ MODE =
|
|||
WEBRTC_CONNECTING: 1
|
||||
WEBRTC_READY: 2
|
||||
|
||||
CONFIRMATION_MESSAGE = "You're currently serving a Tor user via Snowflake."
|
||||
|
||||
# Minimum viable snowflake for now - just 1 client.
|
||||
class Snowflake
|
||||
|
||||
|
@ -200,4 +202,11 @@ init = ->
|
|||
snowflake.setRelayAddr relayAddr
|
||||
snowflake.beginWebRTC()
|
||||
|
||||
# Notification of closing tab with active proxy.
|
||||
# TODO: Opt-in/out parameter or cookie
|
||||
window.onbeforeunload = ->
|
||||
if MODE.WEBRTC_READY == snowflake.state
|
||||
return CONFIRMATION_MESSAGE
|
||||
null
|
||||
|
||||
window.onload = init if window
|
||||
|
|
|
@ -23,6 +23,7 @@ snowflake =
|
|||
ui: fakeUI
|
||||
broker:
|
||||
sendAnswer: ->
|
||||
state: MODE.INIT
|
||||
|
||||
describe 'Snowflake', ->
|
||||
|
||||
|
@ -58,3 +59,14 @@ describe 'Snowflake', ->
|
|||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s.makeProxyPair()
|
||||
expect(s.proxyPairs.length).toBe 2
|
||||
|
||||
it 'gives a dialog when closing, only while active', ->
|
||||
snowflake.state = MODE.WEBRTC_READY
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe MODE.WEBRTC_READY
|
||||
expect(msg).toBe CONFIRMATION_MESSAGE
|
||||
|
||||
snowflake.state = MODE.INIT
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe MODE.INIT
|
||||
expect(msg).toBe null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue