Browse Source

fix code style

deepak1556 8 years ago
parent
commit
cbddbdb296
3 changed files with 28 additions and 9 deletions
  1. 14 2
      atom/browser/api/atom_api_app.cc
  2. 10 0
      spec/api-app-spec.js
  3. 4 7
      spec/static/main.js

+ 14 - 2
atom/browser/api/atom_api_app.cc

@@ -378,12 +378,24 @@ void OnClientCertificateSelected(
     v8::Isolate* isolate,
     std::shared_ptr<content::ClientCertificateDelegate> delegate,
     mate::Arguments* args) {
-  mate::Dictionary cert_data;
-  if (!args->GetNext(&cert_data)) {
+  if (args->Length() == 2) {
+    delegate->ContinueWithCertificate(nullptr);
+    return;
+  }
+
+  v8::Local<v8::Value> val;
+  args->GetNext(&val);
+  if (val->IsNull()) {
     delegate->ContinueWithCertificate(nullptr);
     return;
   }
 
+  mate::Dictionary cert_data;
+  if (!mate::ConvertFromV8(isolate, val, &cert_data)) {
+    args->ThrowError("Must pass valid certificate object.");
+    return;
+  }
+
   std::string data;
   if (!cert_data.Get("data", &data))
     return;

+ 10 - 0
spec/api-app-spec.js

@@ -220,6 +220,16 @@ describe('app module', function () {
         done()
       })
 
+      ipcRenderer.once('select-client-certificate', function (event, webContentsId, list) {
+        assert.equal(webContentsId, w.webContents.id)
+        assert.equal(list.length, 1)
+        assert.equal(list[0].issuerName, 'Intermediate CA')
+        assert.equal(list[0].subjectName, 'Client Cert')
+        assert.equal(list[0].issuer.commonName, 'Intermediate CA')
+        assert.equal(list[0].subject.commonName, 'Client Cert')
+        event.sender.send('client-certificate-response', list[0])
+      })
+
       app.importCertificate(options, function (result) {
         assert(!result)
         ipcRenderer.sendSync('set-client-certificate-option', false)

+ 4 - 7
spec/static/main.js

@@ -11,7 +11,6 @@ const protocol = electron.protocol
 const v8 = require('v8')
 
 const Coverage = require('electabul').Coverage
-const assert = require('assert')
 const fs = require('fs')
 const path = require('path')
 const url = require('url')
@@ -192,12 +191,10 @@ ipcMain.on('set-client-certificate-option', function (event, skip) {
     if (skip) {
       callback()
     } else {
-      assert.equal(list.length, 1)
-      assert.equal(list[0].issuerName, 'Intermediate CA')
-      assert.equal(list[0].subjectName, 'Client Cert')
-      assert.equal(list[0].issuer.commonName, 'Intermediate CA')
-      assert.equal(list[0].subject.commonName, 'Client Cert')
-      callback(list[0])
+      ipcMain.on('client-certificate-response', function (event, certificate) {
+        callback(certificate)
+      })
+      window.webContents.send('select-client-certificate', webContents.id, list)
     }
   })
   event.returnValue = 'done'