Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/autofill_external_delegate_views_browsertest.cc |
| diff --git a/chrome/browser/ui/views/autofill/autofill_external_delegate_views_browsertest.cc b/chrome/browser/ui/views/autofill/autofill_external_delegate_views_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b507545560ad7937f05346bd64466814f4c5ca1c |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/autofill/autofill_external_delegate_views_browsertest.cc |
| @@ -0,0 +1,107 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/autofill/autofill_external_delegate_views.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents.h" |
| +#include "chrome/browser/ui/browser_tabstrip.h" |
| +#include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +namespace { |
| + |
| +class MockAutofillExternalDelegateViews : public AutofillExternalDelegateViews { |
| + public: |
| + MockAutofillExternalDelegateViews(TabContents* tab_contents) : |
| + AutofillExternalDelegateViews(tab_contents, NULL), |
| + popup_hidden_(false) {} |
| + ~MockAutofillExternalDelegateViews() {} |
| + |
| + void HideAutofillPopupInternal() OVERRIDE { |
| + popup_hidden_ = true; |
| + AutofillExternalDelegateViews::HideAutofillPopupInternal(); |
| + } |
| + |
| + AutofillPopupViewViews* GetPopup() { |
| + return AutofillExternalDelegateViews::GetPopup(); |
| + } |
| + |
| + bool popup_hidden_; |
| +}; |
| + |
| +} // namespace |
| + |
| +class AutofillExternalDelegateViewsBrowserTest : public InProcessBrowserTest { |
| + public: |
| + AutofillExternalDelegateViewsBrowserTest() {} |
| + virtual ~AutofillExternalDelegateViewsBrowserTest() {} |
| + |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + tab_contents_ = chrome::GetActiveTabContents(browser()); |
| + ASSERT_TRUE(tab_contents_ != NULL); |
| + |
| + autofill_external_delegate_.reset( |
| + new MockAutofillExternalDelegateViews(tab_contents_)); |
| + } |
| + |
| + protected: |
| + TabContents* tab_contents_; |
| + scoped_ptr<MockAutofillExternalDelegateViews> autofill_external_delegate_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateViewsBrowserTest, |
| + OpenAndClosePopup) { |
| + int query_id = 1; |
| + webkit::forms::FormData form; |
| + webkit::forms::FormField field; |
| + field.is_focusable = true; |
| + field.should_autocomplete = true; |
| + gfx::Rect bounds(100, 100); |
| + |
| + // Ensure that we can populate the popup through the delegate without any |
| + // and then close it. |
| + autofill_external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| + |
| + std::vector<string16> autofill_item; |
| + autofill_item.push_back(string16()); |
| + std::vector<int> autofill_id; |
| + autofill_id.push_back(0); |
| + autofill_external_delegate_->OnSuggestionsReturned( |
| + query_id, autofill_item, autofill_item, autofill_item, autofill_id); |
| + |
| + autofill_external_delegate_->HideAutofillPopup(); |
| + EXPECT_TRUE(autofill_external_delegate_->popup_hidden_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateViewsBrowserTest, |
| + CloseWidgetAndNoLeaking) { |
| + int query_id = 1; |
| + webkit::forms::FormData form; |
| + webkit::forms::FormField field; |
| + field.is_focusable = true; |
| + field.should_autocomplete = true; |
| + gfx::Rect bounds(100, 100); |
| + |
| + // Ensure that we can populate the popup through the delegate without any |
| + // and then close it. |
| + autofill_external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| + |
| + std::vector<string16> autofill_item; |
| + autofill_item.push_back(string16()); |
| + std::vector<int> autofill_id; |
| + autofill_id.push_back(0); |
| + autofill_external_delegate_->OnSuggestionsReturned( |
| + query_id, autofill_item, autofill_item, autofill_item, autofill_id); |
| + |
| + // Delete the popup tyo ensure that the external delegate can handle the |
| + // popup getting deleted elsewhere. |
| + views::View* popup_view = |
|
csharp
2012/08/20 20:59:00
I tried to just close the parent widget, but that
|
| + autofill_external_delegate_->GetPopup(); |
| + delete popup_view; |
| + |
| + EXPECT_TRUE(autofill_external_delegate_->popup_hidden_); |
| +} |