<commit_before>'use strict'

const assert = require('assert')
const fs = require('fs')
const http = require('http')
const path = require('path')
const { closeWindow } = require('./window-helpers')
const { emittedOnce } = require('./events-helpers')
const chai = require('chai')
const dirtyChai = require('dirty-chai')

const { ipcRenderer, remote, clipboard } = require('electron')
const { BrowserWindow, webContents, ipcMain, session } = remote
const { expect } = chai

const isCi = remote.getGlobal('isCi')

chai.use(dirtyChai)

/* The whole webContents API doesn't use standard callbacks */
/* eslint-disable standard/no-callback-literal */

describe('webContents module', () => {
  const fixtures = path.resolve(__dirname, 'fixtures')
  let w

  beforeEach(() => {
    w = new BrowserWindow({
      show: false,
      width: 400,
      height: 400,
      webPreferences: {
        backgroundThrottling: false
      }
    })
  })

  afterEach(() => closeWindow(w).then(() => { w = null }))

  describe('getAllWebContents() API', () => {
    it('returns an array of web contents', (done) => {
      w.webContents.on('devtools-opened', () => {
        const all = webContents.getAllWebContents().sort((a, b) => {
          return a.id - b.id
        })

        assert.ok(all.length >= 4)
        assert.strictEqual(all[0].getType(), 'window')
        assert.strictEqual(all[all.length - 2].getType(), 'remote')
        assert.strictEqual(all[all.length - 1].getType(), 'webview')

        done()
      })

      w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
      w.webContents.openDevTools()
    })
  })

  describe('getFocusedWebContents() API', () => {
    it('returns the focused web contents', (done) => {
      if (isCi) return done()

      const specWebContents = remote.getCurrentWebContents()
      assert.strictEqual(specWebContents.id, webContents.getFocusedWebContents().id)

      specWebContents.once('devtools-opened', () => {
        assert.strictEqual(specWebContents.devToolsWebContents.id, webContents.getFocusedWebContents().id)
        specWebContents.closeDevTools()
      })<commit_msg>test: guarantee the order of webview and devtools creation (#14849)<commit_after>'use strict'

const assert = require('assert')
const fs = require('fs')
const http = require('http')
const path = require('path')
const { closeWindow } = require('./window-helpers')
const { emittedOnce } = require('./events-helpers')
const chai = require('chai')
const dirtyChai = require('dirty-chai')

const { ipcRenderer, remote, clipboard } = require('electron')
const { BrowserWindow, webContents, ipcMain, session } = remote
const { expect } = chai

const isCi = remote.getGlobal('isCi')

chai.use(dirtyChai)

/* The whole webContents API doesn't use standard callbacks */
/* eslint-disable standard/no-callback-literal */

describe('webContents module', () => {
  const fixtures = path.resolve(__dirname, 'fixtures')
  let w

  beforeEach(() => {
    w = new BrowserWindow({
      show: false,
      width: 400,
      height: 400,
      webPreferences: {
        backgroundThrottling: false
      }
    })
  })

  afterEach(() => closeWindow(w).then(() => { w = null }))

  describe('getAllWebContents() API', () => {
    it('returns an array of web contents', (done) => {
      w.webContents.on('devtools-opened', () => {
        const all = webContents.getAllWebContents().sort((a, b) => {
          return a.id - b.id
        })

        assert.ok(all.length >= 4)
        assert.strictEqual(all[0].getType(), 'window')
        assert.strictEqual(all[all.length - 2].getType(), 'webview')
        assert.strictEqual(all[all.length - 1].getType(), 'remote')

        done()
      })

      w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
      w.webContents.on('did-attach-webview', () => {
        w.webContents.openDevTools()
      })
    })
  })

  describe('getFocusedWebContents() API', () => {
    it('returns the focused web contents', (done) => {
      if (isCi) return done()

      const specWebContents = remote.getCurrentWebContents()
      assert.strictEqual(specWebContents.id, webContents.getFocusedWebContents().id)

      specWebContents.once('devtools-opened', () => {
        assert.strictEqual(specWebContents.devToolsWebContents.id, webContents.getFocusedWebContents().id)
        specWebContents.closeDevTools()
      })
{'fraction_non_alphanumeric': 0.15701914311759343, 'fraction_numerical': 0.005697356426618049, 'mean_word_length': 3.3671641791044777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '791370', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1314, 'n_words': 274}