summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 07:35:37 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 07:35:37 +0000
commit79457797443d45463b92abcda0124706bdf1aff5 (patch)
tree83c22707ecc9649686be8d5bb5bd74913c4520d8 /chrome
parentaf980796c6c9df7bd06210397ffa5dad155ebf66 (diff)
downloadchromium_src-79457797443d45463b92abcda0124706bdf1aff5.zip
chromium_src-79457797443d45463b92abcda0124706bdf1aff5.tar.gz
chromium_src-79457797443d45463b92abcda0124706bdf1aff5.tar.bz2
GTTF: Use a fresh TestingBrowserProcess for each test, part #1
This is going to be done in multiple steps, because lots of tests depend on global TestingBrowserProcess. However, the current solution is very error-prone, and may lead to state being carried from one test to another (via NotificationService), resulting in crashes. In theory the ScopedTestingBrowserProcess could be made empty for now, but re-initializing g_browser_process inside it has two benefits: 1) It verifies that changing g_browser_process actually works. 2) It protects at least a subset of tests from carrying state. BUG=61062 TEST=unit_tests, possibly more Review URL: http://codereview.chromium.org/6478005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74926 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/app_controller_mac_unittest.mm3
-rw-r--r--chrome/browser/appcache/chrome_appcache_service_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc14
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete_history_manager_unittest.cc4
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm3
-rw-r--r--chrome/browser/autofill/autofill_download_unittest.cc8
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc2
-rw-r--r--chrome/browser/autofill/autofill_metrics_unittest.cc2
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc2
-rw-r--r--chrome/browser/automation/automation_provider_unittest.cc6
-rw-r--r--chrome/browser/background_contents_service_unittest.cc3
-rw-r--r--chrome/browser/background_mode_manager_unittest.cc4
-rw-r--r--chrome/browser/background_page_tracker_unittest.cc13
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/testing_browser_process.cc23
-rw-r--r--chrome/test/testing_browser_process.h14
-rw-r--r--chrome/test/testing_browser_process_test.h18
23 files changed, 127 insertions, 19 deletions
diff --git a/chrome/browser/app_controller_mac_unittest.mm b/chrome/browser/app_controller_mac_unittest.mm
index 88e8de3..1ea2b38 100644
--- a/chrome/browser/app_controller_mac_unittest.mm
+++ b/chrome/browser/app_controller_mac_unittest.mm
@@ -7,9 +7,12 @@
#include "base/scoped_nsobject.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/app_controller_mac.h"
+#include "chrome/test/testing_browser_process.h"
#include "testing/platform_test.h"
class AppControllerTest : public PlatformTest {
+ private:
+ ScopedTestingBrowserProcess browser_process_;
};
TEST_F(AppControllerTest, DockMenu) {
diff --git a/chrome/browser/appcache/chrome_appcache_service_unittest.cc b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
index 0cb5090..85ba6a24 100644
--- a/chrome/browser/appcache/chrome_appcache_service_unittest.cc
+++ b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
@@ -9,13 +9,15 @@
#include "chrome/browser/appcache/chrome_appcache_service.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/thread_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/appcache/appcache_storage_impl.h"
namespace appcache {
-class ChromeAppCacheServiceTest : public testing::Test {
+class ChromeAppCacheServiceTest : public TestingBrowserProcessTest {
public:
ChromeAppCacheServiceTest()
: message_loop_(MessageLoop::TYPE_IO),
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index 9d54555..5697cb4 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -5,6 +5,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_profile.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -140,6 +141,7 @@ TEST(AutocompleteEditTest, AdjustTextForCopy) {
// Tests that we don't get double http if the user manually inserts http.
{ "a.b/", 0, false, "http://a.b/", "http://a.b/", true, "http://a.b/" },
};
+ ScopedTestingBrowserProcess browser_process;
TestingAutocompleteEditView view;
TestingAutocompleteEditController controller;
TestingProfile profile;
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index 93ce9da..cb8e719 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -16,6 +16,8 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -123,6 +125,8 @@ class AutocompleteProviderTest : public testing::Test,
const NotificationSource& source,
const NotificationDetails& details);
+ ScopedTestingBrowserProcess browser_process_;
+
MessageLoopForUI message_loop_;
scoped_ptr<AutocompleteController> controller_;
NotificationRegistrar registrar_;
@@ -261,7 +265,9 @@ TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {
RunExactKeymatchTest(false);
}
-TEST(AutocompleteTest, InputType) {
+typedef TestingBrowserProcessTest AutocompleteTest;
+
+TEST_F(AutocompleteTest, InputType) {
struct test_data {
const string16 input;
const AutocompleteInput::Type type;
@@ -358,7 +364,7 @@ TEST(AutocompleteTest, InputType) {
}
}
-TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
+TEST_F(AutocompleteTest, InputTypeWithDesiredTLD) {
struct test_data {
const string16 input;
const AutocompleteInput::Type type;
@@ -377,7 +383,7 @@ TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
// This tests for a regression where certain input in the omnibox caused us to
// crash. As long as the test completes without crashing, we're fine.
-TEST(AutocompleteTest, InputCrash) {
+TEST_F(AutocompleteTest, InputCrash) {
AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16(), true, false,
true, false);
}
@@ -440,6 +446,8 @@ TEST(AutocompleteInput, ParseForEmphasizeComponent) {
Component(12, 11), kInvalidComponent }
};
+ ScopedTestingBrowserProcess browser_process;
+
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
Component scheme, host;
AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input,
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index c9067ea..eb6524b 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -12,6 +12,8 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/history/history.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -30,7 +32,7 @@ struct TestEntry {
{"http://www.google.com/3", "PAGETHREE 3", "BAR some hello world for you"},
};
-class HistoryContentsProviderTest : public testing::Test,
+class HistoryContentsProviderTest : public TestingBrowserProcessTest,
public ACProviderListener {
public:
HistoryContentsProviderTest()
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index e9f0581..d5b5e0d 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -19,6 +19,8 @@
#include "chrome/browser/history/url_database.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -64,7 +66,7 @@ struct TestURLInfo {
{"http://xyzabcdefghijklmnopqrstuvw.com/a", "An XYZ", 1, 1, 0},
};
-class HistoryQuickProviderTest : public testing::Test,
+class HistoryQuickProviderTest : public TestingBrowserProcessTest,
public ACProviderListener {
public:
HistoryQuickProviderTest()
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 116cab6..d2a3559 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -11,6 +11,8 @@
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/history/history.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -90,7 +92,7 @@ struct TestURLInfo {
{"http://www.winky.com/", "Internet winky", 5, 0},
};
-class HistoryURLProviderTest : public testing::Test,
+class HistoryURLProviderTest : public TestingBrowserProcessTest,
public ACProviderListener {
public:
HistoryURLProviderTest()
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index 5874cca..37922ba 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -8,10 +8,12 @@
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
-class KeywordProviderTest : public testing::Test {
+class KeywordProviderTest : public TestingBrowserProcessTest {
protected:
template<class ResultType>
struct test_data {
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 0d25649..34d1415 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -15,6 +15,8 @@
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/net/test_url_fetcher_factory.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "net/url_request/url_request_status.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -28,7 +30,7 @@
// . The URL created by using the search term keyword_term_ with keyword_t_url_
// is added to history.
// . test_factory_ is set as the URLFetcher::Factory.
-class SearchProviderTest : public testing::Test,
+class SearchProviderTest : public TestingBrowserProcessTest,
public AutocompleteProvider::ACProviderListener {
public:
SearchProviderTest()
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc
index cfc0c83..09d343f 100644
--- a/chrome/browser/autocomplete_history_manager_unittest.cc
+++ b/chrome/browser/autocomplete_history_manager_unittest.cc
@@ -10,6 +10,8 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -24,7 +26,7 @@ class MockWebDataService : public WebDataService {
void(const std::vector<webkit_glue::FormField>&)); // NOLINT
};
-class AutocompleteHistoryManagerTest : public testing::Test {
+class AutocompleteHistoryManagerTest : public TestingBrowserProcessTest {
protected:
AutocompleteHistoryManagerTest()
: ui_thread_(BrowserThread::UI, &message_loop_) {
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
index 47654a3..1731340 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
@@ -17,6 +17,7 @@
#include "chrome/browser/ui/cocoa/browser_test_helper.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -161,6 +162,8 @@ class AutoFillDialogControllerTest : public CocoaTest {
return helper_.test_profile_->test_manager_->test_credit_cards_;
}
+ ScopedTestingBrowserProcess browser_process_;
+
BrowserMock helper_;
AutoFillDialogObserverMock observer_;
AutoFillDialogController* controller_; // weak reference
diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc
index 099df01..26d1c05 100644
--- a/chrome/browser/autofill/autofill_download_unittest.cc
+++ b/chrome/browser/autofill/autofill_download_unittest.cc
@@ -10,6 +10,8 @@
#include "chrome/browser/autofill/autofill_download.h"
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/common/net/test_url_fetcher_factory.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "net/url_request/url_request_status.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -102,7 +104,9 @@ class AutoFillDownloadTestHelper : public AutoFillDownloadManager::Observer {
AutoFillDownloadManager download_manager;
};
-TEST(AutoFillDownloadTest, QueryAndUploadTest) {
+typedef TestingBrowserProcessTest AutoFillDownloadTest;
+
+TEST_F(AutoFillDownloadTest, QueryAndUploadTest) {
MessageLoopForUI message_loop;
// Create and register factory.
AutoFillDownloadTestHelper helper;
@@ -341,7 +345,7 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) {
URLFetcher::set_factory(NULL);
}
-TEST(AutoFillDownloadTest, CacheQueryTest) {
+TEST_F(AutoFillDownloadTest, CacheQueryTest) {
MessageLoopForUI message_loop;
AutoFillDownloadTestHelper helper;
// Create and register factory.
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index d22f0fd..ad668e4 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/common/autofill_messages.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
@@ -560,6 +561,7 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
}
protected:
+ ScopedTestingBrowserProcess browser_process_;
scoped_ptr<TestAutoFillManager> autofill_manager_;
scoped_refptr<TestPersonalDataManager> test_personal_data_;
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc
index 007b90c..0362f3b 100644
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
+#include "chrome/test/testing_browser_process.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/form_data.h"
@@ -177,6 +178,7 @@ class AutoFillMetricsTest : public RenderViewHostTestHarness {
}
protected:
+ ScopedTestingBrowserProcess browser_process_;
scoped_ptr<TestAutoFillManager> autofill_manager_;
scoped_refptr<TestPersonalDataManager> test_personal_data_;
diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc
index 8687ed2..afda4dc 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -21,6 +21,7 @@
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
+#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_profile.h"
#include "webkit/glue/form_data.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -74,6 +75,7 @@ class PersonalDataManagerTest : public testing::Test {
personal_data_->SetObserver(&personal_data_observer_);
}
+ ScopedTestingBrowserProcess browser_process_;
MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
BrowserThread db_thread_;
diff --git a/chrome/browser/automation/automation_provider_unittest.cc b/chrome/browser/automation/automation_provider_unittest.cc
index c931701..3631c44 100644
--- a/chrome/browser/automation/automation_provider_unittest.cc
+++ b/chrome/browser/automation/automation_provider_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/automation/chrome_frame_automation_provider.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "ipc/ipc_message.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,7 +22,9 @@ class MockChromeFrameAutomationProvider
void (const IPC::Message& message)); // NOLINT
};
-TEST(AutomationProviderTest, TestInvalidChromeFrameMessage) {
+typedef TestingBrowserProcessTest AutomationProviderTest;
+
+TEST_F(AutomationProviderTest, TestInvalidChromeFrameMessage) {
MessageLoop message_loop;
BrowserThread ui_thread(BrowserThread::UI, &message_loop);
diff --git a/chrome/browser/background_contents_service_unittest.cc b/chrome/browser/background_contents_service_unittest.cc
index 0e55dd3..c6d1da0 100644
--- a/chrome/browser/background_contents_service_unittest.cc
+++ b/chrome/browser/background_contents_service_unittest.cc
@@ -14,12 +14,13 @@
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-class BackgroundContentsServiceTest : public testing::Test {
+class BackgroundContentsServiceTest : public TestingBrowserProcessTest {
public:
BackgroundContentsServiceTest() {}
~BackgroundContentsServiceTest() {}
diff --git a/chrome/browser/background_mode_manager_unittest.cc b/chrome/browser/background_mode_manager_unittest.cc
index 13cf9f0..0005afd 100644
--- a/chrome/browser/background_mode_manager_unittest.cc
+++ b/chrome/browser/background_mode_manager_unittest.cc
@@ -7,13 +7,15 @@
#include "chrome/browser/background_mode_manager.h"
#include "chrome/browser/browser_list.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::InSequence;
-class BackgroundModeManagerTest : public testing::Test {
+class BackgroundModeManagerTest : public TestingBrowserProcessTest {
public:
BackgroundModeManagerTest() {}
~BackgroundModeManagerTest() {}
diff --git a/chrome/browser/background_page_tracker_unittest.cc b/chrome/browser/background_page_tracker_unittest.cc
index 74fd7ea..dcba51c 100644
--- a/chrome/browser/background_page_tracker_unittest.cc
+++ b/chrome/browser/background_page_tracker_unittest.cc
@@ -8,6 +8,8 @@
#include "chrome/browser/background_page_tracker.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "chrome/test/testing_browser_process.h"
+#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -25,13 +27,16 @@ class MockBackgroundPageTracker : public BackgroundPageTracker {
TestingPrefService prefs_;
};
-TEST(BackgroundPageTrackerTest, Create) {
+class BackgroundPageTrackerTest : public TestingBrowserProcessTest {
+};
+
+TEST_F(BackgroundPageTrackerTest, Create) {
MockBackgroundPageTracker tracker;
EXPECT_EQ(0, tracker.GetBackgroundPageCount());
EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount());
}
-TEST(BackgroundPageTrackerTest, OnBackgroundPageLoaded) {
+TEST_F(BackgroundPageTrackerTest, OnBackgroundPageLoaded) {
MockBackgroundPageTracker tracker;
EXPECT_EQ(0, tracker.GetBackgroundPageCount());
EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount());
@@ -56,7 +61,7 @@ TEST(BackgroundPageTrackerTest, OnBackgroundPageLoaded) {
EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount());
}
-TEST(BackgroundPageTrackerTest, AcknowledgeBackgroundPages) {
+TEST_F(BackgroundPageTrackerTest, AcknowledgeBackgroundPages) {
MockBackgroundPageTracker tracker;
EXPECT_EQ(0, tracker.GetBackgroundPageCount());
EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount());
@@ -95,7 +100,7 @@ class BadgeChangedNotificationCounter : public NotificationObserver {
NotificationRegistrar registrar_;
};
-TEST(BackgroundPageTrackerTest, TestTrackerChangedNotifications) {
+TEST_F(BackgroundPageTrackerTest, TestTrackerChangedNotifications) {
MockBackgroundPageTracker tracker;
BadgeChangedNotificationCounter counter;
std::string app1 = "app_id_1";
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 61c87eb..f0c67ba 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -158,6 +158,7 @@
'test/test_url_request_context_getter.h',
'test/testing_browser_process.cc',
'test/testing_browser_process.h',
+ 'test/testing_browser_process_test.h',
'test/testing_device_token_fetcher.cc',
'test/testing_device_token_fetcher.h',
'test/testing_pref_service.cc',
diff --git a/chrome/test/testing_browser_process.cc b/chrome/test/testing_browser_process.cc
index 004ac87..4d50fa4 100644
--- a/chrome/test/testing_browser_process.cc
+++ b/chrome/test/testing_browser_process.cc
@@ -192,3 +192,26 @@ void TestingBrowserProcess::SetGoogleURLTracker(
GoogleURLTracker* google_url_tracker) {
google_url_tracker_.reset(google_url_tracker);
}
+
+ScopedTestingBrowserProcess::ScopedTestingBrowserProcess() {
+ // TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
+ // ChromeTestSuite sets up a global TestingBrowserProcess
+ // for all tests. We need to get rid of it, because it contains
+ // a NotificationService, and there can be only one NotificationService
+ // per thread.
+ DCHECK(g_browser_process);
+ delete g_browser_process;
+
+ browser_process_.reset(new TestingBrowserProcess);
+ g_browser_process = browser_process_.get();
+}
+
+ScopedTestingBrowserProcess::~ScopedTestingBrowserProcess() {
+ DCHECK_EQ(browser_process_.get(), g_browser_process);
+
+ // TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
+ // After the transition is over, we should just
+ // reset |g_browser_process| to NULL.
+ browser_process_.reset();
+ g_browser_process = new TestingBrowserProcess();
+}
diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h
index 426c085..0ee682a 100644
--- a/chrome/test/testing_browser_process.h
+++ b/chrome/test/testing_browser_process.h
@@ -145,4 +145,18 @@ class TestingBrowserProcess : public BrowserProcess {
DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
};
+// Scoper to put a TestingBrowserProcess in |g_browser_process|.
+class ScopedTestingBrowserProcess {
+ public:
+ ScopedTestingBrowserProcess();
+ ~ScopedTestingBrowserProcess();
+
+ private:
+ // TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
+ // After the transition is over, we should just stack-allocate it.
+ scoped_ptr<TestingBrowserProcess> browser_process_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTestingBrowserProcess);
+};
+
#endif // CHROME_TEST_TESTING_BROWSER_PROCESS_H_
diff --git a/chrome/test/testing_browser_process_test.h b/chrome/test/testing_browser_process_test.h
new file mode 100644
index 0000000..0bdb417
--- /dev/null
+++ b/chrome/test/testing_browser_process_test.h
@@ -0,0 +1,18 @@
+// 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_TESTING_BROWSER_PROCESS_TEST_H_
+#define CHROME_TEST_TESTING_BROWSER_PROCESS_TEST_H_
+#pragma once
+
+#include "chrome/test/testing_browser_process.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Base class for tests that need |g_browser_process| to be initialized.
+class TestingBrowserProcessTest : public testing::Test {
+ private:
+ ScopedTestingBrowserProcess browser_process_;
+};
+
+#endif // CHROME_TEST_TESTING_BROWSER_PROCESS_TEST_H_