summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 00:44:38 +0000
committermiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 00:44:38 +0000
commit972ecf66c5d52090a813ee943015b2081c9df40d (patch)
treee5bfc113a294492046b53856976486cabb52473c
parent0e3571f32c5c81656b6ae1a6613ac700b061af64 (diff)
downloadchromium_src-972ecf66c5d52090a813ee943015b2081c9df40d.zip
chromium_src-972ecf66c5d52090a813ee943015b2081c9df40d.tar.gz
chromium_src-972ecf66c5d52090a813ee943015b2081c9df40d.tar.bz2
Replace ScopedCommandLineOverride with TestSuite listener.
This was split out of http://codereview.chromium.org/8588067/. BUG=none TEST=none, but this does make testing easier. Review URL: http://codereview.chromium.org/8561031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111057 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/test/test_suite.cc27
-rw-r--r--base/test/test_suite.h4
-rw-r--r--chrome/browser/bookmarks/bookmark_model_unittest.cc9
-rw-r--r--chrome/browser/history/top_sites_unittest.cc6
-rw-r--r--chrome/browser/sync/profile_sync_service_bookmark_unittest.cc5
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/common/extensions/extension_manifests_unittest.cc21
-rw-r--r--chrome/test/base/scoped_command_line_override.cc15
-rw-r--r--chrome/test/base/scoped_command_line_override.h32
9 files changed, 43 insertions, 78 deletions
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index c257b14..e67be8d 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -47,6 +47,26 @@ class MaybeTestDisabler : public testing::EmptyTestEventListener {
}
};
+class TestClientInitializer : public testing::EmptyTestEventListener {
+ public:
+ TestClientInitializer()
+ : old_command_line_(CommandLine::NO_PROGRAM) {
+ }
+
+ virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
+ old_command_line_ = *CommandLine::ForCurrentProcess();
+ }
+
+ virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
+ *CommandLine::ForCurrentProcess() = old_command_line_;
+ }
+
+ private:
+ CommandLine old_command_line_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestClientInitializer);
+};
+
} // namespace
const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling";
@@ -119,6 +139,12 @@ void TestSuite::CatchMaybeTests() {
listeners.Append(new MaybeTestDisabler);
}
+void TestSuite::ResetCommandLine() {
+ testing::TestEventListeners& listeners =
+ testing::UnitTest::GetInstance()->listeners();
+ listeners.Append(new TestClientInitializer);
+}
+
// Don't add additional code to this method. Instead add it to
// Initialize(). See bug 6436.
int TestSuite::Run() {
@@ -229,6 +255,7 @@ void TestSuite::Initialize() {
#endif
CatchMaybeTests();
+ ResetCommandLine();
TestTimeouts::Initialize();
}
diff --git a/base/test/test_suite.h b/base/test/test_suite.h
index 2d4352b..2572756 100644
--- a/base/test/test_suite.h
+++ b/base/test/test_suite.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -50,6 +50,8 @@ class TestSuite {
void CatchMaybeTests();
+ void ResetCommandLine();
+
int Run();
// A command-line flag that makes a test failure always result in a non-zero
diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc
index b3cb34c..8491b71 100644
--- a/chrome/browser/bookmarks/bookmark_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc
@@ -88,16 +88,11 @@ class BookmarkModelTest : public testing::Test,
};
BookmarkModelTest()
- : model_(NULL),
- original_command_line_(*CommandLine::ForCurrentProcess()) {
+ : model_(NULL) {
model_.AddObserver(this);
ClearCounts();
}
- virtual void TearDown() OVERRIDE {
- *CommandLine::ForCurrentProcess() = original_command_line_;
- }
-
void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE {
// We never load from the db, so that this should never get invoked.
NOTREACHED();
@@ -167,8 +162,6 @@ class BookmarkModelTest : public testing::Test,
ObserverDetails observer_details_;
private:
- CommandLine original_command_line_;
-
int added_count_;
int moved_count_;
int removed_count_;
diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc
index 074dee5..bc1c1d6 100644
--- a/chrome/browser/history/top_sites_unittest.cc
+++ b/chrome/browser/history/top_sites_unittest.cc
@@ -4,7 +4,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/command_line.h"
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/path_service.h"
@@ -134,8 +133,7 @@ class TopSitesTest : public HistoryUnitTestBase {
public:
TopSitesTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB, &message_loop_),
- original_command_line_(*CommandLine::ForCurrentProcess()) {
+ db_thread_(BrowserThread::DB, &message_loop_) {
}
virtual void SetUp() {
@@ -149,7 +147,6 @@ class TopSitesTest : public HistoryUnitTestBase {
virtual void TearDown() {
profile_.reset();
- *CommandLine::ForCurrentProcess() = original_command_line_;
}
// Returns true if history and top sites should be created in SetUp.
@@ -323,7 +320,6 @@ class TopSitesTest : public HistoryUnitTestBase {
content::TestBrowserThread db_thread_;
scoped_ptr<TestingProfile> profile_;
CancelableRequestConsumer consumer_;
- CommandLine original_command_line_;
DISALLOW_COPY_AND_ASSIGN(TopSitesTest);
}; // Class TopSitesTest
diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
index f24106e..da29f98 100644
--- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
@@ -286,8 +286,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
ProfileSyncServiceBookmarkTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
- model_(NULL),
- original_command_line_(*CommandLine::ForCurrentProcess()) {
+ model_(NULL) {
}
virtual ~ProfileSyncServiceBookmarkTest() {
@@ -303,7 +302,6 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
virtual void TearDown() {
test_user_share_.TearDown();
- *CommandLine::ForCurrentProcess() = original_command_line_;
}
// Load (or re-load) the bookmark model. |load| controls use of the
@@ -517,7 +515,6 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
protected:
BookmarkModel* model_;
- CommandLine original_command_line_;
TestUserShare test_user_share_;
scoped_ptr<BookmarkChangeProcessor> change_processor_;
StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_;
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 06ae78a..945d1b3 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -213,8 +213,6 @@
'test/base/model_test_utils.h',
'test/base/profile_mock.cc',
'test/base/profile_mock.h',
- 'test/base/scoped_command_line_override.cc',
- 'test/base/scoped_command_line_override.h',
'test/base/test_browser_window.cc',
'test/base/test_browser_window.h',
'test/base/test_html_dialog_observer.cc',
diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc
index 7029570..4eac813 100644
--- a/chrome/common/extensions/extension_manifests_unittest.cc
+++ b/chrome/common/extensions/extension_manifests_unittest.cc
@@ -8,6 +8,7 @@
#include <gtk/gtk.h>
#endif
+#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/i18n/rtl.h"
@@ -26,7 +27,6 @@
#include "chrome/common/extensions/extension_sidebar_defaults.h"
#include "chrome/common/extensions/file_browser_handler.h"
#include "chrome/common/extensions/url_pattern.h"
-#include "chrome/test/base/scoped_command_line_override.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
@@ -377,6 +377,8 @@ TEST_F(ExtensionManifestTest, AppWebUrls) {
TEST_F(ExtensionManifestTest, AppLaunchContainer) {
scoped_refptr<Extension> extension;
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePlatformApps);
extension = LoadAndExpectSuccess("launch_tab.json");
EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container());
@@ -397,11 +399,8 @@ TEST_F(ExtensionManifestTest, AppLaunchContainer) {
errors::kInvalidLaunchContainer);
LoadAndExpectError("launch_container_invalid_type.json",
errors::kInvalidLaunchContainer);
- {
- ScopedCommandLineOverride override(switches::kEnablePlatformApps);
- LoadAndExpectError("launch_container_invalid_type_for_platform.json",
- errors::kInvalidLaunchContainerForPlatform);
- }
+ LoadAndExpectError("launch_container_invalid_type_for_platform.json",
+ errors::kInvalidLaunchContainerForPlatform);
LoadAndExpectError("launch_container_invalid_value.json",
errors::kInvalidLaunchContainer);
LoadAndExpectError("launch_container_without_launch_url.json",
@@ -536,7 +535,7 @@ TEST_F(ExtensionManifestTest, ExperimentalPermission) {
LoadAndExpectSuccess("experimental.json", Extension::COMPONENT);
LoadAndExpectSuccess("experimental.json", Extension::INTERNAL,
Extension::FROM_WEBSTORE);
- ScopedCommandLineOverride override(
+ CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
LoadAndExpectSuccess("experimental.json");
}
@@ -547,7 +546,7 @@ TEST_F(ExtensionManifestTest, DevToolsExtensions) {
LoadAndExpectError("devtools_extension_url_invalid_type.json",
errors::kInvalidDevToolsPage);
- ScopedCommandLineOverride override(
+ CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
scoped_refptr<Extension> extension;
extension = LoadAndExpectSuccess("devtools_extension.json");
@@ -560,7 +559,7 @@ TEST_F(ExtensionManifestTest, Sidebar) {
LoadAndExpectError("sidebar.json",
errors::kExperimentalFlagRequired);
- ScopedCommandLineOverride override(
+ CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
LoadAndExpectError("sidebar_no_permissions.json",
@@ -817,7 +816,7 @@ TEST_F(ExtensionManifestTest, TtsEngine) {
}
TEST_F(ExtensionManifestTest, WebIntents) {
- ScopedCommandLineOverride override("--enable-web-intents");
+ CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents");
LoadAndExpectError("intent_invalid_1.json",
extension_manifest_errors::kInvalidIntents);
@@ -880,7 +879,7 @@ TEST_F(ExtensionManifestTest, IsolatedApps) {
LoadAndExpectError("isolated_app_valid.json",
errors::kExperimentalFlagRequired);
- ScopedCommandLineOverride override(
+ CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
scoped_refptr<Extension> extension2(
LoadAndExpectSuccess("isolated_app_valid.json"));
diff --git a/chrome/test/base/scoped_command_line_override.cc b/chrome/test/base/scoped_command_line_override.cc
deleted file mode 100644
index bd4cb30a..0000000
--- a/chrome/test/base/scoped_command_line_override.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2011 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/test/base/scoped_command_line_override.h"
-
-ScopedCommandLineOverride::ScopedCommandLineOverride(
- const std::string& new_switch)
- : old_command_line_(*CommandLine::ForCurrentProcess()) {
- CommandLine::ForCurrentProcess()->AppendSwitch(new_switch);
-}
-
-ScopedCommandLineOverride::~ScopedCommandLineOverride() {
- *CommandLine::ForCurrentProcess() = old_command_line_;
-}
diff --git a/chrome/test/base/scoped_command_line_override.h b/chrome/test/base/scoped_command_line_override.h
deleted file mode 100644
index 33ebd8a..0000000
--- a/chrome/test/base/scoped_command_line_override.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef CHROME_TEST_BASE_SCOPED_COMMAND_LINE_OVERRIDE_H_
-#define CHROME_TEST_BASE_SCOPED_COMMAND_LINE_OVERRIDE_H_
-#pragma once
-
-#include <string>
-
-#include "base/command_line.h"
-
-// ScopedCommandLineOverride takes the CommandLine for the current
-// process, saves it, then alters it. When the instance of this class
-// goes out of scope, it restores CommandLine to its prior state. The
-// intended usage is to test something that requires a flag that's off
-// by default:
-//
-// ASSERT_TRUE(!Something::NotFullyBaked());
-// {
-// ScopedCommandLineOverride override(switches:kEnableSomethingHalfBaked);
-// ASSERT_TRUE(Something::NotFullyBaked());
-// }
-class ScopedCommandLineOverride {
- public:
- explicit ScopedCommandLineOverride(const std::string& new_switch);
- virtual ~ScopedCommandLineOverride();
- private:
- CommandLine old_command_line_;
-};
-
-#endif // CHROME_TEST_BASE_SCOPED_COMMAND_LINE_OVERRIDE_H_