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

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

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to fix conflict Created 7 years, 6 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
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 21 matching lines...) Expand all
52 54
53 private: 55 private:
54 TestingPrefServiceSyncable prefs_; 56 TestingPrefServiceSyncable prefs_;
55 57
56 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 58 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
57 }; 59 };
58 60
59 // Subclass AutofillManager so we can create AutofillManager instance. 61 // Subclass AutofillManager so we can create AutofillManager instance.
60 class TestAutofillManager : public AutofillManager { 62 class TestAutofillManager : public AutofillManager {
61 public: 63 public:
62 TestAutofillManager(content::WebContents* web_contents, 64 TestAutofillManager(AutofillDriver* driver,
63 autofill::AutofillManagerDelegate* delegate) 65 autofill::AutofillManagerDelegate* delegate)
64 : AutofillManager(web_contents, 66 : AutofillManager(driver,
65 delegate, 67 delegate,
66 g_browser_process->GetApplicationLocale(), 68 g_browser_process->GetApplicationLocale(),
67 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {} 69 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER) {}
68 virtual ~TestAutofillManager() {} 70 virtual ~TestAutofillManager() {}
69 71
70 private: 72 private:
71 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 73 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
72 }; 74 };
73 75
74 // Subclass AutofillExternalDelegate so we can create an 76 // Subclass AutofillExternalDelegate so we can create an
(...skipping 15 matching lines...) Expand all
90 AutofillExternalDelegateBrowserTest() {} 92 AutofillExternalDelegateBrowserTest() {}
91 virtual ~AutofillExternalDelegateBrowserTest() {} 93 virtual ~AutofillExternalDelegateBrowserTest() {}
92 94
93 virtual void SetUpOnMainThread() OVERRIDE { 95 virtual void SetUpOnMainThread() OVERRIDE {
94 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); 96 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
95 ASSERT_TRUE(web_contents_ != NULL); 97 ASSERT_TRUE(web_contents_ != NULL);
96 Observe(web_contents_); 98 Observe(web_contents_);
97 99
98 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry()); 100 AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry());
99 101
102 autofill_driver_.reset(new TestAutofillDriver(web_contents_));
100 autofill_manager_.reset( 103 autofill_manager_.reset(
101 new TestAutofillManager(web_contents_, &manager_delegate_)); 104 new TestAutofillManager(autofill_driver_.get(), &manager_delegate_));
102 autofill_external_delegate_.reset( 105 autofill_external_delegate_.reset(
103 new TestAutofillExternalDelegate(web_contents_, 106 new TestAutofillExternalDelegate(web_contents_,
104 autofill_manager_.get())); 107 autofill_manager_.get()));
105 } 108 }
106 109
107 // Normally the WebContents will automatically delete the delegate, but here 110 // Normally the WebContents will automatically delete the delegate, but here
108 // 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.
109 virtual void WebContentsDestroyed(content::WebContents* web_contents) 112 virtual void WebContentsDestroyed(content::WebContents* web_contents)
110 OVERRIDE { 113 OVERRIDE {
111 DCHECK_EQ(web_contents_, web_contents); 114 DCHECK_EQ(web_contents_, web_contents);
112 autofill_external_delegate_.reset(); 115 autofill_external_delegate_.reset();
113 autofill_manager_.reset(); 116 autofill_manager_.reset();
117 autofill_driver_.reset();
114 } 118 }
115 119
116 protected: 120 protected:
117 content::WebContents* web_contents_; 121 content::WebContents* web_contents_;
118 122
119 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_; 123 testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_;
124 scoped_ptr<TestAutofillDriver> autofill_driver_;
120 scoped_ptr<TestAutofillManager> autofill_manager_; 125 scoped_ptr<TestAutofillManager> autofill_manager_;
121 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_; 126 scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_;
122 }; 127 };
123 128
124 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest, 129 IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
125 SwitchTabAndHideAutofillPopup) { 130 SwitchTabAndHideAutofillPopup) {
126 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get()); 131 autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
127 132
128 // 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,
129 // while on windows only once. 134 // while on windows only once.
(...skipping 24 matching lines...) Expand all
154 browser()->OpenURL(content::OpenURLParams( 159 browser()->OpenURL(content::OpenURLParams(
155 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(), 160 GURL(chrome::kChromeUIBookmarksURL), content::Referrer(),
156 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 161 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
157 browser()->OpenURL(content::OpenURLParams( 162 browser()->OpenURL(content::OpenURLParams(
158 GURL(chrome::kChromeUIAboutURL), content::Referrer(), 163 GURL(chrome::kChromeUIAboutURL), content::Referrer(),
159 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 164 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
160 observer.Wait(); 165 observer.Wait();
161 } 166 }
162 167
163 } // namespace autofill 168 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_browsertest.cc ('k') | chrome/browser/autofill/autofill_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698