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

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate_browsertest.cc

Issue 12288046: Merge 182751 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1410/src/
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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/autofill/autofill_manager.h" 6 #include "chrome/browser/autofill/autofill_manager.h"
7 #include "chrome/browser/autofill/test_autofill_external_delegate.h" 7 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_tabstrip.h" 11 #include "chrome/browser/ui/browser_tabstrip.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/page_navigator.h" 18 #include "content/public/browser/page_navigator.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
25 24
26 using ::testing::AtLeast;
27 using testing::_;
28
29 namespace { 25 namespace {
30 26
31 class MockAutofillExternalDelegate : public AutofillExternalDelegate { 27 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
32 public: 28 public:
33 explicit MockAutofillExternalDelegate(content::WebContents* web_contents) 29 explicit MockAutofillExternalDelegate(content::WebContents* web_contents)
34 : AutofillExternalDelegate( 30 : AutofillExternalDelegate(
35 web_contents, 31 web_contents,
36 AutofillManager::FromWebContents(web_contents)) {} 32 AutofillManager::FromWebContents(web_contents)),
33 popup_hidden_(true) {}
37 ~MockAutofillExternalDelegate() {} 34 ~MockAutofillExternalDelegate() {}
38 35
39 virtual void DidSelectSuggestion(int unique_id) OVERRIDE {} 36 virtual void DidSelectSuggestion(int unique_id) OVERRIDE {}
40 37
41 virtual void ClearPreviewedForm() OVERRIDE {} 38 virtual void ClearPreviewedForm() OVERRIDE {}
42 39
43 AutofillPopupControllerImpl* GetController() { 40 AutofillPopupControllerImpl* GetController() {
44 return controller(); 41 return controller();
45 } 42 }
46 43
47 MOCK_METHOD0(HideAutofillPopup, void()); 44 virtual void ApplyAutofillSuggestions(
45 const std::vector<string16>& autofill_values,
46 const std::vector<string16>& autofill_labels,
47 const std::vector<string16>& autofill_icons,
48 const std::vector<int>& autofill_unique_ids) OVERRIDE {
49 popup_hidden_ = false;
50
51 AutofillExternalDelegate::ApplyAutofillSuggestions(autofill_values,
52 autofill_labels,
53 autofill_icons,
54 autofill_unique_ids);
55 }
56
57 virtual void HideAutofillPopup() OVERRIDE {
58 popup_hidden_ = true;
59
60 AutofillExternalDelegate::HideAutofillPopup();
61 }
62
63 bool popup_hidden() const { return popup_hidden_; }
64
65 private:
66 bool popup_hidden_;
48 }; 67 };
49 68
50 } // namespace 69 } // namespace
51 70
52 class AutofillExternalDelegateBrowserTest 71 class AutofillExternalDelegateBrowserTest
53 : public InProcessBrowserTest, 72 : public InProcessBrowserTest,
54 public content::WebContentsObserver { 73 public content::WebContentsObserver {
55 public: 74 public:
56 AutofillExternalDelegateBrowserTest() {} 75 AutofillExternalDelegateBrowserTest() {}
57 virtual ~AutofillExternalDelegateBrowserTest() {} 76 virtual ~AutofillExternalDelegateBrowserTest() {}
(...skipping 15 matching lines...) Expand all
73 autofill_external_delegate_.reset(); 92 autofill_external_delegate_.reset();
74 } 93 }
75 94
76 protected: 95 protected:
77 content::WebContents* web_contents_; 96 content::WebContents* web_contents_;
78 scoped_ptr<MockAutofillExternalDelegate> autofill_external_delegate_; 97 scoped_ptr<MockAutofillExternalDelegate> autofill_external_delegate_;
79 }; 98 };
80 99
81 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, 100 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
82 SwitchTabAndHideAutofillPopup) { 101 SwitchTabAndHideAutofillPopup) {
83 EXPECT_CALL(*autofill_external_delegate_,
84 HideAutofillPopup()).Times(AtLeast(1));
85
86 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); 102 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
87 103
88 content::WindowedNotificationObserver observer( 104 content::WindowedNotificationObserver observer(
89 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, 105 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
90 content::Source<content::WebContents>(web_contents_)); 106 content::Source<content::WebContents>(web_contents_));
91 chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL), 107 chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL),
92 content::PAGE_TRANSITION_AUTO_TOPLEVEL); 108 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
93 observer.Wait(); 109 observer.Wait();
94 110
95 // The mock verifies that the call was made. 111 EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
96 } 112 }
97 113
98 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, 114 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
99 TestPageNavigationHidingAutofillPopup) { 115 TestPageNavigationHidingAutofillPopup) {
100 EXPECT_CALL(*autofill_external_delegate_, 116 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
101 HideAutofillPopup()).Times(AtLeast(1));
102 117
103 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); 118 EXPECT_FALSE(autofill_external_delegate_->popup_hidden());
104 119
105 content::WindowedNotificationObserver observer( 120 content::WindowedNotificationObserver observer(
106 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 121 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
107 content::Source<content::NavigationController>( 122 content::Source<content::NavigationController>(
108 &(web_contents_->GetController()))); 123 &(web_contents_->GetController())));
109 browser()->OpenURL(content::OpenURLParams( 124 browser()->OpenURL(content::OpenURLParams(
110 GURL(chrome::kAboutBlankURL), content::Referrer(), 125 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(),
111 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 126 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
112 browser()->OpenURL(content::OpenURLParams( 127 browser()->OpenURL(content::OpenURLParams(
113 GURL(chrome::kChromeUIAboutURL), content::Referrer(), 128 GURL(chrome::kChromeUIAboutURL), content::Referrer(),
114 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 129 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
115 observer.Wait(); 130 observer.Wait();
116 131
117 // The mock verifies that the call was made. 132 EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
118 } 133 }
119 134
120 // Tests that closing the widget does not leak any resources. This test is 135 // Tests that closing the widget does not leak any resources. This test is
121 // only really meaningful when run on the memory bots. 136 // only really meaningful when run on the memory bots.
122 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, 137 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
123 CloseWidgetAndNoLeaking) { 138 CloseWidgetAndNoLeaking) {
124 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); 139 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
125 140
126 // Delete the view from under the delegate to ensure that the 141 // Delete the view from under the delegate to ensure that the
127 // delegate and the controller can handle the popup getting deleted elsewhere. 142 // delegate and the controller can handle the popup getting deleted elsewhere.
128 autofill_external_delegate_->GetController()->view()->Hide(); 143 autofill_external_delegate_->GetController()->view()->Hide();
129 } 144 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.cc ('k') | chrome/browser/autofill/autofill_external_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698