Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/prefs/pref_service.h" | |
| 5 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.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" | |
| 6 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" | 9 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" |
| 7 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 8 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 9 | 12 |
| 10 namespace options { | 13 namespace options { |
| 11 | 14 |
| 12 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest { | 15 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest { |
| 13 protected: | 16 protected: |
| 14 void ClickElement(const std::string& selector) { | 17 void ClickElement(const std::string& selector) { |
| 15 bool element_enabled = false; | 18 bool element_enabled = false; |
| 16 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled)); | 19 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled)); |
| 17 ASSERT_TRUE(element_enabled); | 20 ASSERT_TRUE(element_enabled); |
| 18 ASSERT_TRUE(content::ExecuteScript( | 21 ASSERT_TRUE(content::ExecuteScript( |
| 19 GetSettingsFrame(), | 22 GetSettingsFrame(), |
| 20 "document.querySelector('" + selector + "').click();")); | 23 "document.querySelector('" + selector + "').click();")); |
| 21 } | 24 } |
| 22 | 25 |
| 23 bool IsElementEnabled(const std::string& selector) { | 26 bool IsElementEnabled(const std::string& selector) { |
| 24 bool element_enabled = false; | 27 bool element_enabled = false; |
| 25 GetElementEnabledState(selector, &element_enabled); | 28 GetElementEnabledState(selector, &element_enabled); |
| 26 return element_enabled; | 29 return element_enabled; |
| 27 } | 30 } |
| 28 | 31 |
| 32 bool IsElementInFocus(const std::string& selector) { | |
| 33 bool element_in_focus = false; | |
| 34 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 35 GetSettingsFrame(), | |
| 36 "window.domAutomationController.send(document.querySelector('" + | |
| 37 selector + "') == document.activeElement);", | |
| 38 &element_in_focus)); | |
| 39 return element_in_focus; | |
| 40 } | |
| 41 | |
| 29 private: | 42 private: |
| 30 void GetElementEnabledState( | 43 void GetElementEnabledState( |
| 31 const std::string& selector, | 44 const std::string& selector, |
| 32 bool* enabled) { | 45 bool* enabled) { |
| 33 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 46 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 34 GetSettingsFrame(), | 47 GetSettingsFrame(), |
| 35 "window.domAutomationController.send(!document.querySelector('" + | 48 "window.domAutomationController.send(!document.querySelector('" + |
| 36 selector + "').disabled);", | 49 selector + "').disabled);", |
| 37 enabled)); | 50 enabled)); |
| 38 } | 51 } |
| 39 }; | 52 }; |
| 40 | 53 |
| 41 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, | 54 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, |
| 42 CommitButtonDisabledWhileDeletionInProgress) { | 55 CommitButtonDisabledWhileDeletionInProgress) { |
| 56 const char kTimePeriodSelectorId[] = "#clear-browser-data-time-period"; | |
| 43 const char kCommitButtonId[] = "#clear-browser-data-commit"; | 57 const char kCommitButtonId[] = "#clear-browser-data-commit"; |
| 44 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; | 58 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; |
| 45 | 59 |
| 46 // Navigate to the Clear Browsing Data dialog to ensure that the commit button | 60 // Navigate to the Clear Browsing Data dialog to ensure that the commit button |
| 47 // is initially enabled, usable, and gets disabled after having been pressed. | 61 // is initially enabled, usable, and gets disabled after having been pressed. |
| 62 // Furthermore, verify that the time period combo-box gets the initial focus. | |
| 48 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | 63 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); |
| 64 EXPECT_TRUE(IsElementInFocus(kTimePeriodSelectorId)); | |
| 49 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId)); | 65 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId)); |
| 50 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | 66 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); |
| 51 | 67 |
| 52 completion_inhibitor.BlockUntilNearCompletion(); | 68 completion_inhibitor.BlockUntilNearCompletion(); |
| 53 | 69 |
| 54 // Simulate a reload while the previous removal is still running, and verify | 70 // Simulate a reload while the previous removal is still running, and verify |
| 55 // that the button is still disabled. | 71 // that the button is still disabled. |
| 56 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | 72 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); |
| 57 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | 73 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); |
| 58 | 74 |
| 59 completion_inhibitor.ContinueToCompletion(); | 75 completion_inhibitor.ContinueToCompletion(); |
| 60 | 76 |
| 61 // However, the button should be enabled again once the process has finished. | 77 // However, the button should be enabled again once the process has finished. |
| 62 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | 78 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); |
| 63 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); | 79 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); |
| 64 } | 80 } |
| 65 | 81 |
| 82 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, | |
| 83 CommitButtonDisabledWhenNoDataTypesSelected) { | |
| 84 const char kCommitButtonId[] = "#clear-browser-data-commit"; | |
| 85 const char* kDataTypes[] = {"browser.clear_data.browsing_history", | |
| 86 "browser.clear_data.download_history", | |
| 87 "browser.clear_data.cache", | |
| 88 "browser.clear_data.cookies", | |
| 89 "browser.clear_data.passwords", | |
| 90 "browser.clear_data.form_data", | |
| 91 "browser.clear_data.hosted_apps_data", | |
| 92 "browser.clear_data.content_licenses"}; | |
| 93 | |
| 94 // Navigate to the Clear Browsing Data dialog to ensure that the commit button | |
| 95 // is disabled if clearing is not requested for any of the data types. | |
| 96 PrefService* prefs = browser()->profile()->GetPrefs(); | |
| 97 for (size_t i = 0; i < arraysize(kDataTypes); ++i) | |
|
Dan Beam
2014/05/30 21:11:07
nit: curlies
engedy
2014/05/31 14:25:56
Done.
| |
| 98 prefs->SetBoolean(kDataTypes[i], false); | |
|
Dan Beam
2014/05/30 21:11:07
nit: \n
engedy
2014/05/31 14:25:56
Done.
| |
| 99 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); | |
| 100 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); | |
| 101 | |
| 102 // However, expect the commit button to be re-enabled if any of the data types | |
| 103 // gets selected to be cleared. | |
| 104 for (size_t i = 0; i < arraysize(kDataTypes); ++i) { | |
| 105 prefs->SetBoolean(kDataTypes[i], true); | |
| 106 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); | |
| 107 prefs->SetBoolean(kDataTypes[i], false); | |
| 108 } | |
| 109 } | |
| 110 | |
| 66 } // namespace options | 111 } // namespace options |
| OLD | NEW |