| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" | |
| 12 #include "chrome/common/url_constants.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 #include "content/public/browser/browsing_data_remover.h" | |
| 15 #include "content/public/test/browser_test_utils.h" | |
| 16 #include "content/public/test/browsing_data_remover_test_util.h" | |
| 17 | |
| 18 namespace options { | |
| 19 | |
| 20 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest { | |
| 21 protected: | |
| 22 void ClickElement(const std::string& selector) { | |
| 23 bool element_enabled = false; | |
| 24 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled)); | |
| 25 ASSERT_TRUE(element_enabled); | |
| 26 ASSERT_TRUE(content::ExecuteScript( | |
| 27 GetSettingsFrame(), | |
| 28 "document.querySelector('" + selector + "').click();")); | |
| 29 } | |
| 30 | |
| 31 bool IsElementEnabled(const std::string& selector) { | |
| 32 bool element_enabled = false; | |
| 33 GetElementEnabledState(selector, &element_enabled); | |
| 34 return element_enabled; | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 void GetElementEnabledState( | |
| 39 const std::string& selector, | |
| 40 bool* enabled) { | |
| 41 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 42 GetSettingsFrame(), | |
| 43 "window.domAutomationController.send(!document.querySelector('" + | |
| 44 selector + "').disabled);", | |
| 45 enabled)); | |
| 46 } | |
| 47 }; | |
| 48 | |
| 49 // http://crbug.com/458684 | |
| 50 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 51 #define MAYBE_CommitButtonDisabledWhileDeletionInProgress \ | |
| 52 DISABLED_CommitButtonDisabledWhileDeletionInProgress | |
| 53 #else | |
| 54 #define MAYBE_CommitButtonDisabledWhileDeletionInProgress \ | |
| 55 CommitButtonDisabledWhileDeletionInProgress | |
| 56 #endif | |
| 57 | |
| 58 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, | |
| 59 MAYBE_CommitButtonDisabledWhileDeletionInProgress) { | |
| 60 const char kCommitButtonId[] = "#clear-browser-data-commit"; | |
| 61 content::BrowsingDataRemoverCompletionInhibitor completion_inhibitor( | |
| 62 content::BrowserContext::GetBrowsingDataRemover(browser()->profile())); | |
| 63 | |
| 64 // Navigate to the Clear Browsing Data dialog to ensure that the commit button | |
| 65 // is initially enabled, usable, and gets disabled after having been pressed. | |
| 66 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | |
| 67 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId)); | |
| 68 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | |
| 69 | |
| 70 completion_inhibitor.BlockUntilNearCompletion(); | |
| 71 | |
| 72 // Simulate a reload while the previous removal is still running, and verify | |
| 73 // that the button is still disabled. | |
| 74 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | |
| 75 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | |
| 76 | |
| 77 completion_inhibitor.ContinueToCompletion(); | |
| 78 | |
| 79 // However, the button should be enabled again once the process has finished. | |
| 80 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | |
| 81 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); | |
| 82 } | |
| 83 | |
| 84 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, | |
| 85 CommitButtonDisabledWhenNoDataTypesSelected) { | |
| 86 const char kCommitButtonId[] = "#clear-browser-data-commit"; | |
| 87 const char* kDataTypes[] = {"browser.clear_data.browsing_history", | |
| 88 "browser.clear_data.download_history", | |
| 89 "browser.clear_data.cache", | |
| 90 "browser.clear_data.cookies", | |
| 91 "browser.clear_data.passwords", | |
| 92 "browser.clear_data.form_data", | |
| 93 "browser.clear_data.hosted_apps_data", | |
| 94 "browser.clear_data.media_licenses"}; | |
| 95 | |
| 96 PrefService* prefs = browser()->profile()->GetPrefs(); | |
| 97 for (size_t i = 0; i < arraysize(kDataTypes); ++i) { | |
| 98 prefs->SetBoolean(kDataTypes[i], false); | |
| 99 } | |
| 100 | |
| 101 // Navigate to the Clear Browsing Data dialog to ensure that the commit button | |
| 102 // is disabled if clearing is not requested for any of the data types. | |
| 103 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | |
| 104 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | |
| 105 | |
| 106 // However, expect the commit button to be re-enabled if any of the data types | |
| 107 // gets selected to be cleared. | |
| 108 for (size_t i = 0; i < arraysize(kDataTypes); ++i) { | |
| 109 prefs->SetBoolean(kDataTypes[i], true); | |
| 110 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); | |
| 111 prefs->SetBoolean(kDataTypes[i], false); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 } // namespace options | |
| OLD | NEW |