<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.

#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/browser/url_fixer_upper.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_process_filter.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "chrome/test/perf/mem_usage.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"

namespace {

class MemoryTest : public UITest {
 public:
  MemoryTest() {
    show_window_ = true;

    // For now, turn off plugins because they crash like crazy.
    // TODO(mbelshe): Fix Chrome to not crash with plugins.
    CommandLine::AppendSwitch(&launch_arguments_, switches::kDisablePlugins);

    CommandLine::AppendSwitch(&launch_arguments_, switches::kEnableLogging);

    // Use the playback cache, but don't use playback events.
    CommandLine::AppendSwitch(&launch_arguments_, switches::kPlaybackMode);
    CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents);

    // Compute the user-data-dir which contains our test cache.
    PathService::Get(base::DIR_EXE, &user_data_dir_);
    file_util::UpOneDirectory(&user_data_dir_);
    file_util::UpOneDirectory(&user_data_dir_);
    file_util::AppendToPath(&user_data_dir_, L"data");
    file_util::AppendToPath(&user_data_dir_, L"memory_test");
    file_util::AppendToPath(&user_data_dir_, L"general_mix");
    CommandLine::AppendSwitchWithValue(&launch_arguments_,
                                       switches::kUserDataDir,
                                       user_data_dir_);
  }

  // TODO(mbelshe): Separate this data to an external file.
  // This memory test loads a set of URLs across a set of tabs, maintaining the
  // number of concurrent open tabs at num_target_tabs.
  // <NEWTAB> is a special URL which informs the loop when we should create a
  // new tab.
  // <PAUSE> is a special URL that informs the loop to pause before proceeding
  // to the next URL.
  void RunTest(const wchar_t* test_name, int num_target_tabs) {
    std::string urls[] = {
      "http://www.yahoo.com/",
      "http://hotjobs.yahoo.com/career-articles-the_biggest_resume_mistake_you_can_make-436",
      "http://news.yahoo.com/s/ap/20080804/ap_on_re_mi_ea/odd_israel_home_alone",
      "http://news.yahoo.com/s/nm/20080729/od_nm/subway_dc",
      "http://search.yahoo.com/search?p=new+york+subway&ygmasrchbtn=web+search&fr=ush-news",
      "<NEWTAB>",
      "http://www.cnn.com/",
      "http://www.cnn.com/2008/SHOWBIZ/TV/08/03/applegate.cancer.ap/index.html",
      "http://www.cnn.com/2008/HEALTH/conditions/07/29/black.aids.report/index.html",
      "http://www.cnn.com/POLITICS/",
      "http://search.cnn.com/search.jsp?query=obama&type=web&sortBy=date&intl=false",<commit_msg>Make the user data directory configurable from the cmdline for the memory tests.<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.

#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/browser/url_fixer_upper.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_process_filter.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "chrome/test/perf/mem_usage.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"

namespace {

class MemoryTest : public UITest {
 public:
  MemoryTest() {
    show_window_ = true;

    // For now, turn off plugins because they crash like crazy.
    // TODO(mbelshe): Fix Chrome to not crash with plugins.
    CommandLine::AppendSwitch(&launch_arguments_, switches::kDisablePlugins);

    CommandLine::AppendSwitch(&launch_arguments_, switches::kEnableLogging);

    // Use the playback cache, but don't use playback events.
    CommandLine::AppendSwitch(&launch_arguments_, switches::kPlaybackMode);
    CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents);

    // Get the specified user data dir (optional)
    user_data_dir_ = CommandLine().GetSwitchValue(switches::kUserDataDir);

    if (user_data_dir_.length() == 0) {
      // Compute the user-data-dir which contains our test cache.
      PathService::Get(base::DIR_EXE, &user_data_dir_);
      file_util::UpOneDirectory(&user_data_dir_);
      file_util::UpOneDirectory(&user_data_dir_);
      file_util::AppendToPath(&user_data_dir_, L"data");
      file_util::AppendToPath(&user_data_dir_, L"memory_test");
      file_util::AppendToPath(&user_data_dir_, L"general_mix");
    }
    CommandLine::AppendSwitchWithValue(&launch_arguments_,
                                       switches::kUserDataDir,
                                       user_data_dir_);
  }

  // TODO(mbelshe): Separate this data to an external file.
  // This memory test loads a set of URLs across a set of tabs, maintaining the
  // number of concurrent open tabs at num_target_tabs.
  // <NEWTAB> is a special URL which informs the loop when we should create a
  // new tab.
  // <PAUSE> is a special URL that informs the loop to pause before proceeding
  // to the next URL.
  void RunTest(const wchar_t* test_name, int num_target_tabs) {
    std::string urls[] = {
      "http://www.yahoo.com/",
      "http://hotjobs.yahoo.com/career-articles-the_biggest_resume_mistake_you_can_make-436",
      "http://news.yahoo.com/s/ap/20080804/ap_on_re_mi_ea/odd_israel_home_alone",
      "http://news.yahoo.com/s/nm/20080729/od_nm/subway_dc",
      "http://search.yahoo.com/search?p=new+york+subway&ygmasrchbtn=web+search&fr=ush-news",
      "<NEWTAB>",
      "http://www.cnn.com/",
      "http://www.cnn.com/2008/SHOWBIZ/TV/08/03/applegate.cancer.ap/index.html",
      "http://www.cnn.com/2008/HEALTH/conditions/07/29/black.aids.report/index.html",
      "http://www.cnn.com/POLITICS/",
      "http://search.cnn.com/search.jsp?query=obama&type=web&sortBy=date&intl=false",
{'fraction_non_alphanumeric': 0.13082303914272958, 'fraction_numerical': 0.012948355410031255, 'mean_word_length': 3.9051094890510947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6631092', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2211, 'n_words': 447}