OLD | NEW |
---|---|
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/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_tabstrip.h" | 8 #include "chrome/browser/ui/browser_tabstrip.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "chrome/test/base/testing_pref_service_syncable.h" | 12 #include "chrome/test/base/testing_pref_service_syncable.h" |
13 #include "components/autofill/core/browser/autofill_manager.h" | 13 #include "components/autofill/content/browser/autofill_driver_impl.h" |
14 #include "components/autofill/core/browser/test_autofill_driver.h" | |
15 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | |
16 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 14 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
17 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
20 #include "content/public/browser/page_navigator.h" | 18 #include "content/public/browser/page_navigator.h" |
21 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
24 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
51 base::WeakPtr<AutofillPopupDelegate> delegate)); | 49 base::WeakPtr<AutofillPopupDelegate> delegate)); |
52 | 50 |
53 MOCK_METHOD0(HideAutofillPopup, void()); | 51 MOCK_METHOD0(HideAutofillPopup, void()); |
54 | 52 |
55 private: | 53 private: |
56 TestingPrefServiceSyncable prefs_; | 54 TestingPrefServiceSyncable prefs_; |
57 | 55 |
58 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 56 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
59 }; | 57 }; |
60 | 58 |
61 // Subclass AutofillManager so we can create AutofillManager instance. | 59 // Subclass AutofillDriverImpl so we can create AutofillDriverImpl instance. |
Ilya Sherman
2013/06/26 22:36:18
nit: "AutofillDriverImpl instance" -> "an Autofill
blundell
2013/06/27 14:50:35
Done.
| |
62 class TestAutofillManager : public AutofillManager { | 60 class TestAutofillDriverImpl : public AutofillDriverImpl { |
63 public: | 61 public: |
64 TestAutofillManager(AutofillDriver* driver, | 62 TestAutofillDriverImpl(content::WebContents* web_contents, |
65 autofill::AutofillManagerDelegate* delegate) | 63 AutofillManagerDelegate* delegate) |
66 : AutofillManager(driver, | 64 : AutofillDriverImpl(web_contents, |
67 delegate, | 65 delegate, |
68 g_browser_process->GetApplicationLocale(), | 66 g_browser_process->GetApplicationLocale(), |
69 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} | 67 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} |
Ilya Sherman
2013/06/26 22:36:18
nit: Reduce the indentation of this line by two sp
blundell
2013/06/27 14:50:35
4-space indenting is correct for a wrapped argumen
Ilya Sherman
2013/06/27 22:16:10
Ah, I'd missed that this was also an argument to t
| |
70 virtual ~TestAutofillManager() {} | 68 virtual ~TestAutofillDriverImpl() {} |
71 | 69 |
72 private: | 70 private: |
73 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 71 DISALLOW_COPY_AND_ASSIGN(TestAutofillDriverImpl); |
74 }; | |
75 | |
76 // Subclass AutofillExternalDelegate so we can create an | |
77 // AutofillExternalDelegate instance. | |
78 class TestAutofillExternalDelegate : public AutofillExternalDelegate { | |
79 public: | |
80 TestAutofillExternalDelegate(content::WebContents* web_contents, | |
81 AutofillManager* autofill_manager) | |
82 : AutofillExternalDelegate(web_contents, autofill_manager) {} | |
83 virtual ~TestAutofillExternalDelegate() {} | |
84 }; | 72 }; |
85 | 73 |
86 } // namespace | 74 } // namespace |
87 | 75 |
88 class AutofillExternalDelegateBrowserTest | 76 class AutofillDriverImplBrowserTest |
89 : public InProcessBrowserTest, | 77 : public InProcessBrowserTest, |
90 public content::WebContentsObserver { | 78 public content::WebContentsObserver { |
91 public: | 79 public: |
92 AutofillExternalDelegateBrowserTest() {} | 80 AutofillDriverImplBrowserTest() {} |
93 virtual ~AutofillExternalDelegateBrowserTest() {} | 81 virtual ~AutofillDriverImplBrowserTest() {} |
94 | 82 |
95 virtual void SetUpOnMainThread() OVERRIDE { | 83 virtual void SetUpOnMainThread() OVERRIDE { |
96 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 84 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
97 ASSERT_TRUE(web_contents_ != NULL); | 85 ASSERT_TRUE(web_contents_ != NULL); |
98 Observe(web_contents_); | 86 Observe(web_contents_); |
99 | 87 autofill_driver_.reset(new TestAutofillDriverImpl(web_contents_, |
100 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); | 88 &manager_delegate_)); |
blundell
2013/06/26 20:42:31
Deleting this call doesn't seem to have any effect
Ilya Sherman
2013/06/26 22:36:18
Not sure. This might be meant to suppress some DC
blundell
2013/06/27 14:50:35
Restored the line, as neither of us has a definiti
| |
101 | |
102 autofill_driver_.reset(new TestAutofillDriver(web_contents_)); | |
103 autofill_manager_.reset( | |
104 new TestAutofillManager(autofill_driver_.get(), &manager_delegate_)); | |
105 autofill_external_delegate_.reset( | |
106 new TestAutofillExternalDelegate(web_contents_, | |
107 autofill_manager_.get())); | |
108 } | 89 } |
109 | 90 |
110 // Normally the WebContents will automatically delete the delegate, but here | 91 // Normally the WebContents will automatically delete the driver, but here |
111 // the delegate is owned by this test, so we have to manually destroy. | 92 // the driver is owned by this test, so we have to manually destroy. |
112 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 93 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
113 OVERRIDE { | 94 OVERRIDE { |
114 DCHECK_EQ(web_contents_, web_contents); | 95 DCHECK_EQ(web_contents_, web_contents); |
115 autofill_external_delegate_.reset(); | |
116 autofill_manager_.reset(); | |
117 autofill_driver_.reset(); | 96 autofill_driver_.reset(); |
118 } | 97 } |
119 | 98 |
120 protected: | 99 protected: |
121 content::WebContents* web_contents_; | 100 content::WebContents* web_contents_; |
122 | 101 |
123 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; | 102 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; |
124 scoped_ptr<TestAutofillDriver> autofill_driver_; | 103 scoped_ptr<TestAutofillDriverImpl> autofill_driver_; |
125 scoped_ptr<TestAutofillManager> autofill_manager_; | |
126 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; | |
127 }; | 104 }; |
128 | 105 |
129 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, | 106 IN_PROC_BROWSER_TEST_F(AutofillDriverImplBrowserTest, |
130 SwitchTabAndHideAutofillPopup) { | 107 SwitchTabAndHideAutofillPopup) { |
131 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); | |
blundell
2013/06/26 20:42:31
Code inspection made me think that these calls wer
Ilya Sherman
2013/06/26 22:36:18
These were probably needed when the test relied le
| |
132 | |
133 // Notification is different on platforms. On linux this will be called twice, | 108 // Notification is different on platforms. On linux this will be called twice, |
134 // while on windows only once. | 109 // while on windows only once. |
135 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) | 110 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) |
136 .Times(testing::AtLeast(1)); | 111 .Times(testing::AtLeast(1)); |
137 | 112 |
138 content::WindowedNotificationObserver observer( | 113 content::WindowedNotificationObserver observer( |
139 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 114 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
140 content::Source<content::WebContents>(web_contents_)); | 115 content::Source<content::WebContents>(web_contents_)); |
141 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), | 116 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), |
142 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 117 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
143 observer.Wait(); | 118 observer.Wait(); |
144 } | 119 } |
145 | 120 |
146 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, | 121 IN_PROC_BROWSER_TEST_F(AutofillDriverImplBrowserTest, |
147 TestPageNavigationHidingAutofillPopup) { | 122 TestPageNavigationHidingAutofillPopup) { |
148 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); | |
149 | |
150 // Notification is different on platforms. On linux this will be called twice, | 123 // Notification is different on platforms. On linux this will be called twice, |
151 // while on windows only once. | 124 // while on windows only once. |
152 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) | 125 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) |
153 .Times(testing::AtLeast(1)); | 126 .Times(testing::AtLeast(1)); |
154 | 127 |
155 content::WindowedNotificationObserver observer( | 128 content::WindowedNotificationObserver observer( |
156 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 129 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
157 content::Source<content::NavigationController>( | 130 content::Source<content::NavigationController>( |
158 &(web_contents_->GetController()))); | 131 &(web_contents_->GetController()))); |
159 browser()->OpenURL(content::OpenURLParams( | 132 browser()->OpenURL(content::OpenURLParams( |
160 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), | 133 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), |
161 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 134 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
162 browser()->OpenURL(content::OpenURLParams( | 135 browser()->OpenURL(content::OpenURLParams( |
163 GURL(chrome::kChromeUIAboutURL), content::Referrer(), | 136 GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
164 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 137 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
165 observer.Wait(); | 138 observer.Wait(); |
166 } | 139 } |
167 | 140 |
168 } // namespace autofill | 141 } // namespace autofill |
OLD | NEW |