| 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/browser/autofill_manager.h" | 13 #include "components/autofill/browser/autofill_manager.h" |
| 14 #include "components/autofill/browser/test_autofill_driver.h" |
| 14 #include "components/autofill/browser/test_autofill_external_delegate.h" | 15 #include "components/autofill/browser/test_autofill_external_delegate.h" |
| 15 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 16 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/page_navigator.h" | 20 #include "content/public/browser/page_navigator.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 22 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| 26 | 28 |
| 27 namespace autofill { | 29 namespace autofill { |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 class MockAutofillManagerDelegate | 32 class MockAutofillManagerDelegate |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 | 53 |
| 52 private: | 54 private: |
| 53 TestingPrefServiceSyncable prefs_; | 55 TestingPrefServiceSyncable prefs_; |
| 54 | 56 |
| 55 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 // Subclass AutofillManager so we can create AutofillManager instance. | 60 // Subclass AutofillManager so we can create AutofillManager instance. |
| 59 class TestAutofillManager : public AutofillManager { | 61 class TestAutofillManager : public AutofillManager { |
| 60 public: | 62 public: |
| 61 TestAutofillManager(content::WebContents* web_contents, | 63 TestAutofillManager(AutofillDriver* driver, |
| 62 autofill::AutofillManagerDelegate* delegate) | 64 autofill::AutofillManagerDelegate* delegate) |
| 63 : AutofillManager(web_contents, | 65 : AutofillManager(driver, |
| 64 delegate, | 66 delegate, |
| 65 g_browser_process->GetApplicationLocale(), | 67 g_browser_process->GetApplicationLocale(), |
| 66 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} | 68 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} |
| 67 virtual ~TestAutofillManager() {} | 69 virtual ~TestAutofillManager() {} |
| 68 | 70 |
| 69 private: | 71 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 72 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 // Subclass AutofillExternalDelegate so we can create an | 75 // Subclass AutofillExternalDelegate so we can create an |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 AutofillExternalDelegateBrowserTest() {} | 91 AutofillExternalDelegateBrowserTest() {} |
| 90 virtual ~AutofillExternalDelegateBrowserTest() {} | 92 virtual ~AutofillExternalDelegateBrowserTest() {} |
| 91 | 93 |
| 92 virtual void SetUpOnMainThread() OVERRIDE { | 94 virtual void SetUpOnMainThread() OVERRIDE { |
| 93 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 95 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 94 ASSERT_TRUE(web_contents_ != NULL); | 96 ASSERT_TRUE(web_contents_ != NULL); |
| 95 Observe(web_contents_); | 97 Observe(web_contents_); |
| 96 | 98 |
| 97 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); | 99 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); |
| 98 | 100 |
| 101 autofill_driver_.reset(new TestAutofillDriver(web_contents_)); |
| 99 autofill_manager_.reset( | 102 autofill_manager_.reset( |
| 100 new TestAutofillManager(web_contents_, &manager_delegate_)); | 103 new TestAutofillManager(autofill_driver_.get(), |
| 104 &manager_delegate_)); |
| 101 autofill_external_delegate_.reset( | 105 autofill_external_delegate_.reset( |
| 102 new TestAutofillExternalDelegate(web_contents_, | 106 new TestAutofillExternalDelegate(web_contents_, |
| 103 autofill_manager_.get())); | 107 autofill_manager_.get())); |
| 104 } | 108 } |
| 105 | 109 |
| 106 // Normally the WebContents will automatically delete the delegate, but here | 110 // Normally the WebContents will automatically delete the delegate, but here |
| 107 // the delegate is owned by this test, so we have to manually destroy. | 111 // the delegate is owned by this test, so we have to manually destroy. |
| 108 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 112 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
| 109 OVERRIDE { | 113 OVERRIDE { |
| 110 DCHECK_EQ(web_contents_, web_contents); | 114 DCHECK_EQ(web_contents_, web_contents); |
| 111 autofill_external_delegate_.reset(); | 115 autofill_external_delegate_.reset(); |
| 112 autofill_manager_.reset(); | 116 autofill_manager_.reset(); |
| 117 autofill_driver_.reset(); |
| 113 } | 118 } |
| 114 | 119 |
| 115 protected: | 120 protected: |
| 116 content::WebContents* web_contents_; | 121 content::WebContents* web_contents_; |
| 117 | 122 |
| 118 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; | 123 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; |
| 124 scoped_ptr<TestAutofillDriver> autofill_driver_; |
| 119 scoped_ptr<TestAutofillManager> autofill_manager_; | 125 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 120 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; | 126 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; |
| 121 }; | 127 }; |
| 122 | 128 |
| 123 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, | 129 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, |
| 124 SwitchTabAndHideAutofillPopup) { | 130 SwitchTabAndHideAutofillPopup) { |
| 125 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); | 131 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); |
| 126 | 132 |
| 127 // Notification is different on platforms. On linux this will be called twice, | 133 // Notification is different on platforms. On linux this will be called twice, |
| 128 // while on windows only once. | 134 // while on windows only once. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 153 browser()->OpenURL(content::OpenURLParams( | 159 browser()->OpenURL(content::OpenURLParams( |
| 154 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), | 160 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), |
| 155 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 161 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 156 browser()->OpenURL(content::OpenURLParams( | 162 browser()->OpenURL(content::OpenURLParams( |
| 157 GURL(chrome::kChromeUIAboutURL), content::Referrer(), | 163 GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
| 158 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 164 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 159 observer.Wait(); | 165 observer.Wait(); |
| 160 } | 166 } |
| 161 | 167 |
| 162 } // namespace autofill | 168 } // namespace autofill |
| OLD | NEW |