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

Unified Diff: chrome/browser/media/router/media_router_factory_unittest.cc

Issue 1877273002: [Media Router Tests] Add tests for MediaRouterFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl try 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/router/media_router_factory_unittest.cc
diff --git a/chrome/browser/media/router/media_router_factory_unittest.cc b/chrome/browser/media/router/media_router_factory_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..694e14d27ed1e2c8bef935bb396a113f07e0a7a3
--- /dev/null
+++ b/chrome/browser/media/router/media_router_factory_unittest.cc
@@ -0,0 +1,66 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/router/media_router_factory.h"
+
+#include "chrome/browser/media/router/mock_media_router.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media_router {
+
+namespace {
+
+scoped_ptr<KeyedService> CreateMockMediaRouter(
dcheng 2016/04/26 08:26:12 Please use std::unique_ptr and base::WrapUnique. s
+ content::BrowserContext* context) {
+ return make_scoped_ptr(new MockMediaRouter);
+}
+
+} // namespace
+
+class MediaRouterFactoryTest : public testing::Test {
+ protected:
+ MediaRouterFactoryTest() {}
+ ~MediaRouterFactoryTest() override {}
+
+ Profile* profile() { return &profile_; }
+
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
+ TestingProfile profile_;
+};
+
+TEST_F(MediaRouterFactoryTest, CreateForRegularProfile) {
+ ASSERT_TRUE(MediaRouterFactory::GetApiForBrowserContext(profile()));
+}
+
+TEST_F(MediaRouterFactoryTest, CreateForOffTheRecordProfile) {
+ Profile* otr_profile = profile()->GetOffTheRecordProfile();
+ ASSERT_TRUE(otr_profile);
+
+ // Makes sure a MediaRouter can be created from an OTR Profile.
+ MediaRouter* router =
+ MediaRouterFactory::GetApiForBrowserContext(otr_profile);
+ ASSERT_TRUE(router);
+
+ // A Profile and its OTR Profile share the same MediaRouter instance.
+ ASSERT_EQ(router, MediaRouterFactory::GetApiForBrowserContext(profile()));
+}
+
+TEST_F(MediaRouterFactoryTest, OffTheRecordBrowserContextShutdown) {
+ MediaRouterFactory::GetMediaRouterFactoryForTest()->SetTestingFactory(
+ profile(), &CreateMockMediaRouter);
+
+ // Creates an off the record profile.
+ profile()->GetOffTheRecordProfile();
+ MockMediaRouter* router = static_cast<MockMediaRouter*>(
+ MediaRouterFactory::GetApiForBrowserContext(profile()));
+ ASSERT_TRUE(router);
+ EXPECT_CALL(*router, OnOffTheRecordProfileShutdown());
+ profile()->DestroyOffTheRecordProfile();
+}
+
+} // namespace media_router
« 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