Index: chrome/renderer/autofill/page_click_tracker_browsertest.cc |
diff --git a/chrome/renderer/autofill/page_click_tracker_browsertest.cc b/chrome/renderer/autofill/page_click_tracker_browsertest.cc |
index 79ca2f169e61176e86ab28cb9b7274c9575de194..943916b2a891be7b566b31cd306d2b5feb9ebcc0 100644 |
--- a/chrome/renderer/autofill/page_click_tracker_browsertest.cc |
+++ b/chrome/renderer/autofill/page_click_tracker_browsertest.cc |
@@ -10,6 +10,7 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/WebKit/public/web/WebDocument.h" |
#include "third_party/WebKit/public/web/WebInputElement.h" |
+#include "third_party/WebKit/public/web/WebTextAreaElement.h" |
#include "third_party/WebKit/public/web/WebView.h" |
#include "third_party/WebKit/public/platform/WebSize.h" |
#include "ui/events/keycodes/keyboard_codes.h" |
@@ -19,36 +20,37 @@ namespace autofill { |
class TestPageClickListener : public PageClickListener { |
public: |
TestPageClickListener() |
- : input_element_clicked_called_(false), |
- input_element_lost_focus_called_(false), |
+ : formcontrol_element_clicked_called_(false), |
+ formcontrol_element_lost_focus_called_(false), |
was_focused_(false), |
is_focused_(false) { |
} |
- virtual void InputElementClicked(const blink::WebInputElement& element, |
- bool was_focused, |
- bool is_focused) OVERRIDE { |
- input_element_clicked_called_ = true; |
- element_clicked_ = element; |
+ virtual void FormControlElementClicked( |
+ const blink::WebFormControlElement& element, |
+ bool was_focused, |
+ bool is_focused) OVERRIDE { |
+ formcontrol_element_clicked_called_ = true; |
+ formcontrol_element_clicked_ = element; |
was_focused_ = was_focused; |
is_focused_ = is_focused; |
} |
- virtual void InputElementLostFocus() OVERRIDE { |
- input_element_lost_focus_called_ = true; |
+ virtual void FormControlElementLostFocus() OVERRIDE { |
+ formcontrol_element_lost_focus_called_ = true; |
} |
- void ClearResults() { |
- input_element_clicked_called_ = false; |
- input_element_lost_focus_called_ = false; |
- element_clicked_.reset(); |
+ void ClearFormControlResults() { |
+ formcontrol_element_clicked_called_ = false; |
+ formcontrol_element_lost_focus_called_ = false; |
+ formcontrol_element_clicked_.reset(); |
was_focused_ = false; |
is_focused_ = false; |
} |
- bool input_element_clicked_called_; |
- bool input_element_lost_focus_called_; |
- blink::WebInputElement element_clicked_; |
+ bool formcontrol_element_clicked_called_; |
+ bool formcontrol_element_lost_focus_called_; |
+ blink::WebFormControlElement formcontrol_element_clicked_; |
bool was_focused_; |
bool is_focused_; |
}; |
@@ -65,18 +67,23 @@ class PageClickTrackerTest : public content::RenderViewTest { |
LoadHTML("<form>" |
" <input type='text' id='text_1'></input><br>" |
" <input type='text' id='text_2'></input><br>" |
+ " <textarea id='textarea_1'></textarea><br>" |
+ " <textarea id='textarea_2'></textarea><br>" |
" <input type='button' id='button'></input><br>" |
"</form>"); |
GetWebWidget()->resize(blink::WebSize(500, 500)); |
GetWebWidget()->setFocus(true); |
blink::WebDocument document = view_->GetWebView()->mainFrame()->document(); |
text_ = document.getElementById("text_1"); |
+ textarea_ = document.getElementById("textarea_1"); |
ASSERT_FALSE(text_.isNull()); |
+ ASSERT_FALSE(textarea_.isNull()); |
} |
virtual void TearDown() OVERRIDE { |
text_.reset(); |
- test_listener_.ClearResults(); |
+ textarea_.reset(); |
+ test_listener_.ClearFormControlResults(); |
page_click_tracker_.reset(); |
content::RenderViewTest::TearDown(); |
} |
@@ -100,29 +107,55 @@ class PageClickTrackerTest : public content::RenderViewTest { |
scoped_ptr<PageClickTracker> page_click_tracker_; |
TestPageClickListener test_listener_; |
blink::WebElement text_; |
+ blink::WebElement textarea_; |
}; |
-// Tests that PageClickTracker does notify correctly when a node is clicked. |
+// Tests that PageClickTracker does notify correctly when a input |
+// node is clicked. |
TEST_F(PageClickTrackerTest, PageClickTrackerInputClicked) { |
// Click the text field once. |
EXPECT_TRUE(SimulateElementClick("text_1")); |
- EXPECT_TRUE(test_listener_.input_element_clicked_called_); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_clicked_called_); |
EXPECT_FALSE(test_listener_.was_focused_); |
EXPECT_TRUE(test_listener_.is_focused_); |
- EXPECT_TRUE(text_ == test_listener_.element_clicked_); |
- test_listener_.ClearResults(); |
+ EXPECT_TRUE(text_ == test_listener_.formcontrol_element_clicked_); |
+ test_listener_.ClearFormControlResults(); |
// Click the text field again to test that was_focused_ is set correctly. |
EXPECT_TRUE(SimulateElementClick("text_1")); |
- EXPECT_TRUE(test_listener_.input_element_clicked_called_); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_clicked_called_); |
EXPECT_TRUE(test_listener_.was_focused_); |
EXPECT_TRUE(test_listener_.is_focused_); |
- EXPECT_TRUE(text_ == test_listener_.element_clicked_); |
- test_listener_.ClearResults(); |
+ EXPECT_TRUE(text_ == test_listener_.formcontrol_element_clicked_); |
+ test_listener_.ClearFormControlResults(); |
// Click the button, no notification should happen (this is not a text-input). |
EXPECT_TRUE(SimulateElementClick("button")); |
- EXPECT_FALSE(test_listener_.input_element_clicked_called_); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_clicked_called_); |
+} |
+ |
+// Tests that PageClickTracker does notify correctly when a textarea |
+// node is clicked. |
+TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaClicked) { |
+ // Click the textarea field once. |
+ EXPECT_TRUE(SimulateElementClick("textarea_1")); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_clicked_called_); |
+ EXPECT_FALSE(test_listener_.was_focused_); |
+ EXPECT_TRUE(test_listener_.is_focused_); |
+ EXPECT_TRUE(textarea_ == test_listener_.formcontrol_element_clicked_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Click the textarea field again to test that was_focused_ is set correctly. |
+ EXPECT_TRUE(SimulateElementClick("textarea_1")); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_clicked_called_); |
+ EXPECT_TRUE(test_listener_.was_focused_); |
+ EXPECT_TRUE(test_listener_.is_focused_); |
+ EXPECT_TRUE(textarea_ == test_listener_.formcontrol_element_clicked_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Click the button, no notification should happen (this is not a text-input). |
+ EXPECT_TRUE(SimulateElementClick("button")); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_clicked_called_); |
} |
TEST_F(PageClickTrackerTest, PageClickTrackerInputFocusLost) { |
@@ -130,35 +163,73 @@ TEST_F(PageClickTrackerTest, PageClickTrackerInputFocusLost) { |
EXPECT_NE(text_, text_.document().focusedNode()); |
SendKeyPress(ui::VKEY_TAB); |
EXPECT_EQ(text_, text_.document().focusedNode()); |
- EXPECT_FALSE(test_listener_.input_element_lost_focus_called_); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
// Click a button and ensure that the lost focus notification was sent, |
// even though focus was gained without the mouse. |
EXPECT_TRUE(SimulateElementClick("button")); |
- EXPECT_TRUE(test_listener_.input_element_lost_focus_called_); |
- test_listener_.ClearResults(); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
// Click a text field and test that no lost focus notifications are sent. |
EXPECT_TRUE(SimulateElementClick("text_1")); |
- EXPECT_FALSE(test_listener_.input_element_lost_focus_called_); |
- test_listener_.ClearResults(); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
// Select another text field to test that the notifcation for the |
// first text field losing focus is sent. |
EXPECT_TRUE(SimulateElementClick("text_2")); |
- EXPECT_TRUE(test_listener_.input_element_lost_focus_called_); |
- test_listener_.ClearResults(); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
// Click the button, a notification should happen since a text field has |
// lost focus. |
EXPECT_TRUE(SimulateElementClick("button")); |
- EXPECT_TRUE(test_listener_.input_element_lost_focus_called_); |
- test_listener_.ClearResults(); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
// Click on a text field while the button has focus and ensure no lost focus |
// notification is sent. |
EXPECT_TRUE(SimulateElementClick("text_1")); |
- EXPECT_FALSE(test_listener_.input_element_lost_focus_called_); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
} |
+TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaFocusLost) { |
+ // Gain focus on the textare field by using tab. |
+ EXPECT_NE(textarea_, textarea_.document().focusedNode()); |
+ SendKeyPress(ui::VKEY_TAB); |
+ SendKeyPress(ui::VKEY_TAB); |
+ SendKeyPress(ui::VKEY_TAB); |
+ EXPECT_EQ(textarea_, textarea_.document().focusedNode()); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
+ |
+ // Click a button and ensure that the lost focus notification was sent, |
+ // even though focus was gained without the mouse. |
+ EXPECT_TRUE(SimulateElementClick("button")); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Click a textarea field and test that no lost focus notifications are sent. |
+ EXPECT_TRUE(SimulateElementClick("textarea_1")); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Select another textarea field to test that the notifcation for the |
+ // first textarea field losing focus is sent. |
+ EXPECT_TRUE(SimulateElementClick("textarea_2")); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Click the button, a notification should happen since a textarea field has |
+ // lost focus. |
+ EXPECT_TRUE(SimulateElementClick("button")); |
+ EXPECT_TRUE(test_listener_.formcontrol_element_lost_focus_called_); |
+ test_listener_.ClearFormControlResults(); |
+ |
+ // Click on a textarea field while the button has focus and ensure no lost |
+ // focus notification is sent. |
+ EXPECT_TRUE(SimulateElementClick("textarea_1")); |
+ EXPECT_FALSE(test_listener_.formcontrol_element_lost_focus_called_); |
+} |
} // namespace autofill |
+ |