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

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

Issue 9595031: [Web Intents] Inline installation of extensions in web intents picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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();
James Hawkins 2012/03/15 01:05:20 Save a row by putting ++iter up here.
binji 2012/03/15 17:53:14 Done.
116 ++iter) {
117 if ((*iter)->id() == extension_id)
118 return &**iter;
119 }
120
121 return NULL;
122 }
123
107 MessageLoopForUI message_loop_; 124 MessageLoopForUI message_loop_;
108 content::TestBrowserThread ui_thread_; 125 content::TestBrowserThread ui_thread_;
109 content::TestBrowserThread db_thread_; 126 content::TestBrowserThread db_thread_;
110 scoped_refptr<WebDataService> wds_; 127 scoped_refptr<WebDataService> wds_;
111 MockExtensionService extension_service_; 128 MockExtensionService extension_service_;
112 ExtensionSet extensions_; 129 ExtensionSet extensions_;
113 WebIntentsRegistry registry_; 130 WebIntentsRegistry registry_;
114 ScopedTempDir temp_dir_; 131 ScopedTempDir temp_dir_;
115 }; 132 };
116 133
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 service.type = ASCIIToUTF16("image/*"); 204 service.type = ASCIIToUTF16("image/*");
188 registry_.UnregisterIntentService(service); 205 registry_.UnregisterIntentService(service);
189 206
190 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), 207 consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"),
191 ASCIIToUTF16("*"), 208 ASCIIToUTF16("*"),
192 &consumer); 209 &consumer);
193 consumer.WaitForData(); 210 consumer.WaitForData();
194 EXPECT_EQ(1U, consumer.services_.size()); 211 EXPECT_EQ(1U, consumer.services_.size());
195 } 212 }
196 213
214 TEST_F(WebIntentsRegistryTest, GetIntentServicesWithExtensionId) {
215 extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
216 extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
217 ASSERT_EQ(2U, extensions_.size());
218
219 TestConsumer consumer;
220 consumer.expected_id_ = registry_.GetIntentServicesWithExtensionId(
221 ASCIIToUTF16("http://webintents.org/edit"),
222 ASCIIToUTF16("image/*"),
223 (*extensions_.begin())->id(),
224 &consumer);
225 consumer.WaitForData();
226 ASSERT_EQ(1U, consumer.services_.size());
227 }
228
197 TEST_F(WebIntentsRegistryTest, GetAllIntents) { 229 TEST_F(WebIntentsRegistryTest, GetAllIntents) {
198 webkit_glue::WebIntentServiceData service; 230 webkit_glue::WebIntentServiceData service;
199 service.service_url = GURL("http://google.com"); 231 service.service_url = GURL("http://google.com");
200 service.action = ASCIIToUTF16("share"); 232 service.action = ASCIIToUTF16("share");
201 service.type = ASCIIToUTF16("image/*"); 233 service.type = ASCIIToUTF16("image/*");
202 service.title = ASCIIToUTF16("Google's Sharing Service"); 234 service.title = ASCIIToUTF16("Google's Sharing Service");
203 registry_.RegisterIntentService(service); 235 registry_.RegisterIntentService(service);
204 236
205 service.action = ASCIIToUTF16("search"); 237 service.action = ASCIIToUTF16("search");
206 registry_.RegisterIntentService(service); 238 registry_.RegisterIntentService(service);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 consumer.expected_id_ = registry_.GetDefaultIntentService( 420 consumer.expected_id_ = registry_.GetDefaultIntentService(
389 ASCIIToUTF16("share"), 421 ASCIIToUTF16("share"),
390 ASCIIToUTF16("notype/plain"), 422 ASCIIToUTF16("notype/plain"),
391 GURL("http://www.google.com/"), 423 GURL("http://www.google.com/"),
392 &consumer); 424 &consumer);
393 425
394 consumer.WaitForData(); 426 consumer.WaitForData();
395 427
396 EXPECT_EQ("", consumer.default_.service_url); 428 EXPECT_EQ("", consumer.default_.service_url);
397 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698