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

Side by Side Diff: chrome/browser/webdata/web_data_service_unittest.cc

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved histograms to protector folder Created 9 years, 1 month 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/webdata/web_data_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 string16 value1_; 139 string16 value1_;
140 string16 value2_; 140 string16 value2_;
141 int unique_id1_, unique_id2_; 141 int unique_id1_, unique_id2_;
142 const TimeDelta test_timeout_; 142 const TimeDelta test_timeout_;
143 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_; 143 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_;
144 WaitableEvent done_event_; 144 WaitableEvent done_event_;
145 }; 145 };
146 146
147 // Simple consumer for WebIntents data. Stores the result data and quits UI 147 // Simple consumer for WebIntents data. Stores the result data and quits UI
148 // message loop when callback is invoked. 148 // message loop when callback is invoked.
149 class WebIntentsConsumer: public WebDataServiceConsumer { 149 class WebIntentsConsumer : public WebDataServiceConsumer {
150 public: 150 public:
151 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 151 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
152 const WDTypedResult* result) { 152 const WDTypedResult* result) {
153 intents.clear(); 153 intents.clear();
154 if (result) { 154 if (result) {
155 DCHECK(result->GetType() == WEB_INTENTS_RESULT); 155 DCHECK(result->GetType() == WEB_INTENTS_RESULT);
156 intents = static_cast< 156 intents = static_cast<
157 const WDResult<std::vector<WebIntentServiceData> >*>(result)-> 157 const WDResult<std::vector<WebIntentServiceData> >*>(result)->
158 GetValue(); 158 GetValue();
159 } 159 }
160 160
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
162 MessageLoop::current()->Quit(); 162 MessageLoop::current()->Quit();
163 } 163 }
164 164
165 // Run the current message loop. OnWebDataServiceRequestDone will invoke 165 // Run the current message loop. OnWebDataServiceRequestDone will invoke
166 // MessageLoop::Quit on completion, so this call will finish at that point. 166 // MessageLoop::Quit on completion, so this call will finish at that point.
167 static void WaitUntilCalled() { 167 static void WaitUntilCalled() {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
169 MessageLoop::current()->Run(); 169 MessageLoop::current()->Run();
170 } 170 }
171 171
172 // Result data from completion callback. 172 // Result data from completion callback.
173 std::vector<WebIntentServiceData> intents; 173 std::vector<WebIntentServiceData> intents;
174 }; 174 };
175 175
176 // Simple consumer for Keywords data. Stores the result data and quits UI
177 // message loop when callback is invoked.
178 class KeywordsConsumer : public WebDataServiceConsumer {
179 public:
180 KeywordsConsumer() : load_succeeded(false) {}
181
182 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
183 const WDTypedResult* result) {
184 if (result) {
185 load_succeeded = true;
186 DCHECK(result->GetType() == KEYWORDS_RESULT);
187 keywords_result =
188 reinterpret_cast<const WDResult<WDKeywordsResult>*>(
189 result)->GetValue();
190 }
191
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
193 MessageLoop::current()->Quit();
194 }
195
196 // Run the current message loop. OnWebDataServiceRequestDone will invoke
197 // MessageLoop::Quit on completion, so this call will finish at that point.
198 static void WaitUntilCalled() {
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
200 MessageLoop::current()->Run();
201 }
202
203 // True if keywords data was loaded successfully.
204 bool load_succeeded;
205 // Result data from completion callback.
206 WDKeywordsResult keywords_result;
207 };
208
176 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { 209 TEST_F(WebDataServiceAutofillTest, FormFillAdd) {
177 const AutofillChange expected_changes[] = { 210 const AutofillChange expected_changes[] = {
178 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), 211 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)),
179 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) 212 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_))
180 }; 213 };
181 214
182 // This will verify that the correct notification is triggered, 215 // This will verify that the correct notification is triggered,
183 // passing the correct list of autofill keys in the details. 216 // passing the correct list of autofill keys in the details.
184 EXPECT_CALL( 217 EXPECT_CALL(
185 *observer_helper_->observer(), 218 *observer_helper_->observer(),
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 WebIntentsConsumer::WaitUntilCalled(); 688 WebIntentsConsumer::WaitUntilCalled();
656 ASSERT_EQ(2U, consumer.intents.size()); 689 ASSERT_EQ(2U, consumer.intents.size());
657 690
658 if (consumer.intents[0].action != ASCIIToUTF16("edit")) 691 if (consumer.intents[0].action != ASCIIToUTF16("edit"))
659 std::swap(consumer.intents[0],consumer.intents[1]); 692 std::swap(consumer.intents[0],consumer.intents[1]);
660 693
661 EXPECT_EQ(service, consumer.intents[0]); 694 EXPECT_EQ(service, consumer.intents[0]);
662 service.action = ASCIIToUTF16("share"); 695 service.action = ASCIIToUTF16("share");
663 EXPECT_EQ(service, consumer.intents[1]); 696 EXPECT_EQ(service, consumer.intents[1]);
664 } 697 }
698
699 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) {
700 KeywordsConsumer consumer;
701 wds_->GetKeywords(&consumer);
702 KeywordsConsumer::WaitUntilCalled();
703 ASSERT_TRUE(consumer.load_succeeded);
704 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change);
705 EXPECT_EQ(0, consumer.keywords_result.default_search_provider_id_backup);
706 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698