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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/synchronization/waitable_event.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/extensions/test_extension_service.h" | 13 #include "chrome/browser/extensions/test_extension_service.h" |
13 #include "chrome/browser/intents/default_web_intent_service.h" | 14 #include "chrome/browser/intents/default_web_intent_service.h" |
14 #include "chrome/browser/intents/web_intents_registry.h" | 15 #include "chrome/browser/intents/web_intents_registry.h" |
15 #include "chrome/browser/webdata/web_data_service.h" | 16 #include "chrome/browser/webdata/web_data_service.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/extensions/extension_set.h" | 18 #include "chrome/common/extensions/extension_set.h" |
18 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 wds_->Init(temp_dir_.path()); | 96 wds_->Init(temp_dir_.path()); |
96 registry_.Initialize(wds_, &extension_service_); | 97 registry_.Initialize(wds_, &extension_service_); |
97 EXPECT_CALL(extension_service_, extensions()). | 98 EXPECT_CALL(extension_service_, extensions()). |
98 WillRepeatedly(testing::Return(&extensions_)); | 99 WillRepeatedly(testing::Return(&extensions_)); |
99 EXPECT_CALL(extension_service_, GetExtensionById(testing::_, testing::_)). | 100 EXPECT_CALL(extension_service_, GetExtensionById(testing::_, testing::_)). |
100 WillRepeatedly( | 101 WillRepeatedly( |
101 testing::Invoke(this, &WebIntentsRegistryTest::GetExtensionById)); | 102 testing::Invoke(this, &WebIntentsRegistryTest::GetExtensionById)); |
102 } | 103 } |
103 | 104 |
104 virtual void TearDown() { | 105 virtual void TearDown() { |
105 if (wds_.get()) | 106 // Clear all references to wds to force it destruction. |
106 wds_->Shutdown(); | 107 wds_->ShutdownOnUIThread(); |
| 108 wds_ = NULL; |
107 | 109 |
| 110 // Schedule another task on the DB thread to notify us that it's safe to |
| 111 // carry on with the test. |
| 112 base::WaitableEvent done(false, false); |
| 113 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 114 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 115 done.Wait(); |
108 db_thread_.Stop(); | 116 db_thread_.Stop(); |
109 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 117 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
110 MessageLoop::current()->Run(); | 118 MessageLoop::current()->Run(); |
111 } | 119 } |
112 | 120 |
113 const Extension* GetExtensionById(const std::string& extension_id, | 121 const Extension* GetExtensionById(const std::string& extension_id, |
114 testing::Unused) { | 122 testing::Unused) { |
115 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 123 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
116 iter != extensions_.end(); ++iter) { | 124 iter != extensions_.end(); ++iter) { |
117 if ((*iter)->id() == extension_id) | 125 if ((*iter)->id() == extension_id) |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 TestConsumer consumer; | 632 TestConsumer consumer; |
625 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), | 633 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), |
626 ASCIIToUTF16("image/*"), | 634 ASCIIToUTF16("image/*"), |
627 base::Bind(&TestConsumer::OnIntentsQueryDone, | 635 base::Bind(&TestConsumer::OnIntentsQueryDone, |
628 base::Unretained(&consumer))); | 636 base::Unretained(&consumer))); |
629 | 637 |
630 consumer.WaitForData(); | 638 consumer.WaitForData(); |
631 ASSERT_EQ(1U, consumer.services_.size()); | 639 ASSERT_EQ(1U, consumer.services_.size()); |
632 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); | 640 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); |
633 } | 641 } |
OLD | NEW |