Browse Source

spec: Test asar archive with unpacked files

Cheng Zhao 10 years ago
parent
commit
dc82553fc3

+ 21 - 0
spec/api-protocol-spec.coffee

@@ -110,6 +110,27 @@ describe 'protocol module', ->
           assert false, 'Got error: ' + errorType + ' ' + error
           protocol.unregisterProtocol 'atom-file-job'
 
+    it 'returns RequestFileJob should send file from asar archive with unpacked file', (done) ->
+      p = path.join __dirname, 'fixtures', 'asar', 'unpack.asar', 'a.txt'
+      job = new protocol.RequestFileJob(p)
+      handler = remote.createFunctionWithReturnValue job
+      protocol.registerProtocol 'atom-file-job', handler
+
+      $.ajax
+        url: 'atom-file-job://' + p
+        success: (response) ->
+          data = require('fs').readFileSync(p)
+          assert.equal response.length, data.length
+          buf = new Buffer(response.length)
+          buf.write(response)
+          console.log buf, data
+          assert buf.equals(data)
+          protocol.unregisterProtocol 'atom-file-job'
+          done()
+        error: (xhr, errorType, error) ->
+          assert false, 'Got error: ' + errorType + ' ' + error
+          protocol.unregisterProtocol 'atom-file-job'
+
   describe 'protocol.isHandledProtocol', ->
     it 'returns true if the scheme can be handled', ->
       assert.equal protocol.isHandledProtocol('file'), true

+ 11 - 0
spec/asar-spec.coffee

@@ -362,6 +362,12 @@ describe 'asar package', ->
         assert.equal data, 'file1\n'
         done()
 
+    it 'can request a file in package with unpacked files', (done) ->
+      p = path.resolve fixtures, 'asar', 'unpack.asar', 'a.txt'
+      $.get "file://#{p}", (data) ->
+        assert.equal data, 'a\n'
+        done()
+
     it 'can request a linked file in package', (done) ->
       p = path.resolve fixtures, 'asar', 'a.asar', 'link2', 'link1'
       $.get "file://#{p}", (data) ->
@@ -431,3 +437,8 @@ describe 'asar package', ->
       p = path.join fixtures, 'asar', 'logo.asar', 'logo.png'
       logo = require('native-image').createFromPath p
       assert.deepEqual logo.getSize(), {width: 55, height: 55}
+
+    it 'reads image from asar archive with unpacked files', ->
+      p = path.join fixtures, 'asar', 'unpack.asar', 'atom.png'
+      logo = require('native-image').createFromPath p
+      assert.deepEqual logo.getSize(), {width: 1024, height: 1024}

BIN
spec/fixtures/asar/unpack.asar


+ 1 - 0
spec/fixtures/asar/unpack.asar.unpacked/a.txt

@@ -0,0 +1 @@
+a

BIN
spec/fixtures/asar/unpack.asar.unpacked/atom.png