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

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

Issue 8417043: Add webkit_glue namespace. Improve some variable and test names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge error Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/intents/web_intents_registry.h" 10 #include "chrome/browser/intents/web_intents_registry.h"
11 #include "chrome/browser/webdata/web_data_service.h" 11 #include "chrome/browser/webdata/web_data_service.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "content/test/test_browser_thread.h" 13 #include "content/test/test_browser_thread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using webkit_glue::WebIntentServiceData;
18
17 class MockExtensionService: public ExtensionServiceInterface { 19 class MockExtensionService: public ExtensionServiceInterface {
18 public: 20 public:
19 virtual ~MockExtensionService() {} 21 virtual ~MockExtensionService() {}
20 MOCK_CONST_METHOD0(extensions, const ExtensionList*()); 22 MOCK_CONST_METHOD0(extensions, const ExtensionList*());
21 MOCK_METHOD0(pending_extension_manager, PendingExtensionManager*()); 23 MOCK_METHOD0(pending_extension_manager, PendingExtensionManager*());
22 MOCK_METHOD4(UpdateExtension, bool(const std::string& id, 24 MOCK_METHOD4(UpdateExtension, bool(const std::string& id,
23 const FilePath& path, 25 const FilePath& path,
24 const GURL& download_url, 26 const GURL& download_url,
25 CrxInstaller** out_crx_installer)); 27 CrxInstaller** out_crx_installer));
26 MOCK_CONST_METHOD2(GetExtensionById, 28 MOCK_CONST_METHOD2(GetExtensionById,
(...skipping 28 matching lines...) Expand all
55 path = path.AppendASCII("extensions") 57 path = path.AppendASCII("extensions")
56 .AppendASCII("manifest_tests") 58 .AppendASCII("manifest_tests")
57 .AppendASCII(filename.c_str()); 59 .AppendASCII(filename.c_str());
58 EXPECT_TRUE(file_util::PathExists(path)); 60 EXPECT_TRUE(file_util::PathExists(path));
59 61
60 JSONFileValueSerializer serializer(path); 62 JSONFileValueSerializer serializer(path);
61 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); 63 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
62 } 64 }
63 65
64 namespace { 66 namespace {
67
65 scoped_refptr<Extension> LoadExtensionWithLocation( 68 scoped_refptr<Extension> LoadExtensionWithLocation(
66 DictionaryValue* value, 69 DictionaryValue* value,
67 Extension::Location location, 70 Extension::Location location,
68 bool strict_error_checks, 71 bool strict_error_checks,
69 std::string* error) { 72 std::string* error) {
70 FilePath path; 73 FilePath path;
71 PathService::Get(chrome::DIR_TEST_DATA, &path); 74 PathService::Get(chrome::DIR_TEST_DATA, &path);
72 path = path.AppendASCII("extensions").AppendASCII("manifest_tests"); 75 path = path.AppendASCII("extensions").AppendASCII("manifest_tests");
73 int flags = Extension::NO_FLAGS; 76 int flags = Extension::NO_FLAGS;
74 if (strict_error_checks) 77 if (strict_error_checks)
(...skipping 19 matching lines...) Expand all
94 } 97 }
95 98
96 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) { 99 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) {
97 std::string error; 100 std::string error;
98 scoped_refptr<Extension> extension = LoadExtension(name, &error); 101 scoped_refptr<Extension> extension = LoadExtension(name, &error);
99 EXPECT_TRUE(extension) << name; 102 EXPECT_TRUE(extension) << name;
100 EXPECT_EQ("", error) << name; 103 EXPECT_EQ("", error) << name;
101 return extension; 104 return extension;
102 } 105 }
103 106
104 } 107 } // namespace
105 108
106 class WebIntentsRegistryTest : public testing::Test { 109 class WebIntentsRegistryTest : public testing::Test {
107 public: 110 public:
108 WebIntentsRegistryTest() 111 WebIntentsRegistryTest()
109 : ui_thread_(BrowserThread::UI, &message_loop_), 112 : ui_thread_(BrowserThread::UI, &message_loop_),
110 db_thread_(BrowserThread::DB) {} 113 db_thread_(BrowserThread::DB) {}
111 114
112 protected: 115 protected:
113 virtual void SetUp() { 116 virtual void SetUp() {
114 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents"); 117 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents");
(...skipping 25 matching lines...) Expand all
140 WebIntentsRegistry registry_; 143 WebIntentsRegistry registry_;
141 ScopedTempDir temp_dir_; 144 ScopedTempDir temp_dir_;
142 }; 145 };
143 146
144 // Simple consumer for WebIntentsRegistry notifications. Stores result data and 147 // Simple consumer for WebIntentsRegistry notifications. Stores result data and
145 // terminates UI thread when callback is invoked. 148 // terminates UI thread when callback is invoked.
146 class TestConsumer: public WebIntentsRegistry::Consumer { 149 class TestConsumer: public WebIntentsRegistry::Consumer {
147 public: 150 public:
148 virtual void OnIntentsQueryDone( 151 virtual void OnIntentsQueryDone(
149 WebIntentsRegistry::QueryID id, 152 WebIntentsRegistry::QueryID id,
150 const std::vector<WebIntentServiceData>& services) { 153 const std::vector<webkit_glue::WebIntentServiceData>& services) {
151 DCHECK(id == expected_id_); 154 DCHECK(id == expected_id_);
152 services_ = services; 155 services_ = services;
153 156
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
155 MessageLoop::current()->Quit(); 158 MessageLoop::current()->Quit();
156 } 159 }
157 160
158 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone 161 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone
159 // is invoked. 162 // is invoked.
160 void WaitForData() { 163 void WaitForData() {
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
162 MessageLoop::current()->Run(); 165 MessageLoop::current()->Run();
163 } 166 }
164 167
165 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. 168 // QueryID callback is tied to.
166 std::vector<WebIntentServiceData> services_; // Result data from callback. 169 WebIntentsRegistry::QueryID expected_id_;
170
171 // Result data from callback.
172 std::vector<webkit_glue::WebIntentServiceData> services_;
167 }; 173 };
168 174
169 TEST_F(WebIntentsRegistryTest, BasicTests) { 175 TEST_F(WebIntentsRegistryTest, BasicTests) {
170 WebIntentServiceData service; 176 webkit_glue::WebIntentServiceData service;
171 service.service_url = GURL("http://google.com"); 177 service.service_url = GURL("http://google.com");
172 service.action = ASCIIToUTF16("share"); 178 service.action = ASCIIToUTF16("share");
173 service.type = ASCIIToUTF16("image/*"); 179 service.type = ASCIIToUTF16("image/*");
174 service.title = ASCIIToUTF16("Google's Sharing Service"); 180 service.title = ASCIIToUTF16("Google's Sharing Service");
175 181
176 registry_.RegisterIntentProvider(service); 182 registry_.RegisterIntentProvider(service);
177 183
178 service.type = ASCIIToUTF16("video/*"); 184 service.type = ASCIIToUTF16("video/*");
179 registry_.RegisterIntentProvider(service); 185 registry_.RegisterIntentProvider(service);
180 186
(...skipping 18 matching lines...) Expand all
199 registry_.UnregisterIntentProvider(service); 205 registry_.UnregisterIntentProvider(service);
200 206
201 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), 207 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"),
202 ASCIIToUTF16("*"), 208 ASCIIToUTF16("*"),
203 &consumer); 209 &consumer);
204 consumer.WaitForData(); 210 consumer.WaitForData();
205 EXPECT_EQ(1U, consumer.services_.size()); 211 EXPECT_EQ(1U, consumer.services_.size());
206 } 212 }
207 213
208 TEST_F(WebIntentsRegistryTest, GetAllIntents) { 214 TEST_F(WebIntentsRegistryTest, GetAllIntents) {
209 WebIntentServiceData service; 215 webkit_glue::WebIntentServiceData service;
210 service.service_url = GURL("http://google.com"); 216 service.service_url = GURL("http://google.com");
211 service.action = ASCIIToUTF16("share"); 217 service.action = ASCIIToUTF16("share");
212 service.type = ASCIIToUTF16("image/*"); 218 service.type = ASCIIToUTF16("image/*");
213 service.title = ASCIIToUTF16("Google's Sharing Service"); 219 service.title = ASCIIToUTF16("Google's Sharing Service");
214 registry_.RegisterIntentProvider(service); 220 registry_.RegisterIntentProvider(service);
215 221
216 service.action = ASCIIToUTF16("search"); 222 service.action = ASCIIToUTF16("search");
217 registry_.RegisterIntentProvider(service); 223 registry_.RegisterIntentProvider(service);
218 224
219 TestConsumer consumer; 225 TestConsumer consumer;
(...skipping 30 matching lines...) Expand all
250 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), 256 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"),
251 &consumer); 257 &consumer);
252 consumer.WaitForData(); 258 consumer.WaitForData();
253 ASSERT_EQ(1U, consumer.services_.size()); 259 ASSERT_EQ(1U, consumer.services_.size());
254 } 260 }
255 261
256 TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) { 262 TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) {
257 extensions_.push_back(LoadAndExpectSuccess("intent_valid.json")); 263 extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
258 extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json")); 264 extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
259 265
260 WebIntentServiceData service; 266 webkit_glue::WebIntentServiceData service;
261 service.service_url = GURL("http://somewhere.com/intent/edit.html"); 267 service.service_url = GURL("http://somewhere.com/intent/edit.html");
262 service.action = ASCIIToUTF16("http://webintents.org/edit"); 268 service.action = ASCIIToUTF16("http://webintents.org/edit");
263 service.type = ASCIIToUTF16("image/*"); 269 service.type = ASCIIToUTF16("image/*");
264 service.title = ASCIIToUTF16("Image Editing Service"); 270 service.title = ASCIIToUTF16("Image Editing Service");
265 registry_.RegisterIntentProvider(service); 271 registry_.RegisterIntentProvider(service);
266 272
267 TestConsumer consumer; 273 TestConsumer consumer;
268 consumer.expected_id_ = registry_.GetIntentProviders( 274 consumer.expected_id_ = registry_.GetIntentProviders(
269 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), 275 ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"),
270 &consumer); 276 &consumer);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 consumer.expected_id_ = registry_.GetIntentProviders( 348 consumer.expected_id_ = registry_.GetIntentProviders(
343 ASCIIToUTF16("http://webintents.org/share"), 349 ASCIIToUTF16("http://webintents.org/share"),
344 ASCIIToUTF16("*"), &consumer); 350 ASCIIToUTF16("*"), &consumer);
345 consumer.WaitForData(); 351 consumer.WaitForData();
346 ASSERT_EQ(4U, consumer.services_.size()); 352 ASSERT_EQ(4U, consumer.services_.size());
347 EXPECT_EQ(services[0], consumer.services_[0]); 353 EXPECT_EQ(services[0], consumer.services_[0]);
348 EXPECT_EQ(services[1], consumer.services_[1]); 354 EXPECT_EQ(services[1], consumer.services_[1]);
349 EXPECT_EQ(services[2], consumer.services_[2]); 355 EXPECT_EQ(services[2], consumer.services_[2]);
350 EXPECT_EQ(services[3], consumer.services_[3]); 356 EXPECT_EQ(services[3], consumer.services_[3]);
351 } 357 }
OLDNEW
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698