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

Side by Side Diff: components/autofill/browser/personal_data_manager_unittest.cc

Issue 14392005: Allowing PersonalDataManagerFactory to create a service while incognito. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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 | « components/autofill/browser/personal_data_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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 personal_data_.reset(new PersonalDataManager("en-US")); 96 personal_data_.reset(new PersonalDataManager("en-US"));
97 personal_data_->Init(profile_.get()); 97 personal_data_->Init(profile_.get());
98 personal_data_->AddObserver(&personal_data_observer_); 98 personal_data_->AddObserver(&personal_data_observer_);
99 99
100 // Verify that the web database has been updated and the notification sent. 100 // Verify that the web database has been updated and the notification sent.
101 EXPECT_CALL(personal_data_observer_, 101 EXPECT_CALL(personal_data_observer_,
102 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 102 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
103 MessageLoop::current()->Run(); 103 MessageLoop::current()->Run();
104 } 104 }
105 105
106 void MakeProfileIncognito() {
107 profile_->set_incognito(true);
108 }
109
106 MessageLoopForUI message_loop_; 110 MessageLoopForUI message_loop_;
107 content::TestBrowserThread ui_thread_; 111 content::TestBrowserThread ui_thread_;
108 content::TestBrowserThread db_thread_; 112 content::TestBrowserThread db_thread_;
109 scoped_ptr<TestingProfile> profile_; 113 scoped_ptr<TestingProfile> profile_;
110 scoped_ptr<PersonalDataManager> personal_data_; 114 scoped_ptr<PersonalDataManager> personal_data_;
111 content::NotificationRegistrar registrar_; 115 content::NotificationRegistrar registrar_;
112 content::MockNotificationObserver observer_; 116 content::MockNotificationObserver observer_;
113 PersonalDataLoadedObserverMock personal_data_observer_; 117 PersonalDataLoadedObserverMock personal_data_observer_;
114 }; 118 };
115 119
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 // Modify expected to include multi-valued fields. 2036 // Modify expected to include multi-valued fields.
2033 std::vector<base::string16> values; 2037 std::vector<base::string16> values;
2034 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 2038 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
2035 values.push_back(ASCIIToUTF16("(214) 555-1234")); 2039 values.push_back(ASCIIToUTF16("(214) 555-1234"));
2036 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); 2040 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
2037 2041
2038 ASSERT_EQ(1U, results2.size()); 2042 ASSERT_EQ(1U, results2.size());
2039 EXPECT_EQ(0, expected.Compare(*results2[0])); 2043 EXPECT_EQ(0, expected.Compare(*results2[0]));
2040 } 2044 }
2041 2045
2046 TEST_F(PersonalDataManagerTest, IncognitoReadOnly) {
2047 ASSERT_TRUE(personal_data_->GetProfiles().empty());
2048 ASSERT_TRUE(personal_data_->credit_cards().empty());
2049
2050 AutofillProfile steve_jobs;
2051 test::SetProfileInfo(&steve_jobs, "Steven", "Paul", "Jobs", "sjobs@apple.com",
2052 "Apple Computer, Inc.", "1 Infinite Loop", "", "Cupertino", "CA", "95014",
2053 "US", "(800) 275-2273");
2054 personal_data_->AddProfile(steve_jobs);
2055
2056 CreditCard bill_gates;
2057 test::SetCreditCardInfo(
2058 &bill_gates, "William H. Gates", "5555555555554444", "1", "2020");
2059 personal_data_->AddCreditCard(bill_gates);
2060
2061 ResetPersonalDataManager();
2062 ASSERT_EQ(1U, personal_data_->GetProfiles().size());
2063 ASSERT_EQ(1U, personal_data_->credit_cards().size());
2064
2065 // After this point no adds, saves, or updates should take effect.
2066 MakeProfileIncognito();
2067 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(0);
2068
2069 // Add profiles or credit card shouldn't work.
2070 personal_data_->AddProfile(test::GetFullProfile());
2071
2072 CreditCard larry_page;
2073 test::SetCreditCardInfo(
2074 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025");
2075 personal_data_->AddCreditCard(larry_page);
2076
2077 ResetPersonalDataManager();
2078 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
2079 EXPECT_EQ(1U, personal_data_->credit_cards().size());
2080
2081 // Saving or creating profiles from imported profiles shouldn't work.
2082 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve"));
2083 personal_data_->SaveImportedProfile(steve_jobs);
2084
2085 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates"));
2086 personal_data_->SaveImportedCreditCard(bill_gates);
2087
2088 ResetPersonalDataManager();
2089 EXPECT_EQ(ASCIIToUTF16("Steven"),
2090 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST));
2091 EXPECT_EQ(ASCIIToUTF16("William H. Gates"),
2092 personal_data_->credit_cards()[0]->GetRawInfo(CREDIT_CARD_NAME));
2093
2094 // Updating existing profiles shouldn't work.
2095 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve"));
2096 personal_data_->UpdateProfile(steve_jobs);
2097
2098 bill_gates.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Bill Gates"));
2099 personal_data_->UpdateCreditCard(bill_gates);
2100
2101 ResetPersonalDataManager();
2102 EXPECT_EQ(ASCIIToUTF16("Steven"),
2103 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST));
2104 EXPECT_EQ(ASCIIToUTF16("William H. Gates"),
2105 personal_data_->credit_cards()[0]->GetRawInfo(CREDIT_CARD_NAME));
2106
2107 // Removing shouldn't work.
2108 personal_data_->RemoveByGUID(steve_jobs.guid());
2109 personal_data_->RemoveByGUID(bill_gates.guid());
2110
2111 ResetPersonalDataManager();
2112 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
2113 EXPECT_EQ(1U, personal_data_->credit_cards().size());
2114 }
2115
2042 } // namespace autofill 2116 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/personal_data_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698