| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/synchronization/waitable_event.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" | |
| 8 #include "chrome/browser/intents/web_intents_registry.h" | |
| 9 #include "chrome/browser/intents/web_intents_registry_factory.h" | |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | |
| 12 #include "content/public/test/test_browser_thread.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "webkit/glue/web_intent_service_data.h" | |
| 16 | |
| 17 using content::BrowserThread; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class MockWebIntentsRegistry : public WebIntentsRegistry { | |
| 22 public: | |
| 23 MOCK_METHOD1(RegisterIntentService, | |
| 24 void(const webkit_glue::WebIntentServiceData&)); | |
| 25 }; | |
| 26 | |
| 27 ProfileKeyedService* BuildMockWebIntentsRegistry(Profile* profile) { | |
| 28 return new MockWebIntentsRegistry; | |
| 29 } | |
| 30 | |
| 31 MockWebIntentsRegistry* BuildForProfile(Profile* profile) { | |
| 32 return static_cast<MockWebIntentsRegistry*>( | |
| 33 WebIntentsRegistryFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 34 profile, BuildMockWebIntentsRegistry)); | |
| 35 } | |
| 36 | |
| 37 class RegisterIntentHandlerInfoBarDelegateTest | |
| 38 : public ChromeRenderViewHostTestHarness { | |
| 39 protected: | |
| 40 RegisterIntentHandlerInfoBarDelegateTest() | |
| 41 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()), | |
| 42 db_thread_(BrowserThread::DB, MessageLoopForUI::current()) {} | |
| 43 | |
| 44 virtual void SetUp() { | |
| 45 ChromeRenderViewHostTestHarness::SetUp(); | |
| 46 | |
| 47 profile()->CreateWebDataService(); | |
| 48 web_intents_registry_ = BuildForProfile(profile()); | |
| 49 } | |
| 50 | |
| 51 virtual void TearDown() { | |
| 52 web_intents_registry_ = NULL; | |
| 53 | |
| 54 ChromeRenderViewHostTestHarness::TearDown(); | |
| 55 } | |
| 56 | |
| 57 MockWebIntentsRegistry* web_intents_registry_; | |
| 58 | |
| 59 private: | |
| 60 content::TestBrowserThread ui_thread_; | |
| 61 content::TestBrowserThread db_thread_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegateTest); | |
| 64 }; | |
| 65 | |
| 66 TEST_F(RegisterIntentHandlerInfoBarDelegateTest, Accept) { | |
| 67 webkit_glue::WebIntentServiceData service; | |
| 68 service.service_url = GURL("google.com"); | |
| 69 service.action = ASCIIToUTF16("http://webintents.org/share"); | |
| 70 service.type = ASCIIToUTF16("text/url"); | |
| 71 scoped_ptr<RegisterIntentHandlerInfoBarDelegate> infobar_delegate( | |
| 72 RegisterIntentHandlerInfoBarDelegate::Create(web_intents_registry_, | |
| 73 service)); | |
| 74 | |
| 75 EXPECT_CALL(*web_intents_registry_, RegisterIntentService(service)); | |
| 76 infobar_delegate->Accept(); | |
| 77 } | |
| 78 | |
| 79 } // namespace | |
| OLD | NEW |