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

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: Adding Tests 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/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h"
7 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_view.h"
17 #include "content/public/test/test_utils.h"
18 #include "ui/gfx/rect.h"
19
20 namespace {
21
22 class TestAutofillPopupController : public AutofillPopupControllerImpl {
23 public:
24 explicit TestAutofillPopupController(
25 AutofillExternalDelegate* external_delegate,
26 gfx::NativeView container_view,
27 const gfx::RectF& element_bounds)
28 : AutofillPopupControllerImpl(external_delegate,
29 container_view,
30 element_bounds) {}
31 virtual ~TestAutofillPopupController() {}
32
33 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr() {
34 return AutofillPopupControllerImpl::GetWeakPtr();
35 }
36
37 private:
38 virtual void ShowView() OVERRIDE {}
39 };
Ilya Sherman 2013/02/22 00:29:04 nit: DISALLOW_COPY_AND_ASSIGN
csharp 2013/02/22 15:41:31 Done.
40
41 class TestAutofillExternalDelegate :
42 public autofill::TestAutofillExternalDelegate {
Ilya Sherman 2013/02/22 00:29:04 nit: Too much indentation?
csharp 2013/02/22 15:41:31 Done.
43 public:
44 explicit TestAutofillExternalDelegate(content::WebContents* web_contents) :
45 autofill::TestAutofillExternalDelegate(web_contents, NULL),
46 popup_hidden_(false),
47 running_(false) {}
48
49 void set_controller(base::WeakPtr<AutofillPopupControllerImpl> controller) {
50 autofill::TestAutofillExternalDelegate::set_controller(controller);
51 }
52
53 virtual void ApplyAutofillSuggestions(
54 const std::vector<string16>& autofill_values,
55 const std::vector<string16>& autofill_labels,
56 const std::vector<string16>& autofill_icons,
57 const std::vector<int>& autofill_unique_ids) OVERRIDE {
Ilya Sherman 2013/02/22 00:29:04 nit: Spurious space before OVERRIDE
csharp 2013/02/22 15:41:31 Done.
58 popup_hidden_ = false;
59
60 AutofillExternalDelegate::ApplyAutofillSuggestions(autofill_values,
61 autofill_labels,
62 autofill_icons,
63 autofill_unique_ids);
64 }
65
66 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE {
67 popup_hidden_ = true;
68
69 AutofillExternalDelegate::OnPopupHidden(listener);
70
71 if (running_) {
72 message_loop_runner_->Quit();
73 running_ = false;
74 }
75 }
76
77 void WaitForPopupHidden() {
78 if (popup_hidden_)
79 return;
80
81 running_ = true;
82 message_loop_runner_ = new content::MessageLoopRunner;
83 message_loop_runner_->Run();
84 }
85
86 bool popup_hidden() const { return popup_hidden_; }
87
88 private:
89 bool popup_hidden_;
90
91 bool running_;
92 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
93
94 };
95
96 } // namespace
97
98 class AutofillPopupControllerBrowserTest
99 : public InProcessBrowserTest,
100 public content::WebContentsObserver {
101 public:
102 AutofillPopupControllerBrowserTest() {}
103 virtual ~AutofillPopupControllerBrowserTest() {}
104
105 virtual void SetUpOnMainThread() OVERRIDE {
106 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
107 ASSERT_TRUE(web_contents_ != NULL);
108 Observe(web_contents_);
109
110 autofill_external_delegate_.reset(
111 new TestAutofillExternalDelegate(web_contents_));
112
113 gfx::NativeView view = web_contents() ?
114 web_contents()->GetView()->GetContentNativeView() : NULL;
115
116 TestAutofillPopupController* controller =
117 new TestAutofillPopupController(autofill_external_delegate_.get(),
118 view,
119 gfx::Rect());
120 autofill_external_delegate_->set_controller(
121 controller->GetWeakPtr());
122 }
123
124 // Normally the WebContents will automatically delete the delegate, but here
125 // the delegate is owned by this test, so we have to manually destroy.
Ilya Sherman 2013/02/22 00:29:04 Why not just do this in a method like TearDown()?
csharp 2013/02/22 15:41:31 Hmm, I don't think we actually need this code at a
126 virtual void WebContentsDestroyed(content::WebContents* web_contents)
127 OVERRIDE {
128 DCHECK_EQ(web_contents_, web_contents);
Ilya Sherman 2013/02/22 00:29:04 Tests should use ASSERT_EQ, not DCHECK_EQ
129 autofill_external_delegate_.reset();
130 }
131
132 protected:
133 content::WebContents* web_contents_;
134 scoped_ptr<TestAutofillExternalDelegate>
135 autofill_external_delegate_;
136 };
137
138 IN_PROC_BROWSER_TEST_F(AutofillPopupControllerBrowserTest,
139 HidePopupOnWindowConfiguration) {
140 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
141
142 EXPECT_FALSE(autofill_external_delegate_->popup_hidden());
143
144 browser()->fullscreen_controller()->ToggleFullscreenMode();
145
146 autofill_external_delegate_->WaitForPopupHidden();
147 EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698