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

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

Issue 9799001: [Web Intents] Inline installation of extensions in web intents picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: i'm dumb Created 8 years, 9 months 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) 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));
28 }; 30 };
29 31
30 namespace { 32 namespace {
31 33
32 // TODO(groby): Unify loading functions with extension_manifest_unittest code. 34 // TODO(groby): Unify loading functions with extension_manifest_unittest code.
33 DictionaryValue* LoadManifestFile(const FilePath& path, 35 DictionaryValue* LoadManifestFile(const FilePath& path,
34 std::string* error) { 36 std::string* error) {
35 EXPECT_TRUE(file_util::PathExists(path)); 37 EXPECT_TRUE(file_util::PathExists(path));
36 JSONFileValueSerializer serializer(path); 38 JSONFileValueSerializer serializer(path);
37 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); 39 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 virtual void SetUp() { 88 virtual void SetUp() {
87 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents"); 89 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents");
88 90
89 db_thread_.Start(); 91 db_thread_.Start();
90 wds_ = new WebDataService(); 92 wds_ = new WebDataService();
91 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 93 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
92 wds_->Init(temp_dir_.path()); 94 wds_->Init(temp_dir_.path());
93 registry_.Initialize(wds_, &extension_service_); 95 registry_.Initialize(wds_, &extension_service_);
94 EXPECT_CALL(extension_service_, extensions()). 96 EXPECT_CALL(extension_service_, extensions()).
95 WillRepeatedly(testing::Return(&extensions_)); 97 WillRepeatedly(testing::Return(&extensions_));
98 EXPECT_CALL(extension_service_, GetExtensionById(testing::_, testing::_)).
99 WillRepeatedly(
100 testing::Invoke(this, &WebIntentsRegistryTest::GetExtensionById));
96 } 101 }
97 102
98 virtual void TearDown() { 103 virtual void TearDown() {
99 if (wds_.get()) 104 if (wds_.get())
100 wds_->Shutdown(); 105 wds_->Shutdown();
101 106
102 db_thread_.Stop(); 107 db_thread_.Stop();
103 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 108 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
104 MessageLoop::current()->Run(); 109 MessageLoop::current()->Run();
105 } 110 }
106 111
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
107 MessageLoopForUI message_loop_; 123 MessageLoopForUI message_loop_;
108 content::TestBrowserThread ui_thread_; 124 content::TestBrowserThread ui_thread_;
109 content::TestBrowserThread db_thread_; 125 content::TestBrowserThread db_thread_;
110 scoped_refptr<WebDataService> wds_; 126 scoped_refptr<WebDataService> wds_;
111 MockExtensionService extension_service_; 127 MockExtensionService extension_service_;
112 ExtensionSet extensions_; 128 ExtensionSet extensions_;
113 WebIntentsRegistry registry_; 129 WebIntentsRegistry registry_;
114 ScopedTempDir temp_dir_; 130 ScopedTempDir temp_dir_;
115 }; 131 };
116 132
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 service.type = ASCIIToUTF16("image/*"); 203 service.type = ASCIIToUTF16("image/*");
188 registry_.UnregisterIntentService(service); 204 registry_.UnregisterIntentService(service);
189 205
190 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), 206 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"),
191 ASCIIToUTF16("*"), 207 ASCIIToUTF16("*"),
192 &consumer); 208 &consumer);
193 consumer.WaitForData(); 209 consumer.WaitForData();
194 EXPECT_EQ(1U, consumer.services_.size()); 210 EXPECT_EQ(1U, consumer.services_.size());
195 } 211 }
196 212
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
197 TEST_F(WebIntentsRegistryTest, GetAllIntents) { 232 TEST_F(WebIntentsRegistryTest, GetAllIntents) {
198 webkit_glue::WebIntentServiceData service; 233 webkit_glue::WebIntentServiceData service;
199 service.service_url = GURL("http://google.com"); 234 service.service_url = GURL("http://google.com");
200 service.action = ASCIIToUTF16("share"); 235 service.action = ASCIIToUTF16("share");
201 service.type = ASCIIToUTF16("image/*"); 236 service.type = ASCIIToUTF16("image/*");
202 service.title = ASCIIToUTF16("Google's Sharing Service"); 237 service.title = ASCIIToUTF16("Google's Sharing Service");
203 registry_.RegisterIntentService(service); 238 registry_.RegisterIntentService(service);
204 239
205 service.action = ASCIIToUTF16("search"); 240 service.action = ASCIIToUTF16("search");
206 registry_.RegisterIntentService(service); 241 registry_.RegisterIntentService(service);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 consumer.expected_id_ = registry_.GetDefaultIntentService( 423 consumer.expected_id_ = registry_.GetDefaultIntentService(
389 ASCIIToUTF16("share"), 424 ASCIIToUTF16("share"),
390 ASCIIToUTF16("notype/plain"), 425 ASCIIToUTF16("notype/plain"),
391 GURL("http://www.google.com/"), 426 GURL("http://www.google.com/"),
392 &consumer); 427 &consumer);
393 428
394 consumer.WaitForData(); 429 consumer.WaitForData();
395 430
396 EXPECT_EQ("", consumer.default_.service_url); 431 EXPECT_EQ("", consumer.default_.service_url);
397 } 432 }
OLDNEW
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/ui/cocoa/web_intent_sheet_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698