| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/test/content_test_suite.h" | 5 #include "content/test/content_test_suite.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/browser/mock_content_browser_client.h" |
| 9 #include "content/common/content_client.h" | 10 #include "content/common/content_client.h" |
| 11 #include "content/common/notification_service.h" |
| 10 #include "content/test/test_content_client.h" | 12 #include "content/test/test_content_client.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 class TestContentClientInitializer : public testing::EmptyTestEventListener { | 17 class TestContentClientInitializer : public testing::EmptyTestEventListener { |
| 16 public: | 18 public: |
| 17 TestContentClientInitializer() { | 19 TestContentClientInitializer() { |
| 18 } | 20 } |
| 19 | 21 |
| 20 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | 22 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| 23 notification_service_.reset(new NotificationService()); |
| 24 |
| 21 DCHECK(!content::GetContentClient()); | 25 DCHECK(!content::GetContentClient()); |
| 22 content_client_.reset(new TestContentClient); | 26 content_client_.reset(new TestContentClient); |
| 23 content::SetContentClient(content_client_.get()); | 27 content::SetContentClient(content_client_.get()); |
| 28 |
| 29 content_browser_client_.reset(new content::MockContentBrowserClient()); |
| 30 content_client_->set_browser(content_browser_client_.get()); |
| 24 } | 31 } |
| 25 | 32 |
| 26 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 33 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| 34 notification_service_.reset(); |
| 35 |
| 27 DCHECK_EQ(content_client_.get(), content::GetContentClient()); | 36 DCHECK_EQ(content_client_.get(), content::GetContentClient()); |
| 28 content::SetContentClient(NULL); | 37 content::SetContentClient(NULL); |
| 29 content_client_.reset(); | 38 content_client_.reset(); |
| 39 |
| 40 content_browser_client_.reset(); |
| 30 } | 41 } |
| 31 | 42 |
| 32 private: | 43 private: |
| 44 scoped_ptr<NotificationService> notification_service_; |
| 33 scoped_ptr<content::ContentClient> content_client_; | 45 scoped_ptr<content::ContentClient> content_client_; |
| 46 scoped_ptr<content::ContentBrowserClient> content_browser_client_; |
| 34 | 47 |
| 35 DISALLOW_COPY_AND_ASSIGN(TestContentClientInitializer); | 48 DISALLOW_COPY_AND_ASSIGN(TestContentClientInitializer); |
| 36 }; | 49 }; |
| 37 | 50 |
| 38 } // namespace | 51 } // namespace |
| 39 | 52 |
| 40 ContentTestSuite::ContentTestSuite(int argc, char** argv) | 53 ContentTestSuite::ContentTestSuite(int argc, char** argv) |
| 41 : base::TestSuite(argc, argv) { | 54 : base::TestSuite(argc, argv) { |
| 42 } | 55 } |
| 43 | 56 |
| 44 ContentTestSuite::~ContentTestSuite() { | 57 ContentTestSuite::~ContentTestSuite() { |
| 45 } | 58 } |
| 46 | 59 |
| 47 void ContentTestSuite::Initialize() { | 60 void ContentTestSuite::Initialize() { |
| 48 base::TestSuite::Initialize(); | 61 base::TestSuite::Initialize(); |
| 49 | 62 |
| 50 testing::TestEventListeners& listeners = | 63 testing::TestEventListeners& listeners = |
| 51 testing::UnitTest::GetInstance()->listeners(); | 64 testing::UnitTest::GetInstance()->listeners(); |
| 52 listeners.Append(new TestContentClientInitializer); | 65 listeners.Append(new TestContentClientInitializer); |
| 53 } | 66 } |
| OLD | NEW |