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

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

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