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