OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "chrome/browser/media/router/media_router_factory.h" | |
6 | |
7 #include "chrome/browser/media/router/mock_media_router.h" | |
8 #include "chrome/test/base/testing_profile.h" | |
9 #include "content/public/browser/browser_context.h" | |
10 #include "content/public/test/test_browser_thread_bundle.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace media_router { | |
14 | |
15 namespace { | |
16 | |
17 scoped_ptr<KeyedService> CreateMockMediaRouter( | |
dcheng
2016/04/26 08:26:12
Please use std::unique_ptr and base::WrapUnique. s
| |
18 content::BrowserContext* context) { | |
19 return make_scoped_ptr(new MockMediaRouter); | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 class MediaRouterFactoryTest : public testing::Test { | |
25 protected: | |
26 MediaRouterFactoryTest() {} | |
27 ~MediaRouterFactoryTest() override {} | |
28 | |
29 Profile* profile() { return &profile_; } | |
30 | |
31 private: | |
32 content::TestBrowserThreadBundle thread_bundle_; | |
33 TestingProfile profile_; | |
34 }; | |
35 | |
36 TEST_F(MediaRouterFactoryTest, CreateForRegularProfile) { | |
37 ASSERT_TRUE(MediaRouterFactory::GetApiForBrowserContext(profile())); | |
38 } | |
39 | |
40 TEST_F(MediaRouterFactoryTest, CreateForOffTheRecordProfile) { | |
41 Profile* otr_profile = profile()->GetOffTheRecordProfile(); | |
42 ASSERT_TRUE(otr_profile); | |
43 | |
44 // Makes sure a MediaRouter can be created from an OTR Profile. | |
45 MediaRouter* router = | |
46 MediaRouterFactory::GetApiForBrowserContext(otr_profile); | |
47 ASSERT_TRUE(router); | |
48 | |
49 // A Profile and its OTR Profile share the same MediaRouter instance. | |
50 ASSERT_EQ(router, MediaRouterFactory::GetApiForBrowserContext(profile())); | |
51 } | |
52 | |
53 TEST_F(MediaRouterFactoryTest, OffTheRecordBrowserContextShutdown) { | |
54 MediaRouterFactory::GetMediaRouterFactoryForTest()->SetTestingFactory( | |
55 profile(), &CreateMockMediaRouter); | |
56 | |
57 // Creates an off the record profile. | |
58 profile()->GetOffTheRecordProfile(); | |
59 MockMediaRouter* router = static_cast<MockMediaRouter*>( | |
60 MediaRouterFactory::GetApiForBrowserContext(profile())); | |
61 ASSERT_TRUE(router); | |
62 EXPECT_CALL(*router, OnOffTheRecordProfileShutdown()); | |
63 profile()->DestroyOffTheRecordProfile(); | |
64 } | |
65 | |
66 } // namespace media_router | |
OLD | NEW |