<commit_before>// Copyright 2014 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/prefs/pref_service.h"
#include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/webui/options/options_ui_browsertest.h"
#include "chrome/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"

namespace options {

class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
 protected:
  void ClickElement(const std::string& selector) {
    bool element_enabled = false;
    ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled));
    ASSERT_TRUE(element_enabled);
    ASSERT_TRUE(content::ExecuteScript(
        GetSettingsFrame(),
        "document.querySelector('" + selector + "').click();"));
  }

  bool IsElementEnabled(const std::string& selector) {
    bool element_enabled = false;
    GetElementEnabledState(selector, &element_enabled);
    return element_enabled;
  }

  bool IsElementInFocus(const std::string& selector) {
    bool element_in_focus = false;
    EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
        GetSettingsFrame(),
        "window.domAutomationController.send(document.querySelector('" +
            selector + "') == document.activeElement);",
        &element_in_focus));
    return element_in_focus;
  }

 private:
  void GetElementEnabledState(
      const std::string& selector,
      bool* enabled) {
    ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
        GetSettingsFrame(),
        "window.domAutomationController.send(!document.querySelector('" +
            selector + "').disabled);",
        enabled));
  }
};

IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
                       CommitButtonDisabledWhileDeletionInProgress) {
  const char kTimePeriodSelectorId[] = "#clear-browser-data-time-period";
  const char kCommitButtonId[] = "#clear-browser-data-commit";
  BrowsingDataRemoverCompletionInhibitor completion_inhibitor;

  // Navigate to the Clear Browsing Data dialog to ensure that the commit button
  // is initially enabled, usable, and gets disabled after having been pressed.
  // Furthermore, verify that the time period combo-box gets the initial focus.
  NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
  EXPECT_TRUE(IsElementInFocus(kTimePeriodSelectorId));
  ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId));<commit_msg>ClearBrowserDataBrowserTest.CommitButtonDisabledWhileDeletionInProgress is still extremely flaky on all bots, so disabling again.<commit_after>// Copyright 2014 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/prefs/pref_service.h"
#include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/webui/options/options_ui_browsertest.h"
#include "chrome/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"

namespace options {

class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
 protected:
  void ClickElement(const std::string& selector) {
    bool element_enabled = false;
    ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled));
    ASSERT_TRUE(element_enabled);
    ASSERT_TRUE(content::ExecuteScript(
        GetSettingsFrame(),
        "document.querySelector('" + selector + "').click();"));
  }

  bool IsElementEnabled(const std::string& selector) {
    bool element_enabled = false;
    GetElementEnabledState(selector, &element_enabled);
    return element_enabled;
  }

  bool IsElementInFocus(const std::string& selector) {
    bool element_in_focus = false;
    EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
        GetSettingsFrame(),
        "window.domAutomationController.send(document.querySelector('" +
            selector + "') == document.activeElement);",
        &element_in_focus));
    return element_in_focus;
  }

 private:
  void GetElementEnabledState(
      const std::string& selector,
      bool* enabled) {
    ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
        GetSettingsFrame(),
        "window.domAutomationController.send(!document.querySelector('" +
            selector + "').disabled);",
        enabled));
  }
};

// Fails flakily. http://crbug.com/379574
IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
                       DISABLED_CommitButtonDisabledWhileDeletionInProgress) {
  const char kTimePeriodSelectorId[] = "#clear-browser-data-time-period";
  const char kCommitButtonId[] = "#clear-browser-data-commit";
  BrowsingDataRemoverCompletionInhibitor completion_inhibitor;

  // Navigate to the Clear Browsing Data dialog to ensure that the commit button
  // is initially enabled, usable, and gets disabled after having been pressed.
  // Furthermore, verify that the time period combo-box gets the initial focus.
  NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
  EXPECT_TRUE(IsElementInFocus(kTimePeriodSelectorId));
  ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId));
{'fraction_non_alphanumeric': 0.09923378807699496, 'fraction_numerical': 0.002616333395626986, 'mean_word_length': 4.681528662420382, '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': '3834723', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1517, 'n_words': 320}