OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/test_extension_service.h" | 11 #include "chrome/browser/extensions/test_extension_service.h" |
12 #include "chrome/browser/intents/default_web_intent_service.h" | 12 #include "chrome/browser/intents/default_web_intent_service.h" |
13 #include "chrome/browser/intents/web_intents_registry.h" | 13 #include "chrome/browser/intents/web_intents_registry.h" |
14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/extensions/extension_set.h" | 16 #include "chrome/common/extensions/extension_set.h" |
17 #include "content/test/test_browser_thread.h" | 17 #include "content/test/test_browser_thread.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using webkit_glue::WebIntentServiceData; | 22 using webkit_glue::WebIntentServiceData; |
23 | 23 |
24 class MockExtensionService: public TestExtensionService { | 24 class MockExtensionService: public TestExtensionService { |
25 public: | 25 public: |
26 virtual ~MockExtensionService() {} | 26 virtual ~MockExtensionService() {} |
27 MOCK_CONST_METHOD0(extensions, const ExtensionSet*()); | 27 MOCK_CONST_METHOD0(extensions, const ExtensionSet*()); |
28 MOCK_CONST_METHOD2(GetExtensionById, | |
29 const Extension*(const std::string&, bool)); | |
30 }; | 28 }; |
31 | 29 |
32 namespace { | 30 namespace { |
33 | 31 |
34 // TODO(groby): Unify loading functions with extension_manifest_unittest code. | 32 // TODO(groby): Unify loading functions with extension_manifest_unittest code. |
35 DictionaryValue* LoadManifestFile(const FilePath& path, | 33 DictionaryValue* LoadManifestFile(const FilePath& path, |
36 std::string* error) { | 34 std::string* error) { |
37 EXPECT_TRUE(file_util::PathExists(path)); | 35 EXPECT_TRUE(file_util::PathExists(path)); |
38 JSONFileValueSerializer serializer(path); | 36 JSONFileValueSerializer serializer(path); |
39 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); | 37 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 virtual void SetUp() { | 86 virtual void SetUp() { |
89 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents"); | 87 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents"); |
90 | 88 |
91 db_thread_.Start(); | 89 db_thread_.Start(); |
92 wds_ = new WebDataService(); | 90 wds_ = new WebDataService(); |
93 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
94 wds_->Init(temp_dir_.path()); | 92 wds_->Init(temp_dir_.path()); |
95 registry_.Initialize(wds_, &extension_service_); | 93 registry_.Initialize(wds_, &extension_service_); |
96 EXPECT_CALL(extension_service_, extensions()). | 94 EXPECT_CALL(extension_service_, extensions()). |
97 WillRepeatedly(testing::Return(&extensions_)); | 95 WillRepeatedly(testing::Return(&extensions_)); |
98 EXPECT_CALL(extension_service_, GetExtensionById(testing::_, testing::_)). | |
99 WillRepeatedly( | |
100 testing::Invoke(this, &WebIntentsRegistryTest::GetExtensionById)); | |
101 } | 96 } |
102 | 97 |
103 virtual void TearDown() { | 98 virtual void TearDown() { |
104 if (wds_.get()) | 99 if (wds_.get()) |
105 wds_->Shutdown(); | 100 wds_->Shutdown(); |
106 | 101 |
107 db_thread_.Stop(); | 102 db_thread_.Stop(); |
108 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 103 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
109 MessageLoop::current()->Run(); | 104 MessageLoop::current()->Run(); |
110 } | 105 } |
111 | 106 |
112 const Extension* GetExtensionById(const std::string& extension_id, | |
113 testing::Unused) { | |
114 for (ExtensionSet::const_iterator iter = extensions_.begin(); | |
115 iter != extensions_.end(); ++iter) { | |
116 if ((*iter)->id() == extension_id) | |
117 return &**iter; | |
118 } | |
119 | |
120 return NULL; | |
121 } | |
122 | |
123 MessageLoopForUI message_loop_; | 107 MessageLoopForUI message_loop_; |
124 content::TestBrowserThread ui_thread_; | 108 content::TestBrowserThread ui_thread_; |
125 content::TestBrowserThread db_thread_; | 109 content::TestBrowserThread db_thread_; |
126 scoped_refptr<WebDataService> wds_; | 110 scoped_refptr<WebDataService> wds_; |
127 MockExtensionService extension_service_; | 111 MockExtensionService extension_service_; |
128 ExtensionSet extensions_; | 112 ExtensionSet extensions_; |
129 WebIntentsRegistry registry_; | 113 WebIntentsRegistry registry_; |
130 ScopedTempDir temp_dir_; | 114 ScopedTempDir temp_dir_; |
131 }; | 115 }; |
132 | 116 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 service.type = ASCIIToUTF16("image/*"); | 187 service.type = ASCIIToUTF16("image/*"); |
204 registry_.UnregisterIntentService(service); | 188 registry_.UnregisterIntentService(service); |
205 | 189 |
206 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), | 190 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), |
207 ASCIIToUTF16("*"), | 191 ASCIIToUTF16("*"), |
208 &consumer); | 192 &consumer); |
209 consumer.WaitForData(); | 193 consumer.WaitForData(); |
210 EXPECT_EQ(1U, consumer.services_.size()); | 194 EXPECT_EQ(1U, consumer.services_.size()); |
211 } | 195 } |
212 | 196 |
213 TEST_F(WebIntentsRegistryTest, GetIntentServicesForExtensionFilter) { | |
214 scoped_refptr<Extension> share_extension( | |
215 LoadAndExpectSuccess("intent_valid.json")); | |
216 scoped_refptr<Extension> edit_extension( | |
217 LoadAndExpectSuccess("intent_valid_2.json")); | |
218 extensions_.Insert(share_extension); | |
219 extensions_.Insert(edit_extension); | |
220 ASSERT_EQ(2U, extensions_.size()); | |
221 | |
222 TestConsumer consumer; | |
223 consumer.expected_id_ = registry_.GetIntentServicesForExtensionFilter( | |
224 ASCIIToUTF16("http://webintents.org/edit"), | |
225 ASCIIToUTF16("image/*"), | |
226 edit_extension->id(), | |
227 &consumer); | |
228 consumer.WaitForData(); | |
229 ASSERT_EQ(1U, consumer.services_.size()); | |
230 } | |
231 | |
232 TEST_F(WebIntentsRegistryTest, GetAllIntents) { | 197 TEST_F(WebIntentsRegistryTest, GetAllIntents) { |
233 webkit_glue::WebIntentServiceData service; | 198 webkit_glue::WebIntentServiceData service; |
234 service.service_url = GURL("http://google.com"); | 199 service.service_url = GURL("http://google.com"); |
235 service.action = ASCIIToUTF16("share"); | 200 service.action = ASCIIToUTF16("share"); |
236 service.type = ASCIIToUTF16("image/*"); | 201 service.type = ASCIIToUTF16("image/*"); |
237 service.title = ASCIIToUTF16("Google's Sharing Service"); | 202 service.title = ASCIIToUTF16("Google's Sharing Service"); |
238 registry_.RegisterIntentService(service); | 203 registry_.RegisterIntentService(service); |
239 | 204 |
240 service.action = ASCIIToUTF16("search"); | 205 service.action = ASCIIToUTF16("search"); |
241 registry_.RegisterIntentService(service); | 206 registry_.RegisterIntentService(service); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 consumer.expected_id_ = registry_.GetDefaultIntentService( | 388 consumer.expected_id_ = registry_.GetDefaultIntentService( |
424 ASCIIToUTF16("share"), | 389 ASCIIToUTF16("share"), |
425 ASCIIToUTF16("notype/plain"), | 390 ASCIIToUTF16("notype/plain"), |
426 GURL("http://www.google.com/"), | 391 GURL("http://www.google.com/"), |
427 &consumer); | 392 &consumer); |
428 | 393 |
429 consumer.WaitForData(); | 394 consumer.WaitForData(); |
430 | 395 |
431 EXPECT_EQ("", consumer.default_.service_url); | 396 EXPECT_EQ("", consumer.default_.service_url); |
432 } | 397 } |
OLD | NEW |