Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_browsertest.cc

Issue 12302034: Always Close the Autofill UI through the same path (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/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/fullscreen/fullscreen_controller.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/browser/web_contents_view.h"
18 #include "content/public/test/test_utils.h"
19 #include "ui/gfx/rect.h"
20
21 namespace {
22
23 class TestAutofillPopupController : public AutofillPopupControllerImpl {
24 public:
25 explicit TestAutofillPopupController(
26 AutofillExternalDelegate* external_delegate,
27 gfx::NativeView container_view,
28 const gfx::RectF& element_bounds)
29 : AutofillPopupControllerImpl(external_delegate,
30 container_view,
31 element_bounds) {}
32 virtual ~TestAutofillPopupController() {}
33
34 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr() {
35 return AutofillPopupControllerImpl::GetWeakPtr();
36 }
37
38 private:
39 virtual void ShowView() OVERRIDE {}
40
41 DISALLOW_COPY_AND_ASSIGN(TestAutofillPopupController);
42 };
43
44 class TestAutofillExternalDelegate :
45 public autofill::TestAutofillExternalDelegate {
46 public:
47 explicit TestAutofillExternalDelegate(content::WebContents* web_contents) :
48 autofill::TestAutofillExternalDelegate(web_contents, NULL),
49 popup_hidden_(false),
50 running_(false) {}
51
52 void set_controller(base::WeakPtr<AutofillPopupControllerImpl> controller) {
53 autofill::TestAutofillExternalDelegate::set_controller(controller);
54 }
55
56 virtual void ApplyAutofillSuggestions(
57 const std::vector<string16>& autofill_values,
58 const std::vector<string16>& autofill_labels,
59 const std::vector<string16>& autofill_icons,
60 const std::vector<int>& autofill_unique_ids) OVERRIDE {
61 popup_hidden_ = false;
62
63 AutofillExternalDelegate::ApplyAutofillSuggestions(autofill_values,
64 autofill_labels,
65 autofill_icons,
66 autofill_unique_ids);
67 }
68
69 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE {
70 popup_hidden_ = true;
71
72 AutofillExternalDelegate::OnPopupHidden(listener);
73
74 if (running_) {
75 message_loop_runner_->Quit();
76 running_ = false;
77 }
78 }
79
80 void WaitForPopupHidden() {
81 if (popup_hidden_)
82 return;
83
84 running_ = true;
85 message_loop_runner_ = new content::MessageLoopRunner;
86 message_loop_runner_->Run();
87 }
88
89 bool popup_hidden() const { return popup_hidden_; }
90
91 private:
92 bool popup_hidden_;
93
94 bool running_;
Ilya Sherman 2013/02/26 01:02:32 nit: This variable shouldn't be necessary; you sho
csharp 2013/02/26 18:33:31 Done.
95 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
96
97 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
98 };
99
100 } // namespace
101
102 class AutofillPopupControllerBrowserTest
103 : public InProcessBrowserTest,
104 public content::WebContentsObserver {
105 public:
106 AutofillPopupControllerBrowserTest() {}
107 virtual ~AutofillPopupControllerBrowserTest() {}
108
109 virtual void SetUpOnMainThread() OVERRIDE {
110 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
111 ASSERT_TRUE(web_contents_ != NULL);
112 Observe(web_contents_);
113
114 autofill_external_delegate_.reset(
115 new TestAutofillExternalDelegate(web_contents_));
116
117 gfx::NativeView view = web_contents() ?
118 web_contents()->GetView()->GetContentNativeView() : NULL;
119
120 TestAutofillPopupController* controller =
121 new TestAutofillPopupController(autofill_external_delegate_.get(),
122 view,
123 gfx::Rect());
124 autofill_external_delegate_->set_controller(
125 controller->GetWeakPtr());
126 }
127
128 protected:
129 content::WebContents* web_contents_;
130 scoped_ptr<TestAutofillExternalDelegate>
131 autofill_external_delegate_;
132 };
133
134 IN_PROC_BROWSER_TEST_F(AutofillPopupControllerBrowserTest,
135 HidePopupOnWindowConfiguration) {
136 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
137
138 EXPECT_FALSE(autofill_external_delegate_->popup_hidden());
139
140 browser()->fullscreen_controller()->ToggleFullscreenMode();
141
142 autofill_external_delegate_->WaitForPopupHidden();
143 EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698