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

Side by Side Diff: chrome/browser/intents/web_intents_registry_unittest.cc

Issue 8733004: Make ExtensionService use ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: + Created 9 years 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/json/json_value_serializer.h" 6 #include "base/json/json_value_serializer.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/test_extension_service.h" 10 #include "chrome/browser/extensions/test_extension_service.h"
11 #include "chrome/browser/intents/web_intents_registry.h" 11 #include "chrome/browser/intents/web_intents_registry.h"
12 #include "chrome/browser/webdata/web_data_service.h" 12 #include "chrome/browser/webdata/web_data_service.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/extension_set.h"
14 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 using webkit_glue::WebIntentServiceData; 20 using webkit_glue::WebIntentServiceData;
20 21
21 class MockExtensionService: public TestExtensionService { 22 class MockExtensionService: public TestExtensionService {
22 public: 23 public:
23 virtual ~MockExtensionService() {} 24 virtual ~MockExtensionService() {}
24 MOCK_CONST_METHOD0(extensions, const ExtensionList*()); 25 MOCK_CONST_METHOD0(extensions, const ExtensionSet*());
25 }; 26 };
26 27
27 // TODO(groby): Unify loading functions with extension_manifest_unittest code.
28 DictionaryValue* LoadManifestFile(const std::string& filename,
29 std::string* error) {
30 FilePath path;
31 PathService::Get(chrome::DIR_TEST_DATA, &path);
32 path = path.AppendASCII("extensions")
33 .AppendASCII("manifest_tests")
34 .AppendASCII(filename.c_str());
35 EXPECT_TRUE(file_util::PathExists(path));
36
37 JSONFileValueSerializer serializer(path);
38 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
39 }
40
41 namespace { 28 namespace {
42 29
43 scoped_refptr<Extension> LoadExtensionWithLocation( 30 // TODO(groby): Unify loading functions with extension_manifest_unittest code.
44 DictionaryValue* value, 31 DictionaryValue* LoadManifestFile(const FilePath& path,
45 Extension::Location location, 32 std::string* error) {
46 bool strict_error_checks, 33 EXPECT_TRUE(file_util::PathExists(path));
47 std::string* error) { 34 JSONFileValueSerializer serializer(path);
48 FilePath path; 35 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
49 PathService::Get(chrome::DIR_TEST_DATA, &path);
50 path = path.AppendASCII("extensions").AppendASCII("manifest_tests");
51 int flags = Extension::NO_FLAGS;
52 if (strict_error_checks)
53 flags |= Extension::STRICT_ERROR_CHECKS;
54 return Extension::Create(path.DirName(), location, *value, flags, error);
55 } 36 }
56 37
57 scoped_refptr<Extension> LoadExtensionWithLocation( 38 scoped_refptr<Extension> LoadExtensionWithLocation(
58 const std::string& name, 39 const std::string& name,
59 Extension::Location location, 40 Extension::Location location,
60 bool strict_error_checks, 41 bool strict_error_checks,
61 std::string* error) { 42 std::string* error) {
62 scoped_ptr<DictionaryValue> value(LoadManifestFile(name, error)); 43 FilePath path;
44 PathService::Get(chrome::DIR_TEST_DATA, &path);
45 path = path.AppendASCII("extensions")
46 .AppendASCII("manifest_tests")
47 .AppendASCII(name.c_str());
48 scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error));
63 if (!value.get()) 49 if (!value.get())
64 return NULL; 50 return NULL;
65 return LoadExtensionWithLocation(value.get(), location, 51 int flags = Extension::NO_FLAGS;
66 strict_error_checks, error); 52 if (strict_error_checks)
53 flags |= Extension::STRICT_ERROR_CHECKS;
54 return Extension::CreateWithId(path.DirName(),
55 location,
56 *value,
57 flags,
58 Extension::GenerateIdForPath(path),
59 error);
67 } 60 }
68 61
69 scoped_refptr<Extension> LoadExtension(const std::string& name, 62 scoped_refptr<Extension> LoadExtension(const std::string& name,
70 std::string* error) { 63 std::string* error) {
71 return LoadExtensionWithLocation(name, Extension::INTERNAL, false, error); 64 return LoadExtensionWithLocation(name, Extension::INTERNAL, false, error);
72 } 65 }
73 66
74 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) { 67 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) {
75 std::string error; 68 std::string error;
76 scoped_refptr<Extension> extension = LoadExtension(name, &error); 69 scoped_refptr<Extension> extension = LoadExtension(name, &error);
(...skipping 30 matching lines...) Expand all
107 db_thread_.Stop(); 100 db_thread_.Stop();
108 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); 101 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
109 MessageLoop::current()->Run(); 102 MessageLoop::current()->Run();
110 } 103 }
111 104
112 MessageLoopForUI message_loop_; 105 MessageLoopForUI message_loop_;
113 content::TestBrowserThread ui_thread_; 106 content::TestBrowserThread ui_thread_;
114 content::TestBrowserThread db_thread_; 107 content::TestBrowserThread db_thread_;
115 scoped_refptr<WebDataService> wds_; 108 scoped_refptr<WebDataService> wds_;
116 MockExtensionService extension_service_; 109 MockExtensionService extension_service_;
117 ExtensionList extensions_; 110 ExtensionSet extensions_;
118 WebIntentsRegistry registry_; 111 WebIntentsRegistry registry_;
119 ScopedTempDir temp_dir_; 112 ScopedTempDir temp_dir_;
120 }; 113 };
121 114
122 // Simple consumer for WebIntentsRegistry notifications. Stores result data and 115 // Simple consumer for WebIntentsRegistry notifications. Stores result data and
123 // terminates UI thread when callback is invoked. 116 // terminates UI thread when callback is invoked.
124 class TestConsumer: public WebIntentsRegistry::Consumer { 117 class TestConsumer: public WebIntentsRegistry::Consumer {
125 public: 118 public:
126 virtual void OnIntentsQueryDone( 119 virtual void OnIntentsQueryDone(
127 WebIntentsRegistry::QueryID id, 120 WebIntentsRegistry::QueryID id,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 std::swap(consumer.services_[0],consumer.services_[1]); 199 std::swap(consumer.services_[0],consumer.services_[1]);
207 200
208 service.action = ASCIIToUTF16("share"); 201 service.action = ASCIIToUTF16("share");
209 EXPECT_EQ(service, consumer.services_[0]); 202 EXPECT_EQ(service, consumer.services_[0]);
210 203
211 service.action = ASCIIToUTF16("search"); 204 service.action = ASCIIToUTF16("search");
212 EXPECT_EQ(service, consumer.services_[1]); 205 EXPECT_EQ(service, consumer.services_[1]);
213 } 206 }
214 207
215 TEST_F(WebIntentsRegistryTest, GetExtensionIntents) { 208 TEST_F(WebIntentsRegistryTest, GetExtensionIntents) {
216 extensions_.push_back(LoadAndExpectSuccess("intent_valid.json")); 209 extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
217 extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json")); 210 extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
211 ASSERT_EQ(2U, extensions_.size());
218 212
219 TestConsumer consumer; 213 TestConsumer consumer;
220 consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer); 214 consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer);
221 consumer.WaitForData(); 215 consumer.WaitForData();
222 ASSERT_EQ(2U, consumer.services_.size()); 216 ASSERT_EQ(2U, consumer.services_.size());
223 } 217 }
224 218
225 TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) { 219 TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) {
226 extensions_.push_back(LoadAndExpectSuccess("intent_valid.json")); 220 extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
227 extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json")); 221 extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
222 ASSERT_EQ(2U, extensions_.size());
228 223
229 TestConsumer consumer; 224 TestConsumer consumer;
230 consumer.expected_id_ = registry_.GetIntentProviders( 225 consumer.expected_id_ = registry_.GetIntentProviders(
231 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), 226 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"),
232 &consumer); 227 &consumer);
233 consumer.WaitForData(); 228 consumer.WaitForData();
234 ASSERT_EQ(1U, consumer.services_.size()); 229 ASSERT_EQ(1U, consumer.services_.size());
235 } 230 }
236 231
237 TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) { 232 TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) {
238 extensions_.push_back(LoadAndExpectSuccess("intent_valid.json")); 233 extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
239 extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json")); 234 extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
235 ASSERT_EQ(2U, extensions_.size());
240 236
241 webkit_glue::WebIntentServiceData service; 237 webkit_glue::WebIntentServiceData service;
242 service.service_url = GURL("http://somewhere.com/intent/edit.html"); 238 service.service_url = GURL("http://somewhere.com/intent/edit.html");
243 service.action = ASCIIToUTF16("http://webintents.org/edit"); 239 service.action = ASCIIToUTF16("http://webintents.org/edit");
244 service.type = ASCIIToUTF16("image/*"); 240 service.type = ASCIIToUTF16("image/*");
245 service.title = ASCIIToUTF16("Image Editing Service"); 241 service.title = ASCIIToUTF16("Image Editing Service");
246 registry_.RegisterIntentProvider(service); 242 registry_.RegisterIntentProvider(service);
247 243
248 TestConsumer consumer; 244 TestConsumer consumer;
249 consumer.expected_id_ = registry_.GetIntentProviders( 245 consumer.expected_id_ = registry_.GetIntentProviders(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 consumer.expected_id_ = registry_.GetIntentProviders( 319 consumer.expected_id_ = registry_.GetIntentProviders(
324 ASCIIToUTF16("http://webintents.org/share"), 320 ASCIIToUTF16("http://webintents.org/share"),
325 ASCIIToUTF16("*"), &consumer); 321 ASCIIToUTF16("*"), &consumer);
326 consumer.WaitForData(); 322 consumer.WaitForData();
327 ASSERT_EQ(4U, consumer.services_.size()); 323 ASSERT_EQ(4U, consumer.services_.size());
328 EXPECT_EQ(services[0], consumer.services_[0]); 324 EXPECT_EQ(services[0], consumer.services_[0]);
329 EXPECT_EQ(services[1], consumer.services_[1]); 325 EXPECT_EQ(services[1], consumer.services_[1]);
330 EXPECT_EQ(services[2], consumer.services_[2]); 326 EXPECT_EQ(services[2], consumer.services_[2]);
331 EXPECT_EQ(services[3], consumer.services_[3]); 327 EXPECT_EQ(services[3], consumer.services_[3]);
332 } 328 }
OLDNEW
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/sync/test/integration/sync_extension_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698