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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 7 years, 6 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
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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/prefs/testing_pref_service.h" 7 #include "base/prefs/testing_pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/autofill/browser/autofill_external_delegate.h" 13 #include "components/autofill/browser/autofill_external_delegate.h"
14 #include "components/autofill/browser/autofill_manager.h" 14 #include "components/autofill/browser/autofill_manager.h"
15 #include "components/autofill/browser/test_autofill_external_delegate.h" 15 #include "components/autofill/browser/test_autofill_external_delegate.h"
16 #include "components/autofill/browser/test_autofill_manager_delegate.h" 16 #include "components/autofill/browser/test_autofill_manager_delegate.h"
17 #include "components/autofill/content/browser/autofill_driver_impl.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
20 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
22 23
23 using ::testing::_; 24 using ::testing::_;
24 using ::testing::AtLeast; 25 using ::testing::AtLeast;
25 using ::testing::NiceMock; 26 using ::testing::NiceMock;
26 using base::WeakPtr; 27 using base::WeakPtr;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { 148 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness {
148 public: 149 public:
149 AutofillPopupControllerUnitTest() 150 AutofillPopupControllerUnitTest()
150 : manager_delegate_(new MockAutofillManagerDelegate()), 151 : manager_delegate_(new MockAutofillManagerDelegate()),
151 autofill_popup_controller_(NULL) {} 152 autofill_popup_controller_(NULL) {}
152 virtual ~AutofillPopupControllerUnitTest() {} 153 virtual ~AutofillPopupControllerUnitTest() {}
153 154
154 virtual void SetUp() OVERRIDE { 155 virtual void SetUp() OVERRIDE {
155 ChromeRenderViewHostTestHarness::SetUp(); 156 ChromeRenderViewHostTestHarness::SetUp();
156 157
157 AutofillManager::CreateForWebContentsAndDelegate( 158 AutofillDriverImpl::CreateForWebContentsAndDelegate(
158 web_contents(), 159 web_contents(),
159 manager_delegate_.get(), 160 manager_delegate_.get(),
160 "en-US", 161 "en-US",
161 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); 162 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER,
163 false);
164 AutofillDriverImpl* driver =
165 AutofillDriverImpl::FromWebContents(web_contents());
162 external_delegate_.reset( 166 external_delegate_.reset(
163 new NiceMock<MockAutofillExternalDelegate>( 167 new NiceMock<MockAutofillExternalDelegate>(
164 web_contents(), AutofillManager::FromWebContents(web_contents()))); 168 web_contents(),
169 driver->autofill_manager()));
165 170
166 autofill_popup_controller_ = 171 autofill_popup_controller_ =
167 new testing::NiceMock<TestAutofillPopupController>( 172 new testing::NiceMock<TestAutofillPopupController>(
168 external_delegate_->GetWeakPtr(), gfx::Rect()); 173 external_delegate_->GetWeakPtr(), gfx::Rect());
169 } 174 }
170 175
171 virtual void TearDown() OVERRIDE { 176 virtual void TearDown() OVERRIDE {
172 // This will make sure the controller and the view (if any) are both 177 // This will make sure the controller and the view (if any) are both
173 // cleaned up. 178 // cleaned up.
174 if (autofill_popup_controller_) 179 if (autofill_popup_controller_)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); 356 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0));
352 EXPECT_EQ(base_size + subtext_increase, 357 EXPECT_EQ(base_size + subtext_increase,
353 autofill_popup_controller_->RowWidthWithoutText(1)); 358 autofill_popup_controller_->RowWidthWithoutText(1));
354 EXPECT_EQ(base_size + icon_increase, 359 EXPECT_EQ(base_size + icon_increase,
355 autofill_popup_controller_->RowWidthWithoutText(2)); 360 autofill_popup_controller_->RowWidthWithoutText(2));
356 EXPECT_EQ(base_size + subtext_increase + icon_increase, 361 EXPECT_EQ(base_size + subtext_increase + icon_increase,
357 autofill_popup_controller_->RowWidthWithoutText(3)); 362 autofill_popup_controller_->RowWidthWithoutText(3));
358 } 363 }
359 364
360 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { 365 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
366 AutofillDriverImpl* driver =
367 AutofillDriverImpl::FromWebContents(web_contents());
361 MockAutofillExternalDelegate delegate( 368 MockAutofillExternalDelegate delegate(
362 web_contents(), AutofillManager::FromWebContents(web_contents())); 369 web_contents(), driver->autofill_manager());
363 370
364 WeakPtr<AutofillPopupControllerImpl> controller = 371 WeakPtr<AutofillPopupControllerImpl> controller =
365 AutofillPopupControllerImpl::GetOrCreate( 372 AutofillPopupControllerImpl::GetOrCreate(
366 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, 373 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL,
367 gfx::Rect()); 374 gfx::Rect());
368 EXPECT_TRUE(controller.get()); 375 EXPECT_TRUE(controller.get());
369 376
370 controller->Hide(); 377 controller->Hide();
371 378
372 controller = AutofillPopupControllerImpl::GetOrCreate( 379 controller = AutofillPopupControllerImpl::GetOrCreate(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 512
506 // The popup would be partially off the bottom and the right side of 513 // The popup would be partially off the bottom and the right side of
507 // the screen. 514 // the screen.
508 element_bounds.push_back( 515 element_bounds.push_back(
509 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); 516 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0));
510 expected_popup_bounds.push_back( 517 expected_popup_bounds.push_back(
511 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, 518 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2,
512 desired_width, desired_height)); 519 desired_width, desired_height));
513 520
514 for (size_t i = 0; i < element_bounds.size(); ++i) { 521 for (size_t i = 0; i < element_bounds.size(); ++i) {
522 AutofillDriverImpl* driver =
523 AutofillDriverImpl::FromWebContents(web_contents());
515 NiceMock<MockAutofillExternalDelegate> external_delegate( 524 NiceMock<MockAutofillExternalDelegate> external_delegate(
516 web_contents(), AutofillManager::FromWebContents(web_contents())); 525 web_contents(), driver->autofill_manager());
517 TestAutofillPopupController* autofill_popup_controller = 526 TestAutofillPopupController* autofill_popup_controller =
518 new TestAutofillPopupController(external_delegate.GetWeakPtr(), 527 new TestAutofillPopupController(external_delegate.GetWeakPtr(),
519 element_bounds[i]); 528 element_bounds[i]);
520 529
521 autofill_popup_controller->set_display(display); 530 autofill_popup_controller->set_display(display);
522 autofill_popup_controller->Show(names, names, names, autofill_ids); 531 autofill_popup_controller->Show(names, names, names, autofill_ids);
523 532
524 EXPECT_EQ(expected_popup_bounds[i].ToString(), 533 EXPECT_EQ(expected_popup_bounds[i].ToString(),
525 autofill_popup_controller->popup_bounds().ToString()) << 534 autofill_popup_controller->popup_bounds().ToString()) <<
526 "Popup bounds failed to match for test " << i; 535 "Popup bounds failed to match for test " << i;
527 536
528 // Hide the controller to delete it. 537 // Hide the controller to delete it.
529 autofill_popup_controller->DoHide(); 538 autofill_popup_controller->DoHide();
530 } 539 }
531 } 540 }
532 541
533 } // namespace autofill 542 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698