 assert   = require 'assert'
 http     = require 'http'
 path     = require 'path'
+qs        = require 'querystring'
 
 {remote} = require 'electron'
 {protocol} = remote.require 'electron'

          error: (xhr, errorType, error) ->
            done(error)

  describe 'protocol.uninterceptProtocol', ->
    it 'returns error when scheme does not exist', (done) ->
      protocol.uninterceptProtocol 'not-exist', (error) ->

          error: (xhr, errorType, error) ->
            done(error)

    it 'can receive post data', (done) ->
      handler = (request, callback) ->
        uploadData = request.uploadData[0].bytes.toString()
        callback({data: uploadData})
      protocol.interceptStringProtocol 'http', handler, (error) ->
        return done(error) if error
        $.ajax
          url: "http://fake-host"
          type: "POST"
          data: postData
          success: (data) ->
            assert.deepEqual qs.parse(data), postData
            done()
          error: (xhr, errorType, error) ->
            done(error)

  describe 'protocol.interceptBufferProtocol', ->
    it 'can intercept http protocol', (done) ->
      handler = (request, callback) -> callback(new Buffer(text))
