<commit_before>assert = require 'assert'
http = require 'http'
https = require 'https'
path = require 'path'
ws = require 'ws'
remote = require 'remote'

describe 'chromium feature', ->
  fixtures = path.resolve __dirname, 'fixtures'

  xdescribe 'heap snapshot', ->
    it 'does not crash', ->
      process.atomBinding('v8_util').takeHeapSnapshot()

  describe 'sending request of http protocol urls', ->
    it 'does not crash', (done) ->
      @timeout 5000
      server = http.createServer (req, res) ->
        res.end()
        server.close()
        done()
      server.listen 0, '127.0.0.1', ->
        {port} = server.address()
        $.get "http://127.0.0.1:#{port}"

  describe 'navigator.webkitGetUserMedia', ->
    it 'calls its callbacks', (done) ->
      @timeout 5000
      navigator.webkitGetUserMedia audio: true, video: false,
        -> done()
        -> done()

  describe 'navigator.language', ->
    it 'should not be empty', ->
      assert.notEqual navigator.language, ''

  describe 'window.open', ->
    it 'returns a BrowserWindowProxy object', ->
      b = window.open 'about:blank', '', 'show=no'
      assert.equal b.closed, false
      assert.equal b.constructor.name, 'BrowserWindowProxy'
      b.close()

    it 'accepts "node-integration" as feature', (done) ->
      listener = (event) ->
        window.removeEventListener 'message', listener
        b.close()
        assert.equal event.data, 'undefined'
        done()
      window.addEventListener 'message', listener
      b = window.open "file://#{fixtures}/pages/window-opener-node.html", '', 'node-integration=no,show=no'

  describe 'window.opener', ->
    ipc = remote.require 'ipc'
    url = "file://#{fixtures}/pages/window-opener.html"
    w = null

    afterEach ->
      w?.destroy()
      ipc.removeAllListeners 'opener'

    it 'is null for main window', (done) ->
      ipc.on 'opener', (event, opener) ->
        done(if opener is null then undefined else opener)
      BrowserWindow = remote.require 'browser-window'
      w = new BrowserWindow(show: false)
      w.loadUrl url

    it 'is not null for window opened by window.open', (done) ->
      b = window.open url, '', 'show=no'
      ipc.on 'opener', (event, opener) ->
        b.close()
        done(if opener isnt null then undefined else opener)

  describe 'window.opener.postMessage', ->
    it 'sets source and origin correctly', (done) -><commit_msg>spec: Delay timeout of window.opener test<commit_after>assert = require 'assert'
http = require 'http'
https = require 'https'
path = require 'path'
ws = require 'ws'
remote = require 'remote'

describe 'chromium feature', ->
  fixtures = path.resolve __dirname, 'fixtures'

  xdescribe 'heap snapshot', ->
    it 'does not crash', ->
      process.atomBinding('v8_util').takeHeapSnapshot()

  describe 'sending request of http protocol urls', ->
    it 'does not crash', (done) ->
      @timeout 5000
      server = http.createServer (req, res) ->
        res.end()
        server.close()
        done()
      server.listen 0, '127.0.0.1', ->
        {port} = server.address()
        $.get "http://127.0.0.1:#{port}"

  describe 'navigator.webkitGetUserMedia', ->
    it 'calls its callbacks', (done) ->
      @timeout 5000
      navigator.webkitGetUserMedia audio: true, video: false,
        -> done()
        -> done()

  describe 'navigator.language', ->
    it 'should not be empty', ->
      assert.notEqual navigator.language, ''

  describe 'window.open', ->
    it 'returns a BrowserWindowProxy object', ->
      b = window.open 'about:blank', '', 'show=no'
      assert.equal b.closed, false
      assert.equal b.constructor.name, 'BrowserWindowProxy'
      b.close()

    it 'accepts "node-integration" as feature', (done) ->
      listener = (event) ->
        window.removeEventListener 'message', listener
        b.close()
        assert.equal event.data, 'undefined'
        done()
      window.addEventListener 'message', listener
      b = window.open "file://#{fixtures}/pages/window-opener-node.html", '', 'node-integration=no,show=no'

  describe 'window.opener', ->
    @timeout 10000

    ipc = remote.require 'ipc'
    url = "file://#{fixtures}/pages/window-opener.html"
    w = null

    afterEach ->
      w?.destroy()
      ipc.removeAllListeners 'opener'

    it 'is null for main window', (done) ->
      ipc.on 'opener', (event, opener) ->
        assert.equal opener, null
        done()
      BrowserWindow = remote.require 'browser-window'
      w = new BrowserWindow(show: false)
      w.loadUrl url

    it 'is not null for window opened by window.open', (done) ->
      ipc.on 'opener', (event, opener) ->
        b.close()
        done(if opener isnt null then undefined else opener)
      b = window.open url, '', 'show=no'

  describe 'window.opener.postMessage', ->
    it 'sets source and origin correctly', (done) ->
{'fraction_non_alphanumeric': 0.14399836132732485, 'fraction_numerical': 0.010036870135190496, 'mean_word_length': 2.625092798812175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6168990', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1464, 'n_words': 411}