<commit_before>/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

function assertEnabled(dbg) {
  is(
    dbg.selectors.getQuickOpenEnabled(dbg.getState()),
    true,
    "quickOpen enabled"
  );
}

function assertDisabled(dbg) {
  is(
    dbg.selectors.getQuickOpenEnabled(dbg.getState()),
    false,
    "quickOpen disabled"
  );
}

function assertLine(dbg, lineNumber) {
  is(
    dbg.selectors.getSelectedLocation(dbg.getState()).line,
    lineNumber,
    `goto line is ${lineNumber}`
  );
}

function assertColumn(dbg, columnNumber) {
  is(
    dbg.selectors.getSelectedLocation(dbg.getState()).column,
    columnNumber,
    `goto column is ${columnNumber}`
  );
}

function waitForSymbols(dbg, url) {
  const source = findSource(dbg, url);
  return waitForState(dbg, state => dbg.selectors.getSymbols(state, source.id));
}

async function waitToClose(dbg) {
  pressKey(dbg, "Escape");
  return new Promise(r => setTimeout(r, 200));
}

function resultCount(dbg) {
  return findAllElements(dbg, "resultItems").length;
}

function quickOpen(dbg, query, shortcut = "quickOpen") {
  pressKey(dbg, shortcut);
  assertEnabled(dbg);
  query !== "" && type(dbg, query);
}

function findResultEl(dbg, index = 1) {
  return waitForElementWithSelector(dbg, `.result-item:nth-child(${index})`);
}

async function assertResultIsTab(dbg, index)  {
  const el = await findResultEl(dbg, index);
  debugger;
  ok(el && !!el.querySelector('.tab.result-item-icon'), 'Result should be a tab');
}

// Testing quick open
add_task(async function() {
  const dbg = await initDebugger("doc-script-switching.html");

  info("test opening and closing");
  quickOpen(dbg, "");
  pressKey(dbg, "Escape");
  assertDisabled(dbg);

  info("Testing the number of results for source search");
  quickOpen(dbg, "sw");
  is(resultCount(dbg), 2, "two file results");
  pressKey(dbg, "Escape");

  info("Testing source search and check to see if source is selected");
  await waitForSource(dbg, "switching-01");
  quickOpen(dbg, "sw1");
  is(resultCount(dbg), 1, "one file results");
  pressKey(dbg, "Enter");
  await waitForSelectedSource(dbg, "switching-01");

  info("Test that results show tab icons");
  quickOpen(dbg, "sw1");
  await assertResultIsTab(dbg, 1);
  pressKey(dbg, "Tab");<commit_msg>[testing] remove debugger statement (#7066)<commit_after>/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

function assertEnabled(dbg) {
  is(
    dbg.selectors.getQuickOpenEnabled(dbg.getState()),
    true,
    "quickOpen enabled"
  );
}

function assertDisabled(dbg) {
  is(
    dbg.selectors.getQuickOpenEnabled(dbg.getState()),
    false,
    "quickOpen disabled"
  );
}

function assertLine(dbg, lineNumber) {
  is(
    dbg.selectors.getSelectedLocation(dbg.getState()).line,
    lineNumber,
    `goto line is ${lineNumber}`
  );
}

function assertColumn(dbg, columnNumber) {
  is(
    dbg.selectors.getSelectedLocation(dbg.getState()).column,
    columnNumber,
    `goto column is ${columnNumber}`
  );
}

function waitForSymbols(dbg, url) {
  const source = findSource(dbg, url);
  return waitForState(dbg, state => dbg.selectors.getSymbols(state, source.id));
}

async function waitToClose(dbg) {
  pressKey(dbg, "Escape");
  return new Promise(r => setTimeout(r, 200));
}

function resultCount(dbg) {
  return findAllElements(dbg, "resultItems").length;
}

function quickOpen(dbg, query, shortcut = "quickOpen") {
  pressKey(dbg, shortcut);
  assertEnabled(dbg);
  query !== "" && type(dbg, query);
}

function findResultEl(dbg, index = 1) {
  return waitForElementWithSelector(dbg, `.result-item:nth-child(${index})`);
}

async function assertResultIsTab(dbg, index)  {
  const el = await findResultEl(dbg, index);
  ok(el && !!el.querySelector('.tab.result-item-icon'), 'Result should be a tab');
}

// Testing quick open
add_task(async function() {
  const dbg = await initDebugger("doc-script-switching.html");

  info("test opening and closing");
  quickOpen(dbg, "");
  pressKey(dbg, "Escape");
  assertDisabled(dbg);

  info("Testing the number of results for source search");
  quickOpen(dbg, "sw");
  is(resultCount(dbg), 2, "two file results");
  pressKey(dbg, "Escape");

  info("Testing source search and check to see if source is selected");
  await waitForSource(dbg, "switching-01");
  quickOpen(dbg, "sw1");
  is(resultCount(dbg), 1, "one file results");
  pressKey(dbg, "Enter");
  await waitForSelectedSource(dbg, "switching-01");

  info("Test that results show tab icons");
  quickOpen(dbg, "sw1");
  await assertResultIsTab(dbg, 1);
  pressKey(dbg, "Tab");
{'fraction_non_alphanumeric': 0.15111301369863014, 'fraction_numerical': 0.007277397260273972, 'mean_word_length': 4.754926108374384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2002512', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1531, 'n_words': 360}