Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/webui/options/clear_browser_data_browsertest.cc

Issue 275483005: Fix initial focus, and the way elements are disabled on the 'Clear browsing data' dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
6 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" 6 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h"
7 #include "chrome/common/url_constants.h" 7 #include "chrome/common/url_constants.h"
8 #include "content/public/test/browser_test_utils.h" 8 #include "content/public/test/browser_test_utils.h"
9 9
10 namespace options { 10 namespace options {
11 11
12 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest { 12 class ClearBrowserDataBrowserTest : public OptionsUIBrowserTest {
13 protected: 13 protected:
14 void ClickElement(const std::string& selector) { 14 void ClickElement(const std::string& selector) {
15 bool element_enabled = false; 15 bool element_enabled = false;
16 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled)); 16 ASSERT_NO_FATAL_FAILURE(GetElementEnabledState(selector, &element_enabled));
17 ASSERT_TRUE(element_enabled); 17 ASSERT_TRUE(element_enabled);
18 ASSERT_TRUE(content::ExecuteScript( 18 ASSERT_TRUE(content::ExecuteScript(
19 GetSettingsFrame(), 19 GetSettingsFrame(),
20 "document.querySelector('" + selector + "').click();")); 20 "document.querySelector('" + selector + "').click();"));
21 } 21 }
22 22
23 bool IsElementEnabled(const std::string& selector) { 23 bool IsElementEnabled(const std::string& selector) {
24 bool element_enabled = false; 24 bool element_enabled = false;
25 GetElementEnabledState(selector, &element_enabled); 25 GetElementEnabledState(selector, &element_enabled);
26 return element_enabled; 26 return element_enabled;
27 } 27 }
28 28
29 bool IsElementInFocus(const std::string& selector) {
30 bool element_in_focus = false;
31 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
32 GetSettingsFrame(),
33 "window.domAutomationController.send(document.querySelector('" +
34 selector + "') == document.activeElement);",
35 &element_in_focus));
36 return element_in_focus;
37 }
38
29 private: 39 private:
30 void GetElementEnabledState( 40 void GetElementEnabledState(
31 const std::string& selector, 41 const std::string& selector,
32 bool* enabled) { 42 bool* enabled) {
33 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 43 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
34 GetSettingsFrame(), 44 GetSettingsFrame(),
35 "window.domAutomationController.send(!document.querySelector('" + 45 "window.domAutomationController.send(!document.querySelector('" +
36 selector + "').disabled);", 46 selector + "').disabled);",
37 enabled)); 47 enabled));
38 } 48 }
39 }; 49 };
40 50
41 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest, 51 IN_PROC_BROWSER_TEST_F(ClearBrowserDataBrowserTest,
42 CommitButtonDisabledWhileDeletionInProgress) { 52 CommitButtonDisabledWhileDeletionInProgress) {
53 const char kTimePeriodSelectorId[] = "#clear-browser-data-time-period";
43 const char kCommitButtonId[] = "#clear-browser-data-commit"; 54 const char kCommitButtonId[] = "#clear-browser-data-commit";
44 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 55 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
45 56
46 // Navigate to the Clear Browsing Data dialog to ensure that the commit button 57 // 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. 58 // is initially enabled, usable, and gets disabled after having been pressed.
59 // Also verify that the time period combo-box gets the initial focus.
48 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); 60 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
61 EXPECT_TRUE(IsElementInFocus(kTimePeriodSelectorId));
49 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId)); 62 ASSERT_NO_FATAL_FAILURE(ClickElement(kCommitButtonId));
50 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); 63 EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
51 64
52 completion_inhibitor.BlockUntilNearCompletion(); 65 completion_inhibitor.BlockUntilNearCompletion();
53 66
54 // Simulate a reload while the previous removal is still running, and verify 67 // Simulate a reload while the previous removal is still running, and verify
55 // that the button is still disabled. 68 // that the button is still disabled.
56 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); 69 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
57 EXPECT_FALSE(IsElementEnabled(kCommitButtonId)); 70 EXPECT_FALSE(IsElementEnabled(kCommitButtonId));
58 71
59 completion_inhibitor.ContinueToCompletion(); 72 completion_inhibitor.ContinueToCompletion();
60 73
61 // However, the button should be enabled again once the process has finished. 74 // However, the button should be enabled again once the process has finished.
62 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage); 75 NavigateToSettingsSubpage(chrome::kClearBrowserDataSubPage);
63 EXPECT_TRUE(IsElementEnabled(kCommitButtonId)); 76 EXPECT_TRUE(IsElementEnabled(kCommitButtonId));
64 } 77 }
65 78
66 } // namespace options 79 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698