define(['core/sync', 'sinonjs'], function(SyncConnection, sinon) {
  var server;

  QUnit.module('Sync tests', {
    setup: function() {
      server = sinon.fakeServer.create();
    },
    teardown: function() {
      server.restore();
    }
  });

  test('Server trailing slash', function() {
    var conn = new SyncConnection({ url: 'http://localhost/' });
    conn.sync();
    equal(server.requests[0].url, 'http://localhost/hostKey',
          'Trailing slash in server URL is ok');

    conn = new SyncConnection({ url: 'http://localhost' });
    conn.sync();
    equal(server.requests[1].url, 'http://localhost/hostKey',
          'No trailing slash in server URL is ok');
  });

  test('Get host key', function() {
    var conn = new SyncConnection(
      { url: 'http://localhost/',
        username: 'abc',
        password: 'def' });
    conn.sync();
    equal(server.requests[0].method, 'POST');
    // XXX Need to put in a mock FormData and catch the results there
    // deepEqual(JSON.parse(server.requests[0].requestBody),
    //          { u: 'abc', p: 'def' });

    server.requests[0].respond(200,
      { 'Content-Type': 'application/json' },
      JSON.stringify({ key: 'ghi' }));

    // XXX Test that if there is no error we don't call hostKey twice
  });
});

@@ -23,16 +23,24 @@
 sinonjs'
+, 'gzip'
 %5D, funct
@@ -64,16 +64,22 @@
 n, sinon
+, gzip
 ) %7B%0A  va
@@ -95,60 +95,721 @@
 %0A%0A  
-QUnit.module('Sync tests', %7B%0A    setup: function() %7B
+function MockFormData(form) %7B%0A    this._form = form;%0A    this._data = %5B%5D;%0A%0A    this.append = function(name, value, filename) %7B%0A      this._data.push(%7B name: name, value: value, filename: filename%7D);%0A    %7D;%0A  %7D%0A%0A  var existingFormData;%0A%0A  QUnit.module('Sync tests', %7B%0A    setup: function() %7B%0A      if (typeof FormData != %22function%22 && typeof FormData != %22object%22) %7B%0A        // There should be an existing implementation of FormData even if it is%0A        // only a polyfilled one. Otherwise, subbing in a mock object here would%0A        // mask a compatibility issue.%0A        ok(false, 'No existing implementation of FormData');%0A      %7D%0A      existingFormData = window.FormData;%0A      window.FormData = MockFormData;
 %0A   
@@ -877,24 +877,66 @@
 unction() %7B%0A
+      window.FormData = existingFormData;%0A
       server
@@ -1395,25 +1395,30 @@
 );%0A  %7D);%0A%0A  
-t
+asyncT
 est('Get hos
@@ -1624,87 +1624,321 @@
 OST'
-);%0A    // XXX Need
+, 'has post method');%0A    equal(server.requests%5B0%5D.requestBody._data.length, 2,%0A          'has
  t
+w
 o 
-put in a mock FormData and catch the results there%0A 
+items in the request');%0A    deepEqual(server.requests%5B0%5D.requestBody._data%5B0%5D,%0A              %7B name: 'c', value: '1', filename: undefined %7D);%0A    deepEqual(server.requests%5B0%5D.requestBody._data%5B1%5D.name, 'data');%0A
    
-//
  dee
@@ -1948,93 +1948,888 @@
 ual(
-JSON.parse(server.requests%5B0%5D.requestBody),%0A    //          %7B u: 'abc', p: 'def' %7D);%0A
+server.requests%5B0%5D.requestBody._data%5B1%5D.filename, 'data');%0A    var blob = server.requests%5B0%5D.requestBody._data%5B1%5D.value;%0A%0A    var reader = new FileReader();%0A    // We'd like to use addEventListener but the version of WebKit in phantomjs%0A    // only supports onload%0A    reader.onload = function() %7B%0A      try %7B%0A        var unzipped = gzip.unzip(new Uint8Array(reader.result));%0A        var json = String.fromCharCode.apply(null,%0A                     Array.prototype.slice.apply(unzipped));%0A        var obj = JSON.parse(json);%0A        deepEqual(obj, %7B u: 'abc', p: 'def' %7D);%0A      %7D catch (e) %7B%0A        ok(false, e);%0A      %7D%0A    %7D;%0A    reader.onerror = function() %7B%0A      ok(false, 'error reading blob');%0A    %7D%0A    // Call start regardless of failure or success%0A    reader.onloadend = function() %7B%0A      start();%0A    %7D;%0A    reader.readAsArrayBuffer(blob);%0A%0A    // XXX Continue%0A    /*
 %0A   
@@ -2945,16 +2945,25 @@
 hi' %7D));
+%0A      */
 %0A%0A    //

Test results of FormData