| 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 <stddef.h> | 5 #include <stddef.h> | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 | 8 | 
| 9 #include "base/macros.h" | 9 #include "base/macros.h" | 
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 62   ~MockAutofillClient() override {} | 62   ~MockAutofillClient() override {} | 
| 63 | 63 | 
| 64   PrefService* GetPrefs() override { return prefs_.get(); } | 64   PrefService* GetPrefs() override { return prefs_.get(); } | 
| 65 | 65 | 
| 66  private: | 66  private: | 
| 67   std::unique_ptr<PrefService> prefs_; | 67   std::unique_ptr<PrefService> prefs_; | 
| 68 | 68 | 
| 69   DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 69   DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 
| 70 }; | 70 }; | 
| 71 | 71 | 
|  | 72 class MockAutofillPopupView : public AutofillPopupView { | 
|  | 73  public: | 
|  | 74   MockAutofillPopupView() {} | 
|  | 75 | 
|  | 76   MOCK_METHOD0(Show, void()); | 
|  | 77   MOCK_METHOD0(Hide, void()); | 
|  | 78   MOCK_METHOD2(OnSelectedRowChanged, | 
|  | 79                void(size_t previous_row_selection, | 
|  | 80                     size_t current_row_selection)); | 
|  | 81   MOCK_METHOD0(OnSuggestionsChanged, void()); | 
|  | 82 | 
|  | 83  private: | 
|  | 84   DISALLOW_COPY_AND_ASSIGN(MockAutofillPopupView); | 
|  | 85 }; | 
|  | 86 | 
| 72 class TestAutofillPopupController : public AutofillPopupControllerImpl { | 87 class TestAutofillPopupController : public AutofillPopupControllerImpl { | 
| 73  public: | 88  public: | 
| 74   TestAutofillPopupController( | 89   TestAutofillPopupController( | 
| 75       base::WeakPtr<AutofillExternalDelegate> external_delegate, | 90       base::WeakPtr<AutofillExternalDelegate> external_delegate, | 
| 76       const gfx::RectF& element_bounds) | 91       const gfx::RectF& element_bounds) | 
| 77       : AutofillPopupControllerImpl(external_delegate, | 92       : AutofillPopupControllerImpl(external_delegate, | 
| 78                                     NULL, | 93                                     NULL, | 
| 79                                     NULL, | 94                                     NULL, | 
| 80                                     element_bounds, | 95                                     element_bounds, | 
| 81                                     base::i18n::UNKNOWN_DIRECTION) {} | 96                                     base::i18n::UNKNOWN_DIRECTION) {} | 
| 82   ~TestAutofillPopupController() override {} | 97   ~TestAutofillPopupController() override {} | 
| 83 | 98 | 
| 84   // Making protected functions public for testing | 99   // Making protected functions public for testing | 
| 85   using AutofillPopupControllerImpl::GetLineCount; | 100   using AutofillPopupControllerImpl::GetLineCount; | 
| 86   using AutofillPopupControllerImpl::GetSuggestionAt; | 101   using AutofillPopupControllerImpl::GetSuggestionAt; | 
| 87   using AutofillPopupControllerImpl::GetElidedValueAt; | 102   using AutofillPopupControllerImpl::GetElidedValueAt; | 
| 88   using AutofillPopupControllerImpl::GetElidedLabelAt; | 103   using AutofillPopupControllerImpl::GetElidedLabelAt; | 
| 89   using AutofillPopupControllerImpl::selected_line; | 104   using AutofillPopupControllerImpl::selected_line; | 
| 90   using AutofillPopupControllerImpl::SetSelectedLine; | 105   using AutofillPopupControllerImpl::SetSelectedLine; | 
| 91   using AutofillPopupControllerImpl::SelectNextLine; | 106   using AutofillPopupControllerImpl::SelectNextLine; | 
| 92   using AutofillPopupControllerImpl::SelectPreviousLine; | 107   using AutofillPopupControllerImpl::SelectPreviousLine; | 
| 93   using AutofillPopupControllerImpl::RemoveSelectedLine; | 108   using AutofillPopupControllerImpl::RemoveSelectedLine; | 
| 94   using AutofillPopupControllerImpl::popup_bounds; | 109   using AutofillPopupControllerImpl::popup_bounds; | 
| 95   using AutofillPopupControllerImpl::element_bounds; | 110   using AutofillPopupControllerImpl::element_bounds; | 
| 96   using AutofillPopupControllerImpl::SetValues; | 111   using AutofillPopupControllerImpl::SetValues; | 
| 97   using AutofillPopupControllerImpl::GetWeakPtr; | 112   using AutofillPopupControllerImpl::GetWeakPtr; | 
| 98   MOCK_METHOD1(InvalidateRow, void(size_t)); | 113   MOCK_METHOD0(OnSuggestionsChanged, void()); | 
| 99   MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); |  | 
| 100   MOCK_METHOD0(Hide, void()); | 114   MOCK_METHOD0(Hide, void()); | 
| 101 | 115 | 
| 102   void DoHide() { | 116   void DoHide() { | 
| 103     AutofillPopupControllerImpl::Hide(); | 117     AutofillPopupControllerImpl::Hide(); | 
| 104   } | 118   } | 
| 105 |  | 
| 106  private: |  | 
| 107   void ShowView() override {} |  | 
| 108 }; | 119 }; | 
| 109 | 120 | 
| 110 }  // namespace | 121 }  // namespace | 
| 111 | 122 | 
| 112 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { | 123 class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness { | 
| 113  public: | 124  public: | 
| 114   AutofillPopupControllerUnitTest() | 125   AutofillPopupControllerUnitTest() | 
| 115       : autofill_client_(new MockAutofillClient()), | 126       : autofill_client_(new MockAutofillClient()), | 
| 116         autofill_popup_controller_(NULL) {} | 127         autofill_popup_controller_(NULL) {} | 
| 117   ~AutofillPopupControllerUnitTest() override {} | 128   ~AutofillPopupControllerUnitTest() override {} | 
| 118 | 129 | 
| 119   void SetUp() override { | 130   void SetUp() override { | 
| 120     ChromeRenderViewHostTestHarness::SetUp(); | 131     ChromeRenderViewHostTestHarness::SetUp(); | 
| 121 | 132 | 
| 122     ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | 133     ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | 
| 123         web_contents(), autofill_client_.get(), "en-US", | 134         web_contents(), autofill_client_.get(), "en-US", | 
| 124         AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 135         AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 
| 125     // Make sure RenderFrame is created. | 136     // Make sure RenderFrame is created. | 
| 126     NavigateAndCommit(GURL("about:blank")); | 137     NavigateAndCommit(GURL("about:blank")); | 
| 127     ContentAutofillDriverFactory* factory = | 138     ContentAutofillDriverFactory* factory = | 
| 128         ContentAutofillDriverFactory::FromWebContents(web_contents()); | 139         ContentAutofillDriverFactory::FromWebContents(web_contents()); | 
| 129     ContentAutofillDriver* driver = | 140     ContentAutofillDriver* driver = | 
| 130         factory->DriverForFrame(web_contents()->GetMainFrame()); | 141         factory->DriverForFrame(web_contents()->GetMainFrame()); | 
| 131     external_delegate_.reset( | 142     external_delegate_.reset( | 
| 132         new NiceMock<MockAutofillExternalDelegate>( | 143         new NiceMock<MockAutofillExternalDelegate>( | 
| 133             driver->autofill_manager(), | 144             driver->autofill_manager(), | 
| 134             driver)); | 145             driver)); | 
| 135 | 146     autofill_popup_view_.reset(new NiceMock<MockAutofillPopupView>()); | 
| 136     autofill_popup_controller_ = | 147     autofill_popup_controller_ = new NiceMock<TestAutofillPopupController>( | 
| 137         new testing::NiceMock<TestAutofillPopupController>( | 148         external_delegate_->GetWeakPtr(), gfx::RectF()); | 
| 138             external_delegate_->GetWeakPtr(), gfx::RectF()); | 149     autofill_popup_controller_->SetViewForTesting(autofill_popup_view()); | 
| 139   } | 150   } | 
| 140 | 151 | 
| 141   void TearDown() override { | 152   void TearDown() override { | 
| 142     // This will make sure the controller and the view (if any) are both | 153     // This will make sure the controller and the view (if any) are both | 
| 143     // cleaned up. | 154     // cleaned up. | 
| 144     if (autofill_popup_controller_) | 155     if (autofill_popup_controller_) | 
| 145       autofill_popup_controller_->DoHide(); | 156       autofill_popup_controller_->DoHide(); | 
| 146 | 157 | 
| 147     external_delegate_.reset(); | 158     external_delegate_.reset(); | 
| 148     ChromeRenderViewHostTestHarness::TearDown(); | 159     ChromeRenderViewHostTestHarness::TearDown(); | 
| 149   } | 160   } | 
| 150 | 161 | 
| 151   TestAutofillPopupController* popup_controller() { | 162   TestAutofillPopupController* popup_controller() { | 
| 152     return autofill_popup_controller_; | 163     return autofill_popup_controller_; | 
| 153   } | 164   } | 
| 154 | 165 | 
| 155   MockAutofillExternalDelegate* delegate() { | 166   MockAutofillExternalDelegate* delegate() { | 
| 156     return external_delegate_.get(); | 167     return external_delegate_.get(); | 
| 157   } | 168   } | 
| 158 | 169 | 
|  | 170   MockAutofillPopupView* autofill_popup_view() { | 
|  | 171     return autofill_popup_view_.get(); | 
|  | 172   } | 
|  | 173 | 
| 159  protected: | 174  protected: | 
| 160   std::unique_ptr<MockAutofillClient> autofill_client_; | 175   std::unique_ptr<MockAutofillClient> autofill_client_; | 
| 161   std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_; | 176   std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_; | 
| 162   testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_; | 177   std::unique_ptr<NiceMock<MockAutofillPopupView>> autofill_popup_view_; | 
|  | 178   NiceMock<TestAutofillPopupController>* autofill_popup_controller_; | 
| 163 }; | 179 }; | 
| 164 | 180 | 
| 165 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { | 181 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { | 
| 166   // Set up the popup. | 182   // Set up the popup. | 
| 167   std::vector<Suggestion> suggestions; | 183   std::vector<Suggestion> suggestions; | 
| 168   suggestions.push_back(Suggestion("", "", "", 0)); | 184   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 169   suggestions.push_back(Suggestion("", "", "", 0)); | 185   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 170   autofill_popup_controller_->Show(suggestions); | 186   autofill_popup_controller_->Show(suggestions); | 
| 171 | 187 | 
| 172   EXPECT_LT(autofill_popup_controller_->selected_line(), 0); | 188   EXPECT_LT(autofill_popup_controller_->selected_line(), 0); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 189 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { | 205 TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) { | 
| 190   // Set up the popup. | 206   // Set up the popup. | 
| 191   std::vector<Suggestion> suggestions; | 207   std::vector<Suggestion> suggestions; | 
| 192   suggestions.push_back(Suggestion("", "", "", 0)); | 208   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 193   suggestions.push_back(Suggestion("", "", "", 0)); | 209   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 194   autofill_popup_controller_->Show(suggestions); | 210   autofill_popup_controller_->Show(suggestions); | 
| 195 | 211 | 
| 196   // Make sure that when a new line is selected, it is invalidated so it can | 212   // Make sure that when a new line is selected, it is invalidated so it can | 
| 197   // be updated to show it is selected. | 213   // be updated to show it is selected. | 
| 198   int selected_line = 0; | 214   int selected_line = 0; | 
| 199   EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 215   EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(-1, selected_line)); | 
|  | 216 | 
| 200   autofill_popup_controller_->SetSelectedLine(selected_line); | 217   autofill_popup_controller_->SetSelectedLine(selected_line); | 
| 201 | 218 | 
| 202   // Ensure that the row isn't invalidated if it didn't change. | 219   // Ensure that the row isn't invalidated if it didn't change. | 
| 203   EXPECT_CALL(*autofill_popup_controller_, | 220   EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); | 
| 204               InvalidateRow(selected_line)).Times(0); |  | 
| 205   autofill_popup_controller_->SetSelectedLine(selected_line); | 221   autofill_popup_controller_->SetSelectedLine(selected_line); | 
| 206 | 222 | 
| 207   // Change back to no selection. | 223   // Change back to no selection. | 
| 208   EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line)); | 224   EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(selected_line, -1)); | 
| 209   autofill_popup_controller_->SetSelectedLine(-1); | 225   autofill_popup_controller_->SetSelectedLine(-1); | 
| 210 } | 226 } | 
| 211 | 227 | 
| 212 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { | 228 TEST_F(AutofillPopupControllerUnitTest, RemoveLine) { | 
| 213   // Set up the popup. | 229   // Set up the popup. | 
| 214   std::vector<Suggestion> suggestions; | 230   std::vector<Suggestion> suggestions; | 
| 215   suggestions.push_back(Suggestion("", "", "", 1)); | 231   suggestions.push_back(Suggestion("", "", "", 1)); | 
| 216   suggestions.push_back(Suggestion("", "", "", 1)); | 232   suggestions.push_back(Suggestion("", "", "", 1)); | 
| 217   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 233   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 
| 218   autofill_popup_controller_->Show(suggestions); | 234   autofill_popup_controller_->Show(suggestions); | 
| 219 | 235 | 
| 220   // Generate a popup, so it can be hidden later. It doesn't matter what the | 236   // Generate a popup, so it can be hidden later. It doesn't matter what the | 
| 221   // external_delegate thinks is being shown in the process, since we are just | 237   // external_delegate thinks is being shown in the process, since we are just | 
| 222   // testing the popup here. | 238   // testing the popup here. | 
| 223   autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 239   autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 
| 224 | 240 | 
| 225   // No line is selected so the removal should fail. | 241   // No line is selected so the removal should fail. | 
| 226   EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 242   EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 
| 227 | 243 | 
| 228   // Remove the first entry. The popup should be redrawn since its size has | 244   // Remove the first entry. The popup should be redrawn since its size has | 
| 229   // changed. | 245   // changed. | 
| 230   EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); | 246   EXPECT_CALL(*autofill_popup_controller_, OnSuggestionsChanged()); | 
| 231   autofill_popup_controller_->SetSelectedLine(0); | 247   autofill_popup_controller_->SetSelectedLine(0); | 
| 232   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 248   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 
| 233 | 249 | 
| 234   // Remove the last entry. The popup should then be hidden since there are | 250   // Remove the last entry. The popup should then be hidden since there are | 
| 235   // no Autofill entries left. | 251   // no Autofill entries left. | 
| 236   EXPECT_CALL(*autofill_popup_controller_, Hide()); | 252   EXPECT_CALL(*autofill_popup_controller_, Hide()); | 
| 237   autofill_popup_controller_->SetSelectedLine(0); | 253   autofill_popup_controller_->SetSelectedLine(0); | 
| 238   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 254   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 
| 239 } | 255 } | 
| 240 | 256 | 
| 241 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { | 257 TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) { | 
| 242   // Set up the popup. | 258   // Set up the popup. | 
| 243   std::vector<Suggestion> suggestions; | 259   std::vector<Suggestion> suggestions; | 
| 244   suggestions.push_back(Suggestion("", "", "", 1)); | 260   suggestions.push_back(Suggestion("", "", "", 1)); | 
| 245   autofill_popup_controller_->Show(suggestions); | 261   autofill_popup_controller_->Show(suggestions); | 
| 246 | 262 | 
| 247   // Generate a popup. | 263   // Generate a popup. | 
| 248   autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 264   autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 
| 249 | 265 | 
| 250   // Select the only line. | 266   // Select the only line. | 
| 251   autofill_popup_controller_->SetSelectedLine(0); | 267   autofill_popup_controller_->SetSelectedLine(0); | 
| 252 | 268 | 
| 253   // Remove the only line. There should be no row invalidation and the popup | 269   // Remove the only line. There should be no row invalidation and the popup | 
| 254   // should then be hidden since there are no Autofill entries left. | 270   // should then be hidden since there are no Autofill entries left. | 
| 255   EXPECT_CALL(*autofill_popup_controller_, Hide()); | 271   EXPECT_CALL(*autofill_popup_controller_, Hide()); | 
| 256   EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0); | 272   EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0); | 
| 257   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 273   EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 
| 258 } | 274 } | 
| 259 | 275 | 
| 260 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 276 TEST_F(AutofillPopupControllerUnitTest, SkipSeparator) { | 
| 261   // Set up the popup. | 277   // Set up the popup. | 
| 262   std::vector<Suggestion> suggestions; | 278   std::vector<Suggestion> suggestions; | 
| 263   suggestions.push_back(Suggestion("", "", "", 1)); | 279   suggestions.push_back(Suggestion("", "", "", 1)); | 
| 264   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); | 280   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_SEPARATOR)); | 
| 265   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 281   suggestions.push_back(Suggestion("", "", "", POPUP_ITEM_ID_AUTOFILL_OPTIONS)); | 
| 266   autofill_popup_controller_->Show(suggestions); | 282   autofill_popup_controller_->Show(suggestions); | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 379       gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 395       gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 
| 380   EXPECT_TRUE(controller.get()); | 396   EXPECT_TRUE(controller.get()); | 
| 381 | 397 | 
| 382   WeakPtr<AutofillPopupControllerImpl> controller2 = | 398   WeakPtr<AutofillPopupControllerImpl> controller2 = | 
| 383       AutofillPopupControllerImpl::GetOrCreate( | 399       AutofillPopupControllerImpl::GetOrCreate( | 
| 384           controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), | 400           controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), | 
| 385           base::i18n::UNKNOWN_DIRECTION); | 401           base::i18n::UNKNOWN_DIRECTION); | 
| 386   EXPECT_EQ(controller.get(), controller2.get()); | 402   EXPECT_EQ(controller.get(), controller2.get()); | 
| 387   controller->Hide(); | 403   controller->Hide(); | 
| 388 | 404 | 
| 389   testing::NiceMock<TestAutofillPopupController>* test_controller = | 405   NiceMock<TestAutofillPopupController>* test_controller = | 
| 390       new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), | 406       new NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), | 
| 391                                                          gfx::RectF()); | 407                                                 gfx::RectF()); | 
| 392   EXPECT_CALL(*test_controller, Hide()); | 408   EXPECT_CALL(*test_controller, Hide()); | 
| 393 | 409 | 
| 394   gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); | 410   gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); | 
| 395   base::WeakPtr<AutofillPopupControllerImpl> controller3 = | 411   base::WeakPtr<AutofillPopupControllerImpl> controller3 = | 
| 396       AutofillPopupControllerImpl::GetOrCreate( | 412       AutofillPopupControllerImpl::GetOrCreate( | 
| 397           test_controller->GetWeakPtr(), | 413           test_controller->GetWeakPtr(), | 
| 398           delegate.GetWeakPtr(), | 414           delegate.GetWeakPtr(), | 
| 399           NULL, | 415           NULL, | 
| 400           NULL, | 416           NULL, | 
| 401           bounds, | 417           bounds, | 
| 402           base::i18n::UNKNOWN_DIRECTION); | 418           base::i18n::UNKNOWN_DIRECTION); | 
| 403   EXPECT_EQ( | 419   EXPECT_EQ( | 
| 404       bounds, | 420       bounds, | 
| 405       static_cast<AutofillPopupController*>(controller3.get())-> | 421       static_cast<AutofillPopupController*>(controller3.get())-> | 
| 406           element_bounds()); | 422           element_bounds()); | 
| 407   controller3->Hide(); | 423   controller3->Hide(); | 
| 408 | 424 | 
| 409   // Hide the test_controller to delete it. | 425   // Hide the test_controller to delete it. | 
| 410   test_controller->DoHide(); | 426   test_controller->DoHide(); | 
| 411 } | 427 } | 
| 412 | 428 | 
| 413 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 429 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 
| 414   std::vector<Suggestion> suggestions; | 430   std::vector<Suggestion> suggestions; | 
| 415   suggestions.push_back(Suggestion("", "", "", 0)); | 431   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 416   suggestions.push_back(Suggestion("", "", "", 0)); | 432   suggestions.push_back(Suggestion("", "", "", 0)); | 
| 417   popup_controller()->SetValues(suggestions); | 433   popup_controller()->Show(suggestions); | 
| 418   popup_controller()->SetSelectedLine(0); | 434   popup_controller()->SetSelectedLine(0); | 
| 419 | 435 | 
| 420   // Now show a new popup with the same controller, but with fewer items. | 436   // Now show a new popup with the same controller, but with fewer items. | 
| 421   WeakPtr<AutofillPopupControllerImpl> controller = | 437   WeakPtr<AutofillPopupControllerImpl> controller = | 
| 422       AutofillPopupControllerImpl::GetOrCreate( | 438       AutofillPopupControllerImpl::GetOrCreate( | 
| 423           popup_controller()->GetWeakPtr(), delegate()->GetWeakPtr(), NULL, | 439           popup_controller()->GetWeakPtr(), delegate()->GetWeakPtr(), NULL, | 
| 424           NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 440           NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); | 
| 425   EXPECT_NE(0, controller->selected_line()); | 441   EXPECT_NE(0, controller->selected_line()); | 
| 426   EXPECT_EQ(0u, controller->GetLineCount()); | 442   EXPECT_EQ(0u, controller->GetLineCount()); | 
| 427 } | 443 } | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 461 | 477 | 
| 462   // The second element was shorter so it should be unchanged. | 478   // The second element was shorter so it should be unchanged. | 
| 463   EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 479   EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 
| 464             autofill_popup_controller_->GetElidedValueAt(1)); | 480             autofill_popup_controller_->GetElidedValueAt(1)); | 
| 465   EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 481   EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 
| 466             autofill_popup_controller_->GetElidedLabelAt(1)); | 482             autofill_popup_controller_->GetElidedLabelAt(1)); | 
| 467 } | 483 } | 
| 468 #endif | 484 #endif | 
| 469 | 485 | 
| 470 }  // namespace autofill | 486 }  // namespace autofill | 
| OLD | NEW | 
|---|