| OLD | NEW |
| 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/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/intents/web_intents_registry.h" | 8 #include "chrome/browser/intents/web_intents_registry.h" |
| 9 #include "chrome/browser/webdata/web_data_service.h" | 9 #include "chrome/browser/webdata/web_data_service.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 class WebIntentsRegistryTest : public testing::Test { | 12 class WebIntentsRegistryTest : public testing::Test { |
| 13 public: | 13 public: |
| 14 WebIntentsRegistryTest() | 14 WebIntentsRegistryTest() |
| 15 : ui_thread_(BrowserThread::UI, &message_loop_), | 15 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 16 db_thread_(BrowserThread::DB) {} | 16 db_thread_(BrowserThread::DB) {} |
| 17 | 17 |
| 18 protected: | 18 protected: |
| 19 virtual void SetUp() { | 19 virtual void SetUp() { |
| 20 db_thread_.Start(); | 20 db_thread_.Start(); |
| 21 wds_ = new WebDataService(); | 21 wds_ = new WebDataService(); |
| 22 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 22 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 23 wds_->Init(temp_dir_.path()); | 23 wds_->Init(temp_dir_.path()); |
| 24 registry_.Initialize(wds_); | 24 |
| 25 registry_ = new WebIntentsRegistry; |
| 26 registry_->Initialize(wds_); |
| 25 } | 27 } |
| 26 | 28 |
| 27 virtual void TearDown() { | 29 virtual void TearDown() { |
| 28 if (wds_.get()) | 30 if (wds_.get()) |
| 29 wds_->Shutdown(); | 31 wds_->Shutdown(); |
| 30 | 32 |
| 31 db_thread_.Stop(); | 33 db_thread_.Stop(); |
| 32 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 34 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 33 MessageLoop::current()->Run(); | 35 MessageLoop::current()->Run(); |
| 34 } | 36 } |
| 35 | 37 |
| 36 MessageLoopForUI message_loop_; | 38 MessageLoopForUI message_loop_; |
| 37 BrowserThread ui_thread_; | 39 BrowserThread ui_thread_; |
| 38 BrowserThread db_thread_; | 40 BrowserThread db_thread_; |
| 39 scoped_refptr<WebDataService> wds_; | 41 scoped_refptr<WebDataService> wds_; |
| 40 WebIntentsRegistry registry_; | 42 scoped_refptr<WebIntentsRegistry> registry_; |
| 41 ScopedTempDir temp_dir_; | 43 ScopedTempDir temp_dir_; |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 // Simple consumer for WebIntentsRegistry notifications. Stores result data and | 46 // Simple consumer for WebIntentsRegistry notifications. Stores result data and |
| 45 // terminates UI thread when callback is invoked. | 47 // terminates UI thread when callback is invoked. |
| 46 class TestConsumer: public WebIntentsRegistry::Consumer { | 48 class TestConsumer: public WebIntentsRegistry::Consumer { |
| 47 public: | 49 public: |
| 48 virtual void OnIntentsQueryDone(WebIntentsRegistry::QueryID id, | 50 virtual void OnIntentsQueryDone(WebIntentsRegistry::QueryID id, |
| 49 const std::vector<WebIntentData>& intents) { | 51 const std::vector<WebIntentData>& intents) { |
| 50 DCHECK(id == expected_id_); | 52 DCHECK(id == expected_id_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. | 66 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. |
| 65 std::vector<WebIntentData> intents_; // Result data from callback. | 67 std::vector<WebIntentData> intents_; // Result data from callback. |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 TEST_F(WebIntentsRegistryTest, BasicTests) { | 70 TEST_F(WebIntentsRegistryTest, BasicTests) { |
| 69 WebIntentData intent; | 71 WebIntentData intent; |
| 70 intent.service_url = GURL("http://google.com"); | 72 intent.service_url = GURL("http://google.com"); |
| 71 intent.action = ASCIIToUTF16("share"); | 73 intent.action = ASCIIToUTF16("share"); |
| 72 intent.type = ASCIIToUTF16("image/*"); | 74 intent.type = ASCIIToUTF16("image/*"); |
| 75 intent.title = ASCIIToUTF16("Google's Sharing Service"); |
| 73 | 76 |
| 74 registry_.RegisterIntentProvider(intent); | 77 registry_->RegisterIntentProvider(intent); |
| 75 | 78 |
| 76 intent.type = ASCIIToUTF16("video/*"); | 79 intent.type = ASCIIToUTF16("video/*"); |
| 77 registry_.RegisterIntentProvider(intent); | 80 registry_->RegisterIntentProvider(intent); |
| 78 | 81 |
| 79 intent.action = ASCIIToUTF16("search"); | 82 intent.action = ASCIIToUTF16("search"); |
| 80 registry_.RegisterIntentProvider(intent); | 83 registry_->RegisterIntentProvider(intent); |
| 81 | 84 |
| 82 TestConsumer consumer; | 85 TestConsumer consumer; |
| 83 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 86 consumer.expected_id_ = registry_->GetIntentProviders(ASCIIToUTF16("share"), |
| 84 &consumer); | 87 &consumer); |
| 85 consumer.WaitForData(); | 88 consumer.WaitForData(); |
| 86 EXPECT_EQ(2U, consumer.intents_.size()); | 89 EXPECT_EQ(2U, consumer.intents_.size()); |
| 87 | 90 |
| 88 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"), | 91 consumer.expected_id_ = registry_->GetIntentProviders(ASCIIToUTF16("search"), |
| 89 &consumer); | 92 &consumer); |
| 90 consumer.WaitForData(); | 93 consumer.WaitForData(); |
| 91 EXPECT_EQ(1U, consumer.intents_.size()); | 94 EXPECT_EQ(1U, consumer.intents_.size()); |
| 92 | 95 |
| 93 intent.action = ASCIIToUTF16("share"); | 96 intent.action = ASCIIToUTF16("share"); |
| 94 intent.type = ASCIIToUTF16("image/*"); | 97 intent.type = ASCIIToUTF16("image/*"); |
| 95 registry_.UnregisterIntentProvider(intent); | 98 registry_->UnregisterIntentProvider(intent); |
| 96 | 99 |
| 97 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 100 consumer.expected_id_ = registry_->GetIntentProviders(ASCIIToUTF16("share"), |
| 98 &consumer); | 101 &consumer); |
| 99 consumer.WaitForData(); | 102 consumer.WaitForData(); |
| 100 EXPECT_EQ(1U, consumer.intents_.size()); | 103 EXPECT_EQ(1U, consumer.intents_.size()); |
| 101 } | 104 } |
| OLD | NEW |