Chromium Code Reviews
Help | Chromium Project | Sign in
(209)

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

Issue 11361142: Fill passwords if password manager is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix lint warnings. Created 1 year, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
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/mock_password_store.h"
11 #include "chrome/browser/password_manager/password_manager.h" 11 #include "chrome/browser/password_manager/password_manager.h"
12 #include "chrome/browser/password_manager/password_manager_delegate.h" 12 #include "chrome/browser/password_manager/password_manager_delegate.h"
13 #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" 14 #include "chrome/browser/password_manager/password_store_factory.h"
15 #include "chrome/common/pref_names.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "chrome/test/base/testing_pref_service.h"
17 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/navigation_details.h" 20 #include "content/public/browser/navigation_details.h"
19 #include "content/public/common/frame_navigate_params.h" 21 #include "content/public/common/frame_navigate_params.h"
20 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
21 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 using content::BrowserThread; 26 using content::BrowserThread;
25 using content::PasswordForm; 27 using content::PasswordForm;
26 using testing::_; 28 using testing::_;
(...skipping 20 matching lines...) Expand all
47 } 49 }
48 50
49 class PasswordManagerTest : public ChromeRenderViewHostTestHarness { 51 class PasswordManagerTest : public ChromeRenderViewHostTestHarness {
50 public: 52 public:
51 PasswordManagerTest() 53 PasswordManagerTest()
52 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {} 54 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {}
53 virtual ~PasswordManagerTest() {} 55 virtual ~PasswordManagerTest() {}
54 56
55 protected: 57 protected:
56 virtual void SetUp() { 58 virtual void SetUp() {
57 TestingProfile* testing_profile = new TestingProfile; 59 testing_profile_ = new TestingProfile;
58 store_ = static_cast<MockPasswordStore*>( 60 store_ = static_cast<MockPasswordStore*>(
59 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( 61 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
60 testing_profile, MockPasswordStore::Build).get()); 62 testing_profile_, MockPasswordStore::Build).get());
61 browser_context_.reset(testing_profile); 63 browser_context_.reset(testing_profile_);
62 ChromeRenderViewHostTestHarness::SetUp(); 64 ChromeRenderViewHostTestHarness::SetUp();
63 65
64 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); 66 EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile()));
65 PasswordManager::CreateForWebContentsAndDelegate( 67 PasswordManager::CreateForWebContentsAndDelegate(
66 web_contents(), &delegate_); 68 web_contents(), &delegate_);
67 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) 69 EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors())
68 .WillRepeatedly(Return(false)); 70 .WillRepeatedly(Return(false));
69 } 71 }
70 72
71 virtual void TearDown() { 73 virtual void TearDown() {
(...skipping 16 matching lines...) Expand all
88 90
89 PasswordManager* manager() { 91 PasswordManager* manager() {
90 return PasswordManager::FromWebContents(web_contents()); 92 return PasswordManager::FromWebContents(web_contents());
91 } 93 }
92 94
93 // We create a UI thread to satisfy PasswordStore. 95 // We create a UI thread to satisfy PasswordStore.
94 content::TestBrowserThread ui_thread_; 96 content::TestBrowserThread ui_thread_;
95 97
96 scoped_refptr<MockPasswordStore> store_; 98 scoped_refptr<MockPasswordStore> store_;
97 MockPasswordManagerDelegate delegate_; // Owned by manager_. 99 MockPasswordManagerDelegate delegate_; // Owned by manager_.
100
101 TestingProfile* testing_profile_;
98 }; 102 };
99 103
100 MATCHER_P(FormMatches, form, "") { 104 MATCHER_P(FormMatches, form, "") {
101 return form.signon_realm == arg.signon_realm && 105 return form.signon_realm == arg.signon_realm &&
102 form.origin == arg.origin && 106 form.origin == arg.origin &&
103 form.action == arg.action && 107 form.action == arg.action &&
104 form.username_element == arg.username_element && 108 form.username_element == arg.username_element &&
105 form.password_element == arg.password_element && 109 form.password_element == arg.password_element &&
106 form.submit_element == arg.submit_element; 110 form.submit_element == arg.submit_element;
107 } 111 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::vector<PasswordForm> observed; 332 std::vector<PasswordForm> observed;
329 PasswordForm form(MakeSimpleForm()); 333 PasswordForm form(MakeSimpleForm());
330 observed.push_back(form); 334 observed.push_back(form);
331 manager()->OnPasswordFormsParsed(observed); // The initial load. 335 manager()->OnPasswordFormsParsed(observed); // The initial load.
332 observed.clear(); 336 observed.clear();
333 manager()->OnPasswordFormsRendered(observed); // The initial layout. 337 manager()->OnPasswordFormsRendered(observed); // The initial layout.
334 338
335 manager()->OnPasswordFormsParsed(observed); // The post-navigation load. 339 manager()->OnPasswordFormsParsed(observed); // The post-navigation load.
336 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout. 340 manager()->OnPasswordFormsRendered(observed); // The post-navigation layout.
337 } 341 }
342
343 TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) {
344 TestingPrefService* prefService = testing_profile_->GetTestingPrefService();
345 prefService->SetUserPref(prefs::kPasswordManagerEnabled,
346 Value::CreateBooleanValue(true));
347 EXPECT_TRUE(manager()->IsSavingEnabled());
348 prefService->SetUserPref(prefs::kPasswordManagerEnabled,
349 Value::CreateBooleanValue(false));
350 EXPECT_FALSE(manager()->IsSavingEnabled());
351 }
352
353 TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) {
354 TestingPrefService* prefService = testing_profile_->GetTestingPrefService();
355 prefService->SetUserPref(prefs::kPasswordManagerEnabled,
356 Value::CreateBooleanValue(false));
357 EXPECT_CALL(*store_, GetLogins(_, _));
Ilya Sherman 2012/11/08 06:11:26 nit: It looks like the other tests also include "E
ttr314 2012/11/08 13:36:06 Agreed -- it should make the unit tests look more
358 std::vector<PasswordForm> observed;
359 PasswordForm form(MakeSimpleForm());
360 observed.push_back(form);
361 manager()->OnPasswordFormsParsed(observed);
362 }
363
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1275:d14800f88434