Fix UserManager to not leak the mock managers created for unit tests.
All tests share the singletons and if mocks are leaked state will be leaked
and possibly corrupted between the tests. This CL tries to force every test
that needs a particular UserManager state to use its own mock object and set
it in the wanted state.
BUG=116996
TEST=unit_tests
Review URL: https://chromiumcodereview.appspot.com/9705016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127946 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc
index 9558dd9..d783af8 100644
--- a/chrome/browser/browser_commands_unittest.cc
+++ b/chrome/browser/browser_commands_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -13,6 +13,10 @@
#include "content/public/browser/web_contents.h"
#include "content/test/test_browser_thread.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/mock_user_manager.h"
+#endif
+
typedef BrowserWithTestWindowTest BrowserCommandsTest;
using content::OpenURLParams;
@@ -174,7 +178,15 @@
// Tests IDC_SEARCH (the Search key on Chrome OS devices).
#if defined(OS_CHROMEOS)
+
+namespace chromeos {
+
TEST_F(BrowserCommandsTest, Search) {
+ scoped_ptr<MockUserManager> mock_user_manager(new MockUserManager());
+ UserManager* old_user_manager = UserManager::Set(mock_user_manager.get());
+ EXPECT_CALL(*mock_user_manager, IsLoggedInAsGuest())
+ .Times(1).WillRepeatedly(::testing::Return(false));
+
// Load a non-NTP URL.
GURL non_ntp_url("http://foo/");
AddTab(browser(), non_ntp_url);
@@ -196,5 +208,9 @@
current_url = browser()->GetSelectedWebContents()->GetURL();
EXPECT_TRUE(current_url.SchemeIs(chrome::kChromeUIScheme));
EXPECT_EQ(chrome::kChromeUINewTabHost, current_url.host());
+
+ UserManager::Set(old_user_manager);
}
+
+} // namespace chromeos
#endif