| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/test/base/chrome_render_view_test.h" | 9 #include "chrome/test/base/chrome_render_view_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "components/autofill/content/common/autofill_messages.h" | 11 #include "components/autofill/content/common/autofill_messages.h" |
| 12 #include "components/autofill/content/renderer/autofill_agent.h" | 12 #include "components/autofill/content/renderer/autofill_agent.h" |
| 13 #include "components/autofill/core/common/form_data.h" | 13 #include "components/autofill/core/common/form_data.h" |
| 14 #include "components/autofill/core/common/form_field_data.h" | 14 #include "components/autofill/core/common/form_field_data.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/renderer/render_frame.h" | 16 #include "content/public/renderer/render_frame.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
| 22 #include "third_party/WebKit/public/web/WebFormElement.h" | 22 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 23 #include "third_party/WebKit/public/web/WebInputElement.h" | 23 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 #include "third_party/WebKit/public/web/WebView.h" |
| 25 | 26 |
| 26 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
| 27 using blink::WebDocument; | 28 using blink::WebDocument; |
| 28 using blink::WebElement; | 29 using blink::WebElement; |
| 29 using blink::WebFormElement; | 30 using blink::WebFormElement; |
| 30 using blink::WebFrame; | 31 using blink::WebFrame; |
| 31 using blink::WebLocalFrame; | 32 using blink::WebLocalFrame; |
| 32 using blink::WebInputElement; | 33 using blink::WebInputElement; |
| 33 using blink::WebString; | 34 using blink::WebString; |
| 34 using blink::WebURLRequest; | 35 using blink::WebURLRequest; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 expected.max_length = WebInputElement::defaultMaxLength(); | 239 expected.max_length = WebInputElement::defaultMaxLength(); |
| 239 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); | 240 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); |
| 240 | 241 |
| 241 expected.name = ASCIIToUTF16("PHONE_HOME_WHOLE_NUMBER"); | 242 expected.name = ASCIIToUTF16("PHONE_HOME_WHOLE_NUMBER"); |
| 242 expected.value.clear(); | 243 expected.value.clear(); |
| 243 expected.form_control_type = "text"; | 244 expected.form_control_type = "text"; |
| 244 expected.max_length = WebInputElement::defaultMaxLength(); | 245 expected.max_length = WebInputElement::defaultMaxLength(); |
| 245 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[8]); | 246 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[8]); |
| 246 } | 247 } |
| 247 | 248 |
| 249 TEST_F(AutofillRendererTest, IgnoreNonUserGestureTextFieldChanges) { |
| 250 LoadHTML("<form method='post'>" |
| 251 " <input type='text' id='full_name'/>" |
| 252 "</form>"); |
| 253 |
| 254 blink::WebInputElement full_name = |
| 255 GetMainFrame()->document().getElementById("full_name") |
| 256 .to<blink::WebInputElement>(); |
| 257 while (!full_name.focused()) |
| 258 GetMainFrame()->view()->advanceFocus(false); |
| 259 |
| 260 // Not a user gesture, so no IPC message to browser. |
| 261 full_name.setValue("Alice", true); |
| 262 GetMainFrame()->toWebLocalFrame()->autofillClient()->textFieldDidChange( |
| 263 full_name); |
| 264 ProcessInputForAutofill(); |
| 265 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 266 AutofillHostMsg_TextFieldDidChange::ID)); |
| 267 |
| 268 // A user gesture will send a message to the browser. |
| 269 SimulateUserInputChangeForElement(&full_name, "Alice"); |
| 270 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 271 AutofillHostMsg_TextFieldDidChange::ID)); |
| 272 } |
| 273 |
| 274 TEST_F(AutofillRendererTest, DesktopCompositionDoesNotTriggerAutofill) { |
| 275 LoadHTML("<form method='post'>" |
| 276 " <input type='text' id='full_name'/>" |
| 277 "</form>"); |
| 278 |
| 279 blink::WebInputElement full_name = |
| 280 GetMainFrame()->document().getElementById("full_name") |
| 281 .to<blink::WebInputElement>(); |
| 282 |
| 283 // Show the popup to verify that it will be closed on desktop. |
| 284 SimulateUserInputChangeForElement(&full_name, "Alice"); |
| 285 render_thread_->sink().ClearMessages(); |
| 286 |
| 287 GetWebWidget()->setComposition(base::ASCIIToUTF16("Bob"), |
| 288 std::vector<blink::WebCompositionUnderline>(), |
| 289 3, 3); |
| 290 ProcessInputForAutofill(); |
| 291 |
| 292 #if defined(OS_ANDROID) |
| 293 // Android will keep the popups open and will trigger autofill when IME is |
| 294 // composing. |
| 295 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 296 AutofillHostMsg_TextFieldDidChange::ID)); |
| 297 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 298 AutofillHostMsg_HidePopup::ID)); |
| 299 #else |
| 300 // Desktop will close popups and will not trigger autofill when IME is |
| 301 // composing, because the IME UI can overlap the autofill UI. |
| 302 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 303 AutofillHostMsg_TextFieldDidChange::ID)); |
| 304 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 305 AutofillHostMsg_HidePopup::ID)); |
| 306 #endif |
| 307 } |
| 308 |
| 248 class RequestAutocompleteRendererTest : public AutofillRendererTest { | 309 class RequestAutocompleteRendererTest : public AutofillRendererTest { |
| 249 public: | 310 public: |
| 250 RequestAutocompleteRendererTest() | 311 RequestAutocompleteRendererTest() |
| 251 : invoking_frame_(NULL), sibling_frame_(NULL) {} | 312 : invoking_frame_(NULL), sibling_frame_(NULL) {} |
| 252 ~RequestAutocompleteRendererTest() override {} | 313 ~RequestAutocompleteRendererTest() override {} |
| 253 | 314 |
| 254 protected: | 315 protected: |
| 255 void SetUp() override { | 316 void SetUp() override { |
| 256 AutofillRendererTest::SetUp(); | 317 AutofillRendererTest::SetUp(); |
| 257 | 318 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 }; | 377 }; |
| 317 | 378 |
| 318 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | 379 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { |
| 319 // Attempting to show the requestAutocomplete dialog again should be ignored. | 380 // Attempting to show the requestAutocomplete dialog again should be ignored. |
| 320 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); | 381 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); |
| 321 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 382 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 322 AutofillHostMsg_RequestAutocomplete::ID)); | 383 AutofillHostMsg_RequestAutocomplete::ID)); |
| 323 } | 384 } |
| 324 | 385 |
| 325 } // namespace autofill | 386 } // namespace autofill |
| OLD | NEW |