GTTF: Use a fresh TestingBrowserProcess for each test, part #5

For a detailed description see part #1, http://codereview.chromium.org/6478005/

This CL fixes the bug fully on Windows. More platforms will follow.

BUG=61062
TEST=unit_tests, possibly more
Review URL: http://codereview.chromium.org/7601006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96098 0039d316-1c4b-4281-b951-d872f2087c98
parent 5cf71c5f
......@@ -9,13 +9,14 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
class BookmarkNodeDataTest : public testing::Test {
class BookmarkNodeDataTest : public TestingBrowserProcessTest {
public:
BookmarkNodeDataTest()
: ui_thread_(BrowserThread::UI, &loop_),
......
......@@ -6,8 +6,9 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_helper_browsertest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/browser_thread.h"
......@@ -24,7 +25,7 @@ class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest {
public:
virtual void CreateDatabases() {
webkit_database::DatabaseTracker* db_tracker =
testing_profile_.GetDatabaseTracker();
browser()->profile()->GetDatabaseTracker();
string16 db_name = ASCIIToUTF16("db");
string16 description = ASCIIToUTF16("db_description");
int64 size;
......@@ -46,9 +47,6 @@ class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest {
db_tracker->GetAllOriginsInfo(&origins);
ASSERT_EQ(2U, origins.size());
}
protected:
TestingProfile testing_profile_;
};
// Called back by BrowsingDataDatabaseHelper on the UI thread once the database
......@@ -77,7 +75,7 @@ class StopTestOnCallback {
IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) {
CreateDatabases();
scoped_refptr<BrowsingDataDatabaseHelper> database_helper(
new BrowsingDataDatabaseHelper(&testing_profile_));
new BrowsingDataDatabaseHelper(browser()->profile()));
StopTestOnCallback stop_test_on_callback(database_helper);
database_helper->StartFetching(
NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback));
......@@ -95,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) {
const char db3[] = "db3";
scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
new CannedBrowsingDataDatabaseHelper(&testing_profile_));
new CannedBrowsingDataDatabaseHelper(browser()->profile()));
helper->AddDatabase(origin1, db1, "");
helper->AddDatabase(origin1, db2, "");
helper->AddDatabase(origin2, db3, "");
......@@ -122,7 +120,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) {
const char db[] = "db1";
scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
new CannedBrowsingDataDatabaseHelper(&testing_profile_));
new CannedBrowsingDataDatabaseHelper(browser()->profile()));
helper->AddDatabase(origin, db, "");
helper->AddDatabase(origin, db, "");
......
......@@ -12,8 +12,9 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/browsing_data_helper_browsertest.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
......@@ -21,8 +22,6 @@ typedef BrowsingDataHelperCallback<BrowsingDataIndexedDBHelper::IndexedDBInfo>
TestCompletionCallback;
class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest {
protected:
TestingProfile testing_profile_;
};
IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) {
......@@ -35,7 +34,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) {
FILE_PATH_LITERAL("http_host2_1.indexeddb.leveldb");
scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
new CannedBrowsingDataIndexedDBHelper(browser()->profile()));
helper->AddIndexedDB(origin1, description);
helper->AddIndexedDB(origin2, description);
......@@ -58,7 +57,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) {
FILE_PATH_LITERAL("http_host1_1.indexeddb.leveldb");
scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
new CannedBrowsingDataIndexedDBHelper(browser()->profile()));
helper->AddIndexedDB(origin, description);
helper->AddIndexedDB(origin, description);
......
......@@ -12,8 +12,9 @@
#include "base/test/thread_test_helper.h"
#include "chrome/browser/browsing_data_helper_browsertest.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "content/browser/in_process_webkit/webkit_thread.h"
......@@ -52,12 +53,11 @@ class BrowsingDataLocalStorageHelperTest : public InProcessBrowserTest {
}
FilePath GetLocalStoragePathForTestingProfile() {
FilePath storage_path(testing_profile_.GetPath());
FilePath storage_path(browser()->profile()->GetPath());
storage_path = storage_path.Append(
DOMStorageContext::kLocalStorageDirectory);
return storage_path;
}
TestingProfile testing_profile_;
};
// This class is notified by BrowsingDataLocalStorageHelper on the UI thread
......@@ -101,7 +101,7 @@ class StopTestOnCallback {
IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CallbackCompletes) {
scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
new BrowsingDataLocalStorageHelper(&testing_profile_));
new BrowsingDataLocalStorageHelper(browser()->profile()));
CreateLocalStorageFilesForTest();
StopTestOnCallback stop_test_on_callback(local_storage_helper);
local_storage_helper->StartFetching(
......@@ -112,7 +112,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CallbackCompletes) {
IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, DeleteSingleFile) {
scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
new BrowsingDataLocalStorageHelper(&testing_profile_));
new BrowsingDataLocalStorageHelper(browser()->profile()));
CreateLocalStorageFilesForTest();
local_storage_helper->DeleteLocalStorageFile(
GetLocalStoragePathForTestingProfile().Append(FilePath(kTestFile0)));
......@@ -145,7 +145,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest,
FILE_PATH_LITERAL("http_host2_1.localstorage");
scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper(
new CannedBrowsingDataLocalStorageHelper(&testing_profile_));
new CannedBrowsingDataLocalStorageHelper(browser()->profile()));
helper->AddLocalStorage(origin1);
helper->AddLocalStorage(origin2);
......@@ -167,7 +167,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataLocalStorageHelperTest, CannedUnique) {
FILE_PATH_LITERAL("http_host1_1.localstorage");
scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper(
new CannedBrowsingDataLocalStorageHelper(&testing_profile_));
new CannedBrowsingDataLocalStorageHelper(browser()->profile()));
helper->AddLocalStorage(origin);
helper->AddLocalStorage(origin);
......
......@@ -9,9 +9,11 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/extensions/extension_bookmark_helpers.h"
#include "chrome/browser/extensions/extension_bookmarks_module_constants.h"
#include "chrome/test/testing_browser_process_test.h"
namespace keys = extension_bookmarks_module_constants;
class ExtensionBookmarksTest : public testing::Test {
class ExtensionBookmarksTest : public TestingBrowserProcessTest {
public:
virtual void SetUp() {
model_.reset(new BookmarkModel(NULL));
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/extensions/extension_cookies_api_constants.h"
#include "chrome/browser/extensions/extension_cookies_helpers.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "googleurl/src/gurl.h"
namespace keys = extension_cookies_api_constants;
......@@ -61,7 +62,7 @@ class OtrTestingProfile : public TestingProfile {
} // namespace
class ExtensionCookiesTest : public testing::Test {
class ExtensionCookiesTest : public TestingBrowserProcessTest {
};
TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) {
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/site_instance.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
......@@ -12,7 +13,7 @@
namespace {
// make the test a PlatformTest to setup autorelease pools properly on mac
class ExtensionProcessManagerTest : public testing::Test {
class ExtensionProcessManagerTest : public TestingBrowserProcessTest {
public:
static void SetUpTestCase() {
ExtensionErrorReporter::Init(false); // no noisy errors
......
......@@ -7,9 +7,10 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/intents/web_intents_registry.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/test/testing_browser_process_test.h"
#include "testing/gtest/include/gtest/gtest.h"
class WebIntentsRegistryTest : public testing::Test {
class WebIntentsRegistryTest : public TestingBrowserProcessTest {
public:
WebIntentsRegistryTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
......
......@@ -22,6 +22,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/signaling_task.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -51,7 +52,7 @@ public:
typedef std::vector<PasswordForm*> VectorOfForms;
class PasswordStoreWinTest : public testing::Test {
class PasswordStoreWinTest : public TestingBrowserProcessTest {
protected:
PasswordStoreWinTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
......
......@@ -22,6 +22,7 @@
#include "chrome/browser/policy/proto/device_management_local.pb.h"
#include "chrome/browser/policy/user_policy_cache.h"
#include "chrome/browser/policy/user_policy_token_cache.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/browser_thread.h"
#include "net/url_request/url_request_status.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -113,7 +114,7 @@ class DeviceManagementBackendTestHelper {
// in its own process to make sure the counters are not initialized before the
// test runs, and that the StatisticsRecorder instance created for the test
// doesn't interfere with counters in other tests.
class EnterpriseMetricsTest : public testing::Test {
class EnterpriseMetricsTest : public TestingBrowserProcessTest {
public:
EnterpriseMetricsTest()
: ui_thread_(BrowserThread::UI, &loop_),
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/profiles/avatar_menu_model_observer.h"
#include "chrome/browser/profiles/profile_info_interface.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/common/notification_service.h"
#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -66,7 +67,7 @@ class MockObserver : public AvatarMenuModelObserver {
int count_;
};
class AvatarMenuModelTest : public testing::Test {
class AvatarMenuModelTest : public TestingBrowserProcessTest {
public:
FakeProfileInfo* cache() {
return &cache_;
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/ui/views/accessibility_event_router_views.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/common/notification_registrar.h"
#include "content/common/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -89,7 +90,7 @@ class AccessibilityWindowDelegate : public views::WidgetDelegate {
};
class AccessibilityEventRouterViewsTest
: public testing::Test,
: public TestingBrowserProcessTest,
public NotificationObserver {
public:
virtual void SetUp() {
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/browser_thread.h"
#include "content/browser/tab_contents/page_navigator.h"
#include "grit/generated_resources.h"
......@@ -48,7 +49,7 @@ class TestingPageNavigator : public PageNavigator {
} // namespace
class BookmarkContextMenuTest : public testing::Test {
class BookmarkContextMenuTest : public TestingBrowserProcessTest {
public:
BookmarkContextMenuTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "content/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -19,7 +20,7 @@ using base::TimeDelta;
// Base class for bookmark editor tests. Creates a BookmarkModel and populates
// it with test data.
class BookmarkEditorViewTest : public testing::Test {
class BookmarkEditorViewTest : public TestingBrowserProcessTest {
public:
BookmarkEditorViewTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
......
......@@ -5,6 +5,7 @@
#include "base/pickle.h"
#include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/dragdrop/os_exchange_data.h"
......@@ -19,7 +20,7 @@ ui::OSExchangeData::Provider* CloneProvider(const ui::OSExchangeData& data) {
} // namespace
typedef testing::Test BrowserActionDragDataTest;
typedef TestingBrowserProcessTest BrowserActionDragDataTest;
TEST_F(BrowserActionDragDataTest, ArbitraryFormat) {
TestingProfile profile;
......
......@@ -1509,8 +1509,6 @@
'browser/net/url_fixer_upper_unittest.cc',
'browser/net/url_info_unittest.cc',
'browser/notifications/desktop_notification_service_unittest.cc',
'browser/notifications/desktop_notifications_unittest.cc',
'browser/notifications/desktop_notifications_unittest.h',
'browser/notifications/notification_exceptions_table_model_unittest.cc',
'browser/notifications/notifications_prefs_cache_unittest.cc',
'browser/parsers/metadata_parser_filebase_unittest.cc',
......@@ -2114,7 +2112,6 @@
}],
['chromeos==1', {
'sources/': [
['exclude', '^browser/notifications/desktop_notifications_unittest.cc'],
['exclude', '^browser/password_manager/native_backend_gnome_x_unittest.cc'],
['exclude', '^browser/renderer_host/gtk_key_bindings_handler_unittest.cc'],
# TODO(thestig) Enable PrintPreviewUI tests on CrOS when
......@@ -2559,6 +2556,8 @@
'browser/magic_iframe_browsertest.cc',
'browser/net/cookie_policy_browsertest.cc',
'browser/net/ftp_browsertest.cc',
'browser/notifications/desktop_notifications_unittest.cc',
'browser/notifications/desktop_notifications_unittest.h',
'browser/plugin_data_remover_browsertest.cc',
'browser/policy/device_management_backend_mock.cc',
'browser/policy/device_management_backend_mock.h',
......@@ -2670,6 +2669,7 @@
],
}, { #else: OS == "chromeos"
'sources!': [
'browser/notifications/desktop_notifications_unittest.cc',
'browser/service/service_process_control_browsertest.cc',
'browser/ui/webui/print_preview.js',
],
......
......@@ -110,7 +110,11 @@ void ChromeTestSuite::Initialize() {
chrome::RegisterPathProvider();
content::RegisterPathProvider();
ui::RegisterPathProvider();
#if !defined(OS_WIN)
// TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
g_browser_process = new TestingBrowserProcess;
#endif
if (!browser_dir_.empty()) {
PathService::Override(base::DIR_EXE, browser_dir_);
......@@ -156,8 +160,11 @@ void ChromeTestSuite::Shutdown() {
base::mac::SetOverrideAppBundle(NULL);
#endif
#if !defined(OS_WIN)
// TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
delete g_browser_process;
g_browser_process = NULL;
#endif
// Tear down shared StatsTable; prevents unit_tests from leaking it.
base::StatsTable::set_current(NULL);
......
......@@ -94,10 +94,17 @@ void InProcessBrowserTest::SetUp() {
ASSERT_TRUE(CreateUserDataDirectory())
<< "Could not create user data directory.";
#if defined(OS_WIN)
// This is not really Windows-specific, the transition is just being done
// in stages, and Windows is first. See below for more info.
DCHECK(!g_browser_process);
#else
// TODO(phajdan.jr): Temporary, for http://crbug.com/61062.
// The unit test suite creates a testingbrowser, but we want the real thing.
// Delete the current one. We'll install the testing one in TearDown.
delete g_browser_process;
g_browser_process = NULL;
#endif
// Allow subclasses the opportunity to make changes to the default user data
// dir before running any tests.
......@@ -218,9 +225,15 @@ bool InProcessBrowserTest::CreateUserDataDirectory() {
}
void InProcessBrowserTest::TearDown() {
#if defined(OS_WIN)
// This is not really Windows-specific, the transition is just being done
// in stages, and Windows is first. See below for more info.
DCHECK(!g_browser_process);
#else
// Reinstall testing browser process.
delete g_browser_process;
g_browser_process = new TestingBrowserProcess();
#endif
browser_shutdown::delete_resources_on_shutdown = true;
......
......@@ -269,6 +269,11 @@ void TestingBrowserProcess::SetDevToolsManager(DevToolsManager* manager) {
}
ScopedTestingBrowserProcess::ScopedTestingBrowserProcess() {
#if defined(OS_WIN)
// This is not really Windows-specific, the transition is just being done
// in stages, and Windows is first. See below for more info.
DCHECK(!g_browser_process);
#else
// 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
......@@ -276,7 +281,7 @@ ScopedTestingBrowserProcess::ScopedTestingBrowserProcess() {
// per thread.
DCHECK(g_browser_process);
delete g_browser_process;
#endif
browser_process_.reset(new TestingBrowserProcess);
g_browser_process = browser_process_.get();
}
......@@ -284,9 +289,15 @@ ScopedTestingBrowserProcess::ScopedTestingBrowserProcess() {
ScopedTestingBrowserProcess::~ScopedTestingBrowserProcess() {
DCHECK_EQ(browser_process_.get(), g_browser_process);
#if defined(OS_WIN)
// This is not really Windows-specific, the transition is just being done
// in stages, and Windows is first. See below for more info.
g_browser_process = NULL;
#else
// 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();
#endif
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment