OLD | NEW |
---|---|
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 Loading... | |
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 class PasswordStoreConsumerVerifier : | |
93 public password_manager::PasswordStoreConsumer { | |
94 public: | |
95 PasswordStoreConsumerVerifier() : called_(false) {} | |
96 | |
97 virtual void OnGetPasswordStoreResults( | |
98 const std::vector<autofill::PasswordForm*>& results) OVERRIDE { | |
99 EXPECT_FALSE(called_); | |
100 called_ = true; | |
101 password_entries_.clear(); | |
102 password_entries_.assign(results.begin(), results.end()); | |
103 } | |
104 | |
105 bool IsCalled() const { return called_; } | |
106 | |
107 const std::vector<autofill::PasswordForm*>& GetPasswords() const { | |
108 return password_entries_.get(); | |
109 } | |
110 private: | |
111 ScopedVector<autofill::PasswordForm> password_entries_; | |
112 bool called_; | |
113 }; | |
114 | |
88 } // namespace | 115 } // namespace |
89 | 116 |
90 // This file contains tests for the ProfileManager that require a heavyweight | 117 // This file contains tests for the ProfileManager that require a heavyweight |
91 // InProcessBrowserTest. These include tests involving profile deletion. | 118 // InProcessBrowserTest. These include tests involving profile deletion. |
92 | 119 |
93 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 120 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
94 // platforms. | 121 // platforms. |
95 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 122 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
96 protected: | 123 protected: |
97 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 124 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 EXPECT_EQ(2U, browser_list->size()); | 389 EXPECT_EQ(2U, browser_list->size()); |
363 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); | 390 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); |
364 | 391 |
365 // The second should though. | 392 // The second should though. |
366 browser_list->get(1)->window()->Close(); | 393 browser_list->get(1)->window()->Close(); |
367 content::RunAllPendingInMessageLoop(); | 394 content::RunAllPendingInMessageLoop(); |
368 EXPECT_EQ(1U, browser_list->size()); | 395 EXPECT_EQ(1U, browser_list->size()); |
369 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); | 396 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); |
370 } | 397 } |
371 | 398 |
399 // The test makes sense on those platforms where the Keychain exists. | |
stuartmorgan
2014/07/07 18:49:42
The term "Keychain" as a proper name is Apple-spec
vasilii
2014/07/08 09:27:39
Done.
| |
400 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | |
401 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { | |
402 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
403 ASSERT_TRUE(profile); | |
404 | |
405 autofill::PasswordForm form; | |
406 form.scheme = autofill::PasswordForm::SCHEME_HTML; | |
407 form.origin = GURL("http://accounts.google.com/LoginAuth"); | |
408 form.signon_realm = "http://accounts.google.com/"; | |
409 form.username_value = base::ASCIIToUTF16("my_username"); | |
410 form.password_value = base::ASCIIToUTF16("my_password"); | |
411 form.ssl_valid = false; | |
412 form.preferred = true; | |
413 form.blacklisted_by_user = false; | |
414 | |
415 scoped_refptr<password_manager::PasswordStore> password_store = | |
416 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | |
417 .get(); | |
418 ASSERT_TRUE(password_store); | |
419 | |
420 password_store->AddLogin(form); | |
421 PasswordStoreConsumerVerifier verify_add; | |
422 password_store->GetAutofillableLogins(&verify_add); | |
423 | |
424 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
425 profile_manager->ScheduleProfileForDeletion(profile->GetPath(), | |
426 ProfileManager::CreateCallback()); | |
427 content::RunAllPendingInMessageLoop(); | |
428 PasswordStoreConsumerVerifier verify_delete; | |
429 password_store->GetAutofillableLogins(&verify_delete); | |
430 | |
431 // Run the password background thread. | |
432 base::RunLoop run_loop; | |
433 base::Closure task = base::Bind( | |
434 base::IgnoreResult(&content::BrowserThread::PostTask), | |
435 content::BrowserThread::UI, | |
436 FROM_HERE, | |
437 run_loop.QuitClosure()); | |
438 EXPECT_TRUE(password_store->ScheduleTask(task)); | |
439 run_loop.Run(); | |
440 | |
441 EXPECT_TRUE(verify_add.IsCalled()); | |
442 EXPECT_EQ(1u, verify_add.GetPasswords().size()); | |
443 EXPECT_TRUE(verify_delete.IsCalled()); | |
444 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); | |
445 } | |
446 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | |
OLD | NEW |