| 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/content/browser/autofill_driver_impl.h" |
| 13 #include "components/autofill/core/browser/autofill_manager.h" | 14 #include "components/autofill/core/browser/autofill_manager.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" | 15 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/page_navigator.h" | 19 #include "content/public/browser/page_navigator.h" |
| 21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 51 base::WeakPtr<AutofillPopupDelegate> delegate)); | 50 base::WeakPtr<AutofillPopupDelegate> delegate)); |
| 52 | 51 |
| 53 MOCK_METHOD0(HideAutofillPopup, void()); | 52 MOCK_METHOD0(HideAutofillPopup, void()); |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 TestingPrefServiceSyncable prefs_; | 55 TestingPrefServiceSyncable prefs_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 // Subclass AutofillManager so we can create AutofillManager instance. | 60 // Subclass AutofillDriverImpl so we can create an AutofillDriverImpl instance. |
| 62 class TestAutofillManager : public AutofillManager { | 61 class TestAutofillDriverImpl : public AutofillDriverImpl { |
| 63 public: | 62 public: |
| 64 TestAutofillManager(AutofillDriver* driver, | 63 TestAutofillDriverImpl(content::WebContents* web_contents, |
| 65 autofill::AutofillManagerDelegate* delegate) | 64 AutofillManagerDelegate* delegate) |
| 66 : AutofillManager(driver, | 65 : AutofillDriverImpl( |
| 67 delegate, | 66 web_contents, |
| 68 g_browser_process->GetApplicationLocale(), | 67 delegate, |
| 69 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} | 68 g_browser_process->GetApplicationLocale(), |
| 70 virtual ~TestAutofillManager() {} | 69 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} |
| 70 virtual ~TestAutofillDriverImpl() {} |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 73 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 }; | 74 }; |
| 85 | 75 |
| 86 } // namespace | 76 } // namespace |
| 87 | 77 |
| 88 class AutofillExternalDelegateBrowserTest | 78 class AutofillDriverImplBrowserTest |
| 89 : public InProcessBrowserTest, | 79 : public InProcessBrowserTest, |
| 90 public content::WebContentsObserver { | 80 public content::WebContentsObserver { |
| 91 public: | 81 public: |
| 92 AutofillExternalDelegateBrowserTest() {} | 82 AutofillDriverImplBrowserTest() {} |
| 93 virtual ~AutofillExternalDelegateBrowserTest() {} | 83 virtual ~AutofillDriverImplBrowserTest() {} |
| 94 | 84 |
| 95 virtual void SetUpOnMainThread() OVERRIDE { | 85 virtual void SetUpOnMainThread() OVERRIDE { |
| 96 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 86 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 97 ASSERT_TRUE(web_contents_ != NULL); | 87 ASSERT_TRUE(web_contents_ != NULL); |
| 98 Observe(web_contents_); | 88 Observe(web_contents_); |
| 99 | |
| 100 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); | 89 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); |
| 101 | 90 |
| 102 autofill_driver_.reset(new TestAutofillDriver(web_contents_)); | 91 autofill_driver_.reset(new TestAutofillDriverImpl(web_contents_, |
| 103 autofill_manager_.reset( | 92 &manager_delegate_)); |
| 104 new TestAutofillManager(autofill_driver_.get(), &manager_delegate_)); | |
| 105 autofill_external_delegate_.reset( | |
| 106 new TestAutofillExternalDelegate(web_contents_, | |
| 107 autofill_manager_.get())); | |
| 108 } | 93 } |
| 109 | 94 |
| 110 // Normally the WebContents will automatically delete the delegate, but here | 95 // Normally the WebContents will automatically delete the driver, but here |
| 111 // the delegate is owned by this test, so we have to manually destroy. | 96 // the driver is owned by this test, so we have to manually destroy. |
| 112 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 97 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
| 113 OVERRIDE { | 98 OVERRIDE { |
| 114 DCHECK_EQ(web_contents_, web_contents); | 99 DCHECK_EQ(web_contents_, web_contents); |
| 115 autofill_external_delegate_.reset(); | |
| 116 autofill_manager_.reset(); | |
| 117 autofill_driver_.reset(); | 100 autofill_driver_.reset(); |
| 118 } | 101 } |
| 119 | 102 |
| 120 protected: | 103 protected: |
| 121 content::WebContents* web_contents_; | 104 content::WebContents* web_contents_; |
| 122 | 105 |
| 123 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; | 106 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; |
| 124 scoped_ptr<TestAutofillDriver> autofill_driver_; | 107 scoped_ptr<TestAutofillDriverImpl> autofill_driver_; |
| 125 scoped_ptr<TestAutofillManager> autofill_manager_; | |
| 126 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; | |
| 127 }; | 108 }; |
| 128 | 109 |
| 129 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, | 110 IN_PROC_BROWSER_TEST_F(AutofillDriverImplBrowserTest, |
| 130 SwitchTabAndHideAutofillPopup) { | 111 SwitchTabAndHideAutofillPopup) { |
| 131 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); | |
| 132 | |
| 133 // Notification is different on platforms. On linux this will be called twice, | 112 // Notification is different on platforms. On linux this will be called twice, |
| 134 // while on windows only once. | 113 // while on windows only once. |
| 135 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) | 114 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) |
| 136 .Times(testing::AtLeast(1)); | 115 .Times(testing::AtLeast(1)); |
| 137 | 116 |
| 138 content::WindowedNotificationObserver observer( | 117 content::WindowedNotificationObserver observer( |
| 139 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 118 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 140 content::Source<content::WebContents>(web_contents_)); | 119 content::Source<content::WebContents>(web_contents_)); |
| 141 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), | 120 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), |
| 142 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 121 content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 143 observer.Wait(); | 122 observer.Wait(); |
| 144 } | 123 } |
| 145 | 124 |
| 146 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, | 125 IN_PROC_BROWSER_TEST_F(AutofillDriverImplBrowserTest, |
| 147 TestPageNavigationHidingAutofillPopup) { | 126 TestPageNavigationHidingAutofillPopup) { |
| 148 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); | |
| 149 | |
| 150 // Notification is different on platforms. On linux this will be called twice, | 127 // Notification is different on platforms. On linux this will be called twice, |
| 151 // while on windows only once. | 128 // while on windows only once. |
| 152 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) | 129 EXPECT_CALL(manager_delegate_, HideAutofillPopup()) |
| 153 .Times(testing::AtLeast(1)); | 130 .Times(testing::AtLeast(1)); |
| 154 | 131 |
| 155 content::WindowedNotificationObserver observer( | 132 content::WindowedNotificationObserver observer( |
| 156 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 133 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 157 content::Source<content::NavigationController>( | 134 content::Source<content::NavigationController>( |
| 158 &(web_contents_->GetController()))); | 135 &(web_contents_->GetController()))); |
| 159 browser()->OpenURL(content::OpenURLParams( | 136 browser()->OpenURL(content::OpenURLParams( |
| 160 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), | 137 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), |
| 161 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 138 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 162 browser()->OpenURL(content::OpenURLParams( | 139 browser()->OpenURL(content::OpenURLParams( |
| 163 GURL(chrome::kChromeUIAboutURL), content::Referrer(), | 140 GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
| 164 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 141 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 165 observer.Wait(); | 142 observer.Wait(); |
| 166 } | 143 } |
| 167 | 144 |
| 168 } // namespace autofill | 145 } // namespace autofill |
| OLD | NEW |