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

Side by Side Diff: components/autofill/content/browser/content_autofill_driver_unittest.cc

Issue 2672243002: Convert ContentAutofillDriverFactory to use the new navigation callbacks. (Closed)
Patch Set: review comment Created 3 years, 10 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
« no previous file with comments | « components/autofill/content/browser/content_autofill_driver_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/autofill/content/browser/content_autofill_driver.h" 5 #include "components/autofill/content/browser/content_autofill_driver.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "components/autofill/core/browser/autofill_external_delegate.h" 17 #include "components/autofill/core/browser/autofill_external_delegate.h"
18 #include "components/autofill/core/browser/autofill_manager.h" 18 #include "components/autofill/core/browser/autofill_manager.h"
19 #include "components/autofill/core/browser/autofill_test_utils.h" 19 #include "components/autofill/core/browser/autofill_test_utils.h"
20 #include "components/autofill/core/browser/test_autofill_client.h" 20 #include "components/autofill/core/browser/test_autofill_client.h"
21 #include "components/autofill/core/common/autofill_switches.h" 21 #include "components/autofill/core/common/autofill_switches.h"
22 #include "components/autofill/core/common/form_data_predictions.h" 22 #include "components/autofill/core/common/form_data_predictions.h"
23 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/navigation_handle.h"
26 #include "content/public/browser/ssl_status.h" 26 #include "content/public/browser/ssl_status.h"
27 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/frame_navigate_params.h" 29 #include "content/public/common/frame_navigate_params.h"
30 #include "content/public/test/test_renderer_host.h" 30 #include "content/public/test/test_renderer_host.h"
31 #include "mojo/public/cpp/bindings/binding_set.h" 31 #include "mojo/public/cpp/bindings/binding_set.h"
32 #include "services/service_manager/public/cpp/interface_provider.h" 32 #include "services/service_manager/public/cpp/interface_provider.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return static_cast<MockAutofillManager*>(autofill_manager()); 257 return static_cast<MockAutofillManager*>(autofill_manager());
258 } 258 }
259 259
260 using ContentAutofillDriver::DidNavigateFrame; 260 using ContentAutofillDriver::DidNavigateFrame;
261 }; 261 };
262 262
263 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { 263 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness {
264 public: 264 public:
265 void SetUp() override { 265 void SetUp() override {
266 content::RenderViewHostTestHarness::SetUp(); 266 content::RenderViewHostTestHarness::SetUp();
267 // This needed to keep the WebContentsObserverSanityChecker checks happy for
268 // when AppendChild is called.
269 NavigateAndCommit(GURL("about:blank"));
267 270
268 test_autofill_client_.reset(new MockAutofillClient()); 271 test_autofill_client_.reset(new MockAutofillClient());
269 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), 272 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(),
270 test_autofill_client_.get())); 273 test_autofill_client_.get()));
271 274
272 service_manager::InterfaceProvider* remote_interfaces = 275 service_manager::InterfaceProvider* remote_interfaces =
273 web_contents()->GetMainFrame()->GetRemoteInterfaces(); 276 web_contents()->GetMainFrame()->GetRemoteInterfaces();
274 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); 277 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces);
275 test_api.SetBinderForName(mojom::AutofillAgent::Name_, 278 test_api.SetBinderForName(mojom::AutofillAgent::Name_,
276 base::Bind(&FakeAutofillAgent::BindRequest, 279 base::Bind(&FakeAutofillAgent::BindRequest,
277 base::Unretained(&fake_agent_))); 280 base::Unretained(&fake_agent_)));
278 } 281 }
279 282
280 void TearDown() override { 283 void TearDown() override {
281 // Reset the driver now to cause all pref observers to be removed and avoid 284 // Reset the driver now to cause all pref observers to be removed and avoid
282 // crashes that otherwise occur in the destructor. 285 // crashes that otherwise occur in the destructor.
283 driver_.reset(); 286 driver_.reset();
284 content::RenderViewHostTestHarness::TearDown(); 287 content::RenderViewHostTestHarness::TearDown();
285 } 288 }
286 289
290 void Navigate(bool main_frame) {
291 content::RenderFrameHost* rfh = main_rfh();
292 content::RenderFrameHostTester* rfh_tester =
293 content::RenderFrameHostTester::For(rfh);
294 if (!main_frame)
295 rfh = rfh_tester->AppendChild("subframe");
296 std::unique_ptr<content::NavigationHandle> navigation_handle =
297 content::NavigationHandle::CreateNavigationHandleForTesting(
298 GURL(), rfh, true);
299 driver_->DidNavigateFrame(navigation_handle.get());
300 }
301
287 protected: 302 protected:
288 std::unique_ptr<MockAutofillClient> test_autofill_client_; 303 std::unique_ptr<MockAutofillClient> test_autofill_client_;
289 std::unique_ptr<TestContentAutofillDriver> driver_; 304 std::unique_ptr<TestContentAutofillDriver> driver_;
290 305
291 FakeAutofillAgent fake_agent_; 306 FakeAutofillAgent fake_agent_;
292 }; 307 };
293 308
294 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { 309 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) {
295 net::URLRequestContextGetter* request_context = 310 net::URLRequestContextGetter* request_context =
296 driver_->GetURLRequestContext(); 311 driver_->GetURLRequestContext();
297 net::URLRequestContextGetter* expected_request_context = 312 net::URLRequestContextGetter* expected_request_context =
298 content::BrowserContext::GetDefaultStoragePartition( 313 content::BrowserContext::GetDefaultStoragePartition(
299 web_contents()->GetBrowserContext())->GetURLRequestContext(); 314 web_contents()->GetBrowserContext())->GetURLRequestContext();
300 EXPECT_EQ(request_context, expected_request_context); 315 EXPECT_EQ(request_context, expected_request_context);
301 } 316 }
302 317
303 TEST_F(ContentAutofillDriverTest, NavigatedToDifferentPage) { 318 TEST_F(ContentAutofillDriverTest, NavigatedToDifferentPage) {
304 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); 319 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset());
305 content::LoadCommittedDetails details = content::LoadCommittedDetails(); 320 Navigate(true);
306 details.is_main_frame = true;
307 details.is_in_page = false;
308 ASSERT_TRUE(details.is_navigation_to_different_page());
309 content::FrameNavigateParams params = content::FrameNavigateParams();
310 driver_->DidNavigateFrame(details, params);
311 } 321 }
312 322
313 TEST_F(ContentAutofillDriverTest, NavigatedWithinSamePage) { 323 TEST_F(ContentAutofillDriverTest, NavigatedWithinSamePage) {
314 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); 324 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0);
315 content::LoadCommittedDetails details = content::LoadCommittedDetails(); 325 Navigate(false);
316 details.is_main_frame = false;
317 ASSERT_TRUE(!details.is_navigation_to_different_page());
318 content::FrameNavigateParams params = content::FrameNavigateParams();
319 driver_->DidNavigateFrame(details, params);
320 } 326 }
321 327
322 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) { 328 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) {
323 int input_page_id = 42; 329 int input_page_id = 42;
324 FormData input_form_data; 330 FormData input_form_data;
325 test::CreateTestAddressFormData(&input_form_data); 331 test::CreateTestAddressFormData(&input_form_data);
326 base::RunLoop run_loop; 332 base::RunLoop run_loop;
327 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); 333 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure());
328 driver_->SendFormDataToRenderer( 334 driver_->SendFormDataToRenderer(
329 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data); 335 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_CALL(fake_agent_, FirstUserGestureObservedInTab()); 496 EXPECT_CALL(fake_agent_, FirstUserGestureObservedInTab());
491 base::RunLoop().RunUntilIdle(); 497 base::RunLoop().RunUntilIdle();
492 } 498 }
493 499
494 TEST_F(ContentAutofillDriverTest, FirstUserGestureObserved) { 500 TEST_F(ContentAutofillDriverTest, FirstUserGestureObserved) {
495 EXPECT_CALL(*test_autofill_client_, OnFirstUserGestureObserved()); 501 EXPECT_CALL(*test_autofill_client_, OnFirstUserGestureObserved());
496 driver_->FirstUserGestureObserved(); 502 driver_->FirstUserGestureObserved();
497 } 503 }
498 504
499 } // namespace autofill 505 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/browser/content_autofill_driver_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698