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

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

Issue 8417043: Add webkit_glue namespace. Improve some variable and test names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 25 matching lines...) Expand all
36 #include "webkit/glue/form_field.h" 36 #include "webkit/glue/form_field.h"
37 37
38 using base::Time; 38 using base::Time;
39 using base::TimeDelta; 39 using base::TimeDelta;
40 using base::WaitableEvent; 40 using base::WaitableEvent;
41 using testing::_; 41 using testing::_;
42 using testing::DoDefault; 42 using testing::DoDefault;
43 using testing::ElementsAreArray; 43 using testing::ElementsAreArray;
44 using testing::Pointee; 44 using testing::Pointee;
45 using testing::Property; 45 using testing::Property;
46 using webkit_glue::WebIntentServiceData;
46 47
47 typedef std::vector<AutofillChange> AutofillChangeList; 48 typedef std::vector<AutofillChange> AutofillChangeList;
48 49
49 static const int kWebDataServiceTimeoutSeconds = 8; 50 static const int kWebDataServiceTimeoutSeconds = 8;
50 51
51 ACTION_P(SignalEvent, event) { 52 ACTION_P(SignalEvent, event) {
52 event->Signal(); 53 event->Signal();
53 } 54 }
54 55
55 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { 56 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_; 144 scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_;
144 WaitableEvent done_event_; 145 WaitableEvent done_event_;
145 }; 146 };
146 147
147 // Simple consumer for WebIntents data. Stores the result data and quits UI 148 // Simple consumer for WebIntents data. Stores the result data and quits UI
148 // message loop when callback is invoked. 149 // message loop when callback is invoked.
149 class WebIntentsConsumer: public WebDataServiceConsumer { 150 class WebIntentsConsumer: public WebDataServiceConsumer {
150 public: 151 public:
151 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 152 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
152 const WDTypedResult* result) { 153 const WDTypedResult* result) {
153 intents.clear(); 154 services.clear();
154 if (result) { 155 if (result) {
155 DCHECK(result->GetType() == WEB_INTENTS_RESULT); 156 DCHECK(result->GetType() == WEB_INTENTS_RESULT);
156 intents = static_cast< 157 services = static_cast<
157 const WDResult<std::vector<WebIntentServiceData> >*>(result)-> 158 const WDResult<std::vector<WebIntentServiceData> >*>(result)->
158 GetValue(); 159 GetValue();
159 } 160 }
160 161
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
162 MessageLoop::current()->Quit(); 163 MessageLoop::current()->Quit();
163 } 164 }
164 165
165 // Run the current message loop. OnWebDataServiceRequestDone will invoke 166 // Run the current message loop. OnWebDataServiceRequestDone will invoke
166 // MessageLoop::Quit on completion, so this call will finish at that point. 167 // MessageLoop::Quit on completion, so this call will finish at that point.
167 static void WaitUntilCalled() { 168 static void WaitUntilCalled() {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
169 MessageLoop::current()->Run(); 170 MessageLoop::current()->Run();
170 } 171 }
171 172
172 // Result data from completion callback. 173 // Result data from completion callback.
173 std::vector<WebIntentServiceData> intents; 174 std::vector<WebIntentServiceData> services;
groby-ooo-7-16 2011/10/31 20:53:37 nit: should be services_
Greg Billock 2011/11/01 17:11:17 Done.
174 }; 175 };
175 176
176 TEST_F(WebDataServiceAutofillTest, FormFillAdd) { 177 TEST_F(WebDataServiceAutofillTest, FormFillAdd) {
177 const AutofillChange expected_changes[] = { 178 const AutofillChange expected_changes[] = {
178 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)), 179 AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)),
179 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_)) 180 AutofillChange(AutofillChange::ADD, AutofillKey(name2_, value2_))
180 }; 181 };
181 182
182 // This will verify that the correct notification is triggered, 183 // This will verify that the correct notification is triggered,
183 // passing the correct list of autofill keys in the details. 184 // passing the correct list of autofill keys in the details.
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 MessageLoop::current()->Run(); 595 MessageLoop::current()->Run();
595 EXPECT_EQ(handle2, card_consumer2.handle()); 596 EXPECT_EQ(handle2, card_consumer2.handle());
596 ASSERT_EQ(0U, card_consumer2.result().size()); 597 ASSERT_EQ(0U, card_consumer2.result().size());
597 } 598 }
598 599
599 TEST_F(WebDataServiceTest, WebIntents) { 600 TEST_F(WebDataServiceTest, WebIntents) {
600 WebIntentsConsumer consumer; 601 WebIntentsConsumer consumer;
601 602
602 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 603 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
603 WebIntentsConsumer::WaitUntilCalled(); 604 WebIntentsConsumer::WaitUntilCalled();
604 EXPECT_EQ(0U, consumer.intents.size()); 605 EXPECT_EQ(0U, consumer.services.size());
605 606
606 WebIntentServiceData service; 607 WebIntentServiceData service;
607 service.service_url = GURL("http://google.com"); 608 service.service_url = GURL("http://google.com");
608 service.action = ASCIIToUTF16("share"); 609 service.action = ASCIIToUTF16("share");
609 service.type = ASCIIToUTF16("image/*"); 610 service.type = ASCIIToUTF16("image/*");
610 wds_->AddWebIntent(service); 611 wds_->AddWebIntent(service);
611 612
612 service.type = ASCIIToUTF16("video/*"); 613 service.type = ASCIIToUTF16("video/*");
613 wds_->AddWebIntent(service); 614 wds_->AddWebIntent(service);
614 615
615 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 616 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
616 WebIntentsConsumer::WaitUntilCalled(); 617 WebIntentsConsumer::WaitUntilCalled();
617 ASSERT_EQ(2U, consumer.intents.size()); 618 ASSERT_EQ(2U, consumer.services.size());
618 619
619 if (consumer.intents[0].type != ASCIIToUTF16("image/*")) 620 if (consumer.services[0].type != ASCIIToUTF16("image/*"))
620 std::swap(consumer.intents[0],consumer.intents[1]); 621 std::swap(consumer.services[0],consumer.services[1]);
621 622
622 EXPECT_EQ(service.service_url, consumer.intents[0].service_url); 623 EXPECT_EQ(service.service_url, consumer.services[0].service_url);
623 EXPECT_EQ(service.action, consumer.intents[0].action); 624 EXPECT_EQ(service.action, consumer.services[0].action);
624 EXPECT_EQ(ASCIIToUTF16("image/*"), consumer.intents[0].type); 625 EXPECT_EQ(ASCIIToUTF16("image/*"), consumer.services[0].type);
625 EXPECT_EQ(service.service_url, consumer.intents[1].service_url); 626 EXPECT_EQ(service.service_url, consumer.services[1].service_url);
626 EXPECT_EQ(service.action, consumer.intents[1].action); 627 EXPECT_EQ(service.action, consumer.services[1].action);
627 EXPECT_EQ(service.type, consumer.intents[1].type); 628 EXPECT_EQ(service.type, consumer.services[1].type);
628 629
629 service.type = ASCIIToUTF16("image/*"); 630 service.type = ASCIIToUTF16("image/*");
630 wds_->RemoveWebIntent(service); 631 wds_->RemoveWebIntent(service);
631 632
632 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 633 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
633 WebIntentsConsumer::WaitUntilCalled(); 634 WebIntentsConsumer::WaitUntilCalled();
634 ASSERT_EQ(1U, consumer.intents.size()); 635 ASSERT_EQ(1U, consumer.services.size());
635 636
636 service.type = ASCIIToUTF16("video/*"); 637 service.type = ASCIIToUTF16("video/*");
637 EXPECT_EQ(service.service_url, consumer.intents[0].service_url); 638 EXPECT_EQ(service.service_url, consumer.services[0].service_url);
638 EXPECT_EQ(service.action, consumer.intents[0].action); 639 EXPECT_EQ(service.action, consumer.services[0].action);
639 EXPECT_EQ(service.type, consumer.intents[0].type); 640 EXPECT_EQ(service.type, consumer.services[0].type);
640 } 641 }
641 642
642 TEST_F(WebDataServiceTest, WebIntentsGetAll) { 643 TEST_F(WebDataServiceTest, WebIntentsGetAll) {
643 WebIntentsConsumer consumer; 644 WebIntentsConsumer consumer;
644 645
645 WebIntentServiceData service; 646 WebIntentServiceData service;
646 service.service_url = GURL("http://google.com"); 647 service.service_url = GURL("http://google.com");
647 service.action = ASCIIToUTF16("share"); 648 service.action = ASCIIToUTF16("share");
648 service.type = ASCIIToUTF16("image/*"); 649 service.type = ASCIIToUTF16("image/*");
649 wds_->AddWebIntent(service); 650 wds_->AddWebIntent(service);
650 651
651 service.action = ASCIIToUTF16("edit"); 652 service.action = ASCIIToUTF16("edit");
652 wds_->AddWebIntent(service); 653 wds_->AddWebIntent(service);
653 654
654 wds_->GetAllWebIntents(&consumer); 655 wds_->GetAllWebIntents(&consumer);
655 WebIntentsConsumer::WaitUntilCalled(); 656 WebIntentsConsumer::WaitUntilCalled();
656 ASSERT_EQ(2U, consumer.intents.size()); 657 ASSERT_EQ(2U, consumer.services.size());
657 658
658 if (consumer.intents[0].action != ASCIIToUTF16("edit")) 659 if (consumer.services[0].action != ASCIIToUTF16("edit"))
659 std::swap(consumer.intents[0],consumer.intents[1]); 660 std::swap(consumer.services[0],consumer.services[1]);
660 661
661 EXPECT_EQ(service, consumer.intents[0]); 662 EXPECT_EQ(service, consumer.services[0]);
662 service.action = ASCIIToUTF16("share"); 663 service.action = ASCIIToUTF16("share");
663 EXPECT_EQ(service, consumer.intents[1]); 664 EXPECT_EQ(service, consumer.services[1]);
664 } 665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698