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/synchronization/waitable_event.h" |
5 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" | 7 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
7 #include "chrome/browser/intents/web_intents_registry.h" | 8 #include "chrome/browser/intents/web_intents_registry.h" |
8 #include "chrome/browser/intents/web_intents_registry_factory.h" | 9 #include "chrome/browser/intents/web_intents_registry_factory.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
10 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
12 #include "content/test/test_browser_thread.h" | 13 #include "content/test/test_browser_thread.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 16 matching lines...) Expand all Loading... |
31 MockWebIntentsRegistry* BuildForProfile(Profile* profile) { | 32 MockWebIntentsRegistry* BuildForProfile(Profile* profile) { |
32 return static_cast<MockWebIntentsRegistry*>( | 33 return static_cast<MockWebIntentsRegistry*>( |
33 WebIntentsRegistryFactory::GetInstance()->SetTestingFactoryAndUse( | 34 WebIntentsRegistryFactory::GetInstance()->SetTestingFactoryAndUse( |
34 profile, BuildMockWebIntentsRegistry)); | 35 profile, BuildMockWebIntentsRegistry)); |
35 } | 36 } |
36 | 37 |
37 class RegisterIntentHandlerInfoBarDelegateTest | 38 class RegisterIntentHandlerInfoBarDelegateTest |
38 : public TabContentsWrapperTestHarness { | 39 : public TabContentsWrapperTestHarness { |
39 protected: | 40 protected: |
40 RegisterIntentHandlerInfoBarDelegateTest() | 41 RegisterIntentHandlerInfoBarDelegateTest() |
41 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {} | 42 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()), |
| 43 db_thread_(BrowserThread::DB) {} |
42 | 44 |
43 virtual void SetUp() { | 45 virtual void SetUp() { |
| 46 db_thread_.Start(); |
44 TabContentsWrapperTestHarness::SetUp(); | 47 TabContentsWrapperTestHarness::SetUp(); |
45 | 48 |
46 profile()->CreateWebDataService(false); | 49 profile()->CreateWebDataService(); |
47 web_intents_registry_ = BuildForProfile(profile()); | 50 web_intents_registry_ = BuildForProfile(profile()); |
48 } | 51 } |
49 | 52 |
50 virtual void TearDown() { | 53 virtual void TearDown() { |
51 web_intents_registry_ = NULL; | 54 web_intents_registry_ = NULL; |
52 | 55 |
53 TabContentsWrapperTestHarness::TearDown(); | 56 TabContentsWrapperTestHarness::TearDown(); |
| 57 // Schedule another task on the DB thread to notify us that it's safe to |
| 58 // carry on with the test. |
| 59 base::WaitableEvent done(false, false); |
| 60 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 61 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 62 done.Wait(); |
| 63 db_thread_.Stop(); |
54 } | 64 } |
55 | 65 |
56 MockWebIntentsRegistry* web_intents_registry_; | 66 MockWebIntentsRegistry* web_intents_registry_; |
57 | 67 |
58 private: | 68 private: |
59 content::TestBrowserThread ui_thread_; | 69 content::TestBrowserThread ui_thread_; |
| 70 content::TestBrowserThread db_thread_; |
60 | 71 |
61 DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegateTest); | 72 DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegateTest); |
62 }; | 73 }; |
63 | 74 |
64 TEST_F(RegisterIntentHandlerInfoBarDelegateTest, Accept) { | 75 TEST_F(RegisterIntentHandlerInfoBarDelegateTest, Accept) { |
65 webkit_glue::WebIntentServiceData service; | 76 webkit_glue::WebIntentServiceData service; |
66 service.service_url = GURL("google.com"); | 77 service.service_url = GURL("google.com"); |
67 service.action = ASCIIToUTF16("http://webintents.org/share"); | 78 service.action = ASCIIToUTF16("http://webintents.org/share"); |
68 service.type = ASCIIToUTF16("text/url"); | 79 service.type = ASCIIToUTF16("text/url"); |
69 RegisterIntentHandlerInfoBarDelegate delegate( | 80 RegisterIntentHandlerInfoBarDelegate delegate( |
70 contents_wrapper()->infobar_tab_helper(), | 81 contents_wrapper()->infobar_tab_helper(), |
71 WebIntentsRegistryFactory::GetForProfile(profile()), | 82 WebIntentsRegistryFactory::GetForProfile(profile()), |
72 service, NULL, GURL()); | 83 service, NULL, GURL()); |
73 | 84 |
74 EXPECT_CALL(*web_intents_registry_, RegisterIntentService(service)); | 85 EXPECT_CALL(*web_intents_registry_, RegisterIntentService(service)); |
75 delegate.Accept(); | 86 delegate.Accept(); |
76 } | 87 } |
77 | 88 |
78 } // namespace | 89 } // namespace |
OLD | NEW |