Permalink
Browse files

[#336] Added atob and btoa to window.

  • Loading branch information...
assaf committed May 16, 2012
1 parent a25cd9b commit 6bdf511898093f9d5c4a649b402e9a2d9f1646c4
Showing with 30 additions and 0 deletions.
  1. +2 −0 CHANGELOG.md
  2. +6 −0 lib/zombie/windows.coffee
  3. +22 −0 test/window_test.coffee
View
@@ -9,6 +9,8 @@ execution.
Added empty `navigator.plugins`.
+Added `atob` and `btoa`.
+
487 tests
12.1 sec to complete
@@ -165,6 +165,12 @@ class Windows
MutationEvent: { value: Events.MutationEvent }
UIEvent: { value: Events.UIEvent }
+ # Base-64 encoding/decoding
+ window.atob = (string)->
+ new Buffer(string, "base64").toString("utf8")
+ window.btoa = (string)->
+ new Buffer(string, "utf8").toString("base64")
+
# Constructor for EventSource, URL is relative to document's.
window.EventSource = (url)->
url = URL.resolve(window.location, url)
View
@@ -177,6 +177,28 @@ describe "Window", ->
assert.equal browser.window.navigator.javaEnabled(), false
+ describe "atob", ->
+ window = null
+
+ before ->
+ browser = new Browser()
+ window = browser.window
+
+ it "should decode base-64 string", ->
+ assert.equal window.atob("SGVsbG8sIHdvcmxk"), "Hello, world"
+
+ describe "btoa", ->
+ window = null
+
+ before ->
+ browser = new Browser()
+ window = browser.window
+
+ it "should encode base-64 string", ->
+ assert.equal window.btoa("Hello, world"), "SGVsbG8sIHdvcmxk"
+
+
+
describe "windows", ->
browser = new Browser(name: "first")

1 comment on commit 6bdf511

@hughlomas

This comment has been minimized.

Show comment Hide comment
@hughlomas

hughlomas May 16, 2012

I don't know how applicable this is but please be aware of this node bug inconsistency of base64 encoding on http.get responses

I don't know how applicable this is but please be aware of this node bug inconsistency of base64 encoding on http.get responses

Please sign in to comment.