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

Side by Side Diff: chrome/renderer/autofill/autofill_renderer_browsertest.cc

Issue 707173004: Refactor Autofill for out of process iframes (OOPIF). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mem leak Created 6 years 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
OLDNEW
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/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/test/base/chrome_render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
9 #include "components/autofill/content/common/autofill_messages.h" 9 #include "components/autofill/content/common/autofill_messages.h"
10 #include "components/autofill/content/renderer/autofill_agent.h" 10 #include "components/autofill/content/renderer/autofill_agent.h"
11 #include "components/autofill/core/common/form_data.h" 11 #include "components/autofill/core/common/form_data.h"
12 #include "components/autofill/core/common/form_field_data.h" 12 #include "components/autofill/core/common/form_field_data.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/renderer/render_frame.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebURLRequest.h" 17 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 18 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFormElement.h" 20 #include "third_party/WebKit/public/web/WebFormElement.h"
20 #include "third_party/WebKit/public/web/WebInputElement.h" 21 #include "third_party/WebKit/public/web/WebInputElement.h"
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" 22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
22 23
23 using base::ASCIIToUTF16; 24 using base::ASCIIToUTF16;
(...skipping 24 matching lines...) Expand all
48 void SetUp() override { 49 void SetUp() override {
49 ChromeRenderViewTest::SetUp(); 50 ChromeRenderViewTest::SetUp();
50 51
51 // Don't want any delay for form state sync changes. This will still post a 52 // Don't want any delay for form state sync changes. This will still post a
52 // message so updates will get coalesced, but as soon as we spin the message 53 // message so updates will get coalesced, but as soon as we spin the message
53 // loop, it will generate an update. 54 // loop, it will generate an update.
54 SendContentStateImmediately(); 55 SendContentStateImmediately();
55 } 56 }
56 57
57 void SimulateRequestAutocompleteResult( 58 void SimulateRequestAutocompleteResult(
59 blink::WebFrame* invoking_frame,
58 const blink::WebFormElement::AutocompleteResult& result, 60 const blink::WebFormElement::AutocompleteResult& result,
59 const base::string16& message) { 61 const base::string16& message) {
60 AutofillMsg_RequestAutocompleteResult msg(0, result, message, FormData()); 62 AutofillMsg_RequestAutocompleteResult msg(0, result, message, FormData());
61 static_cast<content::RenderViewObserver*>(autofill_agent_) 63 content::RenderFrame::FromWebFrame(invoking_frame)->OnMessageReceived(msg);
62 ->OnMessageReceived(msg);
63 } 64 }
64 65
65 private: 66 private:
66 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest); 67 DISALLOW_COPY_AND_ASSIGN(AutofillRendererTest);
67 }; 68 };
68 69
69 TEST_F(AutofillRendererTest, SendForms) { 70 TEST_F(AutofillRendererTest, SendForms) {
70 LoadHTML("<form method='POST'>" 71 LoadHTML("<form method='POST'>"
71 " <input type='text' id='firstname'/>" 72 " <input type='text' id='firstname'/>"
72 " <input type='text' id='middlename'/>" 73 " <input type='text' id='middlename'/>"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 281
281 WebVector<WebFormElement> forms; 282 WebVector<WebFormElement> forms;
282 invoking_frame()->document().forms(forms); 283 invoking_frame()->document().forms(forms);
283 ASSERT_EQ(1U, forms.size()); 284 ASSERT_EQ(1U, forms.size());
284 invoking_form_ = forms[0]; 285 invoking_form_ = forms[0];
285 ASSERT_FALSE(invoking_form().isNull()); 286 ASSERT_FALSE(invoking_form().isNull());
286 287
287 render_thread_->sink().ClearMessages(); 288 render_thread_->sink().ClearMessages();
288 289
289 // Invoke requestAutocomplete to show the dialog. 290 // Invoke requestAutocomplete to show the dialog.
290 static_cast<blink::WebAutofillClient*>(autofill_agent_) 291 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form());
291 ->didRequestAutocomplete(invoking_form());
292 ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching( 292 ASSERT_TRUE(render_thread_->sink().GetFirstMessageMatching(
293 AutofillHostMsg_RequestAutocomplete::ID)); 293 AutofillHostMsg_RequestAutocomplete::ID));
294 294
295 render_thread_->sink().ClearMessages(); 295 render_thread_->sink().ClearMessages();
296 } 296 }
297 297
298 void TearDown() override { 298 void TearDown() override {
299 invoking_form_.reset(); 299 invoking_form_.reset();
300 AutofillRendererTest::TearDown(); 300 AutofillRendererTest::TearDown();
301 } 301 }
302 302
303 void NavigateFrame(WebFrame* frame) { 303 void NavigateFrame(WebFrame* frame) {
304 frame->loadRequest(WebURLRequest(GURL("about:blank"))); 304 frame->loadRequest(WebURLRequest(GURL("about:blank")));
305 ProcessPendingMessages(); 305 ProcessPendingMessages();
306 } 306 }
307 307
308 const WebFormElement& invoking_form() const { return invoking_form_; } 308 const WebFormElement& invoking_form() const { return invoking_form_; }
309 WebLocalFrame* invoking_frame() { return invoking_frame_; } 309 WebLocalFrame* invoking_frame() { return invoking_frame_; }
310 WebFrame* sibling_frame() { return sibling_frame_; } 310 WebFrame* sibling_frame() { return sibling_frame_; }
311 311
312 private: 312 protected:
313 WebFormElement invoking_form_; 313 WebFormElement invoking_form_;
314 WebLocalFrame* invoking_frame_; 314 WebLocalFrame* invoking_frame_;
315 WebFrame* sibling_frame_; 315 WebFrame* sibling_frame_;
316 316
317 private:
317 DISALLOW_COPY_AND_ASSIGN(RequestAutocompleteRendererTest); 318 DISALLOW_COPY_AND_ASSIGN(RequestAutocompleteRendererTest);
318 }; 319 };
319 320
320 TEST_F(RequestAutocompleteRendererTest, SiblingNavigateIgnored) { 321 TEST_F(RequestAutocompleteRendererTest, SiblingNavigateIgnored) {
321 // Pretend that a sibling frame navigated. No cancel should be sent. 322 // Pretend that a sibling frame navigated. No cancel should be sent.
322 NavigateFrame(sibling_frame()); 323 NavigateFrame(sibling_frame());
323 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 324 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
324 AutofillHostMsg_CancelRequestAutocomplete::ID)); 325 AutofillHostMsg_CancelRequestAutocomplete::ID));
325 } 326 }
326 327
327 TEST_F(RequestAutocompleteRendererTest, SubframeNavigateCancels) { 328 TEST_F(RequestAutocompleteRendererTest, SubframeNavigateCancels) {
328 // Pretend that the invoking frame navigated. A cancel should be sent. 329 // Pretend that the invoking frame navigated. A cancel should be sent.
329 NavigateFrame(invoking_frame()); 330 NavigateFrame(invoking_frame());
330 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 331 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
331 AutofillHostMsg_CancelRequestAutocomplete::ID)); 332 AutofillHostMsg_CancelRequestAutocomplete::ID));
332 } 333 }
333 334
334 TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) { 335 TEST_F(RequestAutocompleteRendererTest, MainFrameNavigateCancels) {
335 // Pretend that the top-level frame navigated. A cancel should be sent. 336 // Pretend that the top-level frame navigated. A cancel should be sent.
336 NavigateFrame(GetMainFrame()); 337 NavigateFrame(GetMainFrame());
337 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 338 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
338 AutofillHostMsg_CancelRequestAutocomplete::ID)); 339 AutofillHostMsg_CancelRequestAutocomplete::ID));
339 } 340 }
340 341
341 TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) { 342 TEST_F(RequestAutocompleteRendererTest, NoCancelOnSubframeNavigateAfterDone) {
342 // Pretend that the dialog was cancelled. 343 // Pretend that the dialog was cancelled.
343 SimulateRequestAutocompleteResult( 344 SimulateRequestAutocompleteResult(
344 WebFormElement::AutocompleteResultErrorCancel, 345 invoking_frame_, WebFormElement::AutocompleteResultErrorCancel,
345 base::ASCIIToUTF16("Print me to the console")); 346 base::ASCIIToUTF16("Print me to the console"));
346 347
347 // Additional navigations should not crash nor send cancels. 348 // Additional navigations should not crash nor send cancels.
348 NavigateFrame(invoking_frame()); 349 NavigateFrame(invoking_frame());
349 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 350 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
350 AutofillHostMsg_CancelRequestAutocomplete::ID)); 351 AutofillHostMsg_CancelRequestAutocomplete::ID));
351 } 352 }
352 353
353 TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) { 354 TEST_F(RequestAutocompleteRendererTest, NoCancelOnMainFrameNavigateAfterDone) {
354 // Pretend that the dialog was cancelled. 355 // Pretend that the dialog was cancelled.
355 SimulateRequestAutocompleteResult( 356 SimulateRequestAutocompleteResult(
356 WebFormElement::AutocompleteResultErrorCancel, 357 invoking_frame_, WebFormElement::AutocompleteResultErrorCancel,
357 base::ASCIIToUTF16("Print me to the console")); 358 base::ASCIIToUTF16("Print me to the console"));
358 359
359 // Additional navigations should not crash nor send cancels. 360 // Additional navigations should not crash nor send cancels.
360 NavigateFrame(GetMainFrame()); 361 NavigateFrame(GetMainFrame());
361 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 362 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
362 AutofillHostMsg_CancelRequestAutocomplete::ID)); 363 AutofillHostMsg_CancelRequestAutocomplete::ID));
363 } 364 }
364 365
365 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { 366 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) {
366 // Attempting to show the requestAutocomplete dialog again should be ignored. 367 // Attempting to show the requestAutocomplete dialog again should be ignored.
367 static_cast<blink::WebAutofillClient*>(autofill_agent_) 368 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form());
368 ->didRequestAutocomplete(invoking_form());
369 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 369 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
370 AutofillHostMsg_RequestAutocomplete::ID)); 370 AutofillHostMsg_RequestAutocomplete::ID));
371 } 371 }
372 372
373 } // namespace autofill 373 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_helpers.cc ('k') | chrome/renderer/autofill/password_autofill_agent_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698