Commit 3b823d01 authored by engedy@chromium.org's avatar engedy@chromium.org

Fix initial focus, and the way elements are disabled on the 'Clear browsing data' dialog.

 * Fix a regression so that once again the time range selector combo-box is in focus initially.
 * Clean up the code that determines which controls should be enabled/disabled/hidden on the dialog.
 * Reduce the number of controls that flicker (i.e. change state from disabled->enabled visibly) on opening the dialog in the most likely use-case, i.e., instead of starting with everything disabled, only have the commit button initially disabled.
 * Fix a regression so that once again some checkboxes can be disabled by policies. (I think this was also broken.)

BUG=365206

Review URL: https://codereview.chromium.org/275483005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274090 0039d316-1c4b-4281-b951-d872f2087c98
parent fb5c9998
......@@ -34,7 +34,18 @@ cr.define('options', function() {
* @type {boolean}
* @private
*/
isClearingInProgress_: true,
isClearingInProgress_: false,
/**
* Whether or not the WebUI handler has completed initialization.
*
* Unless this becomes true, it must be assumed that the above flags might
* not contain the authoritative values.
*
* @type {boolean}
* @private
*/
isInitializationComplete_: false,
/**
* Initialize the page.
......@@ -43,7 +54,7 @@ cr.define('options', function() {
// Call base class implementation to starts preference initialization.
OptionsPage.prototype.initializePage.call(this);
var f = this.updateCommitButtonState_.bind(this);
var f = this.updateStateOfControls_.bind(this);
var types = ['browser.clear_data.browsing_history',
'browser.clear_data.download_history',
'browser.clear_data.cache',
......@@ -62,12 +73,6 @@ cr.define('options', function() {
checkboxes[i].onclick = f;
}
// At this point, assume that we are currently in the process of clearing
// data, so as to prevent the controls from being hazardously enabled for
// a very short time before ClearBrowserDataOverlay.setClearing() is
// called by the native side with the authoritative state.
this.setClearing(true);
this.createStuffRemainsFooter_();
$('clear-browser-data-dismiss').onclick = function(event) {
......@@ -78,8 +83,15 @@ cr.define('options', function() {
chrome.send('performClearBrowserData');
};
var show = loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes');
this.showDeleteHistoryCheckboxes_(show);
// For managed profiles, hide the checkboxes controlling whether or not
// browsing and download history should be cleared. Note that this is
// different than just disabling them as a result of enterprise policies.
if (!loadTimeData.getBoolean('showDeleteBrowsingHistoryCheckboxes')) {
$('delete-browsing-history-container').hidden = true;
$('delete-download-history-container').hidden = true;
}
this.updateStateOfControls_();
},
/**
......@@ -133,85 +145,100 @@ cr.define('options', function() {
},
/**
* Sets the enabled state of the checkboxes and buttons based on whether or
* not we are in the process of clearing data.
* @param {boolean} clearing Whether the browsing history is currently
* being cleared.
* Sets whether or not we are in the process of clearing data.
* @param {boolean} clearing Whether the browsing data is currently being
* cleared.
* @private
*/
setClearing: function(clearing) {
$('delete-browsing-history-checkbox').disabled = clearing;
$('delete-download-history-checkbox').disabled = clearing;
$('delete-cache-checkbox').disabled = clearing;
$('delete-cookies-checkbox').disabled = clearing;
$('delete-passwords-checkbox').disabled = clearing;
$('delete-form-data-checkbox').disabled = clearing;
$('delete-hosted-apps-data-checkbox').disabled = clearing;
$('deauthorize-content-licenses-checkbox').disabled = clearing;
$('clear-browser-data-time-period').disabled = clearing;
$('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden';
$('clear-browser-data-dismiss').disabled = clearing;
// The enabled state of the commit button is further based on whether or
// not any of the check boxes are checked.
setClearing_: function(clearing) {
this.isClearingInProgress_ = clearing;
this.updateCommitButtonState_();
this.updateStateOfControls_();
},
/**
* Sets the enabled state of the commit button.
* Sets whether deleting history and downloads is disallowed by enterprise
* policies. This is called on initialization and in response to a change in
* the corresponding preference.
* @param {boolean} allowed Whether to allow deleting history and downloads.
* @private
*/
updateCommitButtonState_: function() {
var checkboxes = document.querySelectorAll(
'#cbd-content-area input[type=checkbox]');
var isChecked = false;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
isChecked = true;
break;
}
}
$('clear-browser-data-commit').disabled =
!isChecked || this.isClearingInProgress_;
setAllowDeletingHistory_: function(allowed) {
this.allowDeletingHistory_ = allowed;
this.updateStateOfControls_();
},
setAllowDeletingHistory: function(allowed) {
this.allowDeletingHistory_ = allowed;
/**
* Called by the WebUI handler to signal that it has finished calling all
* initialization methods.
* @private
*/
markInitializationComplete_: function() {
this.isInitializationComplete_ = true;
this.updateStateOfControls_();
},
showDeleteHistoryCheckboxes_: function(show) {
if (!show) {
$('delete-browsing-history-container').hidden = true;
$('delete-download-history-container').hidden = true;
/**
* Updates the enabled/disabled/hidden status of all controls on the dialog.
* @private
*/
updateStateOfControls_: function() {
// The commit button is enabled if at least one data type selected to be
// cleared, and if we are not already in the process of clearing.
// To prevent the commit button from being hazardously enabled for a very
// short time before setClearing() is called the first time by the native
// side, also disable the button if |isInitializationComplete_| is false.
var enabled = false;
if (this.isInitializationComplete_ && !this.isClearingInProgress_) {
var checkboxes = document.querySelectorAll(
'#cbd-content-area input[type=checkbox]');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
enabled = true;
break;
}
}
}
},
$('clear-browser-data-commit').disabled = !enabled;
/** @override */
didShowPage: function() {
var allowed = ClearBrowserDataOverlay.getInstance().allowDeletingHistory_;
ClearBrowserDataOverlay.updateHistoryCheckboxes(allowed);
},
// The checkboxes for clearing history/downloads are enabled unless they
// are disallowed by policies, or we are in the process of clearing data.
// To prevent flickering, these, and the rest of the controls can safely
// be enabled for a short time before the first call to setClearing().
var enabled = this.allowDeletingHistory_ && !this.isClearingInProgress_;
$('delete-browsing-history-checkbox').disabled = !enabled;
$('delete-download-history-checkbox').disabled = !enabled;
if (!this.allowDeletingHistory_) {
$('delete-browsing-history-checkbox').checked = false;
$('delete-download-history-checkbox').checked = false;
}
// Enable everything else unless we are in the process of clearing.
var clearing = this.isClearingInProgress_;
$('delete-cache-checkbox').disabled = clearing;
$('delete-cookies-checkbox').disabled = clearing;
$('delete-passwords-checkbox').disabled = clearing;
$('delete-form-data-checkbox').disabled = clearing;
$('delete-hosted-apps-data-checkbox').disabled = clearing;
$('deauthorize-content-licenses-checkbox').disabled = clearing;
$('clear-browser-data-time-period').disabled = clearing;
$('cbd-throbber').style.visibility = clearing ? 'visible' : 'hidden';
$('clear-browser-data-dismiss').disabled = clearing;
}
};
//
// Chrome callbacks
//
/**
* Updates the disabled status of the browsing-history and downloads
* checkboxes, also unchecking them if they are disabled. This is called in
* response to a change in the corresponding preference.
*/
ClearBrowserDataOverlay.updateHistoryCheckboxes = function(allowed) {
$('delete-browsing-history-checkbox').disabled = !allowed;
$('delete-download-history-checkbox').disabled = !allowed;
if (!allowed) {
$('delete-browsing-history-checkbox').checked = false;
$('delete-download-history-checkbox').checked = false;
}
ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory(allowed);
ClearBrowserDataOverlay.setAllowDeletingHistory = function(allowed) {
ClearBrowserDataOverlay.getInstance().setAllowDeletingHistory_(allowed);
};
ClearBrowserDataOverlay.setClearing = function(clearing) {
ClearBrowserDataOverlay.getInstance().setClearing(clearing);
ClearBrowserDataOverlay.getInstance().setClearing_(clearing);
};
ClearBrowserDataOverlay.markInitializationComplete = function() {
ClearBrowserDataOverlay.getInstance().markInitializationComplete_();
};
ClearBrowserDataOverlay.setBannerVisibility = function(args) {
......@@ -224,6 +251,7 @@ cr.define('options', function() {
// actually worked. Otherwise the dialog just vanishes instantly in most
// cases.
window.setTimeout(function() {
ClearBrowserDataOverlay.setClearing(false);
ClearBrowserDataOverlay.dismiss();
}, 200);
};
......@@ -232,7 +260,6 @@ cr.define('options', function() {
var topmostVisiblePage = OptionsPage.getTopmostVisiblePage();
if (topmostVisiblePage && topmostVisiblePage.name == 'clearBrowserData')
OptionsPage.closeOverlay();
this.setClearing(false);
};
// Export
......
......@@ -2,7 +2,10 @@
// 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"
......@@ -26,6 +29,16 @@ class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
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,
......@@ -40,12 +53,15 @@ class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
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));
EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
......@@ -63,4 +79,35 @@ IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
EXPECT_TRUE(IsElementEnabled(kCommitButtonId));
}
IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
CommitButtonDisabledWhenNoDataTypesSelected) {
const char kCommitButtonId[] = "#clear-browser-data-commit";
const char* kDataTypes[] = {"browser.clear_data.browsing_history",
"browser.clear_data.download_history",
"browser.clear_data.cache",
"browser.clear_data.cookies",
"browser.clear_data.passwords",
"browser.clear_data.form_data",
"browser.clear_data.hosted_apps_data",
"browser.clear_data.content_licenses"};
PrefService* prefs = browser()->profile()->GetPrefs();
for (size_t i = 0; i < arraysize(kDataTypes); ++i) {
prefs->SetBoolean(kDataTypes[i], false);
}
// Navigate to the Clear Browsing Data dialog to ensure that the commit button
// is disabled if clearing is not requested for any of the data types.
NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
// However, expect the commit button to be re-enabled if any of the data types
// gets selected to be cleared.
for (size_t i = 0; i < arraysize(kDataTypes); ++i) {
prefs->SetBoolean(kDataTypes[i], true);
EXPECT_TRUE(IsElementEnabled(kCommitButtonId));
prefs->SetBoolean(kDataTypes[i], false);
}
}
} // namespace options
......@@ -55,10 +55,12 @@ void ClearBrowserDataHandler::InitializeHandler() {
void ClearBrowserDataHandler::InitializePage() {
UpdateInfoBannerVisibility();
OnBrowsingHistoryPrefChanged();
bool removal_in_progress = !!remover_;
web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearing",
base::FundamentalValue(removal_in_progress));
web_ui()->CallJavascriptFunction(
"ClearBrowserDataOverlay.markInitializationComplete");
}
void ClearBrowserDataHandler::UpdateInfoBannerVisibility() {
......@@ -216,7 +218,7 @@ void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() {
void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() {
web_ui()->CallJavascriptFunction(
"ClearBrowserDataOverlay.updateHistoryCheckboxes",
"ClearBrowserDataOverlay.setAllowDeletingHistory",
base::FundamentalValue(*allow_deleting_browser_history_));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment