<commit_before>describe('Observer', function () {
  var Observer = fontface.Observer,
      Ruler = fontface.Ruler;

  describe('#constructor', function () {
    it('creates a new instance with the correct signature', function () {
      var observer = new Observer('my family', {});
      expect(observer, 'not to be', null);
      expect(observer.check, 'to be a function');
    });

    it('parses descriptors', function () {
      var observer = new Observer('my family', {
        weight: 'bold'
      });

      expect(observer.family, 'to equal', 'my family');
      expect(observer.weight, 'to equal', 'bold');
    });

    it('defaults descriptors that are not given', function () {
      var observer = new Observer('my family', {
        weight: 'bold'
      });

      expect(observer.variant, 'to equal', 'normal');
    });
  });

  describe('#getStyle', function () {
    it('creates the correct default style', function () {
      var observer = new Observer('my family', {});

      expect(observer.getStyle(), 'to equal', 'font-style:normal;font-variant:normal;font-weight:normal;font-stretch:stretch;font-feature-settings:normal;-moz-font-feature-settings:normal;-webkit-font-feature-settings:normal;');
    });

    it('passes through all descriptors', function () {
      var observer = new Observer('my family', {
        style: 'italic',
        variant: 'small-caps',
        weight: 'bold',
        stretch: 'condensed',
        featureSettings: '"kern" 1'
      });

      expect(observer.getStyle(), 'to equal', 'font-style:italic;font-variant:small-caps;font-weight:bold;font-stretch:condensed;font-feature-settings:"kern" 1;-moz-font-feature-settings:"kern" 1;-webkit-font-feature-settings:"kern" 1;');
    });
  });

  describe('#check', function () {
    this.timeout(5000);

    it('finds a font and resolve the promise', function (done) {
      var observer = new Observer('observer-test1', {}),
          ruler = new Ruler('hello');

      document.body.appendChild(ruler.getElement());

      ruler.setFont('monospace', '');
      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test1, monospace', '');
      observer.check(null, 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);
          document.body.removeChild(ruler.getElement());
          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('fails to find a font and reject the promise', function (done) {
      var observer = new Observer('observer-test2', {});

      observer.check(null, 50).then(function () {
        done(new Error('Should not resolve'));
      }, function () {
        done();
      });
    });

    it('finds the font even if it is already loaded', function (done) {
      var observer = new Observer('observer-test3', {});

      observer.check(null, 5000).then(function () {
        observer.check(null, 5000).then(function () {
          done();
        }, function () {
          done(new Error('Second call failed'));
        });
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range within ASCII', function (done) {
      var observer = new Observer('observer-test4', {}),
          ruler = new Ruler('\u0021');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test4,monospace', '');

      observer.check('\u0021', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());
          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range outside ASCII (but within BMP)', function (done) {
      var observer = new Observer('observer-test5', {}),
          ruler = new Ruler('\u4e2d\u56fd');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test5,monospace', '');

      observer.check('\u4e2d\u56fd', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());

          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range outside the BMP', function (done) {
      var observer = new Observer('observer-test6', {}),
          ruler = new Ruler('\udbff\udfff');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test6,monospace', '');

      observer.check('\udbff\udfff', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());

          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('fails to find the font if it is available but does not contain the test string', function (done) {
      var observer = new Observer('observer-test7', {});

      observer.check(null, 50).then(function () {
        done(new Error('Should not be called'));
      }, function () {
        done();
      });
    });

    it('finds a locally installed font', function (done) {
      var observer = new Observer('Georgia', {});

      observer.check(null, 50).then(function () {
        done();
      }, function () {
        done(new Error('Did not detect local font'));
      });
    });

    it('finds a locally installed font with the same metrics as the a fallback font (on OS X)', function (done) {
      var observer = new Observer('Tahoma', {});

      observer.check(null, 50).then(function () {
        done();
      }, function () {
        done(new Error('Did not detect local font'));
      });
    });
  });

  describe('hasWebKitFallbackBug', function () {
    var getUserAgent = null;

    beforeEach(function () {
      Observer.HAS_WEBKIT_FALLBACK_BUG = null;

      getUserAgent = sinon.stub(Observer, 'getUserAgent');
    });<commit_msg>Update local font tests.<commit_after>describe('Observer', function () {
  var Observer = fontface.Observer,
      Ruler = fontface.Ruler;

  describe('#constructor', function () {
    it('creates a new instance with the correct signature', function () {
      var observer = new Observer('my family', {});
      expect(observer, 'not to be', null);
      expect(observer.check, 'to be a function');
    });

    it('parses descriptors', function () {
      var observer = new Observer('my family', {
        weight: 'bold'
      });

      expect(observer.family, 'to equal', 'my family');
      expect(observer.weight, 'to equal', 'bold');
    });

    it('defaults descriptors that are not given', function () {
      var observer = new Observer('my family', {
        weight: 'bold'
      });

      expect(observer.variant, 'to equal', 'normal');
    });
  });

  describe('#getStyle', function () {
    it('creates the correct default style', function () {
      var observer = new Observer('my family', {});

      expect(observer.getStyle(), 'to equal', 'font-style:normal;font-variant:normal;font-weight:normal;font-stretch:stretch;font-feature-settings:normal;-moz-font-feature-settings:normal;-webkit-font-feature-settings:normal;');
    });

    it('passes through all descriptors', function () {
      var observer = new Observer('my family', {
        style: 'italic',
        variant: 'small-caps',
        weight: 'bold',
        stretch: 'condensed',
        featureSettings: '"kern" 1'
      });

      expect(observer.getStyle(), 'to equal', 'font-style:italic;font-variant:small-caps;font-weight:bold;font-stretch:condensed;font-feature-settings:"kern" 1;-moz-font-feature-settings:"kern" 1;-webkit-font-feature-settings:"kern" 1;');
    });
  });

  describe('#check', function () {
    this.timeout(5000);

    it('finds a font and resolve the promise', function (done) {
      var observer = new Observer('observer-test1', {}),
          ruler = new Ruler('hello');

      document.body.appendChild(ruler.getElement());

      ruler.setFont('monospace', '');
      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test1, monospace', '');
      observer.check(null, 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);
          document.body.removeChild(ruler.getElement());
          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('fails to find a font and reject the promise', function (done) {
      var observer = new Observer('observer-test2', {});

      observer.check(null, 50).then(function () {
        done(new Error('Should not resolve'));
      }, function () {
        done();
      });
    });

    it('finds the font even if it is already loaded', function (done) {
      var observer = new Observer('observer-test3', {});

      observer.check(null, 5000).then(function () {
        observer.check(null, 5000).then(function () {
          done();
        }, function () {
          done(new Error('Second call failed'));
        });
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range within ASCII', function (done) {
      var observer = new Observer('observer-test4', {}),
          ruler = new Ruler('\u0021');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test4,monospace', '');

      observer.check('\u0021', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());
          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range outside ASCII (but within BMP)', function (done) {
      var observer = new Observer('observer-test5', {}),
          ruler = new Ruler('\u4e2d\u56fd');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test5,monospace', '');

      observer.check('\u4e2d\u56fd', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());

          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('finds a font with a custom unicode range outside the BMP', function (done) {
      var observer = new Observer('observer-test6', {}),
          ruler = new Ruler('\udbff\udfff');

      ruler.setFont('monospace', '');
      document.body.appendChild(ruler.getElement());

      var beforeWidth = ruler.getWidth();

      ruler.setFont('observer-test6,monospace', '');

      observer.check('\udbff\udfff', 5000).then(function () {
        var activeWidth = ruler.getWidth();

        expect(activeWidth, 'not to equal', beforeWidth);

        setTimeout(function () {
          var afterWidth = ruler.getWidth();

          expect(afterWidth, 'to equal', activeWidth);
          expect(afterWidth, 'not to equal', beforeWidth);

          document.body.removeChild(ruler.getElement());

          done();
        }, 0);
      }, function () {
        done(new Error('Timeout'));
      });
    });

    it('fails to find the font if it is available but does not contain the test string', function (done) {
      var observer = new Observer('observer-test7', {});

      observer.check(null, 50).then(function () {
        done(new Error('Should not be called'));
      }, function () {
        done();
      });
    });

    it('finds a locally installed font', function (done) {
      var observer = new Observer('sans-serif', {});

      observer.check(null, 50).then(function () {
        done();
      }, function () {
        done(new Error('Did not detect local font'));
      });
    });

    it('finds a locally installed font with the same metrics as the a fallback font (on OS X)', function (done) {
      var observer = new Observer('serif', {});

      observer.check(null, 50).then(function () {
        done();
      }, function () {
        done(new Error('Did not detect local font'));
      });
    });
  });

  describe('hasWebKitFallbackBug', function () {
    var getUserAgent = null;

    beforeEach(function () {
      Observer.HAS_WEBKIT_FALLBACK_BUG = null;

      getUserAgent = sinon.stub(Observer, 'getUserAgent');
    });
{'fraction_non_alphanumeric': 0.15758661064811627, 'fraction_numerical': 0.009780287898615608, 'mean_word_length': 2.653749370910921, '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': '3180574', 'n_tokens_mistral': 4338, 'n_tokens_neox': 3996, 'n_words': 969}