<commit_before>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_
#define CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_

#include "build/build_config.h"

#include <string>

#include "app/app_paths.h"
#include "app/resource_bundle.h"
#include "base/stats_table.h"
#include "base/file_util.h"
#if defined(OS_MACOSX)
#include "base/mac_util.h"
#endif
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "base/scoped_nsautorelease_pool.h"
#include "base/test_suite.h"
#include "chrome/app/scoped_ole_initializer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#if defined(OS_MACOSX)
#include "chrome/common/mac_app_names.h"
#endif
#include "chrome/test/testing_browser_process.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/net_util.h"

// In many cases it may be not obvious that a test makes a real DNS lookup.
// We generally don't want to rely on external DNS servers for our tests,
// so this host resolver procedure catches external queries.
class WarningHostResolverProc : public net::HostResolverProc {
 public:
  WarningHostResolverProc() : HostResolverProc(NULL) {}

  virtual int Resolve(const std::string& host, net::AddressList* addrlist) {
    const char* kLocalHostNames[] = {"localhost", "127.0.0.1"};
    bool local = false;

    if (host == net::GetHostName()) {
      local = true;
    } else {
      for (size_t i = 0; i < arraysize(kLocalHostNames); i++)
        if (host == kLocalHostNames[i]) {
          local = true;
          break;
        }
    }

    // Make the test fail so it's harder to ignore.
    // If you really need to make real DNS query, use
    // net::RuleBasedHostResolverProc and its AllowDirectLookup method.
    EXPECT_TRUE(local) << "Making external DNS lookup of " << host;

    return ResolveUsingPrevious(host, addrlist);
  }
};

class ChromeTestSuite : public TestSuite {
 public:
  ChromeTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
  }

 protected:

  virtual void Initialize() {
    base::ScopedNSAutoreleasePool autorelease_pool;

    TestSuite::Initialize();

    host_resolver_proc_ = new WarningHostResolverProc();
    scoped_host_resolver_proc_.Init(host_resolver_proc_.get());

    chrome::RegisterPathProvider();
    app::RegisterPathProvider();<commit_msg>Coverity: Initialize stats_table_ in the constructor.<commit_after>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_
#define CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_

#include <string>

#include "build/build_config.h"

#include "app/app_paths.h"
#include "app/resource_bundle.h"
#include "base/stats_table.h"
#include "base/file_util.h"
#if defined(OS_MACOSX)
#include "base/mac_util.h"
#endif
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "base/scoped_nsautorelease_pool.h"
#include "base/test_suite.h"
#include "chrome/app/scoped_ole_initializer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#if defined(OS_MACOSX)
#include "chrome/common/mac_app_names.h"
#endif
#include "chrome/test/testing_browser_process.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/net_util.h"

// In many cases it may be not obvious that a test makes a real DNS lookup.
// We generally don't want to rely on external DNS servers for our tests,
// so this host resolver procedure catches external queries.
class WarningHostResolverProc : public net::HostResolverProc {
 public:
  WarningHostResolverProc() : HostResolverProc(NULL) {}

  virtual int Resolve(const std::string& host, net::AddressList* addrlist) {
    const char* kLocalHostNames[] = {"localhost", "127.0.0.1"};
    bool local = false;

    if (host == net::GetHostName()) {
      local = true;
    } else {
      for (size_t i = 0; i < arraysize(kLocalHostNames); i++)
        if (host == kLocalHostNames[i]) {
          local = true;
          break;
        }
    }

    // Make the test fail so it's harder to ignore.
    // If you really need to make real DNS query, use
    // net::RuleBasedHostResolverProc and its AllowDirectLookup method.
    EXPECT_TRUE(local) << "Making external DNS lookup of " << host;

    return ResolveUsingPrevious(host, addrlist);
  }
};

class ChromeTestSuite : public TestSuite {
 public:
  ChromeTestSuite(int argc, char** argv)
      : TestSuite(argc, argv),
        stats_table_(NULL) {
  }

 protected:

  virtual void Initialize() {
    base::ScopedNSAutoreleasePool autorelease_pool;

    TestSuite::Initialize();

    host_resolver_proc_ = new WarningHostResolverProc();
    scoped_host_resolver_proc_.Init(host_resolver_proc_.get());

    chrome::RegisterPathProvider();
    app::RegisterPathProvider();
{'fraction_non_alphanumeric': 0.11344868265827762, 'fraction_numerical': 0.005898545025560362, 'mean_word_length': 4.298958333333333, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5814016', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1638, 'n_words': 431}