<commit_before>// Copyright (c) 2011 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 "chrome/browser/extensions/extension_apitest.h"

#include "base/stringprintf.h"
#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/extensions/extension_test_api.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/common/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char kNewInputMethod[] = "ru::rus";
const char kSetInputMethodMessage[] = "setInputMethod";
const char kSetInputMethodDone[] = "done";

// Class that listens for the JS message then changes input method and replies
// back.
class SetInputMethodListener : public content::NotificationObserver {
 public:
  // Creates listener, which should reply exactly |count_| times.
  explicit SetInputMethodListener(int count) : count_(count) {
    registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
                   NotificationService::AllSources());
  }

  virtual ~SetInputMethodListener() {
    EXPECT_EQ(0, count_);
  }

  // Implements the content::NotificationObserver interface.
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) {
    const std::string& content = *Details<std::string>(details).ptr();
    const std::string expected_message = StringPrintf("%s:%s",
                                                      kSetInputMethodMessage,
                                                      kNewInputMethod);
    if (content == expected_message) {
      chromeos::input_method::InputMethodManager::GetInstance()->
          ChangeInputMethod(StringPrintf("xkb:%s", kNewInputMethod));

      ExtensionTestSendMessageFunction* function =
          content::Source<ExtensionTestSendMessageFunction>(source).ptr();
      EXPECT_GT(count_--, 0);
      function->Reply(kSetInputMethodDone);
    }
  }<commit_msg>Fix more cros build errors in tests.<commit_after>// Copyright (c) 2011 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 "chrome/browser/extensions/extension_apitest.h"

#include "base/stringprintf.h"
#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/extensions/extension_test_api.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/common/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char kNewInputMethod[] = "ru::rus";
const char kSetInputMethodMessage[] = "setInputMethod";
const char kSetInputMethodDone[] = "done";

// Class that listens for the JS message then changes input method and replies
// back.
class SetInputMethodListener : public content::NotificationObserver {
 public:
  // Creates listener, which should reply exactly |count_| times.
  explicit SetInputMethodListener(int count) : count_(count) {
    registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
                   NotificationService::AllSources());
  }

  virtual ~SetInputMethodListener() {
    EXPECT_EQ(0, count_);
  }

  // Implements the content::NotificationObserver interface.
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) {
    const std::string& content = *content::Details<std::string>(details).ptr();
    const std::string expected_message = StringPrintf("%s:%s",
                                                      kSetInputMethodMessage,
                                                      kNewInputMethod);
    if (content == expected_message) {
      chromeos::input_method::InputMethodManager::GetInstance()->
          ChangeInputMethod(StringPrintf("xkb:%s", kNewInputMethod));

      ExtensionTestSendMessageFunction* function =
          content::Source<ExtensionTestSendMessageFunction>(source).ptr();
      EXPECT_GT(count_--, 0);
      function->Reply(kSetInputMethodDone);
    }
  }
{'fraction_non_alphanumeric': 0.10534252477380439, 'fraction_numerical': 0.0025850926324859974, 'mean_word_length': 3.67102615694165, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561906', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1209, 'n_words': 278}