| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/autofill/autofill_external_delegate_views.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/rect.h" |
| 14 #include "ui/views/widget/widget.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 class MockAutofillExternalDelegateViews : public AutofillExternalDelegateViews { |
| 19 public: |
| 20 explicit MockAutofillExternalDelegateViews(TabContents* tab_contents) : |
| 21 AutofillExternalDelegateViews(tab_contents, NULL), |
| 22 popup_hidden_(false) {} |
| 23 ~MockAutofillExternalDelegateViews() {} |
| 24 |
| 25 void HideAutofillPopupInternal() OVERRIDE { |
| 26 popup_hidden_ = true; |
| 27 AutofillExternalDelegateViews::HideAutofillPopupInternal(); |
| 28 } |
| 29 |
| 30 AutofillPopupViewViews* popup_view() { |
| 31 return AutofillExternalDelegateViews::popup_view(); |
| 32 } |
| 33 |
| 34 bool popup_hidden_; |
| 35 }; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 class AutofillExternalDelegateViewsBrowserTest : public InProcessBrowserTest { |
| 40 public: |
| 41 AutofillExternalDelegateViewsBrowserTest() {} |
| 42 virtual ~AutofillExternalDelegateViewsBrowserTest() {} |
| 43 |
| 44 virtual void SetUpOnMainThread() OVERRIDE { |
| 45 tab_contents_ = chrome::GetActiveTabContents(browser()); |
| 46 ASSERT_TRUE(tab_contents_ != NULL); |
| 47 |
| 48 autofill_external_delegate_.reset( |
| 49 new MockAutofillExternalDelegateViews(tab_contents_)); |
| 50 } |
| 51 |
| 52 void GeneratePopup() { |
| 53 int query_id = 1; |
| 54 webkit::forms::FormData form; |
| 55 webkit::forms::FormField field; |
| 56 field.is_focusable = true; |
| 57 field.should_autocomplete = true; |
| 58 gfx::Rect bounds(100, 100); |
| 59 |
| 60 // Ensure that we can populate the popup through the delegate without any |
| 61 // and then close it. |
| 62 autofill_external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| 63 |
| 64 std::vector<string16> autofill_item; |
| 65 autofill_item.push_back(string16()); |
| 66 std::vector<int> autofill_id; |
| 67 autofill_id.push_back(0); |
| 68 autofill_external_delegate_->OnSuggestionsReturned( |
| 69 query_id, autofill_item, autofill_item, autofill_item, autofill_id); |
| 70 } |
| 71 |
| 72 protected: |
| 73 TabContents* tab_contents_; |
| 74 scoped_ptr<MockAutofillExternalDelegateViews> autofill_external_delegate_; |
| 75 }; |
| 76 |
| 77 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateViewsBrowserTest, |
| 78 OpenAndClosePopup) { |
| 79 GeneratePopup(); |
| 80 |
| 81 autofill_external_delegate_->HideAutofillPopup(); |
| 82 EXPECT_TRUE(autofill_external_delegate_->popup_hidden_); |
| 83 } |
| 84 |
| 85 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateViewsBrowserTest, |
| 86 CloseWidgetAndNoLeaking) { |
| 87 GeneratePopup(); |
| 88 |
| 89 // Delete the widget to ensure that the external delegate can handle the |
| 90 // popup getting deleted elsewhere and the . |
| 91 views::Widget* popup_widget = |
| 92 autofill_external_delegate_->popup_view()->GetWidget(); |
| 93 popup_widget->CloseNow(); |
| 94 |
| 95 EXPECT_TRUE(autofill_external_delegate_->popup_hidden_); |
| 96 } |
| OLD | NEW |