Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / clear_browser_data_browsertest.cc
bloba97cb8277e0642732b611060f384d4d446a2cb0c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h"
10 #include "chrome/common/url_constants.h"
11 #include "content/public/test/browser_test_utils.h"
13 namespace options {
15 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
16 protected:
17 void ClickElement(const std::string& selector) {
18 bool element_enabled = false;
19 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled));
20 ASSERT_TRUE(element_enabled);
21 ASSERT_TRUE(content::ExecuteScript(
22 GetSettingsFrame(),
23 "document.querySelector('" + selector + "').click();"));
26 bool IsElementEnabled(const std::string& selector) {
27 bool element_enabled = false;
28 GetElementEnabledState(selector, &element_enabled);
29 return element_enabled;
32 private:
33 void GetElementEnabledState(
34 const std::string& selector,
35 bool* enabled) {
36 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
37 GetSettingsFrame(),
38 "window.domAutomationController.send(!document.querySelector('" +
39 selector + "').disabled);",
40 enabled));
44 // http://crbug.com/458684
45 #if defined(OS_WIN) || defined(OS_MACOSX)
46 #define MAYBE_CommitButtonDisabledWhileDeletionInProgress \
47 DISABLED_CommitButtonDisabledWhileDeletionInProgress
48 #else
49 #define MAYBE_CommitButtonDisabledWhileDeletionInProgress \
50 CommitButtonDisabledWhileDeletionInProgress
51 #endif
53 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
54 MAYBE_CommitButtonDisabledWhileDeletionInProgress) {
55 const char kCommitButtonId[] = "#clear-browser-data-commit";
56 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
58 // Navigate to the Clear Browsing Data dialog to ensure that the commit button
59 // is initially enabled, usable, and gets disabled after having been pressed.
60 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
61 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId));
62 EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
64 completion_inhibitor.BlockUntilNearCompletion();
66 // Simulate a reload while the previous removal is still running, and verify
67 // that the button is still disabled.
68 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
69 EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
71 completion_inhibitor.ContinueToCompletion();
73 // However, the button should be enabled again once the process has finished.
74 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
75 EXPECT_TRUE(IsElementEnabled(kCommitButtonId));
78 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
79 CommitButtonDisabledWhenNoDataTypesSelected) {
80 const char kCommitButtonId[] = "#clear-browser-data-commit";
81 const char* kDataTypes[] = {"browser.clear_data.browsing_history",
82 "browser.clear_data.download_history",
83 "browser.clear_data.cache",
84 "browser.clear_data.cookies",
85 "browser.clear_data.passwords",
86 "browser.clear_data.form_data",
87 "browser.clear_data.hosted_apps_data",
88 "browser.clear_data.content_licenses"};
90 PrefService* prefs = browser()->profile()->GetPrefs();
91 for (size_t i = 0; i < arraysize(kDataTypes); ++i) {
92 prefs->SetBoolean(kDataTypes[i], false);
95 // Navigate to the Clear Browsing Data dialog to ensure that the commit button
96 // is disabled if clearing is not requested for any of the data types.
97 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
98 EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
100 // However, expect the commit button to be re-enabled if any of the data types
101 // gets selected to be cleared.
102 for (size_t i = 0; i < arraysize(kDataTypes); ++i) {
103 prefs->SetBoolean(kDataTypes[i], true);
104 EXPECT_TRUE(IsElementEnabled(kCommitButtonId));
105 prefs->SetBoolean(kDataTypes[i], false);
109 } // namespace options