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