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

Unified Diff: chrome_frame/scoped_initialization_manager_unittest.cc

Issue 12521002: Start and stop crash reporting outside of the loader lock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit test Created 7 years, 9 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_frame/scoped_initialization_manager.h ('k') | chrome_frame/utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_frame/scoped_initialization_manager_unittest.cc
diff --git a/chrome_frame/scoped_initialization_manager_unittest.cc b/chrome_frame/scoped_initialization_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5c8c83736c59037f0fa6e0cddc7ed47cee675318
--- /dev/null
+++ b/chrome_frame/scoped_initialization_manager_unittest.cc
@@ -0,0 +1,86 @@
+// Copyright 2013 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_frame/scoped_initialization_manager.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using ::testing::InSequence;
+
+// Initialization traits that delegate to a registered delegate instance.
+class TestInitializationTraits {
+ public:
+ class Delegate {
+ public:
+ virtual void Initialize() = 0;
+ virtual void Shutdown() = 0;
+ };
+
+ static void SetDelegate(Delegate* delegate) {
+ delegate_ = delegate;
+ }
+
+ static void Initialize() {
+ ASSERT_TRUE(delegate_ != NULL);
+ delegate_->Initialize();
+ }
+
+ static void Shutdown() {
+ ASSERT_TRUE(delegate_ != NULL);
+ delegate_->Shutdown();
+ }
+
+ private:
+ static Delegate* delegate_;
+};
+
+TestInitializationTraits::Delegate* TestInitializationTraits::delegate_ = NULL;
+
+// A mock delegate for use in tests.
+class MockInitializationTraitsDelegate
+ : public TestInitializationTraits::Delegate {
+ public:
+ MOCK_METHOD0(Initialize, void());
+ MOCK_METHOD0(Shutdown, void());
+};
+
+// A test fixture that sets up a mock traits delegate for use in tests.
+class ScopedInitializationManagerTest : public ::testing::Test {
+ protected:
+ // A manager type that will invoke methods
+ typedef chrome_frame::ScopedInitializationManager<TestInitializationTraits>
+ TestScopedInitializationManager;
+
+ virtual void SetUp() OVERRIDE {
+ TestInitializationTraits::SetDelegate(&mock_traits_delegate_);
+ }
+ virtual void TearDown() OVERRIDE {
+ TestInitializationTraits::SetDelegate(NULL);
+ }
+
+ MockInitializationTraitsDelegate mock_traits_delegate_;
+};
+
+// Test that Initialize and Shutdown are called in order for the simple case.
+TEST_F(ScopedInitializationManagerTest, InitializeAndShutdown) {
+ {
+ InSequence dummy;
+ EXPECT_CALL(mock_traits_delegate_, Initialize());
+ EXPECT_CALL(mock_traits_delegate_, Shutdown());
+ }
+ TestScopedInitializationManager test_manager;
+}
+
+// Test that Initialize and Shutdown are called in order only once despite
+// multiple instances.
+TEST_F(ScopedInitializationManagerTest, InitializeAndShutdownOnlyOnce) {
+ {
+ InSequence dummy;
+ EXPECT_CALL(mock_traits_delegate_, Initialize());
+ EXPECT_CALL(mock_traits_delegate_, Shutdown());
+ }
+ TestScopedInitializationManager test_manager_1;
+ TestScopedInitializationManager test_manager_2;
+ TestScopedInitializationManager test_manager_3;
+}
« no previous file with comments | « chrome_frame/scoped_initialization_manager.h ('k') | chrome_frame/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698