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

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: Fix merge error 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/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"
(...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_;
174 }; 175 };
175 176
176 // Simple consumer for Keywords data. Stores the result data and quits UI 177 // Simple consumer for Keywords data. Stores the result data and quits UI
177 // message loop when callback is invoked. 178 // message loop when callback is invoked.
178 class KeywordsConsumer : public WebDataServiceConsumer { 179 class KeywordsConsumer : public WebDataServiceConsumer {
179 public: 180 public:
180 KeywordsConsumer() : load_succeeded(false) {} 181 KeywordsConsumer() : load_succeeded(false) {}
181 182
182 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 183 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
183 const WDTypedResult* result) { 184 const WDTypedResult* result) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 MessageLoop::current()->Run(); 628 MessageLoop::current()->Run();
628 EXPECT_EQ(handle2, card_consumer2.handle()); 629 EXPECT_EQ(handle2, card_consumer2.handle());
629 ASSERT_EQ(0U, card_consumer2.result().size()); 630 ASSERT_EQ(0U, card_consumer2.result().size());
630 } 631 }
631 632
632 TEST_F(WebDataServiceTest, WebIntents) { 633 TEST_F(WebDataServiceTest, WebIntents) {
633 WebIntentsConsumer consumer; 634 WebIntentsConsumer consumer;
634 635
635 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 636 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
636 WebIntentsConsumer::WaitUntilCalled(); 637 WebIntentsConsumer::WaitUntilCalled();
637 EXPECT_EQ(0U, consumer.intents.size()); 638 EXPECT_EQ(0U, consumer.services_.size());
638 639
639 WebIntentServiceData service; 640 WebIntentServiceData service;
640 service.service_url = GURL("http://google.com"); 641 service.service_url = GURL("http://google.com");
641 service.action = ASCIIToUTF16("share"); 642 service.action = ASCIIToUTF16("share");
642 service.type = ASCIIToUTF16("image/*"); 643 service.type = ASCIIToUTF16("image/*");
643 wds_->AddWebIntent(service); 644 wds_->AddWebIntent(service);
644 645
645 service.type = ASCIIToUTF16("video/*"); 646 service.type = ASCIIToUTF16("video/*");
646 wds_->AddWebIntent(service); 647 wds_->AddWebIntent(service);
647 648
648 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 649 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
649 WebIntentsConsumer::WaitUntilCalled(); 650 WebIntentsConsumer::WaitUntilCalled();
650 ASSERT_EQ(2U, consumer.intents.size()); 651 ASSERT_EQ(2U, consumer.services_.size());
651 652
652 if (consumer.intents[0].type != ASCIIToUTF16("image/*")) 653 if (consumer.services_[0].type != ASCIIToUTF16("image/*"))
653 std::swap(consumer.intents[0],consumer.intents[1]); 654 std::swap(consumer.services_[0], consumer.services_[1]);
654 655
655 EXPECT_EQ(service.service_url, consumer.intents[0].service_url); 656 EXPECT_EQ(service.service_url, consumer.services_[0].service_url);
656 EXPECT_EQ(service.action, consumer.intents[0].action); 657 EXPECT_EQ(service.action, consumer.services_[0].action);
657 EXPECT_EQ(ASCIIToUTF16("image/*"), consumer.intents[0].type); 658 EXPECT_EQ(ASCIIToUTF16("image/*"), consumer.services_[0].type);
658 EXPECT_EQ(service.service_url, consumer.intents[1].service_url); 659 EXPECT_EQ(service.service_url, consumer.services_[1].service_url);
659 EXPECT_EQ(service.action, consumer.intents[1].action); 660 EXPECT_EQ(service.action, consumer.services_[1].action);
660 EXPECT_EQ(service.type, consumer.intents[1].type); 661 EXPECT_EQ(service.type, consumer.services_[1].type);
661 662
662 service.type = ASCIIToUTF16("image/*"); 663 service.type = ASCIIToUTF16("image/*");
663 wds_->RemoveWebIntent(service); 664 wds_->RemoveWebIntent(service);
664 665
665 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer); 666 wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
666 WebIntentsConsumer::WaitUntilCalled(); 667 WebIntentsConsumer::WaitUntilCalled();
667 ASSERT_EQ(1U, consumer.intents.size()); 668 ASSERT_EQ(1U, consumer.services_.size());
668 669
669 service.type = ASCIIToUTF16("video/*"); 670 service.type = ASCIIToUTF16("video/*");
670 EXPECT_EQ(service.service_url, consumer.intents[0].service_url); 671 EXPECT_EQ(service.service_url, consumer.services_[0].service_url);
671 EXPECT_EQ(service.action, consumer.intents[0].action); 672 EXPECT_EQ(service.action, consumer.services_[0].action);
672 EXPECT_EQ(service.type, consumer.intents[0].type); 673 EXPECT_EQ(service.type, consumer.services_[0].type);
673 } 674 }
674 675
675 TEST_F(WebDataServiceTest, WebIntentsGetAll) { 676 TEST_F(WebDataServiceTest, WebIntentsGetAll) {
676 WebIntentsConsumer consumer; 677 WebIntentsConsumer consumer;
677 678
678 WebIntentServiceData service; 679 WebIntentServiceData service;
679 service.service_url = GURL("http://google.com"); 680 service.service_url = GURL("http://google.com");
680 service.action = ASCIIToUTF16("share"); 681 service.action = ASCIIToUTF16("share");
681 service.type = ASCIIToUTF16("image/*"); 682 service.type = ASCIIToUTF16("image/*");
682 wds_->AddWebIntent(service); 683 wds_->AddWebIntent(service);
683 684
684 service.action = ASCIIToUTF16("edit"); 685 service.action = ASCIIToUTF16("edit");
685 wds_->AddWebIntent(service); 686 wds_->AddWebIntent(service);
686 687
687 wds_->GetAllWebIntents(&consumer); 688 wds_->GetAllWebIntents(&consumer);
688 WebIntentsConsumer::WaitUntilCalled(); 689 WebIntentsConsumer::WaitUntilCalled();
689 ASSERT_EQ(2U, consumer.intents.size()); 690 ASSERT_EQ(2U, consumer.services_.size());
690 691
691 if (consumer.intents[0].action != ASCIIToUTF16("edit")) 692 if (consumer.services_[0].action != ASCIIToUTF16("edit"))
692 std::swap(consumer.intents[0],consumer.intents[1]); 693 std::swap(consumer.services_[0],consumer.services_[1]);
693 694
694 EXPECT_EQ(service, consumer.intents[0]); 695 EXPECT_EQ(service, consumer.services_[0]);
695 service.action = ASCIIToUTF16("share"); 696 service.action = ASCIIToUTF16("share");
696 EXPECT_EQ(service, consumer.intents[1]); 697 EXPECT_EQ(service, consumer.services_[1]);
697 } 698 }
698 699
699 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) { 700 TEST_F(WebDataServiceTest, DidDefaultSearchProviderChangeOnNewProfile) {
700 KeywordsConsumer consumer; 701 KeywordsConsumer consumer;
701 wds_->GetKeywords(&consumer); 702 wds_->GetKeywords(&consumer);
702 KeywordsConsumer::WaitUntilCalled(); 703 KeywordsConsumer::WaitUntilCalled();
703 ASSERT_TRUE(consumer.load_succeeded); 704 ASSERT_TRUE(consumer.load_succeeded);
704 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change); 705 EXPECT_FALSE(consumer.keywords_result.did_default_search_provider_change);
705 EXPECT_EQ(0, consumer.keywords_result.default_search_provider_id_backup); 706 EXPECT_EQ(0, consumer.keywords_result.default_search_provider_id_backup);
706 } 707 }
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