commit d2e61e315c2bc34d28c5f0afeb982804b6abf1ba Author: Serene Han keroserene+git@gmail.com Date: Wed Mar 2 05:45:27 2016 -0800
confirmation dialog on proxy close (close #23) --- proxy/snowflake.coffee | 9 +++++++++ proxy/spec/snowflake.spec.coffee | 12 ++++++++++++ 2 files changed, 21 insertions(+)
diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee index 0df1904..90150ad 100644 --- a/proxy/snowflake.coffee +++ b/proxy/snowflake.coffee @@ -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 diff --git a/proxy/spec/snowflake.spec.coffee b/proxy/spec/snowflake.spec.coffee index be1601b..f3fbae8 100644 --- a/proxy/spec/snowflake.spec.coffee +++ b/proxy/spec/snowflake.spec.coffee @@ -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
tor-commits@lists.torproject.org