<commit_before>'use strict';

describe('_broadcast', function () {
  it('should not throw exception when postMessage is denied', function () {
    var frame = mkFrame(this);
    frame.postMessage = function () {
      throw new Error('Invalid calling object');
    }

    var self = this;
    expect(function () {
      self.bus._broadcast(frame, 'payload', '*');
    }).not.to.throw();
  });
  it('should postMessage to current frame', function () {
    var frame = mkFrame(this);
    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.postMessage).to.have.been.called;
  });

  it("should postMessage to current frame's child frames", function () {
    var frame = mkFrame(this);
    frame.frames.push(mkFrame(this));

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.frames[0].postMessage).to.have.been.called;
  });

  it('should postMessage to window.opener if it exists', function () {
    var frame = mkFrame(this);
    frame.opener = {};
    frame.opener.top = {
      postMessage: this.sandbox.spy(),
      frames: []
    };

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.opener.top.postMessage).to.have.been.called;
  });

  it('should not postMessage to window.opener if it has closed', function () {
    var frame = mkFrame(this);
    frame.opener = {};
    frame.opener.closed = true;
    frame.opener.top = {
      postMessage: this.sandbox.spy(),
      frames: []
    };

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.opener.top.postMessage).not.to.have.been.called;
  });

  it.only('should not infinitely recurse if opener is itself', function (done) {
    var frame = mkFrame(this);
    frame.opener = frame;
    frame.top = frame;
<commit_msg>Fixing frame.opener === frame test to be more consistent<commit_after>'use strict';

describe('_broadcast', function () {
  it('should not throw exception when postMessage is denied', function () {
    var frame = mkFrame(this);
    frame.postMessage = function () {
      throw new Error('Invalid calling object');
    }

    var self = this;
    expect(function () {
      self.bus._broadcast(frame, 'payload', '*');
    }).not.to.throw();
  });
  it('should postMessage to current frame', function () {
    var frame = mkFrame(this);
    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.postMessage).to.have.been.called;
  });

  it("should postMessage to current frame's child frames", function () {
    var frame = mkFrame(this);
    frame.frames.push(mkFrame(this));

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.frames[0].postMessage).to.have.been.called;
  });

  it('should postMessage to window.opener if it exists', function () {
    var frame = mkFrame(this);
    frame.opener = {};
    frame.opener.top = {
      postMessage: this.sandbox.spy(),
      frames: []
    };

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.opener.top.postMessage).to.have.been.called;
  });

  it('should not postMessage to window.opener if it has closed', function () {
    var frame = mkFrame(this);
    frame.opener = {};
    frame.opener.closed = true;
    frame.opener.top = {
      postMessage: this.sandbox.spy(),
      frames: []
    };

    this.bus._broadcast(frame, 'payload', '*');

    expect(frame.opener.top.postMessage).not.to.have.been.called;
  });

  it('should not infinitely recurse if opener is itself', function (done) {
    var frame = mkFrame(this);

    this.timeout(10);
    frame.opener = frame;
    frame.top = frame;

{'fraction_non_alphanumeric': 0.1610337972166998, 'fraction_numerical': 0.001136040897472309, 'mean_word_length': 3.182897862232779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3600155', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1090, 'n_words': 240}