Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_value_serializer.h" | 6 #include "base/json/json_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/web_intents_registry.h" | 13 #include "chrome/browser/intents/web_intents_registry.h" |
| 13 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension_set.h" | 16 #include "chrome/common/extensions/extension_set.h" |
| 16 #include "content/test/test_browser_thread.h" | 17 #include "content/test/test_browser_thread.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 using webkit_glue::WebIntentServiceData; | 22 using webkit_glue::WebIntentServiceData; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 virtual void OnIntentsQueryDone( | 121 virtual void OnIntentsQueryDone( |
| 121 WebIntentsRegistry::QueryID id, | 122 WebIntentsRegistry::QueryID id, |
| 122 const std::vector<webkit_glue::WebIntentServiceData>& services) { | 123 const std::vector<webkit_glue::WebIntentServiceData>& services) { |
| 123 DCHECK(id == expected_id_); | 124 DCHECK(id == expected_id_); |
| 124 services_ = services; | 125 services_ = services; |
| 125 | 126 |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 127 MessageLoop::current()->Quit(); | 128 MessageLoop::current()->Quit(); |
| 128 } | 129 } |
| 129 | 130 |
| 131 virtual void OnIntentsDefaultsQueryDone( | |
| 132 WebIntentsRegistry::QueryID id, | |
| 133 const DefaultWebIntentService& default_service) { | |
| 134 DCHECK(id == expected_id_); | |
| 135 default_ = default_service; | |
| 136 | |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 138 MessageLoop::current()->Quit(); | |
| 139 } | |
| 140 | |
| 130 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone | 141 // Wait for the UI message loop to terminate - happens when OnIntesQueryDone |
| 131 // is invoked. | 142 // is invoked. |
| 132 void WaitForData() { | 143 void WaitForData() { |
| 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 134 MessageLoop::current()->Run(); | 145 MessageLoop::current()->Run(); |
| 135 } | 146 } |
| 136 | 147 |
| 137 // QueryID callback is tied to. | 148 // QueryID callback is tied to. |
| 138 WebIntentsRegistry::QueryID expected_id_; | 149 WebIntentsRegistry::QueryID expected_id_; |
| 139 | 150 |
| 140 // Result data from callback. | 151 // Result data from callback. |
| 141 std::vector<webkit_glue::WebIntentServiceData> services_; | 152 std::vector<webkit_glue::WebIntentServiceData> services_; |
| 153 | |
| 154 // Result default data from callback. | |
| 155 DefaultWebIntentService default_; | |
| 142 }; | 156 }; |
| 143 | 157 |
| 144 TEST_F(WebIntentsRegistryTest, BasicTests) { | 158 TEST_F(WebIntentsRegistryTest, BasicTests) { |
| 145 webkit_glue::WebIntentServiceData service; | 159 webkit_glue::WebIntentServiceData service; |
| 146 service.service_url = GURL("http://google.com"); | 160 service.service_url = GURL("http://google.com"); |
| 147 service.action = ASCIIToUTF16("share"); | 161 service.action = ASCIIToUTF16("share"); |
| 148 service.type = ASCIIToUTF16("image/*"); | 162 service.type = ASCIIToUTF16("image/*"); |
| 149 service.title = ASCIIToUTF16("Google's Sharing Service"); | 163 service.title = ASCIIToUTF16("Google's Sharing Service"); |
| 150 | 164 |
| 151 registry_.RegisterIntentService(service); | 165 registry_.RegisterIntentService(service); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 consumer.expected_id_ = registry_.GetIntentServices( | 334 consumer.expected_id_ = registry_.GetIntentServices( |
| 321 ASCIIToUTF16("http://webintents.org/share"), | 335 ASCIIToUTF16("http://webintents.org/share"), |
| 322 ASCIIToUTF16("*"), &consumer); | 336 ASCIIToUTF16("*"), &consumer); |
| 323 consumer.WaitForData(); | 337 consumer.WaitForData(); |
| 324 ASSERT_EQ(4U, consumer.services_.size()); | 338 ASSERT_EQ(4U, consumer.services_.size()); |
| 325 EXPECT_EQ(services[0], consumer.services_[0]); | 339 EXPECT_EQ(services[0], consumer.services_[0]); |
| 326 EXPECT_EQ(services[1], consumer.services_[1]); | 340 EXPECT_EQ(services[1], consumer.services_[1]); |
| 327 EXPECT_EQ(services[2], consumer.services_[2]); | 341 EXPECT_EQ(services[2], consumer.services_[2]); |
| 328 EXPECT_EQ(services[3], consumer.services_[3]); | 342 EXPECT_EQ(services[3], consumer.services_[3]); |
| 329 } | 343 } |
| 344 | |
| 345 TEST_F(WebIntentsRegistryTest, TestGetDefaults) { | |
| 346 DefaultWebIntentService default_service; | |
| 347 default_service.action = ASCIIToUTF16("share"); | |
| 348 default_service.type = ASCIIToUTF16("type/*"); | |
| 349 default_service.user_date = 1; | |
| 350 default_service.suppression = 4; | |
|
groby-ooo-7-16
2012/02/22 01:40:18
What does user_date = 1 and suppression = 4 mean?
Greg Billock
2012/02/23 23:39:00
Nothing. Just filler to make sure they're preserve
| |
| 351 default_service.service_url = "service_url"; | |
| 352 registry_.RegisterDefaultIntentService(default_service); | |
| 353 | |
| 354 TestConsumer consumer; | |
| 355 | |
| 356 consumer.expected_id_ = registry_.GetDefaultIntentService( | |
| 357 ASCIIToUTF16("share"), | |
| 358 ASCIIToUTF16("type/plain"), | |
| 359 GURL("http://www.google.com/"), | |
| 360 &consumer); | |
| 361 | |
| 362 consumer.WaitForData(); | |
| 363 | |
| 364 EXPECT_EQ("service_url", consumer.default_.service_url); | |
| 365 EXPECT_EQ(1, consumer.default_.user_date); | |
| 366 EXPECT_EQ(4, consumer.default_.suppression); | |
| 367 | |
| 368 consumer.default_ = DefaultWebIntentService(); | |
|
groby-ooo-7-16
2012/02/22 01:40:18
Can you comment the test cases? I.e. "Retrieve exi
Greg Billock
2012/02/23 23:39:00
Done.
| |
| 369 ASSERT_EQ("", consumer.default_.service_url); | |
| 370 consumer.expected_id_ = registry_.GetDefaultIntentService( | |
| 371 ASCIIToUTF16("no-share"), | |
| 372 ASCIIToUTF16("type/plain"), | |
| 373 GURL("http://www.google.com/"), | |
| 374 &consumer); | |
| 375 | |
| 376 consumer.WaitForData(); | |
| 377 | |
| 378 EXPECT_EQ("", consumer.default_.service_url); | |
| 379 | |
| 380 consumer.default_ = DefaultWebIntentService(); | |
| 381 ASSERT_EQ("", consumer.default_.service_url); | |
| 382 consumer.expected_id_ = registry_.GetDefaultIntentService( | |
| 383 ASCIIToUTF16("share"), | |
| 384 ASCIIToUTF16("notype/plain"), | |
| 385 GURL("http://www.google.com/"), | |
| 386 &consumer); | |
| 387 | |
| 388 consumer.WaitForData(); | |
| 389 | |
| 390 EXPECT_EQ("", consumer.default_.service_url); | |
| 391 } | |
| OLD | NEW |