OLD | NEW |
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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/intents/web_intents_registry.h" | 8 #include "chrome/browser/intents/web_intents_registry.h" |
9 #include "chrome/browser/webdata/web_data_service.h" | 9 #include "chrome/browser/webdata/web_data_service.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 BrowserThread db_thread_; | 39 BrowserThread db_thread_; |
40 scoped_refptr<WebDataService> wds_; | 40 scoped_refptr<WebDataService> wds_; |
41 WebIntentsRegistry registry_; | 41 WebIntentsRegistry registry_; |
42 ScopedTempDir temp_dir_; | 42 ScopedTempDir temp_dir_; |
43 }; | 43 }; |
44 | 44 |
45 // Simple consumer for WebIntentsRegistry notifications. Stores result data and | 45 // Simple consumer for WebIntentsRegistry notifications. Stores result data and |
46 // terminates UI thread when callback is invoked. | 46 // terminates UI thread when callback is invoked. |
47 class TestConsumer: public WebIntentsRegistry::Consumer { | 47 class TestConsumer: public WebIntentsRegistry::Consumer { |
48 public: | 48 public: |
49 virtual void OnIntentsQueryDone(WebIntentsRegistry::QueryID id, | 49 virtual void OnIntentsQueryDone( |
50 const std::vector<WebIntentData>& intents) { | 50 WebIntentsRegistry::QueryID id, |
| 51 const std::vector<WebIntentServiceData>& services) { |
51 DCHECK(id == expected_id_); | 52 DCHECK(id == expected_id_); |
52 intents_ = intents; | 53 services_ = services; |
53 | 54 |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
55 MessageLoop::current()->Quit(); | 56 MessageLoop::current()->Quit(); |
56 } | 57 } |
57 | 58 |
58 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone | 59 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone |
59 // is invoked. | 60 // is invoked. |
60 void WaitForData() { | 61 void WaitForData() { |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
62 MessageLoop::current()->Run(); | 63 MessageLoop::current()->Run(); |
63 } | 64 } |
64 | 65 |
65 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. | 66 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. |
66 std::vector<WebIntentData> intents_; // Result data from callback. | 67 std::vector<WebIntentServiceData> services_; // Result data from callback. |
67 }; | 68 }; |
68 | 69 |
69 TEST_F(WebIntentsRegistryTest, BasicTests) { | 70 TEST_F(WebIntentsRegistryTest, BasicTests) { |
70 WebIntentData intent; | 71 WebIntentServiceData service; |
71 intent.service_url = GURL("http://google.com"); | 72 service.service_url = GURL("http://google.com"); |
72 intent.action = ASCIIToUTF16("share"); | 73 service.action = ASCIIToUTF16("share"); |
73 intent.type = ASCIIToUTF16("image/*"); | 74 service.type = ASCIIToUTF16("image/*"); |
74 intent.title = ASCIIToUTF16("Google's Sharing Service"); | 75 service.title = ASCIIToUTF16("Google's Sharing Service"); |
75 | 76 |
76 registry_.RegisterIntentProvider(intent); | 77 registry_.RegisterIntentProvider(service); |
77 | 78 |
78 intent.type = ASCIIToUTF16("video/*"); | 79 service.type = ASCIIToUTF16("video/*"); |
79 registry_.RegisterIntentProvider(intent); | 80 registry_.RegisterIntentProvider(service); |
80 | 81 |
81 intent.action = ASCIIToUTF16("search"); | 82 service.action = ASCIIToUTF16("search"); |
82 registry_.RegisterIntentProvider(intent); | 83 registry_.RegisterIntentProvider(service); |
83 | 84 |
84 TestConsumer consumer; | 85 TestConsumer consumer; |
85 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 86 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), |
86 &consumer); | 87 &consumer); |
87 consumer.WaitForData(); | 88 consumer.WaitForData(); |
88 EXPECT_EQ(2U, consumer.intents_.size()); | 89 EXPECT_EQ(2U, consumer.services_.size()); |
89 | 90 |
90 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"), | 91 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"), |
91 &consumer); | 92 &consumer); |
92 consumer.WaitForData(); | 93 consumer.WaitForData(); |
93 EXPECT_EQ(1U, consumer.intents_.size()); | 94 EXPECT_EQ(1U, consumer.services_.size()); |
94 | 95 |
95 intent.action = ASCIIToUTF16("share"); | 96 service.action = ASCIIToUTF16("share"); |
96 intent.type = ASCIIToUTF16("image/*"); | 97 service.type = ASCIIToUTF16("image/*"); |
97 registry_.UnregisterIntentProvider(intent); | 98 registry_.UnregisterIntentProvider(service); |
98 | 99 |
99 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 100 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), |
100 &consumer); | 101 &consumer); |
101 consumer.WaitForData(); | 102 consumer.WaitForData(); |
102 EXPECT_EQ(1U, consumer.intents_.size()); | 103 EXPECT_EQ(1U, consumer.services_.size()); |
103 } | 104 } |
104 | 105 |
105 TEST_F(WebIntentsRegistryTest, GetAllIntents) { | 106 TEST_F(WebIntentsRegistryTest, GetAllIntents) { |
106 WebIntentData intent; | 107 WebIntentServiceData service; |
107 intent.service_url = GURL("http://google.com"); | 108 service.service_url = GURL("http://google.com"); |
108 intent.action = ASCIIToUTF16("share"); | 109 service.action = ASCIIToUTF16("share"); |
109 intent.type = ASCIIToUTF16("image/*"); | 110 service.type = ASCIIToUTF16("image/*"); |
110 intent.title = ASCIIToUTF16("Google's Sharing Service"); | 111 service.title = ASCIIToUTF16("Google's Sharing Service"); |
111 registry_.RegisterIntentProvider(intent); | 112 registry_.RegisterIntentProvider(service); |
112 | 113 |
113 intent.action = ASCIIToUTF16("search"); | 114 service.action = ASCIIToUTF16("search"); |
114 registry_.RegisterIntentProvider(intent); | 115 registry_.RegisterIntentProvider(service); |
115 | 116 |
116 TestConsumer consumer; | 117 TestConsumer consumer; |
117 consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer); | 118 consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer); |
118 consumer.WaitForData(); | 119 consumer.WaitForData(); |
119 ASSERT_EQ(2U, consumer.intents_.size()); | 120 ASSERT_EQ(2U, consumer.services_.size()); |
120 | 121 |
121 if (consumer.intents_[0].action != ASCIIToUTF16("share")) | 122 if (consumer.services_[0].action != ASCIIToUTF16("share")) |
122 std::swap(consumer.intents_[0],consumer.intents_[1]); | 123 std::swap(consumer.services_[0],consumer.services_[1]); |
123 | 124 |
124 intent.action = ASCIIToUTF16("share"); | 125 service.action = ASCIIToUTF16("share"); |
125 EXPECT_EQ(intent, consumer.intents_[0]); | 126 EXPECT_EQ(service, consumer.services_[0]); |
126 | 127 |
127 intent.action = ASCIIToUTF16("search"); | 128 service.action = ASCIIToUTF16("search"); |
128 EXPECT_EQ(intent, consumer.intents_[1]); | 129 EXPECT_EQ(service, consumer.services_[1]); |
129 } | 130 } |
OLD | NEW |