| 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 <tuple> | 5 #include <tuple> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class AutofillRendererTest : public ChromeRenderViewTest { | 46 class AutofillRendererTest : public ChromeRenderViewTest { |
| 47 public: | 47 public: |
| 48 AutofillRendererTest() {} | 48 AutofillRendererTest() {} |
| 49 ~AutofillRendererTest() override {} | 49 ~AutofillRendererTest() override {} |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 void SetUp() override { | 52 void SetUp() override { |
| 53 ChromeRenderViewTest::SetUp(); | 53 ChromeRenderViewTest::SetUp(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void SimulateRequestAutocompleteResult( | |
| 57 blink::WebFrame* invoking_frame, | |
| 58 const blink::WebFormElement::AutocompleteResult& result, | |
| 59 const base::string16& message) { | |
| 60 AutofillMsg_RequestAutocompleteResult msg(0, result, message, FormData()); | |
| 61 content::RenderFrame::FromWebFrame(invoking_frame)->OnMessageReceived(msg); | |
| 62 } | |
| 63 | |
| 64 private: | 56 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); | 57 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); |
| 66 }; | 58 }; |
| 67 | 59 |
| 68 TEST_F(AutofillRendererTest, SendForms) { | 60 TEST_F(AutofillRendererTest, SendForms) { |
| 69 LoadHTML("<form method='POST'>" | 61 LoadHTML("<form method='POST'>" |
| 70 " <input type='text' id='firstname'/>" | 62 " <input type='text' id='firstname'/>" |
| 71 " <input type='text' id='middlename'/>" | 63 " <input type='text' id='middlename'/>" |
| 72 " <input type='text' id='lastname' autoComplete='off'/>" | 64 " <input type='text' id='lastname' autoComplete='off'/>" |
| 73 " <input type='hidden' id='email'/>" | 65 " <input type='hidden' id='email'/>" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( | 255 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 264 AutofillHostMsg_TextFieldDidChange::ID)); | 256 AutofillHostMsg_TextFieldDidChange::ID)); |
| 265 | 257 |
| 266 // A user gesture will send a message to the browser. | 258 // A user gesture will send a message to the browser. |
| 267 EnableUserGestureSimulationForAutofill(); | 259 EnableUserGestureSimulationForAutofill(); |
| 268 SimulateUserInputChangeForElement(&full_name, "Alice"); | 260 SimulateUserInputChangeForElement(&full_name, "Alice"); |
| 269 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( | 261 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching( |
| 270 AutofillHostMsg_TextFieldDidChange::ID)); | 262 AutofillHostMsg_TextFieldDidChange::ID)); |
| 271 } | 263 } |
| 272 | 264 |
| 273 class RequestAutocompleteRendererTest : public AutofillRendererTest { | |
| 274 public: | |
| 275 RequestAutocompleteRendererTest() | |
| 276 : invoking_frame_(NULL), sibling_frame_(NULL) {} | |
| 277 ~RequestAutocompleteRendererTest() override {} | |
| 278 | |
| 279 protected: | |
| 280 void SetUp() override { | |
| 281 AutofillRendererTest::SetUp(); | |
| 282 | |
| 283 // Bypass the HTTPS-only restriction to show requestAutocomplete. | |
| 284 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 285 command_line->AppendSwitch(::switches::kReduceSecurityForTesting); | |
| 286 | |
| 287 GURL url("data:text/html;charset=utf-8," | |
| 288 "<form><input autocomplete=cc-number></form>"); | |
| 289 const char kDoubleIframeHtml[] = "<iframe id=subframe src='%s'></iframe>" | |
| 290 "<iframe id=sibling></iframe>"; | |
| 291 LoadHTML(base::StringPrintf(kDoubleIframeHtml, url.spec().c_str()).c_str()); | |
| 292 | |
| 293 WebElement subframe = GetMainFrame()->document().getElementById("subframe"); | |
| 294 ASSERT_FALSE(subframe.isNull()); | |
| 295 invoking_frame_ = WebLocalFrame::fromFrameOwnerElement(subframe); | |
| 296 ASSERT_TRUE(invoking_frame()); | |
| 297 ASSERT_EQ(GetMainFrame(), invoking_frame()->parent()); | |
| 298 | |
| 299 WebElement sibling = GetMainFrame()->document().getElementById("sibling"); | |
| 300 ASSERT_FALSE(sibling.isNull()); | |
| 301 sibling_frame_ = WebLocalFrame::fromFrameOwnerElement(sibling); | |
| 302 ASSERT_TRUE(sibling_frame()); | |
| 303 | |
| 304 WebVector<WebFormElement> forms; | |
| 305 invoking_frame()->document().forms(forms); | |
| 306 ASSERT_EQ(1U, forms.size()); | |
| 307 invoking_form_ = forms[0]; | |
| 308 ASSERT_FALSE(invoking_form().isNull()); | |
| 309 | |
| 310 render_thread_->sink().ClearMessages(); | |
| 311 | |
| 312 // Invoke requestAutocomplete to show the dialog. | |
| 313 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); | |
| 314 ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching( | |
| 315 AutofillHostMsg_RequestAutocomplete::ID)); | |
| 316 | |
| 317 render_thread_->sink().ClearMessages(); | |
| 318 } | |
| 319 | |
| 320 void TearDown() override { | |
| 321 invoking_form_.reset(); | |
| 322 AutofillRendererTest::TearDown(); | |
| 323 } | |
| 324 | |
| 325 void NavigateFrame(WebFrame* frame) { | |
| 326 frame->loadRequest(WebURLRequest(GURL("about:blank"))); | |
| 327 ProcessPendingMessages(); | |
| 328 } | |
| 329 | |
| 330 const WebFormElement& invoking_form() const { return invoking_form_; } | |
| 331 WebLocalFrame* invoking_frame() { return invoking_frame_; } | |
| 332 WebFrame* sibling_frame() { return sibling_frame_; } | |
| 333 | |
| 334 protected: | |
| 335 WebFormElement invoking_form_; | |
| 336 WebLocalFrame* invoking_frame_; | |
| 337 WebFrame* sibling_frame_; | |
| 338 | |
| 339 private: | |
| 340 DISALLOW_COPY_AND_ASSIGN(RequestAutocompleteRendererTest); | |
| 341 }; | |
| 342 | |
| 343 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { | |
| 344 // Attempting to show the requestAutocomplete dialog again should be ignored. | |
| 345 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); | |
| 346 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | |
| 347 AutofillHostMsg_RequestAutocomplete::ID)); | |
| 348 } | |
| 349 | |
| 350 } // namespace autofill | 265 } // namespace autofill |
| OLD | NEW |