| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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 "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "chrome/browser/autofill/autofill_manager.h" |
| 8 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
| 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/test/test_utils.h" |
| 18 #include "ui/gfx/rect.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 class TestAutofillExternalDelegate : public AutofillExternalDelegate { |
| 23 public: |
| 24 TestAutofillExternalDelegate(content::WebContents* web_contents, |
| 25 AutofillManager* autofill_manager) |
| 26 : AutofillExternalDelegate(web_contents, autofill_manager), |
| 27 popup_hidden_(true) {} |
| 28 ~TestAutofillExternalDelegate() {} |
| 29 |
| 30 virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE { |
| 31 popup_hidden_ = false; |
| 32 |
| 33 AutofillExternalDelegate::OnPopupShown(listener); |
| 34 } |
| 35 |
| 36 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE { |
| 37 popup_hidden_ = true; |
| 38 |
| 39 if (message_loop_runner_) |
| 40 message_loop_runner_->Quit(); |
| 41 |
| 42 AutofillExternalDelegate::OnPopupHidden(listener); |
| 43 } |
| 44 |
| 45 void WaitForPopupHidden() { |
| 46 if (popup_hidden_) |
| 47 return; |
| 48 |
| 49 message_loop_runner_ = new content::MessageLoopRunner; |
| 50 message_loop_runner_->Run(); |
| 51 } |
| 52 |
| 53 bool popup_hidden() const { return popup_hidden_; } |
| 54 |
| 55 private: |
| 56 bool popup_hidden_; |
| 57 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); |
| 60 }; |
| 61 |
| 62 } // namespace |
| 63 |
| 64 class AutofillPopupControllerBrowserTest |
| 65 : public InProcessBrowserTest, |
| 66 public content::WebContentsObserver { |
| 67 public: |
| 68 AutofillPopupControllerBrowserTest() {} |
| 69 virtual ~AutofillPopupControllerBrowserTest() {} |
| 70 |
| 71 virtual void SetUpOnMainThread() OVERRIDE { |
| 72 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 73 ASSERT_TRUE(web_contents_ != NULL); |
| 74 Observe(web_contents_); |
| 75 |
| 76 autofill_external_delegate_.reset( |
| 77 new TestAutofillExternalDelegate( |
| 78 web_contents_, |
| 79 AutofillManager::FromWebContents(web_contents_))); |
| 80 } |
| 81 |
| 82 // Normally the WebContents will automatically delete the delegate, but here |
| 83 // the delegate is owned by this test, so we have to manually destroy. |
| 84 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
| 85 OVERRIDE { |
| 86 DCHECK_EQ(web_contents_, web_contents); |
| 87 |
| 88 autofill_external_delegate_.reset(); |
| 89 } |
| 90 |
| 91 protected: |
| 92 content::WebContents* web_contents_; |
| 93 |
| 94 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; |
| 95 }; |
| 96 |
| 97 // Autofill UI isn't currently hidden on window move on Mac. |
| 98 // http://crbug.com/180566 |
| 99 #if !defined(OS_MACOSX) |
| 100 IN_PROC_BROWSER_TEST_F(AutofillPopupControllerBrowserTest, |
| 101 HidePopupOnWindowConfiguration) { |
| 102 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); |
| 103 |
| 104 EXPECT_FALSE(autofill_external_delegate_->popup_hidden()); |
| 105 |
| 106 // Resize the window, which should cause the popup to hide. |
| 107 browser()->window()->SetBounds(gfx::Rect(10, 10)); |
| 108 |
| 109 autofill_external_delegate_->WaitForPopupHidden(); |
| 110 EXPECT_TRUE(autofill_external_delegate_->popup_hidden()); |
| 111 } |
| 112 #endif // !defined(OS_MACOSX) |
| OLD | NEW |