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

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: Remove old (now incorrect) test 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/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 TestAutofillPopupController : public AutofillPopupControllerImpl {
25 public:
26 explicit TestAutofillPopupController(
27 AutofillExternalDelegate* external_delegate,
28 gfx::NativeView container_view,
29 const gfx::RectF& element_bounds)
30 : AutofillPopupControllerImpl(external_delegate,
31 container_view,
32 element_bounds) {}
33 virtual ~TestAutofillPopupController() {}
34
35 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr() {
36 return AutofillPopupControllerImpl::GetWeakPtr();
37 }
38
39 private:
40 virtual void ShowView() OVERRIDE {}
41
42 DISALLOW_COPY_AND_ASSIGN(TestAutofillPopupController);
43 };
44
45 class TestAutofillExternalDelegate :
46 public autofill::TestAutofillExternalDelegate {
47 public:
48 explicit TestAutofillExternalDelegate(content::WebContents* web_contents,
49 AutofillManager* autofill_manager) :
50 autofill::TestAutofillExternalDelegate(web_contents, autofill_manager),
51 popup_hidden_(false),
52 running_(false) {}
53
54 void set_controller(base::WeakPtr<AutofillPopupControllerImpl> controller) {
55 autofill::TestAutofillExternalDelegate::set_controller(controller);
56 }
57
58 virtual void ApplyAutofillSuggestions(
59 const std::vector<string16>& autofill_values,
60 const std::vector<string16>& autofill_labels,
61 const std::vector<string16>& autofill_icons,
62 const std::vector<int>& autofill_unique_ids) OVERRIDE {
63 popup_hidden_ = false;
64
65 AutofillExternalDelegate::ApplyAutofillSuggestions(autofill_values,
66 autofill_labels,
67 autofill_icons,
68 autofill_unique_ids);
69 }
70
71 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE {
72 popup_hidden_ = true;
73
74 AutofillExternalDelegate::OnPopupHidden(listener);
75
76 if (message_loop_runner_)
77 message_loop_runner_->Quit();
78 }
79
80 void WaitForPopupHidden() {
81 if (popup_hidden_)
82 return;
83
84 message_loop_runner_ = new content::MessageLoopRunner;
85 message_loop_runner_->Run();
86 }
87
88 bool popup_hidden() const { return popup_hidden_; }
89
90 private:
91 bool popup_hidden_;
92
93 bool running_;
Ilya Sherman 2013/02/26 23:50:34 nit: Remove 'dis guy?
csharp 2013/02/27 18:18:13 Done.
94 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
95
96 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
97 };
98
99 } // namespace
100
101 class AutofillPopupControllerBrowserTest
102 : public InProcessBrowserTest,
103 public content::WebContentsObserver {
104 public:
105 AutofillPopupControllerBrowserTest() {}
106 virtual ~AutofillPopupControllerBrowserTest() {}
107
108 virtual void SetUpOnMainThread() OVERRIDE {
109 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
110 ASSERT_TRUE(web_contents_ != NULL);
111 Observe(web_contents_);
112
113 autofill_external_delegate_.reset(
114 new TestAutofillExternalDelegate(web_contents_,
115 AutofillManager::FromWebContents(
116 web_contents_)));
117
118 gfx::NativeView view = web_contents() ?
119 web_contents()->GetView()->GetContentNativeView() : NULL;
120
121 TestAutofillPopupController* controller =
122 new TestAutofillPopupController(autofill_external_delegate_.get(),
123 view,
124 gfx::Rect());
125 autofill_external_delegate_->set_controller(
126 controller->GetWeakPtr());
Ilya Sherman 2013/02/26 23:50:34 nit: No need to wrap this line?
csharp 2013/02/27 18:18:13 Done.
127 }
128
129 protected:
130 content::WebContents* web_contents_;
131 scoped_ptr<TestAutofillExternalDelegate>
132 autofill_external_delegate_;
Ilya Sherman 2013/02/26 23:50:34 nit: No need to wrap this line?
csharp 2013/02/27 18:18:13 Done.
133 };
134
135 IN_PROC_BROWSER_TEST_F(AutofillPopupControllerBrowserTest,
136 HidePopupOnWindowConfiguration) {
137 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
138
139 EXPECT_FALSE(autofill_external_delegate_->popup_hidden());
140
141 browser()->fullscreen_controller()->ToggleFullscreenMode();
142
143 autofill_external_delegate_->WaitForPopupHidden();
144 EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
145 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_popup_controller.h ('k') | chrome/browser/ui/autofill/autofill_popup_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698