<commit_before>import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';

const { run } = Ember;

moduleFor('service:window-messenger-events', 'Unit | Service | window messenger events', {
  // Specify the other units that are required for this test.
  // needs: ['service:foo']
});

test('it should register and deregister message event listener', function(assert) {
  assert.expect(1);

  let service = this.subject();

  let message = JSON.stringify({
    id: +new Date(),
    type: 'test-dummy',
    name: 'hello-world',
    query: {}
  });

  service.on('from:test-dummy', (payload) => {
    assert.equal(payload.name, 'hello-world');
    run(() => {
      service.destroy();
    });
  });
  // send first message
  window.postMessage(message, '*');

  // send second message
  window.postMessage(message, '*');
});<commit_msg>Add test case for not allowed origin<commit_after>import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';

const { run } = Ember;

moduleFor('service:window-messenger-events', 'Unit | Service | window messenger events', {
  // Specify the other units that are required for this test.
  // needs: ['service:foo']
});

test('it should register and deregister message event listener', function(assert) {
  assert.expect(1);

  let service = this.subject();

  let message = JSON.stringify({
    id: +new Date(),
    type: 'test-dummy',
    name: 'hello-world',
    query: {}
  });

  service.on('from:test-dummy', (payload) => {
    assert.equal(payload.name, 'hello-world');
    run(() => {
      service.destroy();
    });
  });
  // send first message
  window.postMessage(message, '*');

  // send second message
  window.postMessage(message, '*');
});

test('it should handle message, if not allowed origin', function(assert) {
  assert.expect(0);

  let service = this.subject();
  let message = JSON.stringify({
    id: +new Date(),
    type: 'test-dummy',
    name: 'hello-world',
    query: {}
  });

  service.on('from:test-dummy', () => {
    assert.ok(true);
  });

  window.postMessage(message, 'http://localhost:9999');
})
{'fraction_non_alphanumeric': 0.17341591233920914, 'fraction_numerical': 0.0033349213911386373, 'mean_word_length': 3.5454545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4224528', 'n_tokens_mistral': 666, 'n_tokens_neox': 641, 'n_words': 170}