<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


// Ensure l10n is working as expected based on the
// user's `Accept-Language` headers

define([
  'intern',
  'intern!object',
  'intern/chai!assert',
  'intern/dojo/node!../../server/lib/configuration',
  'intern/dojo/node!request'
], function (intern, registerSuite, assert, config, request) {
  'use strict';

  var serverUrl = intern.config.fxaContentRoot.replace(/\/$/, '');

  var asyncTimeout = 5000;

  var suite = {
    name: 'i18n'
  };

  function testClientJson(acceptLanguageHeader, expectedLanguage) {
    /*jshint validthis: true*/
    var dfd = this.async(asyncTimeout);

    var headers = {};
    if (acceptLanguageHeader) {
      headers['Accept-Language'] = acceptLanguageHeader;
    }

    request(serverUrl + '/i18n/client.json', {
      headers: headers
    }, dfd.callback(function (err, res) {
      assert.equal(res.statusCode, 200);
      assert.equal(res.headers['content-type'], 'application/json; charset=utf-8');
      // Response differs depending on the Accept-Language, let all
      // intermediaries know this.
      //
      // Note: in production, for /i18n/client.json, nginx can do gzip compression,
      // and will add the header 'Vary: Accept-Encoding' in addition to the 'Vary:
      // Accept-Language' that is set by nodejs on the server-side. However, while
      // that is legal in HTTP, in nodejs < 0.11.11 on the client-side, the second
      // 'Vary:' header clobbers the first one. In nodejs >= 0.11.11, the two headers
      // are folded into one comma-separated value. Which leads to this way too
      // complicated test condition. See https://github.com/joyent/node/pull/6821.
      //
      assert.ok(res.headers.vary, 'the vary header exists');
      var varyHeader = res.headers.vary.toLowerCase().split(/,\s*/);
      if (intern.config.fxaProduction) {
        if (process.versions['node'] < '0.11.11') {
          assert.ok(varyHeader.indexOf('accept-encoding') !== -1);
        } else {
          assert.ok(varyHeader.indexOf('accept-language') !== -1 &&
                    varyHeader.indexOf('accept-encoding') !== -1);
        }
      } else {
        assert.ok(varyHeader.indexOf('accept-language') !== -1);
      }
<commit_msg>test as two separate assertions<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


// Ensure l10n is working as expected based on the
// user's `Accept-Language` headers

define([
  'intern',
  'intern!object',
  'intern/chai!assert',
  'intern/dojo/node!../../server/lib/configuration',
  'intern/dojo/node!request'
], function (intern, registerSuite, assert, config, request) {
  'use strict';

  var serverUrl = intern.config.fxaContentRoot.replace(/\/$/, '');

  var asyncTimeout = 5000;

  var suite = {
    name: 'i18n'
  };

  function testClientJson(acceptLanguageHeader, expectedLanguage) {
    /*jshint validthis: true*/
    var dfd = this.async(asyncTimeout);

    var headers = {};
    if (acceptLanguageHeader) {
      headers['Accept-Language'] = acceptLanguageHeader;
    }

    request(serverUrl + '/i18n/client.json', {
      headers: headers
    }, dfd.callback(function (err, res) {
      assert.equal(res.statusCode, 200);
      assert.equal(res.headers['content-type'], 'application/json; charset=utf-8');
      // Response differs depending on the Accept-Language, let all
      // intermediaries know this.
      //
      // Note: in production, for /i18n/client.json, nginx can do gzip compression,
      // and will add the header 'Vary: Accept-Encoding' in addition to the 'Vary:
      // Accept-Language' that is set by nodejs on the server-side. However, while
      // that is legal in HTTP, in nodejs < 0.11.11 on the client-side, the second
      // 'Vary:' header clobbers the first one. In nodejs >= 0.11.11, the two headers
      // are folded into one comma-separated value. Which leads to this way too
      // complicated test condition. See https://github.com/joyent/node/pull/6821.
      //
      assert.ok(res.headers.vary, 'the vary header exists');
      var varyHeader = res.headers.vary.toLowerCase().split(/,\s*/);
      if (intern.config.fxaProduction) {
        if (process.versions['node'] < '0.11.11') {
          assert.ok(varyHeader.indexOf('accept-encoding') !== -1);
        } else {
          assert.ok(varyHeader.indexOf('accept-language') !== -1);
          assert.ok(varyHeader.indexOf('accept-encoding') !== -1);
        }
      } else {
        assert.ok(varyHeader.indexOf('accept-language') !== -1);
      }

{'fraction_non_alphanumeric': 0.14118131302737189, 'fraction_numerical': 0.017699115044247787, 'mean_word_length': 2.770364623739333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6774637', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1446, 'n_words': 418}