Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/browser/media/router/media_router_factory_unittest.cc

Issue 1918403002: [Reland] [Media Router Tests] Add tests for MediaRouterFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use unique_tpr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/media/router/media_router_factory.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <memory>
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/media/router/media_router_factory.h"
9 #include "chrome/browser/media/router/mock_media_router.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media_router {
16
17 namespace {
18
19 std::unique_ptr<KeyedService> CreateMockMediaRouter(
20 content::BrowserContext* context) {
21 return base::WrapUnique(new MockMediaRouter);
22 }
23
24 } // namespace
25
26 class MediaRouterFactoryTest : public testing::Test {
27 protected:
28 MediaRouterFactoryTest() {}
29 ~MediaRouterFactoryTest() override {}
30
31 Profile* profile() { return &profile_; }
32
33 private:
34 content::TestBrowserThreadBundle thread_bundle_;
35 TestingProfile profile_;
36 };
37
38 TEST_F(MediaRouterFactoryTest, CreateForRegularProfile) {
39 ASSERT_TRUE(MediaRouterFactory::GetApiForBrowserContext(profile()));
40 }
41
42 TEST_F(MediaRouterFactoryTest, CreateForOffTheRecordProfile) {
43 Profile* otr_profile = profile()->GetOffTheRecordProfile();
44 ASSERT_TRUE(otr_profile);
45
46 // Makes sure a MediaRouter can be created from an OTR Profile.
47 MediaRouter* router =
48 MediaRouterFactory::GetApiForBrowserContext(otr_profile);
49 ASSERT_TRUE(router);
50
51 // A Profile and its OTR Profile share the same MediaRouter instance.
52 ASSERT_EQ(router, MediaRouterFactory::GetApiForBrowserContext(profile()));
53 }
54
55 TEST_F(MediaRouterFactoryTest, OffTheRecordBrowserContextShutdown) {
56 MediaRouterFactory::GetMediaRouterFactoryForTest()->SetTestingFactory(
57 profile(), &CreateMockMediaRouter);
58
59 // Creates an off the record profile.
60 profile()->GetOffTheRecordProfile();
61 MockMediaRouter* router = static_cast<MockMediaRouter*>(
62 MediaRouterFactory::GetApiForBrowserContext(profile()));
63 ASSERT_TRUE(router);
64 EXPECT_CALL(*router, OnOffTheRecordProfileShutdown());
65 profile()->DestroyOffTheRecordProfile();
66 }
67
68 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router_factory.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698