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

Side by Side Diff: chrome/browser/profiles/profile_manager_browsertest.cc

Issue 363013003: Remove passwords from the keychain if the profile is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: The new comment Created 6 years, 5 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_store_factory.h"
9 #include "chrome/browser/profiles/profile_info_cache.h" 10 #include "chrome/browser/profiles/profile_info_cache.h"
10 #include "chrome/browser/profiles/profile_info_cache_observer.h" 11 #include "chrome/browser/profiles/profile_info_cache_observer.h"
11 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profile_window.h" 13 #include "chrome/browser/profiles/profile_window.h"
13 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/host_desktop.h" 18 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/test_switches.h" 21 #include "chrome/test/base/test_switches.h"
21 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/autofill/core/common/password_form.h"
25 #include "components/password_manager/core/browser/password_store.h"
26 #include "components/password_manager/core/browser/password_store_consumer.h"
23 27
24 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
25 #include "base/path_service.h" 29 #include "base/path_service.h"
26 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
28 #include "chromeos/chromeos_switches.h" 32 #include "chromeos/chromeos_switches.h"
29 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
30 #endif 34 #endif
31 35
32 namespace { 36 namespace {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 last_used_profile_name_ = g_browser_process->local_state()->GetString( 82 last_used_profile_name_ = g_browser_process->local_state()->GetString(
79 prefs::kProfileLastUsed); 83 prefs::kProfileLastUsed);
80 } 84 }
81 85
82 private: 86 private:
83 std::string last_used_profile_name_; 87 std::string last_used_profile_name_;
84 88
85 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); 89 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver);
86 }; 90 };
87 91
92 // The class serves to retrieve passwords from PasswordStore asynchronously. It
93 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms.
94 class PasswordStoreConsumerVerifier :
95 public password_manager::PasswordStoreConsumer {
96 public:
97 PasswordStoreConsumerVerifier() : called_(false) {}
98
99 virtual void OnGetPasswordStoreResults(
100 const std::vector<autofill::PasswordForm*>& results) OVERRIDE {
101 EXPECT_FALSE(called_);
102 called_ = true;
103 password_entries_.clear();
104 password_entries_.assign(results.begin(), results.end());
105 }
106
107 bool IsCalled() const { return called_; }
108
109 const std::vector<autofill::PasswordForm*>& GetPasswords() const {
110 return password_entries_.get();
111 }
112 private:
113 ScopedVector<autofill::PasswordForm> password_entries_;
114 bool called_;
115 };
116
88 } // namespace 117 } // namespace
89 118
90 // This file contains tests for the ProfileManager that require a heavyweight 119 // This file contains tests for the ProfileManager that require a heavyweight
91 // InProcessBrowserTest. These include tests involving profile deletion. 120 // InProcessBrowserTest. These include tests involving profile deletion.
92 121
93 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all 122 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all
94 // platforms. 123 // platforms.
95 class ProfileManagerBrowserTest : public InProcessBrowserTest { 124 class ProfileManagerBrowserTest : public InProcessBrowserTest {
96 protected: 125 protected:
97 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 126 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EXPECT_EQ(2U, browser_list->size()); 391 EXPECT_EQ(2U, browser_list->size());
363 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); 392 ASSERT_EQ(2U, cache.GetNumberOfProfiles());
364 393
365 // The second should though. 394 // The second should though.
366 browser_list->get(1)->window()->Close(); 395 browser_list->get(1)->window()->Close();
367 content::RunAllPendingInMessageLoop(); 396 content::RunAllPendingInMessageLoop();
368 EXPECT_EQ(1U, browser_list->size()); 397 EXPECT_EQ(1U, browser_list->size());
369 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); 398 ASSERT_EQ(1U, cache.GetNumberOfProfiles());
370 } 399 }
371 400
401 // The test makes sense on those platforms where the keychain exists.
402 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
403 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) {
404 Profile* profile = ProfileManager::GetActiveUserProfile();
405 ASSERT_TRUE(profile);
406
407 autofill::PasswordForm form;
408 form.scheme = autofill::PasswordForm::SCHEME_HTML;
409 form.origin = GURL("http://accounts.google.com/LoginAuth");
410 form.signon_realm = "http://accounts.google.com/";
411 form.username_value = base::ASCIIToUTF16("my_username");
412 form.password_value = base::ASCIIToUTF16("my_password");
413 form.ssl_valid = false;
414 form.preferred = true;
415 form.blacklisted_by_user = false;
416
417 scoped_refptr<password_manager::PasswordStore> password_store =
418 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)
419 .get();
420 ASSERT_TRUE(password_store);
421
422 password_store->AddLogin(form);
423 PasswordStoreConsumerVerifier verify_add;
424 password_store->GetAutofillableLogins(&verify_add);
425
426 ProfileManager* profile_manager = g_browser_process->profile_manager();
427 profile_manager->ScheduleProfileForDeletion(profile->GetPath(),
428 ProfileManager::CreateCallback());
429 content::RunAllPendingInMessageLoop();
430 PasswordStoreConsumerVerifier verify_delete;
431 password_store->GetAutofillableLogins(&verify_delete);
432
433 // Run the password background thread.
434 base::RunLoop run_loop;
435 base::Closure task = base::Bind(
436 base::IgnoreResult(&content::BrowserThread::PostTask),
437 content::BrowserThread::UI,
438 FROM_HERE,
439 run_loop.QuitClosure());
440 EXPECT_TRUE(password_store->ScheduleTask(task));
441 run_loop.Run();
442
443 EXPECT_TRUE(verify_add.IsCalled());
444 EXPECT_EQ(1u, verify_add.GetPasswords().size());
445 EXPECT_TRUE(verify_delete.IsCalled());
446 EXPECT_EQ(0u, verify_delete.GetPasswords().size());
447 }
448 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698