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

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

Issue 9370043: Add default intents methods for web data service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 10 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/webdata/web_data_service.cc ('k') | chrome/browser/webdata/web_intents_table.h » ('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"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/autofill/autofill_profile.h" 20 #include "chrome/browser/autofill/autofill_profile.h"
21 #include "chrome/browser/autofill/credit_card.h" 21 #include "chrome/browser/autofill/credit_card.h"
22 #include "chrome/browser/intents/default_web_intent_service.h"
22 #include "chrome/browser/webdata/autofill_change.h" 23 #include "chrome/browser/webdata/autofill_change.h"
23 #include "chrome/browser/webdata/autofill_entry.h" 24 #include "chrome/browser/webdata/autofill_entry.h"
24 #include "chrome/browser/webdata/web_data_service.h" 25 #include "chrome/browser/webdata/web_data_service.h"
25 #include "chrome/browser/webdata/web_data_service_test_util.h" 26 #include "chrome/browser/webdata/web_data_service_test_util.h"
26 #include "chrome/browser/webdata/web_intents_table.h" 27 #include "chrome/browser/webdata/web_intents_table.h"
27 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/guid.h" 30 #include "chrome/common/guid.h"
30 #include "chrome/test/base/thread_observer_helper.h" 31 #include "chrome/test/base/thread_observer_helper.h"
31 #include "content/public/browser/notification_details.h" 32 #include "content/public/browser/notification_details.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 string16 name1_; 140 string16 name1_;
140 string16 name2_; 141 string16 name2_;
141 string16 value1_; 142 string16 value1_;
142 string16 value2_; 143 string16 value2_;
143 int unique_id1_, unique_id2_; 144 int unique_id1_, unique_id2_;
144 const TimeDelta test_timeout_; 145 const TimeDelta test_timeout_;
145 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_; 146 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_;
146 WaitableEvent done_event_; 147 WaitableEvent done_event_;
147 }; 148 };
148 149
149 // Simple consumer for WebIntents data. Stores the result data and quits UI 150 // Simple consumer for WebIntents service data. Stores the result data and
150 // message loop when callback is invoked. 151 // quits UI message loop when callback is invoked.
151 class WebIntentsConsumer : public WebDataServiceConsumer { 152 class WebIntentsConsumer : public WebDataServiceConsumer {
152 public: 153 public:
153 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 154 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
154 const WDTypedResult* result) { 155 const WDTypedResult* result) {
155 services_.clear(); 156 services_.clear();
156 if (result) { 157 if (result) {
157 DCHECK(result->GetType() == WEB_INTENTS_RESULT); 158 DCHECK(result->GetType() == WEB_INTENTS_RESULT);
158 services_ = static_cast< 159 services_ = static_cast<
159 const WDResult<std::vector<WebIntentServiceData> >*>(result)-> 160 const WDResult<std::vector<WebIntentServiceData> >*>(result)->
160 GetValue(); 161 GetValue();
161 } 162 }
162 163
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164 MessageLoop::current()->Quit(); 165 MessageLoop::current()->Quit();
165 } 166 }
166 167
167 // Run the current message loop. OnWebDataServiceRequestDone will invoke 168 // Run the current message loop. OnWebDataServiceRequestDone will invoke
168 // MessageLoop::Quit on completion, so this call will finish at that point. 169 // MessageLoop::Quit on completion, so this call will finish at that point.
169 static void WaitUntilCalled() { 170 static void WaitUntilCalled() {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171 MessageLoop::current()->Run(); 172 MessageLoop::current()->Run();
172 } 173 }
173 174
174 // Result data from completion callback. 175 // Result data from completion callback.
175 std::vector<WebIntentServiceData> services_; 176 std::vector<WebIntentServiceData> services_;
176 }; 177 };
177 178
179 // Simple consumer for WebIntents defaults data. Stores the result data and
180 // quits UI message loop when callback is invoked.
181 class WebIntentsDefaultsConsumer : public WebDataServiceConsumer {
groby-ooo-7-16 2012/02/16 23:14:38 That's a lot of copy/paste - can we just templatiz
Greg Billock 2012/02/17 01:12:37 This whole file has tons of this parallel structur
groby-ooo-7-16 2012/02/17 02:15:01 At the very least, let's hoist WaitUntilCalled int
Greg Billock 2012/02/17 17:57:00 I like it. Done. On 2012/02/17 02:15:01, groby wr
182 public:
183 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
184 const WDTypedResult* result) {
185 services_.clear();
186 if (result) {
187 DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT);
188 services_ = static_cast<
189 const WDResult<std::vector<DefaultWebIntentService> >*>(result)->
190 GetValue();
191 }
192
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 MessageLoop::current()->Quit();
195 }
196
197 // Run the current message loop. OnWebDataServiceRequestDone will invoke
198 // MessageLoop::Quit on completion, so this call will finish at that point.
199 static void WaitUntilCalled() {
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 MessageLoop::current()->Run();
202 }
203
204 // Result data from completion callback.
205 std::vector<DefaultWebIntentService> services_;
206 };
207
178 // Simple consumer for Keywords data. Stores the result data and quits UI 208 // Simple consumer for Keywords data. Stores the result data and quits UI
179 // message loop when callback is invoked. 209 // message loop when callback is invoked.
180 class KeywordsConsumer : public WebDataServiceConsumer { 210 class KeywordsConsumer : public WebDataServiceConsumer {
181 public: 211 public:
182 KeywordsConsumer() : load_succeeded(false) {} 212 KeywordsConsumer() : load_succeeded(false) {}
183 213
184 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 214 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
185 const WDTypedResult* result) { 215 const WDTypedResult* result) {
186 if (result) { 216 if (result) {
187 load_succeeded = true; 217 load_succeeded = true;
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 ASSERT_EQ(2U, consumer.services_.size()); 748 ASSERT_EQ(2U, consumer.services_.size());
719 749
720 if (consumer.services_[0].action != ASCIIToUTF16("edit")) 750 if (consumer.services_[0].action != ASCIIToUTF16("edit"))
721 std::swap(consumer.services_[0],consumer.services_[1]); 751 std::swap(consumer.services_[0],consumer.services_[1]);
722 752
723 EXPECT_EQ(service, consumer.services_[0]); 753 EXPECT_EQ(service, consumer.services_[0]);
724 service.action = ASCIIToUTF16("share"); 754 service.action = ASCIIToUTF16("share");
725 EXPECT_EQ(service, consumer.services_[1]); 755 EXPECT_EQ(service, consumer.services_[1]);
726 } 756 }
727 757
758 TEST_F(WebDataServiceTest, WebIntentsDefaultsTest) {
759 WebIntentsDefaultsConsumer consumer;
760
761 wds_->GetDefaultWebIntentServicesForAction(ASCIIToUTF16("share"), &consumer);
762 WebIntentsConsumer::WaitUntilCalled();
763 EXPECT_EQ(0U, consumer.services_.size());
764
765 DefaultWebIntentService default_service;
766 default_service.action = ASCIIToUTF16("share");
767 default_service.type = ASCIIToUTF16("type");
768 default_service.user_date = 1;
769 default_service.suppression = 4;
770 default_service.service_url = "service_url";
771 wds_->AddDefaultWebIntentService(default_service);
772
773 default_service.action = ASCIIToUTF16("share2");
774 default_service.service_url = "service_url_2";
775 wds_->AddDefaultWebIntentService(default_service);
776
777 wds_->GetDefaultWebIntentServicesForAction(ASCIIToUTF16("share"), &consumer);
778 WebIntentsDefaultsConsumer::WaitUntilCalled();
779 EXPECT_EQ(1U, consumer.services_.size());
groby-ooo-7-16 2012/02/16 23:14:38 You probably want ASSERT_EQ on the size. If it's 0
Greg Billock 2012/02/17 01:12:37 Done.
780 EXPECT_EQ("service_url", consumer.services_[0].service_url);
781
782 wds_->GetAllDefaultWebIntentServices(&consumer);
783 WebIntentsDefaultsConsumer::WaitUntilCalled();
784 EXPECT_EQ(2U, consumer.services_.size());
785
786 default_service.action = ASCIIToUTF16("share");
787 wds_->RemoveDefaultWebIntentService(default_service);
788
789 wds_->GetDefaultWebIntentServicesForAction(ASCIIToUTF16("share"), &consumer);
790 WebIntentsDefaultsConsumer::WaitUntilCalled();
791 EXPECT_EQ(0U, consumer.services_.size());
792
793 wds_->GetDefaultWebIntentServicesForAction(ASCIIToUTF16("share2"), &consumer);
794 WebIntentsDefaultsConsumer::WaitUntilCalled();
795 EXPECT_EQ(1U, consumer.services_.size());
796 EXPECT_EQ("service_url_2", consumer.services_[0].service_url);
797
798 wds_->GetAllDefaultWebIntentServices(&consumer);
799 WebIntentsDefaultsConsumer::WaitUntilCalled();
800 EXPECT_EQ(1U, consumer.services_.size());
801 EXPECT_EQ("service_url_2", consumer.services_[0].service_url);
802 }
803
728 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { 804 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) {
729 KeywordsConsumer consumer; 805 KeywordsConsumer consumer;
730 wds_->GetKeywords(&consumer); 806 wds_->GetKeywords(&consumer);
731 KeywordsConsumer::WaitUntilCalled(); 807 KeywordsConsumer::WaitUntilCalled();
732 ASSERT_TRUE(consumer.load_succeeded); 808 ASSERT_TRUE(consumer.load_succeeded);
733 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); 809 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change);
734 EXPECT_EQ(NULL, consumer.keywords_result.default_search_provider_backup); 810 EXPECT_EQ(NULL, consumer.keywords_result.default_search_provider_backup);
735 } 811 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.cc ('k') | chrome/browser/webdata/web_intents_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698