var Chrome = require('../');
var assert = require('assert');

describe('registering event', function () {
    describe('"event"', function () {
        it('should give the raw message', function (done) {
            Chrome(function (chrome) {
                chrome.once('event', function (message) {
                    assert(message.method);
                    chrome.close(done);
                });
                chrome.send('Network.enable');
                chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
            });
        });
    });
    it('should give the payload only', function (done) {
        Chrome(function (chrome) {
            chrome.once('Network.requestWillBeSent', function (message) {
                assert(!message.method);
                chrome.close(done);
            });
            chrome.send('Network.enable');
            chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
        });
    });
    it('should give the payload only (alternate syntax)', function (done) {
        Chrome(function (chrome) {
            chrome.Network.requestWillBeSent(function (message) {
                assert(!message.method);
                chrome.close(done);
            });
            chrome.send('Network.enable');
            chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
        });
    });
});

var Chrome = require('../');
var assert = require('assert');

describe('registering event', function () {
    describe('"event"', function () {
        it('should give the raw message', function (done) {
            Chrome(function (chrome) {
                chrome.once('event', function (message) {
                    assert(message.method);
                    chrome.close(done);
                });
                chrome.send('Network.enable');
                chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
            });
        });
    });
    it('should give the payload only', function (done) {
        Chrome(function (chrome) {
            chrome.once('Network.requestWillBeSent', function (message) {
                assert(!message.method);
                chrome.close(done);
            });
            chrome.send('Network.enable');
            chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
        });
    });
    it('should give the payload only (alternate syntax)', function (done) {
        Chrome(function (chrome) {
            chrome.Network.requestWillBeSent(function (message) {
                assert(!message.method);
                chrome.close(done);
                // avoid to call `done()` more than once
                chrome.removeAllListeners();
            });
            chrome.send('Network.enable');
            chrome.send('Page.navigate', {'url': 'chrome://newtab/'});
        });
    });
});

Fix race condition in test
Fix race condition in test

Registering an event with the shorthand syntax behaves like `.on` and not like
`.once` so in this case, if more than one request *will be sent* by the "New
Tab" of Chrome then the Mocha's `done()` function gets called twice causing an
error.

This has been hidden until 85409d3a4633ddb928c64f00db4edce49e88dd17.
