<commit_before>asynctest(
  'browser.tinymce.plugins.link.AllowUnsafeLinkTargetTest',
  [
    'ephox.agar.api.Pipeline',
    'ephox.agar.api.Step',
    'ephox.mcagar.api.TinyApis',
    'ephox.mcagar.api.TinyLoader',
    'ephox.mcagar.api.TinyUi',
    'tinymce.core.dom.DOMUtils',
    'tinymce.plugins.link.Plugin',
    'tinymce.themes.modern.Theme'
  ],
  function (Pipeline, Step, TinyApis, TinyLoader, TinyUi, DOMUtils, LinkPlugin, ModernTheme) {
    var success = arguments[arguments.length - 2];
    var failure = arguments[arguments.length - 1];

    ModernTheme();
    LinkPlugin();

    var sEnterUrl = function (url) {
      return Step.sync(function () {
        var input = document.activeElement;

        input.value = url;
        DOMUtils.DOM.fire(input, 'change');
      });
    };

    TinyLoader.setup(function (editor, onSuccess, onFailure) {
      var tinyUi = TinyUi(editor);
      var tinyApis = TinyApis(editor);

      Pipeline.async({}, [
        // doesn't add rel noopener stuff with allow_unsafe_link_target: true
        tinyUi.sClickOnToolbar('click link button', 'div[aria-label="Insert/edit link"] > button'),
        tinyUi.sWaitForPopup('wait for link dialog', 'div[aria-label="Insert link"][role="dialog"]'),
        sEnterUrl('http://www.google.com'),
        tinyUi.sClickOnUi('click ok button', 'button:contains("Ok")'),
        tinyApis.sAssertContentPresence({ 'a[rel="noopener"]': 0, 'a': 1 }),
        tinyApis.sSetContent(''),

        // adds if allow_unsafe_link_target: false
        tinyApis.sSetSetting('allow_unsafe_link_target', false),
        tinyUi.sClickOnToolbar('click link button', 'div[aria-label="Insert/edit link"] > button'),
        tinyUi.sWaitForPopup('wait for link dialog', 'div[aria-label="Insert link"][role="dialog"]'),
        sEnterUrl('http://www.google.com'),
        tinyUi.sClickOnUi('click ok button', 'button:contains("Ok")'),
        tinyApis.sAssertContentPresence({ 'a[rel="noopener"]': 1 }),
        tinyApis.sSetContent(''),

        // and if it's undefined
        tinyApis.sSetSetting('allow_unsafe_link_target', undefined),
        tinyUi.sClickOnToolbar('click link button', 'div[aria-label="Insert/edit link"] > button'),
        tinyUi.sWaitForPopup('wait for link dialog', 'div[aria-label="Insert link"][role="dialog"]'),
        sEnterUrl('http://www.google.com'),
        tinyUi.sClickOnUi('click ok button', 'button:contains("Ok")'),
        tinyApis.sAssertContentPresence({ 'a[rel="noopener"]': 1 })
      ], onSuccess, onFailure);
    }, {
      plugins: 'link',
      toolbar: 'link',
      skin_url: '/project/src/skins/lightgray/dist/lightgray',
      allow_unsafe_link_target: true,
      target_list: [
        { title: 'New page', value: '_blank' }
      ]
    }, success, failure);
  }
);<commit_msg>TINY-1069, link: simplify AllowUnsafeLinkTargetTest<commit_after>asynctest(
  'browser.tinymce.plugins.link.AllowUnsafeLinkTargetTest',
  [
    'ephox.agar.api.GeneralSteps',
    'ephox.agar.api.Logger',
    'ephox.agar.api.Pipeline',
    'ephox.agar.api.Step',
    'ephox.mcagar.api.TinyApis',
    'ephox.mcagar.api.TinyLoader',
    'ephox.mcagar.api.TinyUi',
    'tinymce.core.dom.DOMUtils',
    'tinymce.plugins.link.Plugin',
    'tinymce.themes.modern.Theme'
  ],
  function (GeneralSteps, Logger, Pipeline, Step, TinyApis, TinyLoader, TinyUi, DOMUtils, LinkPlugin, ModernTheme) {
    var success = arguments[arguments.length - 2];
    var failure = arguments[arguments.length - 1];

    ModernTheme();
    LinkPlugin();

    var sEnterUrl = function (url) {
      return Step.sync(function () {
        var input = document.activeElement;

        input.value = url;
        DOMUtils.DOM.fire(input, 'change');
      });
    };

    var sInsertLink = function (ui, url) {
      return GeneralSteps.sequence([
        ui.sClickOnToolbar('click link button', 'div[aria-label="Insert/edit link"] > button'),
        ui.sWaitForPopup('wait for link dialog', 'div[aria-label="Insert link"][role="dialog"]'),
        sEnterUrl(url),
        ui.sClickOnUi('click ok button', 'button:contains("Ok")')
      ]);
    };

    TinyLoader.setup(function (editor, onSuccess, onFailure) {
      var ui = TinyUi(editor);
      var api = TinyApis(editor);

      Pipeline.async({}, [
        Logger.t("doesn't add rel noopener stuff with allow_unsafe_link_target: true", GeneralSteps.sequence([
          api.sSetSetting('allow_unsafe_link_target', true),
          sInsertLink(ui, 'http://www.google.com'),
          api.sAssertContentPresence({ 'a[rel="noopener"]': 0, 'a': 1 }),
          api.sSetContent('')
        ])),

        Logger.t("adds if allow_unsafe_link_target: false", GeneralSteps.sequence([
          api.sSetSetting('allow_unsafe_link_target', false),
          sInsertLink(ui, 'http://www.google.com'),
          api.sAssertContentPresence({ 'a[rel="noopener"]': 1 }),
          api.sSetContent('')
        ])),

        Logger.t("...and if it's undefined", GeneralSteps.sequence([
          api.sSetSetting('allow_unsafe_link_target', undefined),
          sInsertLink(ui, 'http://www.google.com'),
          api.sAssertContentPresence({ 'a[rel="noopener"]': 1 })
        ]))

      ], onSuccess, onFailure);
    }, {
      plugins: 'link',
      toolbar: 'link',
      skin_url: '/project/src/skins/lightgray/dist/lightgray',
      target_list: [
        { title: 'New page', value: '_blank' }
      ]
    }, success, failure);
  }
);
{'fraction_non_alphanumeric': 0.15935377271892784, 'fraction_numerical': 0.0029373967321461355, 'mean_word_length': 3.1272727272727274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4044356', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1759, 'n_words': 299}