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

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

Issue 9665007: Profile refactoring: Remove all PasswordStore code from the Profile interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win and Mac Created 8 years, 9 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) 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 <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/mock_password_store.h"
10 #include "chrome/browser/password_manager/password_manager.h" 11 #include "chrome/browser/password_manager/password_manager.h"
11 #include "chrome/browser/password_manager/password_manager_delegate.h" 12 #include "chrome/browser/password_manager/password_manager_delegate.h"
12 #include "chrome/browser/password_manager/password_store.h" 13 #include "chrome/browser/password_manager/password_store.h"
14 #include "chrome/browser/password_manager/password_store_factory.h"
13 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
16 #include "content/browser/tab_contents/test_tab_contents.h" 18 #include "content/browser/tab_contents/test_tab_contents.h"
17 #include "content/public/browser/navigation_details.h" 19 #include "content/public/browser/navigation_details.h"
18 #include "content/public/common/frame_navigate_params.h" 20 #include "content/public/common/frame_navigate_params.h"
19 #include "content/test/test_browser_thread.h" 21 #include "content/test/test_browser_thread.h"
20 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 using content::BrowserThread; 25 using content::BrowserThread;
24 using webkit::forms::PasswordForm; 26 using webkit::forms::PasswordForm;
25 using testing::_; 27 using testing::_;
26 using testing::DoAll; 28 using testing::DoAll;
27 using ::testing::Exactly; 29 using ::testing::Exactly;
28 using ::testing::WithArg; 30 using ::testing::WithArg;
29 using ::testing::Return; 31 using ::testing::Return;
30 32
31 class MockPasswordManagerDelegate : public PasswordManagerDelegate { 33 class MockPasswordManagerDelegate : public PasswordManagerDelegate {
32 public: 34 public:
33 MOCK_METHOD1(FillPasswordForm, void( 35 MOCK_METHOD1(FillPasswordForm, void(
34 const webkit::forms::PasswordFormFillData&)); 36 const webkit::forms::PasswordFormFillData&));
35 MOCK_METHOD1(AddSavePasswordInfoBar, void(PasswordFormManager*)); 37 MOCK_METHOD1(AddSavePasswordInfoBar, void(PasswordFormManager*));
36 MOCK_METHOD0(GetProfileForPasswordManager, Profile*()); 38 MOCK_METHOD0(GetProfileForPasswordManager, Profile*());
37 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 39 MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
38 }; 40 };
39 41
40 class TestingProfileWithPasswordStore : public TestingProfile {
41 public:
42 explicit TestingProfileWithPasswordStore(PasswordStore* store)
43 : store_(store) {}
44 virtual ~TestingProfileWithPasswordStore() {
45 store_->Shutdown();
46 }
47 virtual PasswordStore* GetPasswordStore(ServiceAccessType access) {
48 return store_;
49 }
50 private:
51 scoped_refptr<PasswordStore> store_;
52 };
53
54 class MockPasswordStore : public PasswordStore {
55 public:
56 MOCK_METHOD1(RemoveLogin, void(const PasswordForm&));
57 MOCK_METHOD2(GetLogins, int(const PasswordForm&, PasswordStoreConsumer*));
58 MOCK_METHOD1(AddLogin, void(const PasswordForm&));
59 MOCK_METHOD1(UpdateLogin, void(const PasswordForm&));
60 MOCK_METHOD0(ReportMetrics, void());
61 MOCK_METHOD0(ReportMetricsImpl, void());
62 MOCK_METHOD1(AddLoginImpl, void(const PasswordForm&));
63 MOCK_METHOD1(UpdateLoginImpl, void(const PasswordForm&));
64 MOCK_METHOD1(RemoveLoginImpl, void(const PasswordForm&));
65 MOCK_METHOD2(RemoveLoginsCreatedBetweenImpl, void(const base::Time&,
66 const base::Time&));
67 MOCK_METHOD2(GetLoginsImpl, void(GetLoginsRequest*, const PasswordForm&));
68 MOCK_METHOD1(GetAutofillableLoginsImpl, void(GetLoginsRequest*));
69 MOCK_METHOD1(GetBlacklistLoginsImpl, void(GetLoginsRequest*));
70 MOCK_METHOD1(FillAutofillableLogins,
71 bool(std::vector<webkit::forms::PasswordForm*>*));
72 MOCK_METHOD1(FillBlacklistLogins,
73 bool(std::vector<webkit::forms::PasswordForm*>*));
74 };
75
76 ACTION_P2(InvokeConsumer, handle, forms) { 42 ACTION_P2(InvokeConsumer, handle, forms) {
77 arg0->OnPasswordStoreRequestDone(handle, forms); 43 arg0->OnPasswordStoreRequestDone(handle, forms);
78 } 44 }
79 45
80 ACTION_P(SaveToScopedPtr, scoped) { 46 ACTION_P(SaveToScopedPtr, scoped) {
81 scoped->reset(arg0); 47 scoped->reset(arg0);
82 } 48 }
83 49
84 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { 50 class PasswordManagerTest : public ChromeRenderViewHostTestHarness {
85 public: 51 public:
86 PasswordManagerTest() 52 PasswordManagerTest()
87 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {} 53 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {}
88 protected: 54 protected:
89 55
90 virtual void SetUp() { 56 virtual void SetUp() {
91 store_ = new MockPasswordStore(); 57 TestingProfile* testing_profile = new TestingProfile;
92 browser_context_.reset(new TestingProfileWithPasswordStore(store_)); 58 store_ = static_cast<MockPasswordStore*>(
59 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
60 testing_profile, MockPasswordStore::Build));
61 browser_context_.reset(testing_profile);
93 ChromeRenderViewHostTestHarness::SetUp(); 62 ChromeRenderViewHostTestHarness::SetUp();
94 63
95 EXPECT_CALL(delegate_, GetProfileForPasswordManager()) 64 EXPECT_CALL(delegate_, GetProfileForPasswordManager())
96 .WillRepeatedly(Return(profile())); 65 .WillRepeatedly(Return(profile()));
97 manager_.reset(new PasswordManager(contents(), &delegate_)); 66 manager_.reset(new PasswordManager(contents(), &delegate_));
98 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) 67 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors())
99 .WillRepeatedly(Return(false)); 68 .WillRepeatedly(Return(false));
100 } 69 }
101 70
102 virtual void TearDown() { 71 virtual void TearDown() {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_CALL(*store_, GetLogins(_,_)) 288 EXPECT_CALL(*store_, GetLogins(_,_))
320 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0))); 289 .WillRepeatedly(DoAll(WithArg<1>(InvokeConsumer(0, result)), Return(0)));
321 std::vector<PasswordForm> observed; 290 std::vector<PasswordForm> observed;
322 PasswordForm form(MakeSimpleForm()); 291 PasswordForm form(MakeSimpleForm());
323 observed.push_back(form); 292 observed.push_back(form);
324 manager()->OnPasswordFormsFound(observed); // The initial load. 293 manager()->OnPasswordFormsFound(observed); // The initial load.
325 // PasswordFormsVisible is not called. 294 // PasswordFormsVisible is not called.
326 295
327 manager()->DidStopLoading(); 296 manager()->DidStopLoading();
328 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698