| 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 "chrome/test/testing_browser_process_test.h" | 10 #include "chrome/test/testing_browser_process_test.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 class WebIntentsRegistryTest : public TestingBrowserProcessTest { | 13 class WebIntentsRegistryTest : public TestingBrowserProcessTest { |
| 14 public: | 14 public: |
| 15 WebIntentsRegistryTest() | 15 WebIntentsRegistryTest() |
| 16 : ui_thread_(BrowserThread::UI, &message_loop_), | 16 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 17 db_thread_(BrowserThread::DB) {} | 17 db_thread_(BrowserThread::DB) {} |
| 18 | 18 |
| 19 protected: | 19 protected: |
| 20 virtual void SetUp() { | 20 virtual void SetUp() { |
| 21 db_thread_.Start(); | 21 db_thread_.Start(); |
| 22 wds_ = new WebDataService(); | 22 wds_ = new WebDataService(); |
| 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 24 wds_->Init(temp_dir_.path()); | 24 wds_->Init(temp_dir_.path()); |
| 25 |
| 25 registry_.Initialize(wds_); | 26 registry_.Initialize(wds_); |
| 26 } | 27 } |
| 27 | 28 |
| 28 virtual void TearDown() { | 29 virtual void TearDown() { |
| 29 if (wds_.get()) | 30 if (wds_.get()) |
| 30 wds_->Shutdown(); | 31 wds_->Shutdown(); |
| 31 | 32 |
| 32 db_thread_.Stop(); | 33 db_thread_.Stop(); |
| 33 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 34 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 34 MessageLoop::current()->Run(); | 35 MessageLoop::current()->Run(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 64 | 65 |
| 65 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. | 66 WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to. |
| 66 std::vector<WebIntentData> intents_; // Result data from callback. | 67 std::vector<WebIntentData> intents_; // Result data from callback. |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 TEST_F(WebIntentsRegistryTest, BasicTests) { | 70 TEST_F(WebIntentsRegistryTest, BasicTests) { |
| 70 WebIntentData intent; | 71 WebIntentData intent; |
| 71 intent.service_url = GURL("http://google.com"); | 72 intent.service_url = GURL("http://google.com"); |
| 72 intent.action = ASCIIToUTF16("share"); | 73 intent.action = ASCIIToUTF16("share"); |
| 73 intent.type = ASCIIToUTF16("image/*"); | 74 intent.type = ASCIIToUTF16("image/*"); |
| 75 intent.title = ASCIIToUTF16("Google's Sharing Service"); |
| 74 | 76 |
| 75 registry_.RegisterIntentProvider(intent); | 77 registry_.RegisterIntentProvider(intent); |
| 76 | 78 |
| 77 intent.type = ASCIIToUTF16("video/*"); | 79 intent.type = ASCIIToUTF16("video/*"); |
| 78 registry_.RegisterIntentProvider(intent); | 80 registry_.RegisterIntentProvider(intent); |
| 79 | 81 |
| 80 intent.action = ASCIIToUTF16("search"); | 82 intent.action = ASCIIToUTF16("search"); |
| 81 registry_.RegisterIntentProvider(intent); | 83 registry_.RegisterIntentProvider(intent); |
| 82 | 84 |
| 83 TestConsumer consumer; | 85 TestConsumer consumer; |
| 84 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 86 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), |
| 85 &consumer); | 87 &consumer); |
| 86 consumer.WaitForData(); | 88 consumer.WaitForData(); |
| 87 EXPECT_EQ(2U, consumer.intents_.size()); | 89 EXPECT_EQ(2U, consumer.intents_.size()); |
| 88 | 90 |
| 89 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"), | 91 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"), |
| 90 &consumer); | 92 &consumer); |
| 91 consumer.WaitForData(); | 93 consumer.WaitForData(); |
| 92 EXPECT_EQ(1U, consumer.intents_.size()); | 94 EXPECT_EQ(1U, consumer.intents_.size()); |
| 93 | 95 |
| 94 intent.action = ASCIIToUTF16("share"); | 96 intent.action = ASCIIToUTF16("share"); |
| 95 intent.type = ASCIIToUTF16("image/*"); | 97 intent.type = ASCIIToUTF16("image/*"); |
| 96 registry_.UnregisterIntentProvider(intent); | 98 registry_.UnregisterIntentProvider(intent); |
| 97 | 99 |
| 98 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), | 100 consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"), |
| 99 &consumer); | 101 &consumer); |
| 100 consumer.WaitForData(); | 102 consumer.WaitForData(); |
| 101 EXPECT_EQ(1U, consumer.intents_.size()); | 103 EXPECT_EQ(1U, consumer.intents_.size()); |
| 102 } | 104 } |
| OLD | NEW |