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

Side by Side Diff: chrome/browser/password_manager/password_manager_unittest.cc

Issue 7892007: Add ChromeRenderViewHostTestHarness to get rid of the dependency from RVHTH to profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/password_manager/password_manager.h" 10 #include "chrome/browser/password_manager/password_manager.h"
11 #include "chrome/browser/password_manager/password_manager_delegate.h" 11 #include "chrome/browser/password_manager/password_manager_delegate.h"
12 #include "chrome/browser/password_manager/password_store.h" 12 #include "chrome/browser/password_manager/password_store.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
15 #include "content/browser/browser_thread.h" 16 #include "content/browser/browser_thread.h"
16 #include "content/browser/renderer_host/test_render_view_host.h"
17 #include "content/browser/tab_contents/test_tab_contents.h" 17 #include "content/browser/tab_contents/test_tab_contents.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 20
21 using webkit_glue::PasswordForm; 21 using webkit_glue::PasswordForm;
22 using testing::_; 22 using testing::_;
23 using testing::DoAll; 23 using testing::DoAll;
24 using ::testing::Exactly; 24 using ::testing::Exactly;
25 using ::testing::WithArg; 25 using ::testing::WithArg;
26 using ::testing::Return; 26 using ::testing::Return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 }; 71 };
72 72
73 ACTION_P2(InvokeConsumer, handle, forms) { 73 ACTION_P2(InvokeConsumer, handle, forms) {
74 arg0->OnPasswordStoreRequestDone(handle, forms); 74 arg0->OnPasswordStoreRequestDone(handle, forms);
75 } 75 }
76 76
77 ACTION_P(SaveToScopedPtr, scoped) { 77 ACTION_P(SaveToScopedPtr, scoped) {
78 scoped->reset(arg0); 78 scoped->reset(arg0);
79 } 79 }
80 80
81 class PasswordManagerTest : public RenderViewHostTestHarness { 81 class PasswordManagerTest : public ChromeRenderViewHostTestHarness {
82 public: 82 public:
83 PasswordManagerTest() 83 PasswordManagerTest()
84 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {} 84 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {}
85 protected: 85 protected:
86 86
87 virtual void SetUp() { 87 virtual void SetUp() {
88 RenderViewHostTestHarness::SetUp(); 88 store_ = new MockPasswordStore();
89 browser_context_.reset(new TestingProfileWithPasswordStore(store_));
90 ChromeRenderViewHostTestHarness::SetUp();
89 91
90 store_ = new MockPasswordStore();
91 profile_.reset(new TestingProfileWithPasswordStore(store_));
92 EXPECT_CALL(delegate_, GetProfileForPasswordManager()) 92 EXPECT_CALL(delegate_, GetProfileForPasswordManager())
93 .WillRepeatedly(Return(profile_.get())); 93 .WillRepeatedly(Return(profile()));
94 manager_.reset(new PasswordManager(contents(), &delegate_)); 94 manager_.reset(new PasswordManager(contents(), &delegate_));
95 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) 95 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors())
96 .WillRepeatedly(Return(false)); 96 .WillRepeatedly(Return(false));
97 } 97 }
98 98
99 virtual void TearDown() { 99 virtual void TearDown() {
100 manager_.reset(); 100 manager_.reset();
101 store_ = NULL; 101 store_ = NULL;
102 ChromeRenderViewHostTestHarness::TearDown();
102 } 103 }
103 104
104 PasswordForm MakeSimpleForm() { 105 PasswordForm MakeSimpleForm() {
105 PasswordForm form; 106 PasswordForm form;
106 form.origin = GURL("http://www.google.com/a/LoginAuth"); 107 form.origin = GURL("http://www.google.com/a/LoginAuth");
107 form.action = GURL("http://www.google.com/a/Login"); 108 form.action = GURL("http://www.google.com/a/Login");
108 form.username_element = ASCIIToUTF16("Email"); 109 form.username_element = ASCIIToUTF16("Email");
109 form.password_element = ASCIIToUTF16("Passwd"); 110 form.password_element = ASCIIToUTF16("Passwd");
110 form.username_value = ASCIIToUTF16("google"); 111 form.username_value = ASCIIToUTF16("google");
111 form.password_value = ASCIIToUTF16("password"); 112 form.password_value = ASCIIToUTF16("password");
112 form.submit_element = ASCIIToUTF16("signIn"); 113 form.submit_element = ASCIIToUTF16("signIn");
113 form.signon_realm = "http://www.google.com"; 114 form.signon_realm = "http://www.google.com";
114 return form; 115 return form;
115 } 116 }
116 117
117 PasswordManager* manager() { return manager_.get(); } 118 PasswordManager* manager() { return manager_.get(); }
118 119
119 // We create a UI thread to satisfy PasswordStore. 120 // We create a UI thread to satisfy PasswordStore.
120 BrowserThread ui_thread_; 121 BrowserThread ui_thread_;
121 122
122 scoped_ptr<Profile> profile_;
123 scoped_refptr<MockPasswordStore> store_; 123 scoped_refptr<MockPasswordStore> store_;
124 MockPasswordManagerDelegate delegate_; // Owned by manager_. 124 MockPasswordManagerDelegate delegate_; // Owned by manager_.
125 scoped_ptr<PasswordManager> manager_; 125 scoped_ptr<PasswordManager> manager_;
126 }; 126 };
127 127
128 MATCHER_P(FormMatches, form, "") { 128 MATCHER_P(FormMatches, form, "") {
129 return form.signon_realm == arg.signon_realm && 129 return form.signon_realm == arg.signon_realm &&
130 form.origin == arg.origin && 130 form.origin == arg.origin &&
131 form.action == arg.action && 131 form.action == arg.action &&
132 form.username_element == arg.username_element && 132 form.username_element == arg.username_element &&
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 EXPECT_CALL(*store_, GetLogins(_,_)) 273 EXPECT_CALL(*store_, GetLogins(_,_))
274 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 274 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
275 std::vector<PasswordForm> observed; 275 std::vector<PasswordForm> observed;
276 PasswordForm form(MakeSimpleForm()); 276 PasswordForm form(MakeSimpleForm());
277 observed.push_back(form); 277 observed.push_back(form);
278 manager()->OnPasswordFormsFound(observed); // The initial load. 278 manager()->OnPasswordFormsFound(observed); // The initial load.
279 // PasswordFormsVisible is not called. 279 // PasswordFormsVisible is not called.
280 280
281 manager()->DidStopLoading(); 281 manager()->DidStopLoading();
282 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698