]> khamidou — GitHub mirrors - electron.git/commitdiff
Enable customing mime type and charset when returning reqeust string job.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 25 Aug 2013 07:07:07 +0000 (15:07 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 25 Aug 2013 07:07:07 +0000 (15:07 +0800)
browser/api/lib/protocol.coffee
spec/api/protocol.coffee
spec/main.js

index dadc17e32452aa9956dc819afdfaae9ec08fd7fc..350a3d609748f65fd51518e484b28fdf9460485b 100644 (file)
@@ -1 +1,11 @@
 module.exports = process.atomBinding 'protocol'
+
+module.exports.RequestStringJob =
+class RequestStringJob
+  constructor: ({mimeType, charset, data}) ->
+    if typeof data isnt 'string' and not data instanceof Buffer
+      throw new TypeError('Data should be string or Buffer')
+
+    @mimeType = mimeType ? 'text/plain'
+    @charset = charset ? 'UTF-8'
+    @data = String data
index 5be7b4a46875ec066e62e4b01a58e105a94d4007..6f20fcf4454bbc047c28618c7c0cde6b508fce4e 100644 (file)
@@ -11,7 +11,9 @@ describe 'protocol API', ->
       protocol.unregisterProtocol 'test1'
 
     it 'calls the callback when scheme is visited', (done) ->
-      protocol.registerProtocol 'test2', -> done()
+      protocol.registerProtocol 'test2', (url) ->
+        assert.equal url, 'test2://test2'
+        done()
       $.get 'test2://test2', ->
       protocol.unregisterProtocol 'test2'
 
@@ -28,4 +30,13 @@ describe 'protocol API', ->
           assert.equal data, 'atom-string://something'
           done()
         error: (xhr, errorType, error) ->
-          console.log xhr, errorType, error
+          assert false, 'Got error: ' + errorType + ' ' + error
+
+    it 'returns RequestStringJob should send string', (done) ->
+      $.ajax
+        url: 'atom-string-job://something'
+        success: (data) ->
+          assert.equal data, 'atom-string-job://something'
+          done()
+        error: (xhr, errorType, error) ->
+          assert false, 'Got error: ' + errorType + ' ' + error
index ba05d6fdd0b3dbb56c1fe43fabbf1b88bdad2724..851f608177965ca25e54f4a520fe824e6a549bf8 100644 (file)
@@ -41,6 +41,10 @@ app.on('will-finish-launching', function() {
   protocol.registerProtocol('atom-string', function(url) {
     return url;
   });
+
+  protocol.registerProtocol('atom-string-job', function(url) {
+    return new protocol.RequestStringJob({mimeType: 'text/html', data: url});
+  });
 });
 
 app.on('finish-launching', function() {