summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc73
-rw-r--r--chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc5
-rw-r--r--chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc48
-rw-r--r--chrome/browser/browsing_data/browsing_data_database_helper_unittest.cc14
-rw-r--r--chrome/browser/browsing_data/browsing_data_local_storage_helper_unittest.cc5
-rw-r--r--chrome/browser/browsing_data/browsing_data_remover_unittest.cc2
-rw-r--r--chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc25
-rw-r--r--chrome/browser/browsing_data/cookies_tree_model_unittest.cc1
-rw-r--r--chrome/browser/captive_portal/captive_portal_detector_unittest.cc9
-rw-r--r--chrome/browser/captive_portal/captive_portal_service_unittest.cc17
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_private_api_unittest.cc9
-rw-r--r--chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc8
-rw-r--r--chrome/browser/chromeos/login/online_attempt_unittest.cc90
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator_unittest.cc42
-rw-r--r--chrome/browser/chromeos/login/user_manager_unittest.cc15
-rw-r--r--chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc62
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc27
-rw-r--r--chrome/browser/extensions/browser_permissions_policy_delegate_unittest.cc10
-rw-r--r--chrome/browser/extensions/extension_protocols_unittest.cc4
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc15
-rw-r--r--chrome/browser/extensions/extension_service_unittest.h2
-rw-r--r--chrome/browser/extensions/updater/extension_updater_unittest.cc10
-rw-r--r--chrome/browser/google/google_url_tracker_unittest.cc9
-rw-r--r--chrome/browser/io_thread.cc6
-rw-r--r--chrome/browser/io_thread.h5
-rw-r--r--chrome/browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc15
-rw-r--r--chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc9
-rw-r--r--chrome/browser/page_cycler/page_cycler_unittest.cc5
-rw-r--r--chrome/browser/password_manager/password_generation_manager_unittest.cc8
-rw-r--r--chrome/browser/password_manager/password_store_x_unittest.cc144
-rw-r--r--chrome/browser/policy/cloud/device_management_service_unittest.cc19
-rw-r--r--chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc13
-rw-r--r--chrome/browser/policy/policy_service_impl_unittest.cc9
-rw-r--r--chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc100
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl_unittest.cc15
-rw-r--r--chrome/browser/profiles/profile_browsertest.cc1
-rw-r--r--chrome/browser/profiles/profile_manager_unittest.cc43
-rw-r--r--chrome/browser/safe_browsing/malware_details_unittest.cc3
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_unittest.cc6
-rw-r--r--chrome/browser/search/iframe_source_unittest.cc19
-rw-r--r--chrome/browser/search_engines/search_provider_install_data_unittest.cc145
-rw-r--r--chrome/browser/search_engines/template_url_fetcher_unittest.cc3
-rw-r--r--chrome/browser/search_engines/template_url_service_sync_unittest.cc3
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc95
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.h21
-rw-r--r--chrome/browser/search_engines/template_url_service_unittest.cc150
-rw-r--r--chrome/browser/signin/oauth2_token_service_unittest.cc58
-rw-r--r--chrome/browser/signin/profile_oauth2_token_service_unittest.cc63
-rw-r--r--chrome/browser/signin/signin_manager_unittest.cc153
-rw-r--r--chrome/browser/signin/token_service_unittest.cc310
-rw-r--r--chrome/browser/signin/token_service_unittest.h19
-rw-r--r--chrome/browser/signin/ubertoken_fetcher_unittest.cc18
-rw-r--r--chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc15
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc75
-rw-r--r--chrome/browser/spellchecker/spellcheck_message_filter_unittest.cc6
-rw-r--r--chrome/browser/spellchecker/spellcheck_service_unittest.cc23
-rw-r--r--chrome/browser/spellchecker/spelling_service_client_unittest.cc8
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.cc21
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.h8
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc18
-rw-r--r--chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc5
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc34
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service_password_unittest.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service_preference_unittest.cc1
-rw-r--r--chrome/browser/sync/profile_sync_service_session_unittest.cc21
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc27
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc4
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc36
-rw-r--r--chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_fake_unittest.cc21
-rw-r--r--chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_unittest.cc20
-rw-r--r--chrome/browser/sync_file_system/local_file_sync_service_unittest.cc31
-rw-r--r--chrome/browser/sync_file_system/sync_file_system_service_unittest.cc41
-rw-r--r--chrome/browser/sync_file_system/sync_file_system_test_util.cc31
-rw-r--r--chrome/browser/sync_file_system/sync_file_system_test_util.h36
-rw-r--r--chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc12
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc14
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc5
-rw-r--r--chrome/browser/ui/ash/screenshot_taker_unittest.cc5
-rw-r--r--chrome/browser/ui/ash/window_positioner_unittest.cc21
-rw-r--r--chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc2
-rw-r--r--chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm1
-rw-r--r--chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc17
-rw-r--r--chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc10
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc25
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc4
-rw-r--r--chrome/browser/ui/views/frame/browser_view_unittest.cc11
-rw-r--r--chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc36
88 files changed, 983 insertions, 1628 deletions
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index b32cadc..4aeb1c1 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -31,7 +31,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_status.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -78,10 +78,7 @@ class SearchProviderTest : public testing::Test,
term1_(ASCIIToUTF16("term1")),
keyword_t_url_(NULL),
keyword_term_(ASCIIToUTF16("keyword")),
- ui_thread_(content::BrowserThread::UI, &message_loop_),
- io_thread_(content::BrowserThread::IO),
- quit_when_done_(false) {
- io_thread_.Start();
+ run_loop_(NULL) {
}
static void SetUpTestCase();
@@ -117,9 +114,6 @@ class SearchProviderTest : public testing::Test,
// If we're waiting for the provider to finish, this exits the message loop.
virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
- // Waits until the provider instantiates a URLFetcher and returns it.
- net::TestURLFetcher* WaitUntilURLFetcherIsReady(int fetcher_id);
-
// Runs a nested message loop until provider_ is done. The message loop is
// exited by way of OnProviderUpdate.
void RunTillProviderDone();
@@ -147,9 +141,7 @@ class SearchProviderTest : public testing::Test,
const string16 keyword_term_;
GURL keyword_url_;
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
// URLFetcherFactory implementation registered.
net::TestURLFetcherFactory test_factory_;
@@ -160,8 +152,8 @@ class SearchProviderTest : public testing::Test,
// The provider.
scoped_refptr<SearchProvider> provider_;
- // If true, OnProviderUpdate exits out of the current message loop.
- bool quit_when_done_;
+ // If non-NULL, OnProviderUpdate quits the current |run_loop_|.
+ base::RunLoop* run_loop_;
DISALLOW_COPY_AND_ASSIGN(SearchProviderTest);
};
@@ -238,7 +230,7 @@ void SearchProviderTest::SetUp() {
}
void SearchProviderTest::TearDown() {
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// Shutdown the provider before the profile.
provider_ = NULL;
@@ -273,32 +265,19 @@ void SearchProviderTest::RunTest(TestData* cases,
}
void SearchProviderTest::OnProviderUpdate(bool updated_matches) {
- if (quit_when_done_ && provider_->done()) {
- quit_when_done_ = false;
- message_loop_.Quit();
+ if (run_loop_ && provider_->done()) {
+ run_loop_->Quit();
+ run_loop_ = NULL;
}
}
-net::TestURLFetcher* SearchProviderTest::WaitUntilURLFetcherIsReady(
- int fetcher_id) {
- net::TestURLFetcher* url_fetcher = test_factory_.GetFetcherByID(fetcher_id);
- for (; !url_fetcher; url_fetcher = test_factory_.GetFetcherByID(fetcher_id))
- message_loop_.RunUntilIdle();
- return url_fetcher;
-}
-
void SearchProviderTest::RunTillProviderDone() {
if (provider_->done())
return;
- quit_when_done_ = true;
-#if defined(OS_ANDROID)
- // Android doesn't have Run(), only Start().
- message_loop_.Start();
-#else
base::RunLoop run_loop;
+ run_loop_ = &run_loop;
run_loop.Run();
-#endif
}
void SearchProviderTest::QueryForInput(const string16& text,
@@ -312,7 +291,7 @@ void SearchProviderTest::QueryForInput(const string16& text,
// RunUntilIdle so that the task scheduled by SearchProvider to create the
// URLFetchers runs.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void SearchProviderTest::QueryForInputAndSetWYTMatch(
@@ -372,8 +351,9 @@ bool SearchProviderTest::FindMatchWithDestination(const GURL& url,
}
void SearchProviderTest::FinishDefaultSuggestQuery() {
- net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kDefaultProviderURLFetcherID);
+ net::TestURLFetcher* default_fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
ASSERT_TRUE(default_fetcher);
// Tell the SearchProvider the default suggest query is done.
@@ -1041,8 +1021,9 @@ TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
QueryForInput(ASCIIToUTF16("a"), false, false);
- net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kDefaultProviderURLFetcherID);
+ net::TestURLFetcher* fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
ASSERT_TRUE(fetcher);
fetcher->set_response_code(200);
fetcher->SetResponseString(cases[i].json);
@@ -1506,16 +1487,18 @@ TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) {
QueryForInput(ASCIIToUTF16("k a"), false, true);
// Set up a default fetcher with no results.
- net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kDefaultProviderURLFetcherID);
+ net::TestURLFetcher* default_fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
ASSERT_TRUE(default_fetcher);
default_fetcher->set_response_code(200);
default_fetcher->delegate()->OnURLFetchComplete(default_fetcher);
default_fetcher = NULL;
// Set up a keyword fetcher with provided results.
- net::TestURLFetcher* keyword_fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kKeywordProviderURLFetcherID);
+ net::TestURLFetcher* keyword_fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kKeywordProviderURLFetcherID);
ASSERT_TRUE(keyword_fetcher);
keyword_fetcher->set_response_code(200);
keyword_fetcher->SetResponseString(cases[i].json);
@@ -1626,8 +1609,9 @@ TEST_F(SearchProviderTest, LocalAndRemoteRelevances) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
QueryForInput(cases[i].input, false, false);
- net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kDefaultProviderURLFetcherID);
+ net::TestURLFetcher* fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
ASSERT_TRUE(fetcher);
fetcher->set_response_code(200);
fetcher->SetResponseString(cases[i].json);
@@ -1726,8 +1710,9 @@ TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
QueryForInput(ASCIIToUTF16(cases[i].input), false, false);
- net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady(
- SearchProvider::kDefaultProviderURLFetcherID);
+ net::TestURLFetcher* fetcher =
+ test_factory_.GetFetcherByID(
+ SearchProvider::kDefaultProviderURLFetcherID);
ASSERT_TRUE(fetcher);
fetcher->set_response_code(200);
fetcher->SetResponseString(cases[i].json);
diff --git a/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
index b138ac7..b06f9ae 100644
--- a/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_appcache_helper_unittest.cc
@@ -8,6 +8,7 @@
#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -29,7 +30,9 @@ class TestCompletionCallback {
} // namespace
-typedef testing::Test CannedBrowsingDataAppCacheHelperTest;
+class CannedBrowsingDataAppCacheHelperTest : public testing::Test {
+ content::TestBrowserThreadBundle thread_bundle_;
+};
TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) {
TestingProfile profile;
diff --git a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
index eb6ab9f..7e02b83 100644
--- a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
@@ -5,45 +5,20 @@
#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/parsed_cookie.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
namespace {
class BrowsingDataCookieHelperTest : public testing::Test {
public:
- void SetUpOnIOThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // This is a workaround for a bug in the TestingProfile.
- // The URLRequestContext will be created by GetCookieMonster on the UI
- // thread, if it does not already exist. But it must be created on the IO
- // thread or else it will DCHECK upon destruction.
- // Force it to be created here.
- testing_profile_->CreateRequestContext();
- testing_profile_->GetRequestContext()->GetURLRequestContext();
- }
-
- virtual void SetUp() {
- testing_profile_.reset(new TestingProfile());
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&BrowsingDataCookieHelperTest::SetUpOnIOThread,
- base::Unretained(this)));
- base::MessageLoop::current()->RunUntilIdle();
- }
-
- virtual void TearDown() {
- // This must be reset before the IO thread stops, because the
- // URLRequestContextGetter forces its own deletion to occur on that thread.
- testing_profile_->ResetRequestContext();
+ BrowsingDataCookieHelperTest()
+ : testing_profile_(new TestingProfile()) {
}
void CreateCookiesForTest() {
@@ -83,7 +58,6 @@ class BrowsingDataCookieHelperTest : public testing::Test {
EXPECT_EQ("B", it->Name());
ASSERT_TRUE(++it == cookies.end());
- base::MessageLoop::current()->Quit();
}
void DomainCookieCallback(const net::CookieList& cookies) {
@@ -103,7 +77,6 @@ class BrowsingDataCookieHelperTest : public testing::Test {
EXPECT_EQ("2", it->Value());
ASSERT_TRUE(++it == cookies.end());
- base::MessageLoop::current()->Quit();
}
void DeleteCallback(const net::CookieList& cookies) {
@@ -115,7 +88,6 @@ class BrowsingDataCookieHelperTest : public testing::Test {
EXPECT_EQ("B", it->Name());
ASSERT_TRUE(++it == cookies.end());
- base::MessageLoop::current()->Quit();
}
void CannedUniqueCallback(const net::CookieList& cookies) {
@@ -212,9 +184,7 @@ TEST_F(BrowsingDataCookieHelperTest, FetchData) {
cookie_helper->StartFetching(
base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
base::Unretained(this)));
-
- // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(BrowsingDataCookieHelperTest, DomainCookie) {
@@ -225,9 +195,7 @@ TEST_F(BrowsingDataCookieHelperTest, DomainCookie) {
cookie_helper->StartFetching(
base::Bind(&BrowsingDataCookieHelperTest::DomainCookieCallback,
base::Unretained(this)));
-
- // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
@@ -238,9 +206,7 @@ TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
cookie_helper->StartFetching(
base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
base::Unretained(this)));
-
- // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
net::CanonicalCookie cookie = cookie_list_[0];
cookie_helper->DeleteCookie(cookie);
@@ -248,7 +214,7 @@ TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
cookie_helper->StartFetching(
base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback,
base::Unretained(this)));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) {
diff --git a/chrome/browser/browsing_data/browsing_data_database_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_database_helper_unittest.cc
index 565ef8c..276cb89 100644
--- a/chrome/browser/browsing_data/browsing_data_database_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_database_helper_unittest.cc
@@ -4,24 +4,14 @@
#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
-#include "base/message_loop/message_loop.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
namespace {
class CannedBrowsingDataDatabaseHelperTest : public testing::Test {
- public:
- CannedBrowsingDataDatabaseHelperTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {
- }
-
- protected:
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
};
TEST_F(CannedBrowsingDataDatabaseHelperTest, Empty) {
diff --git a/chrome/browser/browsing_data/browsing_data_local_storage_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_local_storage_helper_unittest.cc
index 2ad644a..e9739e1 100644
--- a/chrome/browser/browsing_data/browsing_data_local_storage_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_local_storage_helper_unittest.cc
@@ -5,11 +5,14 @@
#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-typedef testing::Test CannedBrowsingDataLocalStorageTest;
+class CannedBrowsingDataLocalStorageTest : public testing::Test {
+ content::TestBrowserThreadBundle thread_bundle_;
+};
TEST_F(CannedBrowsingDataLocalStorageTest, Empty) {
TestingProfile profile;
diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
index 3d659ce..fc758e4 100644
--- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
@@ -223,7 +223,6 @@ class RemoveCookieTester {
class RemoveProfileCookieTester : public RemoveCookieTester {
public:
explicit RemoveProfileCookieTester(TestingProfile* profile) {
- profile->CreateRequestContext();
SetMonster(profile->GetRequestContext()->GetURLRequestContext()->
cookie_store()->GetCookieMonster());
}
@@ -265,7 +264,6 @@ class RemoveServerBoundCertTester : public net::SSLConfigService::Observer {
public:
explicit RemoveServerBoundCertTester(TestingProfile* profile)
: ssl_config_changed_count_(0) {
- profile->CreateRequestContext();
server_bound_cert_service_ = profile->GetRequestContext()->
GetURLRequestContext()->server_bound_cert_service();
ssl_config_service_ = profile->GetSSLConfigService();
diff --git a/chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc
index 68db3dc..4a12c5a 100644
--- a/chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_server_bound_cert_helper_unittest.cc
@@ -5,10 +5,10 @@
#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
-#include "base/synchronization/waitable_event.h"
+#include "base/run_loop.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/ssl/server_bound_cert_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
@@ -24,12 +24,7 @@ class BrowsingDataServerBoundCertHelperTest
}
virtual void SetUp() OVERRIDE {
- ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
- &message_loop_));
- io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO,
- &message_loop_));
testing_profile_.reset(new TestingProfile());
- testing_profile_->CreateRequestContext();
testing_profile_->GetSSLConfigService()->AddObserver(this);
}
@@ -57,7 +52,6 @@ class BrowsingDataServerBoundCertHelperTest
const net::ServerBoundCertStore::ServerBoundCertList& certs) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
server_bound_cert_list_ = certs;
- base::MessageLoop::current()->Quit();
}
// net::SSLConfigService::Observer implementation:
@@ -66,9 +60,7 @@ class BrowsingDataServerBoundCertHelperTest
}
protected:
- base::MessageLoop message_loop_;
- scoped_ptr<content::TestBrowserThread> ui_thread_;
- scoped_ptr<content::TestBrowserThread> io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> testing_profile_;
net::ServerBoundCertStore::ServerBoundCertList server_bound_cert_list_;
@@ -87,7 +79,7 @@ TEST_F(BrowsingDataServerBoundCertHelperTest, FetchData) {
// Blocks until BrowsingDataServerBoundCertHelperTest::FetchCallback is
// notified.
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(2UL, server_bound_cert_list_.size());
net::ServerBoundCertStore::ServerBoundCertList::const_iterator it =
@@ -116,7 +108,7 @@ TEST_F(BrowsingDataServerBoundCertHelperTest, DeleteCert) {
helper->StartFetching(
base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
base::Unretained(this)));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, ssl_config_changed_count_);
ASSERT_EQ(1UL, server_bound_cert_list_.size());
@@ -133,7 +125,8 @@ TEST_F(BrowsingDataServerBoundCertHelperTest, DeleteCert) {
helper->StartFetching(
base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
base::Unretained(this)));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
+
EXPECT_EQ(2, ssl_config_changed_count_);
ASSERT_EQ(0UL, server_bound_cert_list_.size());
}
@@ -155,7 +148,7 @@ TEST_F(BrowsingDataServerBoundCertHelperTest, CannedUnique) {
helper->StartFetching(
base::Bind(&BrowsingDataServerBoundCertHelperTest::FetchCallback,
base::Unretained(this)));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(1UL, server_bound_cert_list_.size());
net::ServerBoundCertStore::ServerBoundCert& cert =
diff --git a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc
index af509bc..6b6825d 100644
--- a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc
+++ b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc
@@ -47,7 +47,6 @@ class CookiesTreeModelTest : public testing::Test {
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
- profile_->CreateRequestContext();
mock_browsing_data_cookie_helper_ =
new MockBrowsingDataCookieHelper(profile_->GetRequestContext());
mock_browsing_data_database_helper_ =
diff --git a/chrome/browser/captive_portal/captive_portal_detector_unittest.cc b/chrome/browser/captive_portal/captive_portal_detector_unittest.cc
index 00c2489..49bd2b9 100644
--- a/chrome/browser/captive_portal/captive_portal_detector_unittest.cc
+++ b/chrome/browser/captive_portal/captive_portal_detector_unittest.cc
@@ -6,10 +6,11 @@
#include "base/basictypes.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/time/time.h"
#include "chrome/browser/captive_portal/testing_utils.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_fetcher.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -72,7 +73,7 @@ class CaptivePortalDetectorTest : public testing::Test,
base::Unretained(&client)));
ASSERT_TRUE(FetchingURL());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net_error, status_code, response_headers);
@@ -96,7 +97,7 @@ class CaptivePortalDetectorTest : public testing::Test,
base::Unretained(&client)));
ASSERT_TRUE(FetchingURL());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
detector()->Cancel();
@@ -105,7 +106,7 @@ class CaptivePortalDetectorTest : public testing::Test,
}
private:
- base::MessageLoop message_loop_;
+ content::TestBrowserThreadBundle thread_bundle_;
// Definition order does matter.
TestingProfile profile_;
diff --git a/chrome/browser/captive_portal/captive_portal_service_unittest.cc b/chrome/browser/captive_portal/captive_portal_service_unittest.cc
index 17cba3a..7357b22 100644
--- a/chrome/browser/captive_portal/captive_portal_service_unittest.cc
+++ b/chrome/browser/captive_portal/captive_portal_service_unittest.cc
@@ -7,8 +7,8 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
#include "base/test/test_timeouts.h"
#include "chrome/browser/captive_portal/testing_utils.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -20,6 +20,7 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -167,7 +168,7 @@ class CaptivePortalServiceTest : public testing::Test,
EXPECT_FALSE(FetchingURL());
ASSERT_TRUE(TimerRunning());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(CaptivePortalService::STATE_CHECKING_FOR_PORTAL,
service()->state());
ASSERT_TRUE(FetchingURL());
@@ -199,7 +200,7 @@ class CaptivePortalServiceTest : public testing::Test,
EXPECT_FALSE(FetchingURL());
ASSERT_TRUE(TimerRunning());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(FetchingURL());
EXPECT_FALSE(TimerRunning());
EXPECT_EQ(1, observer.num_results_received());
@@ -274,7 +275,7 @@ class CaptivePortalServiceTest : public testing::Test,
// after the test.
const CaptivePortalService::TestingState old_captive_portal_testing_state_;
- base::MessageLoop message_loop_;
+ content::TestBrowserThreadBundle thread_bundle_;
// Note that the construction order of these matters.
scoped_ptr<TestingProfile> profile_;
@@ -372,7 +373,7 @@ TEST_F(CaptivePortalServiceTest, CaptivePortalPrefDisabledWhileRunning) {
// Needed to create the URLFetcher, even if it never returns any results.
service()->DetectCaptivePortal();
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(FetchingURL());
EXPECT_FALSE(TimerRunning());
@@ -381,7 +382,7 @@ TEST_F(CaptivePortalServiceTest, CaptivePortalPrefDisabledWhileRunning) {
EXPECT_TRUE(TimerRunning());
EXPECT_EQ(0, observer.num_results_received());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(FetchingURL());
EXPECT_FALSE(TimerRunning());
@@ -406,7 +407,7 @@ TEST_F(CaptivePortalServiceTest, CaptivePortalPrefDisabledWhilePending) {
EXPECT_TRUE(TimerRunning());
EXPECT_EQ(0, observer.num_results_received());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(FetchingURL());
EXPECT_FALSE(TimerRunning());
@@ -432,7 +433,7 @@ TEST_F(CaptivePortalServiceTest, CaptivePortalPrefEnabledWhilePending) {
EXPECT_FALSE(FetchingURL());
EXPECT_TRUE(TimerRunning());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(FetchingURL());
EXPECT_FALSE(TimerRunning());
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api_unittest.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api_unittest.cc
index e98365c..f72c1654 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api_unittest.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api_unittest.cc
@@ -8,7 +8,6 @@
#include "ash/wm/window_util.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
-#include "content/public/test/test_browser_thread.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
@@ -16,14 +15,6 @@
namespace {
class WallpaperPrivateApiUnittest : public ash::test::AshTestBase {
- public:
- WallpaperPrivateApiUnittest()
- : ui_thread_(content::BrowserThread::UI, message_loop()) {}
-
- private:
- content::TestBrowserThread ui_thread_;
-
- DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateApiUnittest);
};
class TestMinimizeFunction
diff --git a/chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc
index 6699856..e722eff 100644
--- a/chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc
+++ b/chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout_unittest.cc
@@ -17,18 +17,14 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
namespace chromeos {
class KioskModeIdleLogoutTest : public ash::test::AshTestBase {
public:
KioskModeIdleLogoutTest()
- : ui_thread_(BrowserThread::UI, message_loop()),
- idle_logout_(NULL) {
+ : idle_logout_(NULL) {
}
virtual void SetUp() OVERRIDE {
@@ -53,8 +49,6 @@ class KioskModeIdleLogoutTest : public ash::test::AshTestBase {
idle_logout_);
}
- content::TestBrowserThread ui_thread_;
-
ScopedDeviceSettingsTestHelper device_settings_test_helper_;
KioskModeIdleLogout* idle_logout_;
diff --git a/chrome/browser/chromeos/login/online_attempt_unittest.cc b/chrome/browser/chromeos/login/online_attempt_unittest.cc
index 5692686..24f6f17 100644
--- a/chrome/browser/chromeos/login/online_attempt_unittest.cc
+++ b/chrome/browser/chromeos/login/online_attempt_unittest.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/login/auth_attempt_state.h"
#include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h"
@@ -15,7 +15,8 @@
#include "chrome/browser/chromeos/login/test_attempt_state.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/mock_url_fetcher_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -33,23 +34,12 @@ namespace chromeos {
class OnlineAttemptTest : public testing::Test {
public:
OnlineAttemptTest()
- : message_loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(BrowserThread::UI, &message_loop_),
- state_(UserContext(), "", "", "", User::USER_TYPE_REGULAR, false),
- resolver_(new MockAuthAttemptStateResolver) {
- }
-
- virtual ~OnlineAttemptTest() {}
-
- virtual void SetUp() {
- attempt_.reset(new OnlineAttempt(&state_, resolver_.get()));
- }
-
- virtual void TearDown() {
+ : state_(UserContext(), "", "", "", User::USER_TYPE_REGULAR, false),
+ attempt_(new OnlineAttempt(&state_, &resolver_)) {
}
void RunFailureTest(const GoogleServiceAuthError& error) {
- EXPECT_CALL(*(resolver_.get()), Resolve())
+ EXPECT_CALL(resolver_, Resolve())
.Times(1)
.RetiresOnSaturation();
@@ -59,7 +49,7 @@ class OnlineAttemptTest : public testing::Test {
attempt_->weak_factory_.GetWeakPtr(),
error));
// Force UI thread to finish tasks so I can verify |state_|.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(error == state_.online_outcome().error());
}
@@ -70,19 +60,9 @@ class OnlineAttemptTest : public testing::Test {
auth->weak_factory_.GetWeakPtr()));
}
- static void Quit() {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
- }
-
- static void RunThreadTest() {
- base::MessageLoop::current()->RunUntilIdle();
- }
-
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
TestAttemptState state_;
- scoped_ptr<MockAuthAttemptStateResolver> resolver_;
+ MockAuthAttemptStateResolver resolver_;
scoped_ptr<OnlineAttempt> attempt_;
// Initializes / shuts down a stub NetworkLibrary.
@@ -90,7 +70,7 @@ class OnlineAttemptTest : public testing::Test {
};
TEST_F(OnlineAttemptTest, LoginSuccess) {
- EXPECT_CALL(*(resolver_.get()), Resolve())
+ EXPECT_CALL(resolver_, Resolve())
.Times(1)
.RetiresOnSaturation();
@@ -100,15 +80,16 @@ TEST_F(OnlineAttemptTest, LoginSuccess) {
attempt_->weak_factory_.GetWeakPtr(),
GaiaAuthConsumer::ClientLoginResult()));
// Force UI thread to finish tasks so I can verify |state_|.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(OnlineAttemptTest, LoginCancelRetry) {
GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
TestingProfile profile;
- EXPECT_CALL(*(resolver_.get()), Resolve())
- .WillOnce(Invoke(OnlineAttemptTest::Quit))
+ base::RunLoop run_loop;
+ EXPECT_CALL(resolver_, Resolve())
+ .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit))
.RetiresOnSaturation();
// This is how we inject fake URLFetcher objects, with a factory.
@@ -117,11 +98,8 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) {
MockURLFetcherFactory<GotCanceledFetcher> factory;
attempt_->Initiate(&profile);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&OnlineAttemptTest::RunThreadTest));
- base::MessageLoop::current()->Run();
+ run_loop.Run();
EXPECT_TRUE(error == state_.online_outcome().error());
EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
@@ -132,8 +110,9 @@ TEST_F(OnlineAttemptTest, LoginTimeout) {
LoginFailure error(LoginFailure::LOGIN_TIMED_OUT);
TestingProfile profile;
- EXPECT_CALL(*(resolver_.get()), Resolve())
- .WillOnce(Invoke(OnlineAttemptTest::Quit))
+ base::RunLoop run_loop;
+ EXPECT_CALL(resolver_, Resolve())
+ .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit))
.RetiresOnSaturation();
// This is how we inject fake URLFetcher objects, with a factory.
@@ -142,14 +121,11 @@ TEST_F(OnlineAttemptTest, LoginTimeout) {
MockURLFetcherFactory<ExpectCanceledFetcher> factory;
attempt_->Initiate(&profile);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&OnlineAttemptTest::RunThreadTest));
// Post a task to cancel the login attempt.
CancelLogin(attempt_.get());
- base::MessageLoop::current()->Run();
+ run_loop.Run();
EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason());
}
@@ -161,8 +137,9 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) {
GoogleServiceAuthError::HOSTED_NOT_ALLOWED)));
TestingProfile profile;
- EXPECT_CALL(*(resolver_.get()), Resolve())
- .WillOnce(Invoke(OnlineAttemptTest::Quit))
+ base::RunLoop run_loop;
+ EXPECT_CALL(resolver_, Resolve())
+ .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit))
.RetiresOnSaturation();
// This is how we inject fake URLFetcher objects, with a factory.
@@ -170,13 +147,10 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) {
TestAttemptState local_state(UserContext(), "", "", "",
User::USER_TYPE_REGULAR, true);
- attempt_.reset(new OnlineAttempt(&local_state, resolver_.get()));
+ attempt_.reset(new OnlineAttempt(&local_state, &resolver_));
attempt_->Initiate(&profile);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&OnlineAttemptTest::RunThreadTest));
- base::MessageLoop::current()->Run();
+ run_loop.Run();
EXPECT_EQ(error, local_state.online_outcome());
EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
@@ -186,8 +160,9 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) {
TEST_F(OnlineAttemptTest, FullLogin) {
TestingProfile profile;
- EXPECT_CALL(*(resolver_.get()), Resolve())
- .WillOnce(Invoke(OnlineAttemptTest::Quit))
+ base::RunLoop run_loop;
+ EXPECT_CALL(resolver_, Resolve())
+ .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit))
.RetiresOnSaturation();
// This is how we inject fake URLFetcher objects, with a factory.
@@ -195,13 +170,10 @@ TEST_F(OnlineAttemptTest, FullLogin) {
TestAttemptState local_state(UserContext(), "", "", "",
User::USER_TYPE_REGULAR, true);
- attempt_.reset(new OnlineAttempt(&local_state, resolver_.get()));
+ attempt_.reset(new OnlineAttempt(&local_state, &resolver_));
attempt_->Initiate(&profile);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&OnlineAttemptTest::RunThreadTest));
- base::MessageLoop::current()->Run();
+ run_loop.Run();
EXPECT_EQ(LoginFailure::LoginFailureNone(), local_state.online_outcome());
}
@@ -241,7 +213,7 @@ TEST_F(OnlineAttemptTest, CaptchaErrorOutputted) {
}
TEST_F(OnlineAttemptTest, TwoFactorSuccess) {
- EXPECT_CALL(*(resolver_.get()), Resolve())
+ EXPECT_CALL(resolver_, Resolve())
.Times(1)
.RetiresOnSaturation();
GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
@@ -252,7 +224,7 @@ TEST_F(OnlineAttemptTest, TwoFactorSuccess) {
error));
// Force UI thread to finish tasks so I can verify |state_|.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() ==
state_.online_outcome().error());
}
diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
index f0fd212..9875995 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
@@ -27,7 +27,7 @@
#include "chromeos/cryptohome/mock_cryptohome_library.h"
#include "chromeos/dbus/fake_cryptohome_client.h"
#include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/mock_url_fetcher_factory.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_status.h"
@@ -36,13 +36,9 @@
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "url/gurl.h"
-using ::testing::AnyNumber;
-using ::testing::DoAll;
using ::testing::Invoke;
using ::testing::Return;
-using ::testing::SetArgPointee;
using ::testing::_;
-using content::BrowserThread;
namespace chromeos {
@@ -57,15 +53,10 @@ class TestOnlineAttempt : public OnlineAttempt {
class ParallelAuthenticatorTest : public testing::Test {
public:
ParallelAuthenticatorTest()
- : message_loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_),
- io_thread_(BrowserThread::IO),
- username_("me@nowhere.org"),
+ : username_("me@nowhere.org"),
password_("fakepass"),
+ hash_ascii_("0a010000000000a0" + std::string(16, '0')),
user_manager_enabler_(new MockUserManager) {
- hash_ascii_.assign("0a010000000000a0");
- hash_ascii_.append(std::string(16, '0'));
}
virtual ~ParallelAuthenticatorTest() {
@@ -79,8 +70,6 @@ class ParallelAuthenticatorTest : public testing::Test {
mock_cryptohome_library_ .reset(new MockCryptohomeLibrary());
CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get());
- io_thread_.Start();
-
auth_ = new ParallelAuthenticator(&consumer_);
state_.reset(new TestAttemptState(UserContext(username_,
password_,
@@ -177,7 +166,7 @@ class ParallelAuthenticatorTest : public testing::Test {
void RunResolve(ParallelAuthenticator* auth) {
auth->Resolve();
- message_loop_.RunUntilIdle();
+ base::MessageLoop::current()->RunUntilIdle();
}
void SetAttemptState(ParallelAuthenticator* auth, TestAttemptState* state) {
@@ -198,10 +187,7 @@ class ParallelAuthenticatorTest : public testing::Test {
auth_->set_online_attempt(new TestOnlineAttempt(state_.get(), auth_.get()));
}
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
std::string username_;
std::string password_;
@@ -390,7 +376,7 @@ TEST_F(ParallelAuthenticatorTest, DriveGuestLogin) {
.RetiresOnSaturation();
auth_->LoginOffTheRecord();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveGuestLoginButFail) {
@@ -405,7 +391,7 @@ TEST_F(ParallelAuthenticatorTest, DriveGuestLoginButFail) {
.RetiresOnSaturation();
auth_->LoginOffTheRecord();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveRetailModeUserLogin) {
@@ -420,7 +406,7 @@ TEST_F(ParallelAuthenticatorTest, DriveRetailModeUserLogin) {
.RetiresOnSaturation();
auth_->LoginRetailMode();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveRetailModeLoginButFail) {
@@ -435,7 +421,7 @@ TEST_F(ParallelAuthenticatorTest, DriveRetailModeLoginButFail) {
.RetiresOnSaturation();
auth_->LoginRetailMode();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveDataResync) {
@@ -464,7 +450,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataResync) {
SetAttemptState(auth_.get(), state_.release());
auth_->ResyncEncryptedData();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveResyncFail) {
@@ -480,7 +466,7 @@ TEST_F(ParallelAuthenticatorTest, DriveResyncFail) {
SetAttemptState(auth_.get(), state_.release());
auth_->ResyncEncryptedData();
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) {
@@ -521,7 +507,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecover) {
SetAttemptState(auth_.get(), state_.release());
auth_->RecoverEncryptedData(std::string());
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) {
@@ -541,7 +527,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) {
SetAttemptState(auth_.get(), state_.release());
auth_->RecoverEncryptedData(std::string());
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
TEST_F(ParallelAuthenticatorTest, ResolveNoMount) {
@@ -652,7 +638,7 @@ TEST_F(ParallelAuthenticatorTest, DriveUnlock) {
auth_->AuthenticateToUnlock(UserContext(username_,
std::string(),
std::string()));
- message_loop_.Run();
+ base::MessageLoop::current()->Run();
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/user_manager_unittest.cc b/chrome/browser/chromeos/login/user_manager_unittest.cc
index 5ae5ae6..c26a764 100644
--- a/chrome/browser/chromeos/login/user_manager_unittest.cc
+++ b/chrome/browser/chromeos/login/user_manager_unittest.cc
@@ -6,7 +6,6 @@
#include <cstring>
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h"
@@ -22,19 +21,13 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/test/base/testing_browser_process.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
class UserManagerTest : public testing::Test {
- public:
- UserManagerTest()
- : message_loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(content::BrowserThread::UI, &message_loop_),
- file_thread_(content::BrowserThread::FILE, &message_loop_) {
- }
-
+ protected:
virtual void SetUp() OVERRIDE {
cros_settings_ = CrosSettings::Get();
@@ -126,9 +119,7 @@ class UserManagerTest : public testing::Test {
}
protected:
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
CrosSettings* cros_settings_;
CrosSettingsProvider* device_settings_provider_;
diff --git a/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc b/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc
index 2b6b410..320ee4a 100644
--- a/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc
+++ b/chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc
@@ -5,7 +5,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "chrome/browser/captive_portal/captive_portal_detector.h"
#include "chrome/browser/captive_portal/testing_utils.h"
#include "chrome/browser/chromeos/net/network_portal_detector_impl.h"
@@ -15,6 +15,7 @@
#include "chromeos/dbus/shill_service_client.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "dbus/object_path.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -40,10 +41,7 @@ const char* kStubCellular = "stub_cellular";
class NetworkPortalDetectorImplTest
: public testing::Test,
public captive_portal::CaptivePortalDetectorTestBase {
- public:
- NetworkPortalDetectorImplTest() {}
- virtual ~NetworkPortalDetectorImplTest() {}
-
+ protected:
virtual void SetUp() {
DBusThreadManager::InitializeWithStub();
SetupNetworkHandler();
@@ -170,13 +168,13 @@ class NetworkPortalDetectorImplTest
dbus::ObjectPath(service_path),
flimflam::kStateProperty, base::StringValue(flimflam::kStatePortal),
base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void SetNetworkDeviceEnabled(const std::string& type, bool enabled) {
NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
type, enabled, network_handler::ErrorCallback());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void SetConnected(const std::string& service_path) {
@@ -184,12 +182,12 @@ class NetworkPortalDetectorImplTest
dbus::ObjectPath(service_path),
flimflam::kStateProperty, base::StringValue(flimflam::kStateOnline),
base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
private:
void SetupDefaultShillState() {
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ShillServiceClient::TestInterface* service_test =
DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
service_test->ClearServices();
@@ -218,7 +216,7 @@ class NetworkPortalDetectorImplTest
NetworkHandler::Initialize();
}
- base::MessageLoop message_loop_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
scoped_ptr<NetworkPortalDetectorImpl> network_portal_detector_;
};
@@ -381,7 +379,7 @@ TEST_F(NetworkPortalDetectorImplTest, PortalDetectionTimeout) {
ASSERT_EQ(0, attempt_count());
SetConnected(kStubWireless1);
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// First portal detection timeouts, next portal detection is
// scheduled.
@@ -444,7 +442,7 @@ TEST_F(NetworkPortalDetectorImplTest, FirstAttemptFailed) {
ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 204, NULL);
ASSERT_TRUE(is_state_idle());
@@ -470,7 +468,7 @@ TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) {
ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 503, retry_after);
ASSERT_TRUE(is_state_portal_detection_pending());
@@ -478,7 +476,7 @@ TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) {
ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 503, retry_after);
ASSERT_TRUE(is_state_idle());
@@ -499,7 +497,7 @@ TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 407, NULL);
ASSERT_EQ(2, attempt_count());
@@ -508,7 +506,7 @@ TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 407, NULL);
ASSERT_EQ(3, attempt_count());
@@ -532,7 +530,7 @@ TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) {
ASSERT_TRUE(is_state_portal_detection_pending());
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID,
@@ -541,7 +539,7 @@ TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) {
ASSERT_TRUE(is_state_portal_detection_pending());
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID,
@@ -581,7 +579,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 204, NULL);
@@ -592,7 +590,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
disable_lazy_detection();
@@ -623,7 +621,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID,
@@ -634,7 +632,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CompleteURLFetch(net::OK, 200, NULL);
ASSERT_EQ(3, attempt_count());
@@ -643,7 +641,7 @@ TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForPortalNetwork) {
kStubWireless1);
// To run CaptivePortalDetector::DetectCaptivePortal().
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
disable_lazy_detection();
@@ -693,7 +691,7 @@ TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) {
ASSERT_TRUE(is_state_portal_detection_pending());
ASSERT_FALSE(start_detection_if_idle());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(is_state_checking_for_portal());
CompleteURLFetch(net::OK, 200, NULL);
@@ -716,13 +714,13 @@ TEST_F(NetworkPortalDetectorImplTest, RequestTimeouts) {
// Second portal detection attempt for cellular1 uses 10sec timeout.
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID);
// Third portal detection attempt for cellular1 uses 15sec timeout.
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID);
@@ -731,7 +729,7 @@ TEST_F(NetworkPortalDetectorImplTest, RequestTimeouts) {
// Check that in lazy detection for cellular1 15sec timeout is used.
enable_lazy_detection();
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
disable_lazy_detection();
CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID);
@@ -746,14 +744,14 @@ TEST_F(NetworkPortalDetectorImplTest, RequestTimeouts) {
// Second portal detection attempt for wifi1 also uses 5sec timeout.
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CheckRequestTimeoutAndCompleteAttempt(2, 10, net::OK, 204);
ASSERT_TRUE(is_state_idle());
// Check that in lazy detection for wifi1 5sec timeout is used.
enable_lazy_detection();
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
disable_lazy_detection();
CheckRequestTimeoutAndCompleteAttempt(3, 15, net::OK, 204);
ASSERT_TRUE(is_state_idle());
@@ -768,13 +766,13 @@ TEST_F(NetworkPortalDetectorImplTest, StartDetectionIfIdle) {
CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID);
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// Second portal detection attempt for wifi1 uses 10sec timeout.
CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED,
net::URLFetcher::RESPONSE_CODE_INVALID);
ASSERT_TRUE(is_state_portal_detection_pending());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// Second portal detection attempt for wifi1 uses 15sec timeout.
CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
@@ -785,7 +783,7 @@ TEST_F(NetworkPortalDetectorImplTest, StartDetectionIfIdle) {
ASSERT_TRUE(is_state_portal_detection_pending());
// First portal detection attempt for wifi1 uses 5sec timeout.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
CheckRequestTimeoutAndCompleteAttempt(1, 5, net::OK, 204);
ASSERT_TRUE(is_state_idle());
}
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
index 53c3c82..7c3d9df 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc
@@ -33,7 +33,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/url_request/test_url_fetcher_factory.h"
@@ -75,9 +75,7 @@ const char kOAuth2AccessTokenData[] =
class UserCloudPolicyManagerChromeOSTest : public testing::Test {
protected:
UserCloudPolicyManagerChromeOSTest()
- : ui_thread_(content::BrowserThread::UI, &loop_),
- io_thread_(content::BrowserThread::IO, &loop_),
- store_(NULL),
+ : store_(NULL),
profile_(NULL),
signin_profile_(NULL) {}
@@ -90,14 +88,13 @@ class UserCloudPolicyManagerChromeOSTest : public testing::Test {
profile_ = profile_manager_->CreateTestingProfile(
chrome::kInitialProfile, scoped_ptr<PrefServiceSyncable>(),
UTF8ToUTF16("testing_profile"), 0);
- signin_profile_ = profile_manager_->CreateTestingProfile("signin_profile");
+ signin_profile_ = profile_manager_->CreateTestingProfile(kSigninProfile);
signin_profile_->set_incognito(true);
// Usually the signin Profile and the main Profile are separate, but since
// the signin Profile is an OTR Profile then for this test it suffices to
// attach it to the main Profile.
profile_->SetOffTheRecordProfile(signin_profile_);
signin_profile_->SetOriginalProfile(profile_);
- signin_profile_->CreateRequestContext();
ASSERT_EQ(signin_profile_, chromeos::ProfileHelper::GetSigninProfile());
chrome::RegisterLocalState(prefs_.registry());
@@ -136,7 +133,10 @@ class UserCloudPolicyManagerChromeOSTest : public testing::Test {
manager_->RemoveObserver(&observer_);
manager_->Shutdown();
}
- signin_profile_->ResetRequestContext();
+ signin_profile_ = NULL;
+ profile_ = NULL;
+ profile_manager_->DeleteTestingProfile(kSigninProfile);
+ profile_manager_->DeleteTestingProfile(chrome::kInitialProfile);
}
void CreateManager(bool wait_for_fetch) {
@@ -265,11 +265,9 @@ class UserCloudPolicyManagerChromeOSTest : public testing::Test {
EXPECT_TRUE(manager_->policies().Equals(expected_bundle_));
}
- // Required by the refresh scheduler that's created by the manager.
- base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
- // Required to cleanup the URLRequestContextGetter of the |signin_profile_|.
- content::TestBrowserThread io_thread_;
+ // Required by the refresh scheduler that's created by the manager and
+ // for the cleanup of URLRequestContextGetter in the |signin_profile_|.
+ content::TestBrowserThreadBundle thread_bundle_;
// Convenience policy objects.
em::PolicyData policy_data_;
@@ -292,10 +290,15 @@ class UserCloudPolicyManagerChromeOSTest : public testing::Test {
TestingProfile* profile_;
TestingProfile* signin_profile_;
+ static const char kSigninProfile[];
+
private:
DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest);
};
+const char UserCloudPolicyManagerChromeOSTest::kSigninProfile[] =
+ "signin_profile";
+
TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) {
// Tests the initialization of a manager whose Profile is waiting for the
// initial fetch, when the policy cache is empty.
diff --git a/chrome/browser/extensions/browser_permissions_policy_delegate_unittest.cc b/chrome/browser/extensions/browser_permissions_policy_delegate_unittest.cc
index b3088d0..db5b0e2 100644
--- a/chrome/browser/extensions/browser_permissions_policy_delegate_unittest.cc
+++ b/chrome/browser/extensions/browser_permissions_policy_delegate_unittest.cc
@@ -11,7 +11,7 @@
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/mock_render_process_host.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
@@ -19,10 +19,7 @@ namespace extensions {
namespace {
class BrowserPermissionsPolicyDelegateTest : public testing::Test {
-public:
- BrowserPermissionsPolicyDelegateTest()
- : loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(content::BrowserThread::UI, &loop_) {}
+ protected:
virtual void SetUp() {
profile_manager_.reset(
new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
@@ -35,8 +32,7 @@ public:
profile_manager_.reset();
}
protected:
- base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfileManager> profile_manager_;
TestingProfile* profile_;
};
diff --git a/chrome/browser/extensions/extension_protocols_unittest.cc b/chrome/browser/extensions/extension_protocols_unittest.cc
index 0e41a0d..2a2ae7c 100644
--- a/chrome/browser/extensions/extension_protocols_unittest.cc
+++ b/chrome/browser/extensions/extension_protocols_unittest.cc
@@ -86,7 +86,8 @@ scoped_refptr<Extension> CreateTestResponseHeaderExtension() {
class ExtensionProtocolTest : public testing::Test {
public:
ExtensionProtocolTest()
- : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
+ resource_context_(&test_url_request_context_) {}
virtual void SetUp() OVERRIDE {
testing::Test::SetUp();
@@ -128,6 +129,7 @@ class ExtensionProtocolTest : public testing::Test {
net::URLRequestJobFactoryImpl job_factory_;
const net::URLRequestJobFactory* old_factory_;
net::TestDelegate test_delegate_;
+ net::TestURLRequestContext test_url_request_context_;
content::MockResourceContext resource_context_;
};
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 580e728..e8f452b 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -578,13 +578,6 @@ void ExtensionServiceTestBase::InitializeExtensionServiceHelper(
InitializeExtensionService(params);
}
-void ExtensionServiceTestBase::InitializeRequestContext() {
- ASSERT_TRUE(profile_.get());
- TestingProfile* profile =
- static_cast<TestingProfile*>(profile_.get());
- profile->CreateRequestContext();
-}
-
// static
void ExtensionServiceTestBase::SetUpTestCase() {
ExtensionErrorReporter::Init(false); // no noisy errors
@@ -1974,7 +1967,6 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
// default apps.
TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
base::FilePath path = data_dir_
.AppendASCII("permissions");
@@ -2607,7 +2599,6 @@ TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) {
TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
EXPECT_TRUE(service_->extensions()->is_empty());
int pref_count = 0;
@@ -2659,7 +2650,6 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
EXPECT_TRUE(service_->extensions()->is_empty());
int pref_count = 0;
@@ -3744,7 +3734,6 @@ TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) {
// This tests if default apps are installed correctly.
TEST_F(ExtensionServiceTest, DefaultAppsInstall) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
set_extensions_enabled(true);
{
@@ -3853,7 +3842,6 @@ TEST_F(ExtensionServiceTest, DisableAllExtensions) {
// Tests reloading extensions.
TEST_F(ExtensionServiceTest, ReloadExtensions) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
// Simple extension that should install without error.
base::FilePath path = data_dir_.AppendASCII("good.crx");
@@ -4184,7 +4172,6 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) {
// Verifies app state is removed upon uninstall.
TEST_F(ExtensionServiceTest, ClearAppData) {
InitializeEmptyExtensionService();
- InitializeRequestContext();
ExtensionCookieCallback callback;
int pref_count = 0;
@@ -5641,7 +5628,6 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
InitializeExtensionServiceWithUpdater();
- InitializeRequestContext();
TestSyncProcessorStub processor;
service_->MergeDataAndStartSyncing(
syncer::EXTENSIONS, syncer::SyncDataList(),
@@ -5709,7 +5695,6 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
InitializeExtensionServiceWithUpdater();
- InitializeRequestContext();
TestSyncProcessorStub processor;
service_->MergeDataAndStartSyncing(
syncer::EXTENSIONS, syncer::SyncDataList(),
diff --git a/chrome/browser/extensions/extension_service_unittest.h b/chrome/browser/extensions/extension_service_unittest.h
index 24be033..884681e 100644
--- a/chrome/browser/extensions/extension_service_unittest.h
+++ b/chrome/browser/extensions/extension_service_unittest.h
@@ -55,8 +55,6 @@ class ExtensionServiceTestBase : public testing::Test {
void InitializeExtensionServiceWithUpdater();
- void InitializeRequestContext();
-
static void SetUpTestCase();
virtual void SetUp() OVERRIDE;
diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc
index 8fdd4bf..3c78899 100644
--- a/chrome/browser/extensions/updater/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc
@@ -239,7 +239,6 @@ class MockService : public TestExtensionService {
: prefs_(prefs),
pending_extension_manager_(*this),
blacklist_(prefs_->prefs()) {
- profile_.CreateRequestContext();
}
virtual ~MockService() {}
@@ -498,13 +497,10 @@ static void VerifyQueryAndExtractParameters(
class ExtensionUpdaterTest : public testing::Test {
public:
ExtensionUpdaterTest()
- : test_browser_thread_bundle_(
+ : thread_bundle_(
content::TestBrowserThreadBundle::IO_MAINLOOP) {
}
- virtual ~ExtensionUpdaterTest() {
- }
-
virtual void SetUp() OVERRIDE {
prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current()));
content::RenderProcessHost::SetRunRendererInProcess(true);
@@ -751,7 +747,6 @@ class ExtensionUpdaterTest : public testing::Test {
void TestDetermineUpdates() {
TestingProfile profile;
- profile.CreateRequestContext();
MockExtensionDownloaderDelegate delegate;
ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
@@ -795,7 +790,6 @@ class ExtensionUpdaterTest : public testing::Test {
SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
TestingProfile profile;
- profile.CreateRequestContext();
MockExtensionDownloaderDelegate delegate;
ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
@@ -1502,7 +1496,7 @@ class ExtensionUpdaterTest : public testing::Test {
scoped_ptr<TestExtensionPrefs> prefs_;
private:
- content::TestBrowserThreadBundle test_browser_thread_bundle_;
+ content::TestBrowserThreadBundle thread_bundle_;
#if defined OS_CHROMEOS
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc
index 88bdc5a..1ddda26 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -18,14 +18,13 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher.h"
#include "testing/gtest/include/gtest/gtest.h"
class GoogleURLTrackerTest;
-
namespace {
// TestInfoBarDelegate --------------------------------------------------------
@@ -249,8 +248,7 @@ class GoogleURLTrackerTest : public testing::Test {
// These are required by the TestURLFetchers GoogleURLTracker will create (see
// test_url_fetcher_factory.h).
- base::MessageLoop message_loop_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
// Creating this allows us to call
// net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
@@ -283,8 +281,7 @@ void GoogleURLTrackerTest::OnInfoBarClosed(scoped_ptr<InfoBarDelegate> infobar,
}
GoogleURLTrackerTest::GoogleURLTrackerTest()
- : message_loop_(base::MessageLoop::TYPE_IO),
- io_thread_(content::BrowserThread::IO, &message_loop_) {
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnBrowserContext(
&profile_);
}
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 3688996..44cd6cd 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -439,6 +439,12 @@ IOThread::Globals* IOThread::globals() {
return globals_;
}
+void IOThread::SetGlobalsForTesting(Globals* globals) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(!globals || !globals_);
+ globals_ = globals;
+}
+
ChromeNetLog* IOThread::net_log() {
return net_log_;
}
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index 4b1b9ef..4408a50 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -187,6 +187,11 @@ class IOThread : public content::BrowserThreadDelegate {
// Can only be called on the IO thread.
Globals* globals();
+ // Allows overriding Globals in tests where IOThread::Init() and
+ // IOThread::CleanUp() are not called. This allows for injecting mocks into
+ // IOThread global objects.
+ void SetGlobalsForTesting(Globals* globals);
+
ChromeNetLog* net_log();
// Handles changing to On The Record mode, discarding confidential data.
diff --git a/chrome/browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc b/chrome/browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc
index 7b7bebf..c547599 100644
--- a/chrome/browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc
+++ b/chrome/browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc
@@ -4,13 +4,12 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h"
#include "chrome/browser/signin/oauth2_token_service.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
@@ -195,9 +194,7 @@ class ManagedUserRefreshTokenFetcherTest : public testing::Test {
void OnTokenFetched(const GoogleServiceAuthError& error,
const std::string& token);
- base::WeakPtrFactory<ManagedUserRefreshTokenFetcherTest> weak_ptr_factory_;
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
MockOAuth2TokenService oauth2_token_service_;
net::TestURLFetcherFactory url_fetcher_factory_;
@@ -205,15 +202,15 @@ class ManagedUserRefreshTokenFetcherTest : public testing::Test {
GoogleServiceAuthError error_;
std::string token_;
+ base::WeakPtrFactory<ManagedUserRefreshTokenFetcherTest> weak_ptr_factory_;
};
ManagedUserRefreshTokenFetcherTest::ManagedUserRefreshTokenFetcherTest()
- : weak_ptr_factory_(this),
- ui_thread_(content::BrowserThread::UI, &message_loop_),
- token_fetcher_(
+ : token_fetcher_(
ManagedUserRefreshTokenFetcher::Create(&oauth2_token_service_,
profile_.GetRequestContext())),
- error_(GoogleServiceAuthError::NONE) {}
+ error_(GoogleServiceAuthError::NONE),
+ weak_ptr_factory_(this) {}
void ManagedUserRefreshTokenFetcherTest::StartFetching() {
token_fetcher_->Start(kManagedUserId, UTF8ToUTF16(kName), kDeviceName,
diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc
index 3b64e1d..d8ab2c7 100644
--- a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc
+++ b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc
@@ -8,10 +8,10 @@
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "chrome/browser/net/gaia/gaia_oauth_consumer.h"
#include "chrome/browser/net/gaia/gaia_oauth_fetcher.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
@@ -23,8 +23,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
-using ::testing::_;
-
class MockGaiaOAuthConsumer : public GaiaOAuthConsumer {
public:
MockGaiaOAuthConsumer() {}
@@ -123,7 +121,10 @@ TEST(GaiaOAuthFetcherTest, GetOAuthToken) {
}
#endif // 0 // Suppressing for now
-typedef testing::Test GaiaOAuthFetcherTest;
+class GaiaOAuthFetcherTest : public testing::Test {
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
+};
TEST_F(GaiaOAuthFetcherTest, OAuthGetAccessToken) {
const std::string oauth_token =
diff --git a/chrome/browser/page_cycler/page_cycler_unittest.cc b/chrome/browser/page_cycler/page_cycler_unittest.cc
index cbfc07e..2ef95fe 100644
--- a/chrome/browser/page_cycler/page_cycler_unittest.cc
+++ b/chrome/browser/page_cycler/page_cycler_unittest.cc
@@ -5,6 +5,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/prefs/testing_pref_service.h"
+#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -150,7 +151,7 @@ class PageCyclerTest : public BrowserWithTestWindowTest {
void PumpLoop() {
content::BrowserThread::GetBlockingPool()->FlushForTesting();
- message_loop()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void CloseBrowser() {
@@ -310,7 +311,7 @@ TEST_F(PageCyclerTest, KillBrowserAndAbort) {
DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _))
.WillOnce(Invoke(page_cycler(),
&MockPageCycler::PageCyclerDidFinishLoad));
- message_loop()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
FinishLoad();
diff --git a/chrome/browser/password_manager/password_generation_manager_unittest.cc b/chrome/browser/password_manager/password_generation_manager_unittest.cc
index ac691d9..22f2050 100644
--- a/chrome/browser/password_manager/password_generation_manager_unittest.cc
+++ b/chrome/browser/password_manager/password_generation_manager_unittest.cc
@@ -44,7 +44,6 @@ class TestPasswordGenerationManager : public PasswordGenerationManager {
class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness {
protected:
virtual void SetUp() OVERRIDE {
-
SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
ChromeRenderViewHostTestHarness::SetUp();
@@ -56,12 +55,6 @@ class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness {
ChromeRenderViewHostTestHarness::TearDown();
}
- virtual content::BrowserContext* CreateBrowserContext() OVERRIDE {
- TestingProfile* profile = new TestingProfile();
- profile->CreateRequestContext();
- return profile;
- }
-
void UpdateState(bool new_renderer) {
password_generation_manager_->UpdateState(NULL, new_renderer);
}
@@ -77,7 +70,6 @@ class IncognitoPasswordGenerationManagerTest :
TestingProfile::Builder builder;
scoped_ptr<TestingProfile> profile = builder.Build();
profile->set_incognito(true);
- profile->CreateRequestContext();
return profile.release();
}
};
diff --git a/chrome/browser/password_manager/password_store_x_unittest.cc b/chrome/browser/password_manager/password_store_x_unittest.cc
index ed6e8fe..a8d718d 100644
--- a/chrome/browser/password_manager/password_store_x_unittest.cc
+++ b/chrome/browser/password_manager/password_store_x_unittest.cc
@@ -9,11 +9,11 @@
#include "base/files/scoped_temp_dir.h"
#include "base/platform_file.h"
#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/synchronization/waitable_event.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/password_manager/password_form_data.h"
@@ -23,15 +23,15 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/test/mock_notification_observer.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-using base::WaitableEvent;
using content::BrowserThread;
using testing::_;
using testing::DoAll;
@@ -56,44 +56,25 @@ class MockPasswordStoreConsumer : public PasswordStoreConsumer {
// This class will add and remove a mock notification observer from
// the DB thread.
-class DBThreadObserverHelper
- : public base::RefCountedThreadSafe<DBThreadObserverHelper,
- BrowserThread::DeleteOnDBThread> {
+class DBThreadObserverHelper {
public:
- DBThreadObserverHelper() : done_event_(true, false) {}
+ DBThreadObserverHelper() {}
- void Init(PasswordStore* password_store) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&DBThreadObserverHelper::AddObserverTask,
- this, make_scoped_refptr(password_store)));
- done_event_.Wait();
- }
-
- content::MockNotificationObserver& observer() {
- return observer_;
- }
-
- protected:
- friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>;
- friend class base::DeleteHelper<DBThreadObserverHelper>;
-
- virtual ~DBThreadObserverHelper() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ ~DBThreadObserverHelper() {
registrar_.RemoveAll();
}
- void AddObserverTask(PasswordStore* password_store) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ void Init(PasswordStore* password_store) {
registrar_.Add(&observer_,
chrome::NOTIFICATION_LOGINS_CHANGED,
content::Source<PasswordStore>(password_store));
- done_event_.Signal();
}
- WaitableEvent done_event_;
+ content::MockNotificationObserver& observer() {
+ return observer_;
+ }
+
+ private:
content::NotificationRegistrar registrar_;
content::MockNotificationObserver observer_;
};
@@ -269,13 +250,7 @@ enum BackendType {
class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
protected:
- PasswordStoreXTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB) {
- }
-
virtual void SetUp() {
- ASSERT_TRUE(db_thread_.Start());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new TestingProfile());
@@ -285,10 +260,7 @@ class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
}
virtual void TearDown() {
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- base::MessageLoop::current()->Run();
- db_thread_.Stop();
+ base::RunLoop().RunUntilIdle();
}
PasswordStoreX::NativeBackend* GetBackend() {
@@ -302,10 +274,7 @@ class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
}
}
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- // PasswordStore, WDS schedule work on this thread.
- content::TestBrowserThread db_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<LoginDatabase> login_db_;
scoped_ptr<TestingProfile> profile_;
@@ -316,11 +285,6 @@ ACTION(STLDeleteElements0) {
STLDeleteContainerPointers(arg0.begin(), arg0.end());
}
-ACTION(QuitUIMessageLoop) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- base::MessageLoop::current()->Quit();
-}
-
TEST_P(PasswordStoreXTest, Notifications) {
scoped_refptr<PasswordStoreX> store(
new PasswordStoreX(login_db_.release(),
@@ -341,15 +305,15 @@ TEST_P(PasswordStoreXTest, Notifications) {
true, false, 1 };
scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data));
- scoped_refptr<DBThreadObserverHelper> helper = new DBThreadObserverHelper;
- helper->Init(store.get());
+ DBThreadObserverHelper helper;
+ helper.Init(store.get());
const PasswordStoreChange expected_add_changes[] = {
PasswordStoreChange(PasswordStoreChange::ADD, *form),
};
EXPECT_CALL(
- helper->observer(),
+ helper.observer(),
Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
content::Source<PasswordStore>(store.get()),
Property(&content::Details<const PasswordStoreChangeList>::ptr,
@@ -358,12 +322,9 @@ TEST_P(PasswordStoreXTest, Notifications) {
// Adding a login should trigger a notification.
store->AddLogin(*form);
- // The PasswordStore schedules tasks to run on the DB thread so we schedule
- // yet another task to notify us that it's safe to carry on with the test.
- WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
+ // The PasswordStore schedules tasks to run on the DB thread. Wait for them
+ // to complete.
+ base::RunLoop().RunUntilIdle();
// Change the password.
form->password_value = WideToUTF16(L"a different password");
@@ -373,7 +334,7 @@ TEST_P(PasswordStoreXTest, Notifications) {
};
EXPECT_CALL(
- helper->observer(),
+ helper.observer(),
Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
content::Source<PasswordStore>(store.get()),
Property(&content::Details<const PasswordStoreChangeList>::ptr,
@@ -382,17 +343,15 @@ TEST_P(PasswordStoreXTest, Notifications) {
// Updating the login with the new password should trigger a notification.
store->UpdateLogin(*form);
- // Wait for PasswordStore to send the notification.
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
+ // Wait for PasswordStore to send execute.
+ base::RunLoop().RunUntilIdle();
const PasswordStoreChange expected_delete_changes[] = {
PasswordStoreChange(PasswordStoreChange::REMOVE, *form),
};
EXPECT_CALL(
- helper->observer(),
+ helper.observer(),
Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
content::Source<PasswordStore>(store.get()),
Property(&content::Details<const PasswordStoreChangeList>::ptr,
@@ -401,10 +360,8 @@ TEST_P(PasswordStoreXTest, Notifications) {
// Deleting the login should trigger a notification.
store->RemoveLogin(*form);
- // Wait for PasswordStore to send the notification.
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
+ // Wait for PasswordStore to execute.
+ base::RunLoop().RunUntilIdle();
// Public in PasswordStore, protected in PasswordStoreX.
static_cast<PasswordStore*>(store.get())->ShutdownOnUIThread();
@@ -428,26 +385,13 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
// Populate the login DB with logins that should be migrated.
for (VectorOfForms::iterator it = expected_autofillable.begin();
it != expected_autofillable.end(); ++it) {
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(
- base::IgnoreResult(&LoginDatabase::AddLogin),
- base::Unretained(login_db), **it));
+ login_db->AddLogin(**it);
}
for (VectorOfForms::iterator it = expected_blacklisted.begin();
it != expected_blacklisted.end(); ++it) {
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(
- base::IgnoreResult(&LoginDatabase::AddLogin),
- base::Unretained(login_db), **it));
+ login_db->AddLogin(**it);
}
- // Schedule another task on the DB thread to notify us that it's safe to
- // carry on with the test.
- WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
-
// Get the new size of the login DB file. We expect it to be larger.
base::PlatformFileInfo db_file_full_info;
ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info));
@@ -462,27 +406,23 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
MockPasswordStoreConsumer consumer;
- // Make sure we quit the MessageLoop even if the test fails.
- ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
- .WillByDefault(QuitUIMessageLoop());
-
// The autofillable forms should have been migrated to the native backend.
EXPECT_CALL(consumer,
OnPasswordStoreRequestDone(_,
ContainsAllPasswordForms(expected_autofillable)))
- .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
+ .WillOnce(WithArg<1>(STLDeleteElements0()));
store->GetAutofillableLogins(&consumer);
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
// The blacklisted forms should have been migrated to the native backend.
EXPECT_CALL(consumer,
OnPasswordStoreRequestDone(_,
ContainsAllPasswordForms(expected_blacklisted)))
- .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
+ .WillOnce(WithArg<1>(STLDeleteElements0()));
store->GetBlacklistLogins(&consumer);
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
VectorOfForms empty;
MockLoginDatabaseReturn ld_return;
@@ -499,14 +439,10 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
.WillOnce(WithArg<0>(STLDeleteElements0()));
}
- BrowserThread::PostTask(
- BrowserThread::DB, FROM_HERE,
- base::Bind(&LoginDatabaseQueryCallback, login_db, true, &ld_return));
+ LoginDatabaseQueryCallback(login_db, true, &ld_return);
- // Wait for the login DB methods to execute on the DB thread.
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
+ // Wait for the login DB methods to execute.
+ base::RunLoop().RunUntilIdle();
if (GetParam() == WORKING_BACKEND) {
// Likewise, no blacklisted logins should be left in the login DB.
@@ -520,14 +456,10 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
.WillOnce(WithArg<0>(STLDeleteElements0()));
}
- BrowserThread::PostTask(
- BrowserThread::DB, FROM_HERE,
- base::Bind(&LoginDatabaseQueryCallback, login_db, false, &ld_return));
+ LoginDatabaseQueryCallback(login_db, false, &ld_return);
- // Wait for the login DB methods to execute on the DB thread.
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
+ // Wait for the login DB methods to execute.
+ base::RunLoop().RunUntilIdle();
if (GetParam() == WORKING_BACKEND) {
// If the migration succeeded, then not only should there be no logins left
diff --git a/chrome/browser/policy/cloud/device_management_service_unittest.cc b/chrome/browser/policy/cloud/device_management_service_unittest.cc
index e1b1f2f..2838bfc 100644
--- a/chrome/browser/policy/cloud/device_management_service_unittest.cc
+++ b/chrome/browser/policy/cloud/device_management_service_unittest.cc
@@ -6,12 +6,12 @@
#include <vector>
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
#include "chrome/browser/policy/cloud/device_management_service.h"
#include "chrome/test/base/testing_browser_process.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
@@ -22,7 +22,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
using testing::Mock;
using testing::_;
@@ -49,16 +48,14 @@ const char kRobotAuthCode[] = "robot-oauth-auth-code";
// without calling into the actual network stack.
class DeviceManagementServiceTestBase : public testing::Test {
protected:
- DeviceManagementServiceTestBase()
- : ui_thread_(BrowserThread::UI, &loop_),
- io_thread_(BrowserThread::IO, &loop_) {
+ DeviceManagementServiceTestBase() {
ResetService();
InitializeService();
}
- virtual void TearDown() {
+ ~DeviceManagementServiceTestBase() {
service_.reset();
- loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void ResetService() {
@@ -67,7 +64,7 @@ class DeviceManagementServiceTestBase : public testing::Test {
void InitializeService() {
service_->ScheduleInitialization(0);
- loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
net::TestURLFetcher* GetFetcher() {
@@ -166,9 +163,7 @@ class DeviceManagementServiceTestBase : public testing::Test {
scoped_ptr<DeviceManagementService> service_;
private:
- base::MessageLoopForUI loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
};
struct FailedRequestParams {
diff --git a/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc b/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc
index 82539a3..70b0c46 100644
--- a/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc
+++ b/chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc
@@ -28,7 +28,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_status_code.h"
@@ -140,10 +140,7 @@ class FakeProfileOAuth2TokenService : public AndroidProfileOAuth2TokenService {
class UserPolicySigninServiceTest : public testing::Test {
public:
UserPolicySigninServiceTest()
- : loop_(base::MessageLoop::TYPE_IO),
- ui_thread_(content::BrowserThread::UI, &loop_),
- file_thread_(content::BrowserThread::FILE, &loop_),
- io_thread_(content::BrowserThread::IO, &loop_),
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
register_completed_(false) {}
MOCK_METHOD1(OnPolicyRefresh, void(bool));
@@ -186,7 +183,6 @@ class UserPolicySigninServiceTest : public testing::Test {
TestingProfile::Builder builder;
builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass()));
profile_ = builder.Build().Pass();
- profile_->CreateRequestContext();
mock_store_ = new MockUserCloudPolicyStore();
EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber());
@@ -340,10 +336,7 @@ class UserPolicySigninServiceTest : public testing::Test {
// BrowserPolicyConnector and UrlFetcherFactory want to initialize and free
// various components asynchronously via tasks, so create fake threads here.
- base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
net::TestURLFetcherFactory url_factory_;
diff --git a/chrome/browser/policy/policy_service_impl_unittest.cc b/chrome/browser/policy/policy_service_impl_unittest.cc
index f185abc..508ae445 100644
--- a/chrome/browser/policy/policy_service_impl_unittest.cc
+++ b/chrome/browser/policy/policy_service_impl_unittest.cc
@@ -9,7 +9,6 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/policy/external_data_fetcher.h"
@@ -18,7 +17,7 @@
#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/common/policy/policy_schema.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -155,7 +154,7 @@ class PolicyServiceTest : public testing::Test {
PolicyMap policy1_;
PolicyMap policy2_;
scoped_ptr<PolicyServiceImpl> policy_service_;
- base::MessageLoop loop_;
+ content::TestBrowserThreadBundle thread_bundle_;
private:
DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest);
@@ -436,10 +435,6 @@ TEST_F(PolicyServiceTest, PolicyChangeRegistrar) {
}
TEST_F(PolicyServiceTest, RefreshPolicies) {
- content::TestBrowserThread ui_thread(content::BrowserThread::UI, &loop_);
- content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop_);
- content::TestBrowserThread io_thread(content::BrowserThread::IO, &loop_);
-
EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber());
EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber());
EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber());
diff --git a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
index 79e0280..7064156 100644
--- a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
+++ b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
@@ -11,9 +11,12 @@
#include "base/message_loop/message_loop.h"
#include "base/process_util.h"
#include "base/rand_util.h"
+#include "base/synchronization/waitable_event.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
+#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
+#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
#include "chrome/browser/service/service_process_control.h"
@@ -26,13 +29,14 @@
#include "chrome/service/service_process.h"
#include "chrome/test/base/test_launcher_utils.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_io_thread_state.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "ipc/ipc_descriptors.h"
#include "ipc/ipc_multiprocess_test.h"
#include "ipc/ipc_switches.h"
@@ -57,6 +61,7 @@ using ::testing::Property;
using ::testing::Return;
using ::testing::WithoutArgs;
using ::testing::_;
+using content::BrowserThread;
namespace {
@@ -205,17 +210,23 @@ typedef base::Callback<void(MockServiceIPCServer* server)>
int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) {
base::MessageLoopForUI main_message_loop;
main_message_loop.set_thread_name("Main Thread");
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
#if defined(OS_MACOSX)
- CommandLine* cl = CommandLine::ForCurrentProcess();
- if (!cl->HasSwitch(kTestExecutablePath))
+ if (!command_line->HasSwitch(kTestExecutablePath))
return kMissingSwitch;
- base::FilePath executable_path = cl->GetSwitchValuePath(kTestExecutablePath);
+ base::FilePath executable_path =
+ command_line->GetSwitchValuePath(kTestExecutablePath);
EXPECT_FALSE(executable_path.empty());
MockLaunchd mock_launchd(executable_path, &main_message_loop, true, true);
Launchd::ScopedInstance use_mock(&mock_launchd);
#endif
+ base::FilePath user_data_dir =
+ command_line->GetSwitchValuePath(switches::kUserDataDir);
+ CHECK(!user_data_dir.empty());
+ CHECK(test_launcher_utils::OverrideUserDataDir(user_data_dir));
+
ServiceProcessState* state(new ServiceProcessState);
bool service_process_state_initialized = state->Initialize();
EXPECT_TRUE(service_process_state_initialized);
@@ -289,8 +300,8 @@ class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest,
virtual ~CloudPrintProxyPolicyStartupTest();
virtual void SetUp();
- base::MessageLoopProxy* IOMessageLoopProxy() {
- return io_thread_.message_loop_proxy().get();
+ scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() {
+ return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
}
base::ProcessHandle Launch(const std::string& name);
void WaitForConnect();
@@ -316,9 +327,8 @@ class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest,
}
protected:
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- base::Thread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ base::ScopedTempDir temp_user_data_dir_;
std::string startup_channel_id_;
scoped_ptr<IPC::ChannelProxy> startup_channel_;
@@ -359,28 +369,43 @@ class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest,
};
CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest()
- : ui_thread_(content::BrowserThread::UI, &message_loop_),
- io_thread_("CloudPrintProxyPolicyTestThread") {
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {
}
CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() {
}
void CloudPrintProxyPolicyStartupTest::SetUp() {
- base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
- ASSERT_TRUE(io_thread_.StartWithOptions(options));
-
#if defined(OS_MACOSX)
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
EXPECT_TRUE(MockLaunchd::MakeABundle(temp_dir_.path(),
"CloudPrintProxyTest",
&bundle_path_,
&executable_path_));
- mock_launchd_.reset(new MockLaunchd(executable_path_, &message_loop_,
+ mock_launchd_.reset(new MockLaunchd(executable_path_,
+ base::MessageLoopForUI::current(),
true, false));
scoped_launchd_instance_.reset(
new Launchd::ScopedInstance(mock_launchd_.get()));
#endif
+
+ // Ensure test does not use the standard profile directory. This is copied
+ // from InProcessBrowserTest::SetUp(). These tests require a more complex
+ // process startup so they are unable to just inherit from
+ // InProcessBrowserTest.
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ base::FilePath user_data_dir =
+ command_line->GetSwitchValuePath(switches::kUserDataDir);
+ if (user_data_dir.empty()) {
+ ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir() &&
+ temp_user_data_dir_.IsValid())
+ << "Could not create temporary user data directory \""
+ << temp_user_data_dir_.path().value() << "\".";
+
+ user_data_dir = temp_user_data_dir_.path();
+ command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
+ }
+ ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir));
}
base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch(
@@ -452,10 +477,21 @@ CommandLine CloudPrintProxyPolicyStartupTest::MakeCmdLine(
}
TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) {
+ TestingBrowserProcess* browser_process =
+ TestingBrowserProcess::GetGlobal();
+ TestingProfileManager profile_manager(browser_process);
+ ASSERT_TRUE(profile_manager.SetUp());
+
+ // Must be created after the TestingProfileManager since that creates the
+ // LocalState for the BrowserProcess. Must be created before profiles are
+ // constructed.
+ chrome::TestingIOThreadState testing_io_thread_state;
+
base::ProcessHandle handle =
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
WaitForConnect();
ShutdownAndWaitForExitWithTimeout(handle);
+ content::RunAllPendingInMessageLoop();
}
BrowserContextKeyedService* CloudPrintProxyServiceFactoryForPolicyTest(
@@ -470,11 +506,18 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
base::ProcessHandle handle =
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
+ // Setup the Browser Process with a full IOThread::Globals.
TestingBrowserProcess* browser_process =
TestingBrowserProcess::GetGlobal();
+
TestingProfileManager profile_manager(browser_process);
ASSERT_TRUE(profile_manager.SetUp());
+ // Must be created after the TestingProfileManager since that creates the
+ // LocalState for the BrowserProcess. Must be created before profiles are
+ // constructed.
+ chrome::TestingIOThreadState testing_io_thread_state;
+
TestingProfile* profile =
profile_manager.CreateTestingProfile("StartBrowserWithoutPolicy");
CloudPrintProxyServiceFactory::GetInstance()->
@@ -490,20 +533,22 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line);
WaitForConnect();
+ base::RunLoop run_loop;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::MessageLoop::QuitClosure(),
+ run_loop.QuitClosure(),
TestTimeouts::action_timeout());
- bool run_loop = LaunchBrowser(command_line, profile);
- EXPECT_FALSE(run_loop);
- if (run_loop)
- base::MessageLoop::current()->Run();
+ bool should_run_loop = LaunchBrowser(command_line, profile);
+ EXPECT_FALSE(should_run_loop);
+ if (should_run_loop)
+ run_loop.Run();
EXPECT_EQ(MockServiceIPCServer::EnabledUserId(),
prefs->GetString(prefs::kCloudPrintEmail));
ShutdownAndWaitForExitWithTimeout(handle);
+ content::RunAllPendingInMessageLoop();
profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy");
}
@@ -516,6 +561,11 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
TestingProfileManager profile_manager(browser_process);
ASSERT_TRUE(profile_manager.SetUp());
+ // Must be created after the TestingProfileManager since that creates the
+ // LocalState for the BrowserProcess. Must be created before profiles are
+ // constructed.
+ chrome::TestingIOThreadState testing_io_thread_state;
+
TestingProfile* profile =
profile_manager.CreateTestingProfile("StartBrowserWithPolicy");
CloudPrintProxyServiceFactory::GetInstance()->
@@ -533,20 +583,22 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line);
WaitForConnect();
+ base::RunLoop run_loop;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::MessageLoop::QuitClosure(),
+ run_loop.QuitClosure(),
TestTimeouts::action_timeout());
- bool run_loop = LaunchBrowser(command_line, profile);
+ bool should_run_loop = LaunchBrowser(command_line, profile);
// No expectations on run_loop being true here; that would be a race
// condition.
- if (run_loop)
- base::MessageLoop::current()->Run();
+ if (should_run_loop)
+ run_loop.Run();
EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail));
ShutdownAndWaitForExitWithTimeout(handle);
+ content::RunAllPendingInMessageLoop();
profile_manager.DeleteTestingProfile("StartBrowserWithPolicy");
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
index 0b9a9b9..630fc6e 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc
@@ -6,16 +6,19 @@
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
#include "chrome/browser/net/ssl_config_service_manager.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_io_thread_state.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
#include "content/public/browser/host_zoom_map.h"
+#include "net/dns/mock_host_resolver.h"
using content::HostZoomMap;
@@ -68,7 +71,7 @@ class TestingProfileWithHostZoomMap : public TestingProfile {
scoped_ptr<Profile> off_the_record_profile_;
scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
- content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_;
+ HostZoomMap::ZoomLevelChangedCallback zoom_callback_;
DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap);
};
@@ -85,19 +88,21 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
virtual ~OffTheRecordProfileImplTest() {}
virtual void SetUp() OVERRIDE {
- prefs_.reset(new TestingPrefServiceSimple);
+ prefs_.reset(new TestingPrefServiceSimple());
chrome::RegisterLocalState(prefs_->registry());
browser_process()->SetLocalState(prefs_.get());
-
+ testing_io_thread_state_.reset(new chrome::TestingIOThreadState());
+ testing_io_thread_state_->io_thread_state()->globals()->host_resolver.reset(
+ new net::MockHostResolver());
BrowserWithTestWindowTest::SetUp();
}
virtual void TearDown() OVERRIDE {
BrowserWithTestWindowTest::TearDown();
+ testing_io_thread_state_.reset();
browser_process()->SetLocalState(NULL);
DestroyBrowserAndProfile();
- prefs_.reset();
}
private:
@@ -106,6 +111,7 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
}
scoped_ptr<TestingPrefServiceSimple> prefs_;
+ scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_;
DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImplTest);
};
@@ -178,4 +184,5 @@ TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) {
EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) <<
"Parent change should propagate to child.";
+ base::RunLoop().RunUntilIdle();
}
diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc
index 6d128a72..0386d22 100644
--- a/chrome/browser/profiles/profile_browsertest.cc
+++ b/chrome/browser/profiles/profile_browsertest.cc
@@ -186,6 +186,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) {
// for README creation).
profile.reset();
content::RunAllPendingInMessageLoop();
+ content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
}
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 57ad936..ca66dba9 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -7,8 +7,8 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
@@ -34,7 +34,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -95,10 +95,7 @@ class ProfileManagerTest : public testing::Test {
};
ProfileManagerTest()
- : local_state_(TestingBrowserProcess::GetGlobal()),
- ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_) {
+ : local_state_(TestingBrowserProcess::GetGlobal()) {
}
virtual void SetUp() {
@@ -115,7 +112,7 @@ class ProfileManagerTest : public testing::Test {
virtual void TearDown() {
TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
// Helper function to create a profile with |name| for a profile |manager|.
@@ -139,10 +136,8 @@ class ProfileManagerTest : public testing::Test {
// The path to temporary directory used to contain the test operations.
base::ScopedTempDir temp_dir_;
ScopedTestingLocalState local_state_;
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread file_thread_;
+
+ content::TestBrowserThreadBundle thread_bundle_;
#if defined(OS_CHROMEOS)
chromeos::ScopedTestUserManager test_user_manager_;
@@ -232,12 +227,12 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
Profile::EXPLICIT_ACCESS));
// Make sure any pending tasks run before we destroy the profiles.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
// Make sure history cleans up correctly.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
MATCHER(NotFail, "Profile creation failure status is not reported.") {
@@ -255,7 +250,7 @@ TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) {
CreateProfileAsync(g_browser_process->profile_manager(),
"New Profile", &mock_observer);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
MATCHER(SameNotNull, "The same non-NULL value for all calls.") {
@@ -283,7 +278,7 @@ TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) {
CreateProfileAsync(profile_manager, profile_name, &mock_observer2);
CreateProfileAsync(profile_manager, profile_name, &mock_observer3);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(ProfileManagerTest, CreateProfilesAsync) {
@@ -299,7 +294,7 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) {
CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
CreateProfileAsync(profile_manager, profile_name2, &mock_observer);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(ProfileManagerTest, GetGuestProfilePath) {
@@ -645,7 +640,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeleted) {
CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
CreateProfileAsync(profile_manager, profile_name2, &mock_observer);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size());
EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
@@ -658,7 +653,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeleted) {
profile_manager->ScheduleProfileForDeletion(dest_path1,
ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
@@ -684,13 +679,13 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) {
EXPECT_CALL(mock_observer, OnProfileCreated(
testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// Track the profile, but don't load it.
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2),
string16(), 0, false);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
EXPECT_EQ(2u, cache.GetNumberOfProfiles());
@@ -706,7 +701,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) {
ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
@@ -735,7 +730,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) {
EXPECT_CALL(mock_observer, OnProfileCreated(
testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// Create the other profiles, but don't load them. Assign a fake avatar icon
// to ensure that profiles in the info cache are sorted by the profile name,
@@ -746,7 +741,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) {
cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3),
ASCIIToUTF16(profile_name3), 2, false);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
EXPECT_EQ(3u, cache.GetNumberOfProfiles());
@@ -770,7 +765,7 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) {
profile_manager->ScheduleProfileForDeletion(dest_path2,
ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc
index 37ada0c..3e8ee59 100644
--- a/chrome/browser/safe_browsing/malware_details_unittest.cc
+++ b/chrome/browser/safe_browsing/malware_details_unittest.cc
@@ -531,7 +531,6 @@ TEST_F(MalwareDetailsTest, HTTPCache) {
UnsafeResource resource;
InitResource(&resource, true, GURL(kMalwareURL));
- profile()->CreateRequestContext();
scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
ui_manager_.get(), web_contents(), resource,
profile()->GetRequestContext());
@@ -594,7 +593,6 @@ TEST_F(MalwareDetailsTest, HTTPCache) {
expected.set_complete(true);
VerifyResults(actual, expected);
- profile()->ResetRequestContext();
}
// Tests the interaction with the HTTP cache (where the cache is empty).
@@ -605,7 +603,6 @@ TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) {
UnsafeResource resource;
InitResource(&resource, true, GURL(kMalwareURL));
- profile()->CreateRequestContext();
scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
ui_manager_.get(), web_contents(), resource,
profile()->GetRequestContext());
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 483a464..ec50a66 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -12,7 +12,7 @@
#include "chrome/browser/safe_browsing/safe_browsing_database.h"
#include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
#include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "crypto/sha2.h"
#include "sql/connection.h"
#include "sql/statement.h"
@@ -21,7 +21,6 @@
#include "url/gurl.h"
using base::Time;
-using content::BrowserThread;
namespace {
@@ -1252,10 +1251,9 @@ TEST_F(SafeBrowsingDatabaseTest, ContainsDownloadUrl) {
// Checks that the whitelists are handled properly.
TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
database_.reset();
- base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
// We expect all calls to ContainsCsdWhitelistedUrl in particular to be made
// from the IO thread. In general the whitelist lookups are thread-safe.
- content::TestBrowserThread io_thread(BrowserThread::IO, &loop);
+ content::TestBrowserThreadBundle thread_bundle_;
// If the whitelist is disabled everything should match the whitelist.
database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(),
diff --git a/chrome/browser/search/iframe_source_unittest.cc b/chrome/browser/search/iframe_source_unittest.cc
index 0dfee16..38cbba9 100644
--- a/chrome/browser/search/iframe_source_unittest.cc
+++ b/chrome/browser/search/iframe_source_unittest.cc
@@ -12,10 +12,11 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/test/mock_resource_context.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "grit/browser_resources.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -73,11 +74,10 @@ class IframeSourceTest : public testing::Test {
// else happen on the IO thread. This setup is a hacky way to satisfy all
// those constraints.
IframeSourceTest()
- : message_loop_(base::MessageLoop::TYPE_IO),
- ui_thread_(content::BrowserThread::UI, &message_loop_),
- io_thread_(content::BrowserThread::IO, &message_loop_),
- instant_io_context_(NULL),
- response_(NULL) {
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
+ resource_context_(&test_url_request_context_),
+ instant_io_context_(NULL),
+ response_(NULL) {
}
TestIframeSource* source() { return source_.get(); }
@@ -121,7 +121,7 @@ class IframeSourceTest : public testing::Test {
}
private:
- virtual void SetUp() {
+ virtual void SetUp() OVERRIDE {
source_.reset(new TestIframeSource());
callback_ = base::Bind(&IframeSourceTest::SaveResponse,
base::Unretained(this));
@@ -140,10 +140,9 @@ class IframeSourceTest : public testing::Test {
response_ = data;
}
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ net::TestURLRequestContext test_url_request_context_;
content::MockResourceContext resource_context_;
scoped_ptr<TestIframeSource> source_;
content::URLDataSource::GotDataCallback callback_;
diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
index 019c2c1..15aa4df 100644
--- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc
+++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/search_engines/search_provider_install_data.h"
@@ -30,113 +31,72 @@ namespace {
// TestGetInstallState --------------------------------------------------------
// Test the SearchProviderInstallData::GetInstallState.
-class TestGetInstallState :
- public base::RefCountedThreadSafe<TestGetInstallState> {
+class TestGetInstallState {
public:
explicit TestGetInstallState(SearchProviderInstallData* install_data);
- void set_search_provider_host(
- const std::string& search_provider_host) {
- search_provider_host_ = search_provider_host;
- }
-
- void set_default_search_provider_host(
- const std::string& default_search_provider_host) {
- default_search_provider_host_ = default_search_provider_host;
- }
-
- // Runs the test. Returns true if all passed. False if any failed.
- bool RunTests();
+ // Runs all of the test cases.
+ void RunTests(const std::string& search_provider_host,
+ const std::string& default_search_provider_host);
private:
- friend class base::RefCountedThreadSafe<TestGetInstallState>;
- ~TestGetInstallState();
-
- // Starts the test run on the IO thread.
- void StartTestOnIOThread();
-
// Callback for when SearchProviderInstallData is ready to have
// GetInstallState called. Runs all of the test cases.
- void DoInstallStateTests();
+ void DoInstallStateTests(const std::string& search_provider_host,
+ const std::string& default_search_provider_host);
// Does a verification for one url and its expected state.
void VerifyInstallState(SearchProviderInstallData::State expected_state,
const std::string& url);
SearchProviderInstallData* install_data_;
- base::MessageLoop* main_loop_;
-
- // A host which should be a search provider but not the default.
- std::string search_provider_host_;
-
- // A host which should be a search provider but not the default.
- std::string default_search_provider_host_;
-
- // Used to indicate if DoInstallStateTests passed all test.
- bool passed_;
DISALLOW_COPY_AND_ASSIGN(TestGetInstallState);
};
TestGetInstallState::TestGetInstallState(
SearchProviderInstallData* install_data)
- : install_data_(install_data),
- main_loop_(NULL),
- passed_(false) {
-}
-
-bool TestGetInstallState::RunTests() {
- passed_ = true;
-
- main_loop_ = base::MessageLoop::current();
-
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask(
- FROM_HERE,
- base::Bind(&TestGetInstallState::StartTestOnIOThread, this));
- // Run the current message loop. When the test is finished on the I/O thread,
- // it invokes Quit, which unblocks this.
- base::MessageLoop::current()->Run();
- main_loop_ = NULL;
-
- // Let the testing code know what the result is.
- return passed_;
+ : install_data_(install_data) {
}
-TestGetInstallState::~TestGetInstallState() {
-}
-
-void TestGetInstallState::StartTestOnIOThread() {
+void TestGetInstallState::RunTests(
+ const std::string& search_provider_host,
+ const std::string& default_search_provider_host) {
install_data_->CallWhenLoaded(
- base::Bind(&TestGetInstallState::DoInstallStateTests, this));
+ base::Bind(&TestGetInstallState::DoInstallStateTests,
+ base::Unretained(this),
+ search_provider_host, default_search_provider_host));
+ base::RunLoop().RunUntilIdle();
}
-void TestGetInstallState::DoInstallStateTests() {
+void TestGetInstallState::DoInstallStateTests(
+ const std::string& search_provider_host,
+ const std::string& default_search_provider_host) {
+ SCOPED_TRACE("search provider: " + search_provider_host +
+ ", default search provider: " + default_search_provider_host);
// Installed but not default.
VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT,
- "http://" + search_provider_host_ + "/");
+ "http://" + search_provider_host + "/");
VerifyInstallState(SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT,
- "http://" + search_provider_host_ + ":80/");
+ "http://" + search_provider_host + ":80/");
// Not installed.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "http://" + search_provider_host_ + ":96/");
+ "http://" + search_provider_host + ":96/");
// Not installed due to different scheme.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "https://" + search_provider_host_ + "/");
+ "https://" + search_provider_host + "/");
// Not installed.
VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED,
- "http://a" + search_provider_host_ + "/");
+ "http://a" + search_provider_host + "/");
// Installed as default.
- if (!default_search_provider_host_.empty()) {
+ if (!default_search_provider_host.empty()) {
VerifyInstallState(SearchProviderInstallData::INSTALLED_AS_DEFAULT,
- "http://" + default_search_provider_host_ + "/");
+ "http://" + default_search_provider_host + "/");
}
-
- // All done.
- main_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
}
void TestGetInstallState::VerifyInstallState(
@@ -145,16 +105,12 @@ void TestGetInstallState::VerifyInstallState(
SearchProviderInstallData::State actual_state =
install_data_->GetInstallState(GURL(url));
- if (expected_state == actual_state)
- return;
-
- passed_ = false;
- LOG(ERROR) << "GetInstallState for " << url << " failed. Expected " <<
- expected_state << ". Actual " << actual_state << ".";
+ EXPECT_EQ(expected_state, actual_state)
+ << "GetInstallState for " << url << " failed. Expected "
+ << expected_state << ". Actual " << actual_state << ".";
}
-}; // namespace
-
+} // namespace
// SearchProviderInstallDataTest ----------------------------------------------
@@ -193,7 +149,6 @@ void SearchProviderInstallDataTest::SetUp() {
std::string() /* unknown country code */);
#endif
util_.SetUp();
- util_.StartIOThread();
install_data_ = new SearchProviderInstallData(util_.profile(),
content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::Source<SearchProviderInstallDataTest>(this));
@@ -247,7 +202,6 @@ TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL(
return t_url;
}
-
// Actual tests ---------------------------------------------------------------
TEST_F(SearchProviderInstallDataTest, GetInstallState) {
@@ -257,24 +211,20 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) {
AddNewTemplateURL("http://" + host + "/path", ASCIIToUTF16("unittest"));
// Wait for the changes to be saved.
- TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state (with no default set).
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
- test_get_install_state->set_search_provider_host(host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ TestGetInstallState test_get_install_state(install_data_);
+ test_get_install_state.RunTests(host, std::string());
// Set-up a default and try it all one more time.
std::string default_host = "www.mmm.com";
TemplateURL* default_url =
AddNewTemplateURL("http://" + default_host + "/", ASCIIToUTF16("mmm"));
util_.model()->SetDefaultSearchProvider(default_url);
- test_get_install_state->set_default_search_provider_host(default_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(host, default_host);
}
-
TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
// Set up the database.
util_.ChangeModelToLoadState();
@@ -288,28 +238,23 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) {
EXPECT_TRUE(util_.model()->is_default_search_managed());
// Wait for the changes to be saved.
- util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state. The default search should be
// the managed one we previously set.
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
- test_get_install_state->set_search_provider_host(host);
- test_get_install_state->set_default_search_provider_host(host2);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ TestGetInstallState test_get_install_state(install_data_);
+ test_get_install_state.RunTests(host, host2);
}
-
TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
- scoped_refptr<TestGetInstallState> test_get_install_state(
- new TestGetInstallState(install_data_));
+ TestGetInstallState test_get_install_state(install_data_);
// Set up the database.
util_.ChangeModelToLoadState();
std::string google_host = "w.com";
util_.SetGoogleBaseURL(GURL("http://" + google_host + "/"));
// Wait for the I/O thread to process the update notification.
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
+ base::RunLoop().RunUntilIdle();
AddNewTemplateURL("{google:baseURL}?q={searchTerms}", ASCIIToUTF16("t"));
TemplateURL* default_url =
@@ -317,19 +262,17 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) {
util_.model()->SetDefaultSearchProvider(default_url);
// Wait for the changes to be saved.
- TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify the search providers install state (with no default set).
- test_get_install_state->set_search_provider_host(google_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(google_host, std::string());
// Change the Google base url.
google_host = "foo.com";
util_.SetGoogleBaseURL(GURL("http://" + google_host + "/"));
// Wait for the I/O thread to process the update notification.
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Verify that the change got picked up.
- test_get_install_state->set_search_provider_host(google_host);
- EXPECT_TRUE(test_get_install_state->RunTests());
+ test_get_install_state.RunTests(google_host, std::string());
}
diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
index e2eaec1..f55aca1 100644
--- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc
+++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_thread.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -46,12 +47,10 @@ class TemplateURLFetcherTest : public testing::Test {
virtual void SetUp() OVERRIDE {
test_util_.SetUp();
- test_util_.StartIOThread();
TestingProfile* profile = test_util_.profile();
ASSERT_TRUE(profile);
ASSERT_TRUE(TemplateURLFetcherFactory::GetForProfile(profile));
- profile->CreateRequestContext();
ASSERT_TRUE(profile->GetRequestContext());
ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady());
}
diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
index 9b8461b..643e7d38 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -4,6 +4,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -1895,7 +1896,7 @@ TEST_F(TemplateURLServiceSyncTest, PreSyncUpdates) {
// Merge the prepopulate search engines.
base::Time pre_merge_time = base::Time::Now();
- test_util_a_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
test_util_a_.ResetModel(true);
// The newly added search engine should have been safely merged, with an
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
index 850b5e3..5c5e43c 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -5,9 +5,7 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
-#include "base/synchronization/waitable_event.h"
+#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_url_tracker.h"
@@ -20,43 +18,12 @@
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-
#if defined(OS_CHROMEOS)
#include "chrome/browser/google/google_util_chromeos.h"
#endif
-using content::BrowserThread;
-
-namespace {
-
-// A callback used to coordinate when the database has finished processing
-// requests. See note in BlockTillServiceProcessesRequests for details.
-//
-// Schedules a QuitClosure on the message loop it was created with.
-void QuitCallback(base::MessageLoop* message_loop) {
- message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
-}
-
-// Blocks the caller until thread has finished servicing all pending
-// requests.
-static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
- // Schedule a task on the thread that is processed after all
- // pending requests on the thread.
- BrowserThread::PostTask(
- identifier,
- FROM_HERE,
- base::Bind(&QuitCallback, base::MessageLoop::current()));
- base::MessageLoop::current()->Run();
-}
-
-} // namespace
-
-
-// TestingTemplateURLService --------------------------------------------------
-
// Trivial subclass of TemplateURLService that records the last invocation of
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
@@ -88,14 +55,14 @@ class TestingTemplateURLService : public TemplateURLService {
DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService);
};
-
// TemplateURLServiceTestUtilBase ---------------------------------------------
TemplateURLServiceTestUtilBase::TemplateURLServiceTestUtilBase()
: changed_count_(0) {
}
-TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() {}
+TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() {
+}
void TemplateURLServiceTestUtilBase::CreateTemplateUrlService() {
profile()->CreateWebDataService();
@@ -118,18 +85,10 @@ void TemplateURLServiceTestUtilBase::ResetObserverCount() {
changed_count_ = 0;
}
-void TemplateURLServiceTestUtilBase::BlockTillServiceProcessesRequests() {
- WaitForThreadToProcessRequests(BrowserThread::DB);
-}
-
-void TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests() {
- WaitForThreadToProcessRequests(BrowserThread::IO);
-}
-
void TemplateURLServiceTestUtilBase::VerifyLoad() {
ASSERT_FALSE(model()->loaded());
model()->Load();
- BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, GetObserverCount());
ResetObserverCount();
}
@@ -140,7 +99,7 @@ void TemplateURLServiceTestUtilBase::ChangeModelToLoadState() {
// any changes made.
model()->service_ = WebDataService::FromBrowserContext(profile());
- BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
}
void TemplateURLServiceTestUtilBase::ClearModel() {
@@ -238,9 +197,7 @@ TemplateURLService* TemplateURLServiceTestUtilBase::model() const {
// TemplateURLServiceTestUtil -------------------------------------------------
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB),
- io_thread_(BrowserThread::IO) {
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
}
TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
@@ -250,7 +207,6 @@ void TemplateURLServiceTestUtil::SetUp() {
// Make unique temp directory.
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new TestingProfile(temp_dir_.path()));
- db_thread_.Start();
TemplateURLServiceTestUtilBase::CreateTemplateUrlService();
@@ -260,49 +216,14 @@ void TemplateURLServiceTestUtil::SetUp() {
}
void TemplateURLServiceTestUtil::TearDown() {
- if (profile_.get()) {
- // Clear the request context so it will get deleted. This should be done
- // before shutting down the I/O thread to avoid memory leaks.
- profile_->ResetRequestContext();
- profile_.reset();
- }
-
- // Wait for the delete of the request context to happen.
- if (io_thread_.IsRunning())
- TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests();
-
- // The I/O thread must be shutdown before the DB thread.
- io_thread_.Stop();
-
- // Note that we must ensure the DB thread is stopped after WDS
- // shutdown (so it can commit pending transactions) but before
- // deleting the test profile directory, otherwise we may not be
- // able to delete it due to an open transaction.
- // Schedule another task on the DB thread to notify us that it's safe to
- // carry on with the test.
- base::WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- base::MessageLoop::current()->Run();
- db_thread_.Stop();
+ profile_.reset();
UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
// Flush the message loop to make application verifiers happy.
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
TestingProfile* TemplateURLServiceTestUtil::profile() const {
return profile_.get();
}
-
-void TemplateURLServiceTestUtil::StartIOThread() {
- io_thread_.StartIOThread();
-}
-
-void TemplateURLServiceTestUtil::PumpLoop() {
- message_loop_.RunUntilIdle();
-}
diff --git a/chrome/browser/search_engines/template_url_service_test_util.h b/chrome/browser/search_engines/template_url_service_test_util.h
index 7ddd4fd..6c7c379 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.h
+++ b/chrome/browser/search_engines/template_url_service_test_util.h
@@ -15,7 +15,7 @@
#include "base/strings/string16.h"
#include "chrome/browser/search_engines/template_url_service_observer.h"
#include "chrome/test/base/testing_browser_process.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
class GURL;
class TemplateURLService;
@@ -42,14 +42,6 @@ class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver {
// Sets the observer count to 0.
void ResetObserverCount();
- // Blocks the caller until the service has finished servicing all pending
- // requests.
- static void BlockTillServiceProcessesRequests();
-
- // Blocks the caller until the I/O thread has finished servicing all pending
- // requests.
- static void BlockTillIOThreadProcessesRequests();
-
// Makes sure the load was successful and sent the correct notification.
void VerifyLoad();
@@ -119,19 +111,10 @@ class TemplateURLServiceTestUtil : public TemplateURLServiceTestUtilBase {
// Returns the TestingProfile.
virtual TestingProfile* profile() const OVERRIDE;
- // Starts an I/O thread.
- void StartIOThread();
-
- // Runs all pending tasks on the UI loop.
- void PumpLoop();
-
private:
- base::MessageLoopForUI message_loop_;
// Needed to make the DeleteOnUIThread trait of WebDataService work
// properly.
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
base::ScopedTempDir temp_dir_;
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index b1e95de..a230386 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
+#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -41,72 +42,6 @@ using ::testing::StrictMock;
namespace {
-// TestGenerateSearchURL ------------------------------------------------------
-
-// Test the GenerateSearchURL on a thread or the main thread.
-class TestGenerateSearchURL
- : public base::RefCountedThreadSafe<TestGenerateSearchURL> {
- public:
- explicit TestGenerateSearchURL(SearchTermsData* search_terms_data);
-
- // Run the test cases for GenerateSearchURL.
- void RunTest();
-
- // Did the test pass?
- bool passed() const { return passed_; }
-
- private:
- friend class base::RefCountedThreadSafe<TestGenerateSearchURL>;
- ~TestGenerateSearchURL();
-
- SearchTermsData* search_terms_data_;
- bool passed_;
-
- DISALLOW_COPY_AND_ASSIGN(TestGenerateSearchURL);
-};
-
-TestGenerateSearchURL::TestGenerateSearchURL(SearchTermsData* search_terms_data)
- : search_terms_data_(search_terms_data),
- passed_(false) {
-}
-
-void TestGenerateSearchURL::RunTest() {
- struct GenerateSearchURLCase {
- const char* test_name;
- const char* url;
- const char* expected;
- } generate_url_cases[] = {
- { "invalid URL", "foo{searchTerms}", "" },
- { "URL with no replacements", "http://foo/", "http://foo/" },
- { "basic functionality", "http://foo/{searchTerms}",
- "http://foo/blah.blah.blah.blah.blah" }
- };
-
- // Don't use ASSERT/EXPECT since this is run on a thread in one test
- // and those macros aren't meant for threads at this time according to
- // gtest documentation.
- bool everything_passed = true;
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
- TemplateURLData data;
- data.SetURL(generate_url_cases[i].url);
- TemplateURL t_url(NULL, data);
- std::string result = (search_terms_data_ ?
- TemplateURLService::GenerateSearchURLUsingTermsData(&t_url,
- *search_terms_data_) :
- TemplateURLService::GenerateSearchURL(&t_url)).spec();
- if (result != generate_url_cases[i].expected) {
- LOG(ERROR) << generate_url_cases[i].test_name << " failed. Expected " <<
- generate_url_cases[i].expected << " Actual " << result;
- everything_passed = false;
- }
- }
- passed_ = everything_passed;
-}
-
-TestGenerateSearchURL::~TestGenerateSearchURL() {
-}
-
-
// TestSearchTermsData --------------------------------------------------------
// Simple implementation of SearchTermsData.
@@ -303,6 +238,36 @@ class TemplateURLServiceTest : public testing::Test {
protected:
TemplateURLServiceTestUtil test_util_;
+ void TestGenerateSearchURL(SearchTermsData* search_terms_data) {
+ struct GenerateSearchURLCase {
+ const char* test_name;
+ const char* url;
+ const char* expected;
+ } generate_url_cases[] = {
+ { "invalid URL", "foo{searchTerms}", "" },
+ { "URL with no replacements", "http://foo/", "http://foo/" },
+ { "basic functionality", "http://foo/{searchTerms}",
+ "http://foo/blah.blah.blah.blah.blah" }
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
+ TemplateURLData data;
+ data.SetURL(generate_url_cases[i].url);
+ TemplateURL t_url(NULL, data);
+ std::string result;
+ if (search_terms_data) {
+ result = TemplateURLService::GenerateSearchURLUsingTermsData(
+ &t_url, *search_terms_data).spec();
+ } else {
+ result = TemplateURLService::GenerateSearchURL(&t_url).spec();
+ }
+ EXPECT_EQ(result, generate_url_cases[i].expected)
+ << generate_url_cases[i].test_name << " failed. Expected "
+ << generate_url_cases[i].expected << " Actual " << result;
+ }
+ }
+
+
DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest);
};
@@ -405,7 +370,7 @@ void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL(
ASSERT_TRUE(keyword_url != NULL);
EXPECT_EQ(t_url, keyword_url);
EXPECT_EQ(original_url, keyword_url->url_ref().DisplayURL());
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Now reload the model and verify that the merge updates the url, and
// preserves the sync GUID.
@@ -416,7 +381,7 @@ void TemplateURLServiceTest::TestLoadUpdatingPreloadedURL(
EXPECT_EQ(original_guid, keyword_url->sync_guid());
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that change was saved correctly.
test_util_.ResetModel(true);
@@ -462,7 +427,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
NULL));
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword()));
// We need to make a second copy as the model takes ownership of |t_url| and
@@ -499,7 +464,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
NULL));
ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data()));
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
test_util_.ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
@@ -676,25 +641,14 @@ TEST_F(TemplateURLServiceTest, GenerateKeyword) {
}
TEST_F(TemplateURLServiceTest, GenerateSearchURL) {
- scoped_refptr<TestGenerateSearchURL> test_generate_search_url(
- new TestGenerateSearchURL(NULL));
- test_generate_search_url->RunTest();
- EXPECT_TRUE(test_generate_search_url->passed());
+ TestGenerateSearchURL(NULL);
}
TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) {
// Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and
// wait for it to finish.
TestSearchTermsData search_terms_data("http://google.com/");
- scoped_refptr<TestGenerateSearchURL> test_generate_search_url(
- new TestGenerateSearchURL(&search_terms_data));
-
- test_util_.StartIOThread();
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask(
- FROM_HERE, base::Bind(&TestGenerateSearchURL::RunTest,
- test_generate_search_url.get()));
- TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests();
- EXPECT_TRUE(test_generate_search_url->passed());
+ TestGenerateSearchURL(&search_terms_data);
}
TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
@@ -826,7 +780,7 @@ TEST_F(TemplateURLServiceTest, Reset) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
StrictMock<base::MockTimeProvider> mock_time;
model()->set_time_provider(&base::MockTimeProvider::StaticNow);
@@ -874,7 +828,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
// Setting the default search provider should have caused notification.
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
t_url->data()));
@@ -953,7 +907,7 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
const TemplateURLID id = t_url->id();
model()->SetDefaultSearchProvider(t_url);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
t_url->data()));
@@ -1243,7 +1197,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
model()->Add(t_url);
ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging clears this engine.
test_util_.ResetModel(true);
@@ -1251,7 +1205,7 @@ TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) {
model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL);
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that the database was updated as a result of the
// merge.
@@ -1274,7 +1228,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging won't clear it if the user has edited it.
test_util_.ResetModel(true);
@@ -1284,7 +1238,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
AssertEquals(*cloned_url, *url_for_unittest);
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that save/reload retains the item.
test_util_.ResetModel(true);
@@ -1304,7 +1258,7 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
default_search->data()));
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model and check that the default search provider
// was properly saved.
@@ -1368,7 +1322,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Ensure that merging won't clear the prepopulated template url
// which is no longer present if it's the default engine.
@@ -1382,7 +1336,7 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
}
// Wait for any saves to finish.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reload the model to verify that the update was saved.
test_util_.ResetModel(true);
@@ -1418,7 +1372,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
// Now remove it.
model()->SetDefaultSearchProvider(NULL);
model()->Remove(old_default);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(model()->GetDefaultSearchProvider());
@@ -1432,7 +1386,7 @@ TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) {
model()->ResetTemplateURL(model()->GetDefaultSearchProvider(),
ASCIIToUTF16("test"), ASCIIToUTF16("test"),
"http://example.com/");
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
// Reset the model and load it. There should be a usable default search
// provider.
@@ -1454,7 +1408,7 @@ TEST_F(TemplateURLServiceTest, FailedInit) {
test_util_.ResetModel(false);
model()->Load();
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model()->GetDefaultSearchProvider());
}
@@ -1610,7 +1564,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
// Reload the model to verify it was actually saved to the database and
@@ -1647,7 +1601,7 @@ TEST_F(TemplateURLServiceTest, DuplicateInputEncodings) {
model()->Add(t_url);
VerifyObserverCount(1);
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
const TemplateURL* loaded_url =
model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
diff --git a/chrome/browser/signin/oauth2_token_service_unittest.cc b/chrome/browser/signin/oauth2_token_service_unittest.cc
index 6859f37..ba68353 100644
--- a/chrome/browser/signin/oauth2_token_service_unittest.cc
+++ b/chrome/browser/signin/oauth2_token_service_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/signin/oauth2_token_service.h"
@@ -11,6 +12,7 @@
#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/signin/token_service_unittest.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
@@ -70,19 +72,13 @@ class OAuth2TokenServiceTest : public TokenServiceTestHarness {
public:
virtual void SetUp() OVERRIDE {
TokenServiceTestHarness::SetUp();
- io_thread_.reset(new content::TestBrowserThread(content::BrowserThread::IO,
- &message_loop_));
oauth2_service_.reset(
new TestOAuth2TokenService(new net::TestURLRequestContextGetter(
- message_loop_.message_loop_proxy())));
- }
-
- virtual void TearDown() OVERRIDE {
- TokenServiceTestHarness::TearDown();
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::IO))));
}
protected:
- scoped_ptr<content::TestBrowserThread> io_thread_;
net::TestURLFetcherFactory factory_;
scoped_ptr<TestOAuth2TokenService> oauth2_service_;
TestingOAuth2TokenServiceConsumer consumer_;
@@ -91,7 +87,7 @@ class OAuth2TokenServiceTest : public TokenServiceTestHarness {
TEST_F(OAuth2TokenServiceTest, NoOAuth2RefreshToken) {
scoped_ptr<OAuth2TokenService::Request> request(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(1, consumer_.number_of_errors_);
@@ -101,7 +97,7 @@ TEST_F(OAuth2TokenServiceTest, FailureShouldNotRetry) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -119,7 +115,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithoutCaching) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -148,7 +144,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
scopes1, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -165,7 +161,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
// without needing a network request.
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(scopes1_same, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// No new network fetcher.
EXPECT_EQ(fetcher, factory_.GetFetcherByID(0));
@@ -176,7 +172,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
// Third request to a new set of scopes, should return another token.
scoped_ptr<OAuth2TokenService::Request> request3(
oauth2_service_->StartRequest(scopes2, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
fetcher = factory_.GetFetcherByID(0);
@@ -195,7 +191,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndFailure) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
@@ -210,7 +206,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndFailure) {
// Second request must try to access the network as the token has expired.
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -230,7 +226,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndSuccess) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
@@ -245,7 +241,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndSuccess) {
// Second request must try to access the network as the token has expired.
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -264,7 +260,7 @@ TEST_F(OAuth2TokenServiceTest, RequestDeletedBeforeCompletion) {
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
@@ -284,7 +280,7 @@ TEST_F(OAuth2TokenServiceTest, RequestDeletedAfterCompletion) {
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
fetcher->SetResponseString(GetValidTokenResponse("token", 3600));
@@ -305,10 +301,10 @@ TEST_F(OAuth2TokenServiceTest, MultipleRequestsForTheSameScopesWithOneDeleted) {
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
request.reset();
@@ -325,7 +321,7 @@ TEST_F(OAuth2TokenServiceTest, ClearedRefreshTokenFailsSubsequentRequests) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
fetcher->SetResponseString(GetValidTokenResponse("token", 3600));
@@ -337,7 +333,7 @@ TEST_F(OAuth2TokenServiceTest, ClearedRefreshTokenFailsSubsequentRequests) {
// The refresh token is no longer available; subsequent requests fail.
oauth2_service_->set_refresh_token("");
request = oauth2_service_->StartRequest(std::set<std::string>(), &consumer_);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(fetcher, factory_.GetFetcherByID(0));
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(1, consumer_.number_of_errors_);
@@ -352,7 +348,7 @@ TEST_F(OAuth2TokenServiceTest,
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
scopes, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher1 = factory_.GetFetcherByID(0);
// Note |request| is still pending when the refresh token changes.
@@ -363,7 +359,7 @@ TEST_F(OAuth2TokenServiceTest,
TestingOAuth2TokenServiceConsumer consumer2;
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(scopes, &consumer2));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher2 = factory_.GetFetcherByID(0);
fetcher2->set_response_code(net::HTTP_OK);
@@ -385,7 +381,7 @@ TEST_F(OAuth2TokenServiceTest, ServiceShutDownBeforeFetchComplete) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -401,7 +397,7 @@ TEST_F(OAuth2TokenServiceTest, RetryingConsumer) {
RetryingTestingOAuth2TokenServiceConsumer consumer(oauth2_service_.get());
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
std::set<std::string>(), &consumer));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer.number_of_successful_tokens_);
EXPECT_EQ(0, consumer.number_of_errors_);
@@ -429,7 +425,7 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(
oauth2_service_->StartRequest(scopes, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -446,7 +442,7 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
// request.
scoped_ptr<OAuth2TokenService::Request> request2(
oauth2_service_->StartRequest(scopes, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
// No new network fetcher.
EXPECT_EQ(fetcher, factory_.GetFetcherByID(0));
@@ -458,7 +454,7 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
oauth2_service_->InvalidateToken(scopes, consumer_.last_token_);
scoped_ptr<OAuth2TokenService::Request> request3(
oauth2_service_->StartRequest(scopes, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
fetcher = factory_.GetFetcherByID(0);
diff --git a/chrome/browser/signin/profile_oauth2_token_service_unittest.cc b/chrome/browser/signin/profile_oauth2_token_service_unittest.cc
index 8170bfe..0cbb571 100644
--- a/chrome/browser/signin/profile_oauth2_token_service_unittest.cc
+++ b/chrome/browser/signin/profile_oauth2_token_service_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/run_loop.h"
#include "chrome/browser/signin/oauth2_token_service.h"
#include "chrome/browser/signin/oauth2_token_service_test_util.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
@@ -27,12 +28,9 @@ class ProfileOAuth2TokenServiceTest : public TokenServiceTestHarness,
virtual void SetUp() OVERRIDE {
TokenServiceTestHarness::SetUp();
- io_thread_.reset(new content::TestBrowserThread(content::BrowserThread::IO,
- &message_loop_));
- service_->UpdateCredentials(credentials_);
- profile_->CreateRequestContext();
+ UpdateCredentialsOnService();
oauth2_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(
- profile_.get());
+ profile());
oauth2_service_->AddObserver(this);
}
@@ -106,7 +104,6 @@ class ProfileOAuth2TokenServiceTest : public TokenServiceTestHarness,
}
protected:
- scoped_ptr<content::TestBrowserThread> io_thread_;
net::TestURLFetcherFactory factory_;
ProfileOAuth2TokenService* oauth2_service_;
TestingOAuth2TokenServiceConsumer consumer_;
@@ -118,12 +115,12 @@ class ProfileOAuth2TokenServiceTest : public TokenServiceTestHarness,
TEST_F(ProfileOAuth2TokenServiceTest, Notifications) {
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
ExpectOneTokenAvailableNotification();
- service_->EraseTokensFromDB();
- service_->ResetCredentialsInMemory();
+ service()->EraseTokensFromDB();
+ service()->ResetCredentialsInMemory();
ExpectOneTokensClearedNotification();
}
@@ -133,11 +130,11 @@ TEST_F(ProfileOAuth2TokenServiceTest, LsoNotification) {
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
// Get a valid token.
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
ExpectOneTokenAvailableNotification();
- service_->OnIssueAuthTokenFailure(
+ service()->OnIssueAuthTokenFailure(
GaiaConstants::kLSOService,
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
ExpectOneTokenRevokedNotification();
@@ -147,22 +144,22 @@ TEST_F(ProfileOAuth2TokenServiceTest, LsoNotification) {
// should translate to finish token loading in ProfileOAuth2TokenService.
TEST_F(ProfileOAuth2TokenServiceTest, TokensLoaded) {
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
- service_->LoadTokensFromDB();
- WaitForDBLoadCompletion();
+ service()->LoadTokensFromDB();
+ base::RunLoop().RunUntilIdle();
ExpectOneTokensLoadedNotification();
}
TEST_F(ProfileOAuth2TokenServiceTest, UnknownNotificationsAreNoops) {
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
- service_->IssueAuthTokenForTest("foo", "toto");
+ service()->IssueAuthTokenForTest("foo", "toto");
ExpectNoNotifications();
// Get a valid token.
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
ExpectOneTokenAvailableNotification();
- service_->IssueAuthTokenForTest("bar", "baz");
+ service()->IssueAuthTokenForTest("bar", "baz");
ExpectNoNotifications();
}
@@ -170,12 +167,12 @@ TEST_F(ProfileOAuth2TokenServiceTest, TokenServiceUpdateClearsCache) {
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
std::set<std::string> scope_list;
scope_list.insert("scope");
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
ExpectOneTokenAvailableNotification();
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
scope_list, &consumer_));
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
fetcher->SetResponseString(GetValidTokenResponse("token", 3600));
@@ -186,19 +183,19 @@ TEST_F(ProfileOAuth2TokenServiceTest, TokenServiceUpdateClearsCache) {
EXPECT_EQ(1, oauth2_service_->cache_size_for_testing());
// Signs out and signs in
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
"");
ExpectOneTokenAvailableNotification();
- service_->EraseTokensFromDB();
+ service()->EraseTokensFromDB();
ExpectOneTokensClearedNotification();
EXPECT_EQ(0, oauth2_service_->cache_size_for_testing());
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
"refreshToken");
ExpectOneTokenAvailableNotification();
request = oauth2_service_->StartRequest(scope_list, &consumer_);
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
fetcher->SetResponseString(GetValidTokenResponse("another token", 3600));
@@ -212,19 +209,19 @@ TEST_F(ProfileOAuth2TokenServiceTest, TokenServiceUpdateClearsCache) {
// Android doesn't use the current profile's TokenService login refresh token.
#if !defined(OS_ANDROID)
TEST_F(ProfileOAuth2TokenServiceTest, StaleRefreshTokensNotCached) {
- EXPECT_FALSE(service_->HasOAuthLoginToken());
- EXPECT_FALSE(oauth2_service_->ShouldCacheForRefreshToken(service_, "T1"));
+ EXPECT_FALSE(service()->HasOAuthLoginToken());
+ EXPECT_FALSE(oauth2_service_->ShouldCacheForRefreshToken(service(), "T1"));
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
"T1");
ExpectOneTokenAvailableNotification();
- EXPECT_TRUE(oauth2_service_->ShouldCacheForRefreshToken(service_, "T1"));
- EXPECT_FALSE(oauth2_service_->ShouldCacheForRefreshToken(service_, "T2"));
+ EXPECT_TRUE(oauth2_service_->ShouldCacheForRefreshToken(service(), "T1"));
+ EXPECT_FALSE(oauth2_service_->ShouldCacheForRefreshToken(service(), "T2"));
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
"T2");
ExpectOneTokenAvailableNotification();
- EXPECT_TRUE(oauth2_service_->ShouldCacheForRefreshToken(service_, "T2"));
+ EXPECT_TRUE(oauth2_service_->ShouldCacheForRefreshToken(service(), "T2"));
EXPECT_FALSE(oauth2_service_->ShouldCacheForRefreshToken(NULL, "T2"));
}
#endif
diff --git a/chrome/browser/signin/signin_manager_unittest.cc b/chrome/browser/signin/signin_manager_unittest.cc
index 232d9c5..f008430 100644
--- a/chrome/browser/signin/signin_manager_unittest.cc
+++ b/chrome/browser/signin/signin_manager_unittest.cc
@@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_service.h"
+#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -22,7 +23,7 @@
#include "chrome/test/base/testing_profile.h"
#include "components/webdata/encryptor/encryptor.h"
#include "content/public/browser/child_process_security_policy.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/cookies/cookie_monster.h"
@@ -34,8 +35,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
namespace {
const char kGetTokenPairValidResponse[] =
@@ -53,18 +52,6 @@ const char kUberAuthTokenURLFormat[] = "%s?source=%s&issueuberauth=1";
class SigninManagerTest : public TokenServiceTestHarness {
public:
- void SetUpOnIOThread(base::WaitableEvent* io_setup_complete) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // This is a workaround for a bug in the TestingProfile.
- // The URLRequestContext will be created by GetCookieMonster on the UI
- // thread, if it does not already exist. But it must be created on the IO
- // thread or else it will DCHECK upon destruction.
- // Force it to be created here.
- profile_->CreateRequestContext();
- profile_->GetRequestContext()->GetURLRequestContext();
- io_setup_complete->Signal();
- }
-
virtual void SetUp() OVERRIDE {
prefs_.reset(new TestingPrefServiceSimple);
chrome::RegisterLocalState(prefs_->registry());
@@ -73,32 +60,22 @@ class SigninManagerTest : public TokenServiceTestHarness {
TokenServiceTestHarness::SetUp();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
+ new ChromeSigninManagerDelegate(profile()))));
google_login_success_.ListenFor(
chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
- content::Source<Profile>(profile_.get()));
+ content::Source<Profile>(profile()));
google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
- content::Source<Profile>(profile_.get()));
-
- io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
- ASSERT_TRUE(io_thread_->Start());
- base::WaitableEvent io_setup_complete(true, false);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&SigninManagerTest::SetUpOnIOThread,
- base::Unretained(this), &io_setup_complete));
- io_setup_complete.Wait();
+ content::Source<Profile>(profile()));
}
virtual void TearDown() OVERRIDE {
- // Destroy the SigninManager here, because it relies on profile_ which is
+ // Destroy the SigninManager here, because it relies on profile() which is
// freed in the base class.
manager_->Shutdown();
manager_.reset(NULL);
TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
prefs_.reset(NULL);
TokenServiceTestHarness::TearDown();
- io_thread_->Stop();
}
void SetupFetcherAndComplete(const std::string& url,
@@ -170,26 +147,6 @@ class SigninManagerTest : public TokenServiceTestHarness {
cookies, "<html></html>");
}
- void WaitUntilUIDone() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&SigninManagerTest::NotifyUIOnComplete,
- base::Unretained(this)));
- base::MessageLoop::current()->Run();
- }
-
- void NotifyUIOnComplete () {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- // Redo on UI thread.
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&SigninManagerTest::NotifyUIOnComplete,
- base::Unretained(this)));
- return;
- }
- base::MessageLoop::current()->Quit();
- }
-
void ExpectSignInWithCredentialsSuccess() {
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
@@ -199,7 +156,7 @@ class SigninManagerTest : public TokenServiceTestHarness {
// This is flow, the oauth2 credentials should already be available in
// the token service.
- EXPECT_TRUE(service_->HasOAuthLoginToken());
+ EXPECT_TRUE(service()->HasOAuthLoginToken());
// Should go into token service and stop.
EXPECT_EQ(1U, google_login_success_.size());
@@ -209,8 +166,8 @@ class SigninManagerTest : public TokenServiceTestHarness {
manager_->Shutdown();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
- manager_->Initialize(profile_.get(), NULL);
+ new ChromeSigninManagerDelegate(profile()))));
+ manager_->Initialize(profile(), NULL);
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
}
@@ -226,7 +183,7 @@ class SigninManagerTest : public TokenServiceTestHarness {
// The oauth2 credentials should not be available in the token service
// because the email was incorrect.
- EXPECT_FALSE(service_->HasOAuthLoginToken());
+ EXPECT_FALSE(service()->HasOAuthLoginToken());
// Should go into token service and stop.
EXPECT_EQ(0U, google_login_success_.size());
@@ -249,14 +206,13 @@ class SigninManagerTest : public TokenServiceTestHarness {
content::TestNotificationTracker google_login_failure_;
std::vector<std::string> oauth_tokens_fetched_;
scoped_ptr<TestingPrefServiceSimple> prefs_;
- scoped_ptr<content::TestBrowserThread> io_thread_;
std::vector<std::string> cookies_;
};
// NOTE: ClientLogin's "StartSignin" is called after collecting credentials
// from the user.
TEST_F(SigninManagerTest, SignInClientLogin) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->StartSignIn(
@@ -270,8 +226,9 @@ TEST_F(SigninManagerTest, SignInClientLogin) {
EXPECT_EQ(1U, google_login_success_.size());
EXPECT_EQ(0U, google_login_failure_.size());
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "oauth2Token");
+ service()->OnIssueAuthTokenSuccess(
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "oauth2Token");
SimulateValidUberToken();
// Check that the login cookie has been sent.
ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"),
@@ -281,13 +238,13 @@ TEST_F(SigninManagerTest, SignInClientLogin) {
manager_->Shutdown();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
- manager_->Initialize(profile_.get(), NULL);
+ new ChromeSigninManagerDelegate(profile()))));
+ manager_->Initialize(profile(), NULL);
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
}
TEST_F(SigninManagerTest, SignInWithCredentials) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->StartSignInWithCredentials(
@@ -300,7 +257,7 @@ TEST_F(SigninManagerTest, SignInWithCredentials) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->StartSignInWithCredentials(
@@ -313,7 +270,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// If the email address used to start the sign in does not match the
@@ -328,12 +285,12 @@ TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// Set a valid LSID cookie in the test cookie store.
scoped_refptr<net::CookieMonster> cookie_monster =
- profile_->GetCookieMonster();
+ profile()->GetCookieMonster();
net::CookieOptions options;
options.set_include_httponly();
cookie_monster->SetCookieWithOptionsAsync(
@@ -348,14 +305,14 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) {
std::string(),
SigninManager::OAuthTokenFetchedCallback());
- WaitUntilUIDone();
+ base::RunLoop().RunUntilIdle();
// Verification should succeed and continue with auto signin.
ExpectSignInWithCredentialsSuccess();
}
TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// Since the password is empty, will verify the gaia cookies first.
@@ -365,7 +322,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) {
std::string(),
SigninManager::OAuthTokenFetchedCallback());
- WaitUntilUIDone();
+ base::RunLoop().RunUntilIdle();
// Since the test cookie store is empty, verification should fail and throws
// a login error.
@@ -373,12 +330,12 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// Set an invalid LSID cookie in the test cookie store.
scoped_refptr<net::CookieMonster> cookie_monster =
- profile_->GetCookieMonster();
+ profile()->GetCookieMonster();
net::CookieOptions options;
options.set_include_httponly();
cookie_monster->SetCookieWithOptionsAsync(
@@ -393,7 +350,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
std::string(),
SigninManager::OAuthTokenFetchedCallback());
- WaitUntilUIDone();
+ base::RunLoop().RunUntilIdle();
// Since the LSID cookie is invalid, verification should fail and throws
// a login error.
@@ -401,7 +358,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// Since the password is empty, must verify the gaia cookies first.
@@ -420,7 +377,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) {
}
TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
// Since the password is empty, must verify the gaia cookies first.
@@ -440,7 +397,7 @@ TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) {
}
TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->StartSignIn("username", "password", std::string(), std::string());
@@ -451,7 +408,7 @@ TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) {
}
TEST_F(SigninManagerTest, ClearTransientSigninData) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->StartSignIn("username", "password", std::string(), std::string());
@@ -472,24 +429,24 @@ TEST_F(SigninManagerTest, ClearTransientSigninData) {
// Ensure preferences are not modified.
EXPECT_FALSE(
- profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
+ profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
// On reset it should be regenerated.
manager_->Shutdown();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
- manager_->Initialize(profile_.get(), NULL);
+ new ChromeSigninManagerDelegate(profile()))));
+ manager_->Initialize(profile(), NULL);
// Now make sure we have the right user name.
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
}
TEST_F(SigninManagerTest, SignOutClientLogin) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
manager_->StartSignIn("username", "password", std::string(), std::string());
SimulateValidResponseClientLogin(false);
- manager_->OnClientLoginSuccess(credentials_);
+ manager_->OnClientLoginSuccess(credentials());
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
manager_->SignOut();
@@ -498,13 +455,13 @@ TEST_F(SigninManagerTest, SignOutClientLogin) {
manager_->Shutdown();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
- manager_->Initialize(profile_.get(), NULL);
+ new ChromeSigninManagerDelegate(profile()))));
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
}
TEST_F(SigninManagerTest, SignInFailureClientLogin) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
manager_->StartSignIn("username", "password", std::string(), std::string());
GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
manager_->OnClientLoginFailure(error);
@@ -518,13 +475,13 @@ TEST_F(SigninManagerTest, SignInFailureClientLogin) {
manager_->Shutdown();
manager_.reset(new SigninManager(
scoped_ptr<SigninManagerDelegate>(
- new ChromeSigninManagerDelegate(profile_.get()))));
- manager_->Initialize(profile_.get(), NULL);
+ new ChromeSigninManagerDelegate(profile()))));
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
}
TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
manager_->StartSignIn("username", "password", std::string(), std::string());
GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
manager_->OnClientLoginFailure(error);
@@ -543,7 +500,7 @@ TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
}
TEST_F(SigninManagerTest, ProvideSecondFactorFailure) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
manager_->StartSignIn("username", "password", std::string(), std::string());
GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR);
manager_->OnClientLoginFailure(error1);
@@ -573,7 +530,7 @@ TEST_F(SigninManagerTest, ProvideSecondFactorFailure) {
}
TEST_F(SigninManagerTest, SignOutMidConnect) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
manager_->StartSignIn("username", "password", std::string(), std::string());
EXPECT_EQ("username", manager_->GetUsernameForAuthInProgress());
manager_->SignOut();
@@ -585,7 +542,7 @@ TEST_F(SigninManagerTest, SignOutMidConnect) {
}
TEST_F(SigninManagerTest, SignOutWhileProhibited) {
- manager_->Initialize(profile_.get(), NULL);
+ manager_->Initialize(profile(), NULL);
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
manager_->SetAuthenticatedUsername("user@gmail.com");
@@ -617,7 +574,7 @@ TEST_F(SigninManagerTest, TestIsWebBasedSigninFlowURL) {
TEST_F(SigninManagerTest, Prohibited) {
g_browser_process->local_state()->SetString(
prefs::kGoogleServicesUsernamePattern, ".*@google.com");
- manager_->Initialize(profile_.get(), g_browser_process->local_state());
+ manager_->Initialize(profile(), g_browser_process->local_state());
EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
@@ -630,7 +587,7 @@ TEST_F(SigninManagerTest, TestAlternateWildcard) {
// the admin entered ".*@google.com").
g_browser_process->local_state()->SetString(
prefs::kGoogleServicesUsernamePattern, "*@google.com");
- manager_->Initialize(profile_.get(), g_browser_process->local_state());
+ manager_->Initialize(profile(), g_browser_process->local_state());
EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
@@ -639,19 +596,19 @@ TEST_F(SigninManagerTest, TestAlternateWildcard) {
}
TEST_F(SigninManagerTest, ProhibitedAtStartup) {
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
- "monkey@invalid.com");
+ profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
+ "monkey@invalid.com");
g_browser_process->local_state()->SetString(
prefs::kGoogleServicesUsernamePattern, ".*@google.com");
- manager_->Initialize(profile_.get(), g_browser_process->local_state());
+ manager_->Initialize(profile(), g_browser_process->local_state());
// Currently signed in user is prohibited by policy, so should be signed out.
EXPECT_EQ("", manager_->GetAuthenticatedUsername());
}
TEST_F(SigninManagerTest, ProhibitedAfterStartup) {
std::string user("monkey@invalid.com");
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user);
- manager_->Initialize(profile_.get(), g_browser_process->local_state());
+ profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user);
+ manager_->Initialize(profile(), g_browser_process->local_state());
EXPECT_EQ(user, manager_->GetAuthenticatedUsername());
// Update the profile - user should be signed out.
g_browser_process->local_state()->SetString(
@@ -660,9 +617,9 @@ TEST_F(SigninManagerTest, ProhibitedAfterStartup) {
}
TEST_F(SigninManagerTest, ExternalSignIn) {
- manager_->Initialize(profile_.get(), g_browser_process->local_state());
+ manager_->Initialize(profile(), g_browser_process->local_state());
EXPECT_EQ("",
- profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
+ profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
EXPECT_EQ("", manager_->GetAuthenticatedUsername());
EXPECT_EQ(0u, google_login_success_.size());
@@ -670,6 +627,6 @@ TEST_F(SigninManagerTest, ExternalSignIn) {
EXPECT_EQ(1u, google_login_success_.size());
EXPECT_EQ(0u, google_login_failure_.size());
EXPECT_EQ("external@example.com",
- profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
+ profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername());
}
diff --git a/chrome/browser/signin/token_service_unittest.cc b/chrome/browser/signin/token_service_unittest.cc
index 50dc429..0617ae5 100644
--- a/chrome/browser/signin/token_service_unittest.cc
+++ b/chrome/browser/signin/token_service_unittest.cc
@@ -9,8 +9,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
-#include "base/synchronization/waitable_event.h"
+#include "base/run_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/webdata/token_web_data.h"
@@ -20,8 +19,6 @@
#include "google_apis/gaia/mock_url_fetcher_factory.h"
#include "net/url_request/test_url_fetcher_factory.h"
-using content::BrowserThread;
-
TokenAvailableTracker::TokenAvailableTracker() {}
TokenAvailableTracker::~TokenAvailableTracker() {}
@@ -52,10 +49,7 @@ void TokenFailedTracker::Observe(int type,
}
}
-TokenServiceTestHarness::TokenServiceTestHarness()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB) {
-}
+TokenServiceTestHarness::TokenServiceTestHarness() {}
TokenServiceTestHarness::~TokenServiceTestHarness() {}
@@ -70,12 +64,13 @@ void TokenServiceTestHarness::SetUp() {
oauth_token_ = "oauth";
oauth_secret_ = "secret";
- ASSERT_TRUE(db_thread_.Start());
-
profile_.reset(new TestingProfile());
profile_->CreateWebDataService();
- WaitForDBLoadCompletion();
+ // Force the loading of the WebDataService.
+ TokenWebData::FromBrowserContext(profile_.get());
+ base::RunLoop().RunUntilIdle();
+
service_ = TokenServiceFactory::GetForProfile(profile_.get());
success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE,
@@ -83,103 +78,78 @@ void TokenServiceTestHarness::SetUp() {
failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
content::Source<TokenService>(service_));
- service_->Initialize("test", profile_.get());
+ service()->Initialize("test", profile_.get());
}
void TokenServiceTestHarness::TearDown() {
- // You have to destroy the profile before the db_thread_ stops.
- if (profile_.get()) {
- profile_.reset(NULL);
- }
- // Schedule another task on the DB thread to notify us that it's safe to
- // carry on with the test.
- base::WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- base::MessageLoop::current()->Run();
- db_thread_.Stop();
+ // You have to destroy the profile before the threads are shut down.
+ profile_.reset();
}
-void TokenServiceTestHarness::WaitForDBLoadCompletion() {
- // Force the loading of the WebDataService.
- TokenWebData::FromBrowserContext(profile_.get());
-
- // The WebDB does all work on the DB thread. This will add an event
- // to the end of the DB thread, so when we reach this task, all DB
- // operations should be complete.
- base::WaitableEvent done(false, false);
- BrowserThread::PostTask(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
- done.Wait();
-
- // Notifications should be returned from the DB thread onto the UI thread.
- message_loop_.RunUntilIdle();
+void TokenServiceTestHarness::UpdateCredentialsOnService() {
+ service()->UpdateCredentials(credentials_);
}
class TokenServiceTest : public TokenServiceTestHarness {
public:
virtual void SetUp() {
TokenServiceTestHarness::SetUp();
- service_->UpdateCredentials(credentials_);
+ UpdateCredentialsOnService();
}
protected:
void TestLoadSingleToken(
std::map<std::string, std::string>* db_tokens,
std::map<std::string, std::string>* memory_tokens,
- const std::string& service) {
- std::string token = service + "_token";
- (*db_tokens)[service] = token;
- size_t prev_success_size = success_tracker_.size();
- service_->LoadTokensIntoMemory(*db_tokens, memory_tokens);
+ const std::string& service_name) {
+ std::string token = service_name + "_token";
+ (*db_tokens)[service_name] = token;
+ size_t prev_success_size = success_tracker()->size();
+ service()->LoadTokensIntoMemory(*db_tokens, memory_tokens);
// Check notification.
- EXPECT_EQ(prev_success_size + 1, success_tracker_.size());
- TokenService::TokenAvailableDetails details = success_tracker_.details();
- EXPECT_EQ(details.service(), service);
+ EXPECT_EQ(prev_success_size + 1, success_tracker()->size());
+ TokenService::TokenAvailableDetails details = success_tracker()->details();
+ EXPECT_EQ(details.service(), service_name);
EXPECT_EQ(details.token(), token);
// Check memory tokens.
- EXPECT_EQ(1U, memory_tokens->count(service));
- EXPECT_EQ((*memory_tokens)[service], token);
+ EXPECT_EQ(1U, memory_tokens->count(service_name));
+ EXPECT_EQ((*memory_tokens)[service_name], token);
}
};
TEST_F(TokenServiceTest, SanityCheck) {
- EXPECT_FALSE(service_->HasTokenForService("nonexistent service"));
- EXPECT_FALSE(service_->TokensLoadedFromDB());
+ EXPECT_FALSE(service()->HasTokenForService("nonexistent service"));
+ EXPECT_FALSE(service()->TokensLoadedFromDB());
}
TEST_F(TokenServiceTest, NoToken) {
- EXPECT_FALSE(service_->HasTokenForService("nonexistent service"));
- EXPECT_EQ(service_->GetTokenForService("nonexistent service"), std::string());
+ EXPECT_FALSE(service()->HasTokenForService("nonexistent service"));
+ EXPECT_EQ(service()->GetTokenForService("nonexistent service"),
+ std::string());
}
TEST_F(TokenServiceTest, NotificationSuccess) {
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- EXPECT_EQ(1U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ EXPECT_EQ(1U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
- TokenService::TokenAvailableDetails details = success_tracker_.details();
+ TokenService::TokenAvailableDetails details = success_tracker()->details();
// MSVC doesn't like this comparison as EQ.
EXPECT_TRUE(details.service() == GaiaConstants::kSyncService);
EXPECT_EQ(details.token(), "token");
}
TEST_F(TokenServiceTest, NotificationOAuthLoginTokenSuccess) {
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
- service_->OnClientOAuthSuccess(
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
+ service()->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600));
- EXPECT_EQ(1U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
+ EXPECT_EQ(1U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
- TokenService::TokenAvailableDetails details = success_tracker_.details();
+ TokenService::TokenAvailableDetails details = success_tracker()->details();
// MSVC doesn't like this comparison as EQ.
EXPECT_TRUE(details.service() ==
GaiaConstants::kGaiaOAuth2LoginRefreshToken);
@@ -187,28 +157,30 @@ TEST_F(TokenServiceTest, NotificationOAuthLoginTokenSuccess) {
}
TEST_F(TokenServiceTest, NotificationFailed) {
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
- service_->OnIssueAuthTokenFailure(GaiaConstants::kSyncService, error);
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(1U, failure_tracker_.size());
+ service()->OnIssueAuthTokenFailure(GaiaConstants::kSyncService, error);
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(1U, failure_tracker()->size());
- TokenService::TokenRequestFailedDetails details = failure_tracker_.details();
+ TokenService::TokenRequestFailedDetails details =
+ failure_tracker()->details();
// MSVC doesn't like this comparison as EQ.
EXPECT_TRUE(details.service() == GaiaConstants::kSyncService);
EXPECT_TRUE(details.error() == error); // Struct has no print function.
}
TEST_F(TokenServiceTest, NotificationOAuthLoginTokenFailed) {
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(0U, failure_tracker_.size());
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(0U, failure_tracker()->size());
GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
- service_->OnClientOAuthFailure(error);
- EXPECT_EQ(0U, success_tracker_.size());
- EXPECT_EQ(1U, failure_tracker_.size());
+ service()->OnClientOAuthFailure(error);
+ EXPECT_EQ(0U, success_tracker()->size());
+ EXPECT_EQ(1U, failure_tracker()->size());
- TokenService::TokenRequestFailedDetails details = failure_tracker_.details();
+ TokenService::TokenRequestFailedDetails details =
+ failure_tracker()->details();
// MSVC doesn't like this comparison as EQ.
EXPECT_TRUE(details.service() ==
@@ -217,69 +189,73 @@ TEST_F(TokenServiceTest, NotificationOAuthLoginTokenFailed) {
}
TEST_F(TokenServiceTest, OnTokenSuccessUpdate) {
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "token");
-
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token2");
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService),
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService),
+ "token");
+
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token2");
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService),
"token2");
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, std::string());
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "");
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService,
+ std::string());
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService), "");
}
TEST_F(TokenServiceTest, OnOAuth2LoginTokenSuccessUpdate) {
- EXPECT_FALSE(service_->HasOAuthLoginToken());
+ EXPECT_FALSE(service()->HasOAuthLoginToken());
- service_->OnClientOAuthSuccess(
+ service()->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600));
- EXPECT_TRUE(service_->HasOAuthLoginToken());
- EXPECT_EQ(service_->GetOAuth2LoginRefreshToken(), "rt1");
+ EXPECT_TRUE(service()->HasOAuthLoginToken());
+ EXPECT_EQ(service()->GetOAuth2LoginRefreshToken(), "rt1");
- service_->OnClientOAuthSuccess(
+ service()->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("rt2", "at2", 3600));
- EXPECT_TRUE(service_->HasOAuthLoginToken());
- EXPECT_EQ(service_->GetOAuth2LoginRefreshToken(), "rt2");
+ EXPECT_TRUE(service()->HasOAuthLoginToken());
+ EXPECT_EQ(service()->GetOAuth2LoginRefreshToken(), "rt2");
- service_->OnClientOAuthSuccess(
+ service()->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("rt3", "at3", 3600));
- EXPECT_TRUE(service_->HasOAuthLoginToken());
- EXPECT_EQ(service_->GetOAuth2LoginRefreshToken(), "rt3");
+ EXPECT_TRUE(service()->HasOAuthLoginToken());
+ EXPECT_EQ(service()->GetOAuth2LoginRefreshToken(), "rt3");
}
TEST_F(TokenServiceTest, OnTokenSuccess) {
// Don't "start fetching", just go ahead and issue the callback.
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
// Gaia returns the entire result as the token so while this is a shared
// result with ClientLogin, it doesn't matter, we should still get it back.
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "token");
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService),
+ "token");
}
TEST_F(TokenServiceTest, Reset) {
net::TestURLFetcherFactory factory;
- service_->StartFetchingTokens();
+ service()->StartFetchingTokens();
// You have to call delegates by hand with the test fetcher,
// Let's pretend only one returned.
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "eraseme");
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService),
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "eraseme");
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService),
"eraseme");
- service_->ResetCredentialsInMemory();
- EXPECT_FALSE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ service()->ResetCredentialsInMemory();
+ EXPECT_FALSE(service()->HasTokenForService(GaiaConstants::kSyncService));
// Now start using it again.
- service_->UpdateCredentials(credentials_);
- service_->StartFetchingTokens();
+ UpdateCredentialsOnService();
+ service()->StartFetchingTokens();
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "token");
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService),
+ "token");
}
TEST_F(TokenServiceTest, FullIntegration) {
@@ -288,17 +264,17 @@ TEST_F(TokenServiceTest, FullIntegration) {
{
MockURLFetcherFactory<MockFetcher> factory;
factory.set_results(result);
- EXPECT_FALSE(service_->HasTokenForService(GaiaConstants::kSyncService));
- service_->StartFetchingTokens();
+ EXPECT_FALSE(service()->HasTokenForService(GaiaConstants::kSyncService));
+ service()->StartFetchingTokens();
}
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
// Gaia returns the entire result as the token so while this is a shared
// result with ClientLogin, it doesn't matter, we should still get it back.
- EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), result);
+ EXPECT_EQ(service()->GetTokenForService(GaiaConstants::kSyncService), result);
- service_->ResetCredentialsInMemory();
- EXPECT_FALSE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ service()->ResetCredentialsInMemory();
+ EXPECT_FALSE(service()->HasTokenForService(GaiaConstants::kSyncService));
}
TEST_F(TokenServiceTest, LoadTokensIntoMemoryBasic) {
@@ -306,11 +282,11 @@ TEST_F(TokenServiceTest, LoadTokensIntoMemoryBasic) {
std::map<std::string, std::string> db_tokens;
std::map<std::string, std::string> memory_tokens;
- EXPECT_FALSE(service_->TokensLoadedFromDB());
- service_->LoadTokensIntoMemory(db_tokens, &memory_tokens);
+ EXPECT_FALSE(service()->TokensLoadedFromDB());
+ service()->LoadTokensIntoMemory(db_tokens, &memory_tokens);
EXPECT_TRUE(db_tokens.empty());
EXPECT_TRUE(memory_tokens.empty());
- EXPECT_EQ(0U, success_tracker_.size());
+ EXPECT_EQ(0U, success_tracker()->size());
std::vector<std::string> services;
TokenService::GetServiceNames(&services);
@@ -331,80 +307,80 @@ TEST_F(TokenServiceTest, LoadTokensIntoMemoryAdvanced) {
db_tokens["ignore"] = "token";
- service_->LoadTokensIntoMemory(db_tokens, &memory_tokens);
+ service()->LoadTokensIntoMemory(db_tokens, &memory_tokens);
EXPECT_TRUE(memory_tokens.empty());
db_tokens[GaiaConstants::kSyncService] = "pepper";
- service_->LoadTokensIntoMemory(db_tokens, &memory_tokens);
+ service()->LoadTokensIntoMemory(db_tokens, &memory_tokens);
EXPECT_EQ(1U, memory_tokens.count(GaiaConstants::kSyncService));
EXPECT_EQ(memory_tokens[GaiaConstants::kSyncService], "pepper");
- EXPECT_EQ(1U, success_tracker_.size());
- success_tracker_.Reset();
+ EXPECT_EQ(1U, success_tracker()->size());
+ success_tracker()->Reset();
// SyncService token is already in memory. Pretend we got it off
// the disk as well, but an older token.
db_tokens[GaiaConstants::kSyncService] = "ignoreme";
- service_->LoadTokensIntoMemory(db_tokens, &memory_tokens);
+ service()->LoadTokensIntoMemory(db_tokens, &memory_tokens);
EXPECT_EQ(1U, memory_tokens.size());
- EXPECT_EQ(0U, success_tracker_.size());
+ EXPECT_EQ(0U, success_tracker()->size());
EXPECT_EQ(1U, memory_tokens.count(GaiaConstants::kSyncService));
EXPECT_EQ(memory_tokens[GaiaConstants::kSyncService], "pepper");
}
TEST_F(TokenServiceTest, WebDBLoadIntegration) {
- service_->LoadTokensFromDB();
- WaitForDBLoadCompletion();
- EXPECT_TRUE(service_->TokensLoadedFromDB());
- EXPECT_EQ(0U, success_tracker_.size());
+ service()->LoadTokensFromDB();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(service()->TokensLoadedFromDB());
+ EXPECT_EQ(0U, success_tracker()->size());
// Should result in DB write.
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- EXPECT_EQ(1U, success_tracker_.size());
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ EXPECT_EQ(1U, success_tracker()->size());
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
// Clean slate.
- service_->ResetCredentialsInMemory();
- success_tracker_.Reset();
- EXPECT_FALSE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ service()->ResetCredentialsInMemory();
+ success_tracker()->Reset();
+ EXPECT_FALSE(service()->HasTokenForService(GaiaConstants::kSyncService));
- service_->LoadTokensFromDB();
- WaitForDBLoadCompletion();
+ service()->LoadTokensFromDB();
+ base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1U, success_tracker_.size());
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(1U, success_tracker()->size());
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
}
TEST_F(TokenServiceTest, MultipleLoadResetIntegration) {
// Should result in DB write.
- service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
- service_->ResetCredentialsInMemory();
- success_tracker_.Reset();
- EXPECT_FALSE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ service()->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token");
+ service()->ResetCredentialsInMemory();
+ success_tracker()->Reset();
+ EXPECT_FALSE(service()->HasTokenForService(GaiaConstants::kSyncService));
- EXPECT_FALSE(service_->TokensLoadedFromDB());
- service_->LoadTokensFromDB();
- WaitForDBLoadCompletion();
- EXPECT_TRUE(service_->TokensLoadedFromDB());
+ EXPECT_FALSE(service()->TokensLoadedFromDB());
+ service()->LoadTokensFromDB();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(service()->TokensLoadedFromDB());
- service_->LoadTokensFromDB(); // Should do nothing.
- WaitForDBLoadCompletion();
- EXPECT_TRUE(service_->TokensLoadedFromDB());
+ service()->LoadTokensFromDB(); // Should do nothing.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(service()->TokensLoadedFromDB());
- EXPECT_EQ(1U, success_tracker_.size());
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(1U, success_tracker()->size());
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
// Reset it one more time so there's no surprises.
- service_->ResetCredentialsInMemory();
- EXPECT_FALSE(service_->TokensLoadedFromDB());
- success_tracker_.Reset();
+ service()->ResetCredentialsInMemory();
+ EXPECT_FALSE(service()->TokensLoadedFromDB());
+ success_tracker()->Reset();
- service_->LoadTokensFromDB();
- WaitForDBLoadCompletion();
- EXPECT_TRUE(service_->TokensLoadedFromDB());
+ service()->LoadTokensFromDB();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(service()->TokensLoadedFromDB());
- EXPECT_EQ(1U, success_tracker_.size());
- EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService));
+ EXPECT_EQ(1U, success_tracker()->size());
+ EXPECT_TRUE(service()->HasTokenForService(GaiaConstants::kSyncService));
}
#ifndef NDEBUG
@@ -415,14 +391,14 @@ class TokenServiceCommandLineTest : public TokenServiceTestHarness {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSetToken, "my_service:my_value");
TokenServiceTestHarness::SetUp();
- service_->UpdateCredentials(credentials_);
+ UpdateCredentialsOnService();
*CommandLine::ForCurrentProcess() = original_cl;
}
};
TEST_F(TokenServiceCommandLineTest, TestValueOverride) {
- EXPECT_TRUE(service_->HasTokenForService("my_service"));
- EXPECT_EQ("my_value", service_->GetTokenForService("my_service"));
+ EXPECT_TRUE(service()->HasTokenForService("my_service"));
+ EXPECT_EQ("my_value", service()->GetTokenForService("my_service"));
}
#endif // ifndef NDEBUG
diff --git a/chrome/browser/signin/token_service_unittest.h b/chrome/browser/signin/token_service_unittest.h
index a333d7c..34aa043 100644
--- a/chrome/browser/signin/token_service_unittest.h
+++ b/chrome/browser/signin/token_service_unittest.h
@@ -13,7 +13,7 @@
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_notification_tracker.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -56,19 +56,24 @@ class TokenFailedTracker : public content::TestNotificationTracker {
};
class TokenServiceTestHarness : public testing::Test {
- public:
+ protected:
TokenServiceTestHarness();
virtual ~TokenServiceTestHarness();
virtual void SetUp() OVERRIDE;
-
virtual void TearDown() OVERRIDE;
- void WaitForDBLoadCompletion();
+ void UpdateCredentialsOnService();
+ TestingProfile* profile() const { return profile_.get(); }
+ TokenService* service() const { return service_; }
+ const GaiaAuthConsumer::ClientLoginResult& credentials() const {
+ return credentials_;
+ }
+ TokenAvailableTracker* success_tracker() { return &success_tracker_; }
+ TokenFailedTracker* failure_tracker() { return &failure_tracker_; }
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_; // Mostly so DCHECKS pass.
- content::TestBrowserThread db_thread_; // WDS on here
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
TokenService* service_;
TokenAvailableTracker success_tracker_;
diff --git a/chrome/browser/signin/ubertoken_fetcher_unittest.cc b/chrome/browser/signin/ubertoken_fetcher_unittest.cc
index eddb39a..ec752c7 100644
--- a/chrome/browser/signin/ubertoken_fetcher_unittest.cc
+++ b/chrome/browser/signin/ubertoken_fetcher_unittest.cc
@@ -11,8 +11,6 @@
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
class MockUbertokenConsumer : public UbertokenConsumer {
public:
MockUbertokenConsumer()
@@ -43,8 +41,8 @@ class UbertokenFetcherTest : public TokenServiceTestHarness {
public:
virtual void SetUp() OVERRIDE {
TokenServiceTestHarness::SetUp();
- service_->UpdateCredentials(credentials_);
- fetcher_.reset(new UbertokenFetcher(profile_.get(), &consumer_));
+ UpdateCredentialsOnService();
+ fetcher_.reset(new UbertokenFetcher(profile(), &consumer_));
}
virtual void TearDown() OVERRIDE {
@@ -61,10 +59,10 @@ TEST_F(UbertokenFetcherTest, TestSuccessWithoutRefreshToken) {
fetcher_->StartFetchingToken();
TokenService::TokenAvailableDetails
details(GaiaConstants::kGaiaOAuth2LoginRefreshToken, "refreshToken");
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
fetcher_->Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE,
- content::Source<TokenService>(service_),
+ content::Source<TokenService>(service()),
content::Details<const TokenService::TokenAvailableDetails>(
&details));
fetcher_->OnRefreshTokenResponse("accessToken", 3600);
@@ -75,8 +73,8 @@ TEST_F(UbertokenFetcherTest, TestSuccessWithoutRefreshToken) {
}
TEST_F(UbertokenFetcherTest, TestSuccessWithRefreshToken) {
- service_->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
- "refreshToken");
+ service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
+ "refreshToken");
fetcher_->StartFetchingToken();
fetcher_->OnRefreshTokenResponse("accessToken", 3600);
fetcher_->OnUberAuthTokenSuccess("uberToken");
@@ -93,7 +91,7 @@ TEST_F(UbertokenFetcherTest, TestFailures) {
details(GaiaConstants::kGaiaOAuth2LoginRefreshToken, error);
fetcher_->Observe(
chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
- content::Source<TokenService>(service_),
+ content::Source<TokenService>(service()),
content::Details<const TokenService::TokenRequestFailedDetails>(
&details));
EXPECT_EQ(1, consumer_.nb_error_);
diff --git a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc
index c428e1d..f1380c9 100644
--- a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc
+++ b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/speech/speech_recognition_bubble_controller.h"
#include "chrome/browser/ui/browser.h"
@@ -79,7 +80,6 @@ class SpeechRecognitionBubbleControllerTest
public:
SpeechRecognitionBubbleControllerTest()
: BrowserWithTestWindowTest(),
- io_thread_(BrowserThread::IO), // constructs a new thread and loop
cancel_clicked_(false),
try_again_clicked_(false),
focus_changed_(false),
@@ -103,14 +103,12 @@ class SpeechRecognitionBubbleControllerTest
} else if (button == SpeechRecognitionBubble::BUTTON_TRY_AGAIN) {
try_again_clicked_ = true;
}
- message_loop()->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
}
virtual void InfoBubbleFocusChanged(int session_id) OVERRIDE {
VLOG(1) << "Received InfoBubbleFocusChanged";
EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
focus_changed_ = true;
- message_loop()->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
}
// testing::Test methods.
@@ -118,12 +116,10 @@ class SpeechRecognitionBubbleControllerTest
BrowserWithTestWindowTest::SetUp();
SpeechRecognitionBubble::set_factory(
&SpeechRecognitionBubbleControllerTest::CreateBubble);
- io_thread_.Start();
}
virtual void TearDown() {
SpeechRecognitionBubble::set_factory(NULL);
- io_thread_.Stop();
BrowserWithTestWindowTest::TearDown();
}
@@ -157,9 +153,6 @@ class SpeechRecognitionBubbleControllerTest
}
protected:
- // The main thread of the test is marked as the IO thread and we create a new
- // one for the UI thread.
- content::TestBrowserThread io_thread_;
bool cancel_clicked_;
bool try_again_clicked_;
bool focus_changed_;
@@ -184,7 +177,7 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestFocusChanged) {
MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED);
controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(focus_changed_);
EXPECT_FALSE(cancel_clicked_);
EXPECT_FALSE(try_again_clicked_);
@@ -198,7 +191,7 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestRecognitionCancelled) {
MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_CANCEL);
controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(cancel_clicked_);
EXPECT_FALSE(try_again_clicked_);
EXPECT_FALSE(focus_changed_);
@@ -212,7 +205,7 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestTryAgainClicked) {
MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_TRY_AGAIN);
controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1));
- base::MessageLoop::current()->Run();
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(cancel_clicked_);
EXPECT_TRUE(try_again_clicked_);
EXPECT_FALSE(focus_changed_);
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
index c18ce33..e20932d 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
@@ -5,8 +5,6 @@
#include <vector>
#include "base/file_util.h"
-#include "base/message_loop/message_loop.h"
-#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/string_number_conversions.h"
@@ -17,7 +15,8 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "net/url_request/test_url_fetcher_factory.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_data.h"
#include "sync/api/sync_error_factory.h"
@@ -29,7 +28,6 @@
using base::HistogramBase;
using base::HistogramSamples;
using base::StatisticsRecorder;
-using content::BrowserThread;
using chrome::spellcheck_common::WordList;
using chrome::spellcheck_common::WordSet;
@@ -60,24 +58,14 @@ static BrowserContextKeyedService* BuildSpellcheckService(
class SpellcheckCustomDictionaryTest : public testing::Test {
protected:
- SpellcheckCustomDictionaryTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_),
- profile_(new TestingProfile) {
- }
-
virtual void SetUp() OVERRIDE {
// Use SetTestingFactoryAndUse to force creation and initialization.
SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(), &BuildSpellcheckService);
+ &profile_, &BuildSpellcheckService);
StatisticsRecorder::Initialize();
}
- virtual void TearDown() OVERRIDE {
- base::MessageLoop::current()->RunUntilIdle();
- }
-
// A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private
// function to avoid a large number of FRIEND_TEST declarations in
// SpellcheckCustomDictionary.
@@ -112,11 +100,10 @@ class SpellcheckCustomDictionaryTest : public testing::Test {
return dictionary.Apply(change);
}
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
- scoped_ptr<TestingProfile> profile_;
+ TestingProfile profile_;
+ net::TestURLFetcherFactory fetcher_factory_;
};
// A wrapper around SpellcheckCustomDictionary that does not own the wrapped
@@ -187,7 +174,7 @@ class DictionaryObserverCounter : public SpellcheckCustomDictionary::Observer {
TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
WordList loaded_custom_words = LoadDictionaryFile(path);
// The custom word list should be empty now.
@@ -217,7 +204,7 @@ TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -251,7 +238,7 @@ TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
// Legacy empty dictionary should be converted to new format empty dictionary.
TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) {
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
std::string content;
file_util::WriteFile(path, content.c_str(), content.length());
@@ -264,7 +251,7 @@ TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) {
TEST_F(SpellcheckCustomDictionaryTest,
LegacyDictionaryWithTwoWordsShouldBeConverted) {
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
std::string content = "foo\nbar\nfoo\n";
file_util::WriteFile(path, content.c_str(), content.length());
@@ -280,7 +267,7 @@ TEST_F(SpellcheckCustomDictionaryTest,
TEST_F(SpellcheckCustomDictionaryTest,
IllegalWordsShouldBeRemovedFromDictionary) {
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
std::string content = "foo\n foo bar \n\n \nbar\n"
"01234567890123456789012345678901234567890123456789"
@@ -299,7 +286,7 @@ TEST_F(SpellcheckCustomDictionaryTest,
// previous version should be reloaded.
TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) {
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
std::string content = "foo\nbar";
file_util::WriteFile(path, content.c_str(), content.length());
@@ -324,7 +311,7 @@ TEST_F(SpellcheckCustomDictionaryTest,
GetAllSyncDataAccuratelyReflectsDictionaryState) {
SpellcheckCustomDictionary* dictionary =
SpellcheckServiceFactory::GetForProfile(
- profile_.get())->GetCustomDictionary();
+ &profile_)->GetCustomDictionary();
syncer::SyncDataList data = dictionary->GetAllSyncData(syncer::DICTIONARY);
EXPECT_TRUE(data.empty());
@@ -354,7 +341,7 @@ TEST_F(SpellcheckCustomDictionaryTest,
TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) {
SpellcheckCustomDictionary* dictionary =
SpellcheckServiceFactory::GetForProfile(
- profile_.get())->GetCustomDictionary();
+ &profile_)->GetCustomDictionary();
SpellcheckCustomDictionary::Change change;
for (size_t i = 0;
@@ -389,7 +376,7 @@ TEST_F(SpellcheckCustomDictionaryTest, GetAllSyncDataHasLimit) {
TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* dictionary =
spellcheck_service->GetCustomDictionary();
@@ -460,7 +447,7 @@ TEST_F(SpellcheckCustomDictionaryTest, ProcessSyncChanges) {
TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -506,7 +493,7 @@ TEST_F(SpellcheckCustomDictionaryTest, MergeDataAndStartSyncing) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -549,7 +536,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigBeforeSyncing) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -601,7 +588,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigAndServerFull) {
TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -652,7 +639,7 @@ TEST_F(SpellcheckCustomDictionaryTest, ServerTooBig) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -698,7 +685,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToStartSyncing) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -749,7 +736,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryTooBigToContiueSyncing) {
TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -787,7 +774,7 @@ TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStart) {
TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -834,7 +821,7 @@ TEST_F(SpellcheckCustomDictionaryTest, LoadAfterSyncStartTooBigToSync) {
TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -881,7 +868,7 @@ TEST_F(SpellcheckCustomDictionaryTest, LoadDuplicatesAfterSync) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
@@ -902,7 +889,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryLoadNotification) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
@@ -922,7 +909,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryAddWordNotification) {
TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
@@ -945,7 +932,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionaryRemoveWordNotification) {
TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncNotification) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
TestingProfile profile2;
@@ -1006,7 +993,7 @@ TEST_F(SpellcheckCustomDictionaryTest, DictionarySyncLimit) {
// Upload the maximum number of words to the sync server.
{
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
@@ -1092,7 +1079,7 @@ TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) {
// Load the dictionary which should be empty.
base::FilePath path =
- profile_->GetPath().Append(chrome::kCustomDictionaryFileName);
+ profile_.GetPath().Append(chrome::kCustomDictionaryFileName);
WordList loaded_custom_words = LoadDictionaryFile(path);
EXPECT_EQ(0u, loaded_custom_words.size());
@@ -1125,7 +1112,7 @@ TEST_F(SpellcheckCustomDictionaryTest, RecordSizeStatsCorrectly) {
TEST_F(SpellcheckCustomDictionaryTest, HasWord) {
SpellcheckService* spellcheck_service =
- SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckServiceFactory::GetForProfile(&profile_);
SpellcheckCustomDictionary* custom_dictionary =
spellcheck_service->GetCustomDictionary();
OnLoaded(*custom_dictionary, WordList());
diff --git a/chrome/browser/spellchecker/spellcheck_message_filter_unittest.cc b/chrome/browser/spellchecker/spellcheck_message_filter_unittest.cc
index d0fb26f..8504256 100644
--- a/chrome/browser/spellchecker/spellcheck_message_filter_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_message_filter_unittest.cc
@@ -9,7 +9,7 @@
#include "chrome/common/spellcheck_marker.h"
#include "chrome/common/spellcheck_messages.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,7 +17,6 @@ class TestingSpellCheckMessageFilter : public SpellCheckMessageFilter {
public:
TestingSpellCheckMessageFilter()
: SpellCheckMessageFilter(0),
- ui_thread_(content::BrowserThread::UI, &message_loop_),
spellcheck_(new SpellcheckService(&profile_)) {}
virtual bool Send(IPC::Message* message) OVERRIDE {
@@ -46,8 +45,7 @@ class TestingSpellCheckMessageFilter : public SpellCheckMessageFilter {
private:
virtual ~TestingSpellCheckMessageFilter() {}
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
scoped_ptr<SpellcheckService> spellcheck_;
diff --git a/chrome/browser/spellchecker/spellcheck_service_unittest.cc b/chrome/browser/spellchecker/spellcheck_service_unittest.cc
index 1f68810..c481af2 100644
--- a/chrome/browser/spellchecker/spellcheck_service_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_service_unittest.cc
@@ -11,11 +11,10 @@
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
using chrome::spellcheck_common::WordList;
static BrowserContextKeyedService* BuildSpellcheckService(
@@ -25,27 +24,15 @@ static BrowserContextKeyedService* BuildSpellcheckService(
class SpellcheckServiceTest : public testing::Test {
protected:
- SpellcheckServiceTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_),
- profile_(new TestingProfile()) {
- }
-
virtual void SetUp() OVERRIDE {
// Use SetTestingFactoryAndUse to force creation and initialization.
SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(), &BuildSpellcheckService);
+ &profile_, &BuildSpellcheckService);
}
- virtual void TearDown() OVERRIDE {
- base::MessageLoop::current()->RunUntilIdle();
- }
-
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
-
- scoped_ptr<TestingProfile> profile_;
+ private:
+ content::TestBrowserThreadBundle thread_bundle_;
+ TestingProfile profile_;
};
TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages1) {
diff --git a/chrome/browser/spellchecker/spelling_service_client_unittest.cc b/chrome/browser/spellchecker/spelling_service_client_unittest.cc
index c40bc55..b3ac8d2 100644
--- a/chrome/browser/spellchecker/spelling_service_client_unittest.cc
+++ b/chrome/browser/spellchecker/spelling_service_client_unittest.cc
@@ -16,6 +16,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_result.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/load_flags.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -191,12 +192,6 @@ class TestingSpellingServiceClient : public SpellingServiceClient {
// monitor the class calls the callback with expected results.
class SpellingServiceClientTest : public testing::Test {
public:
- SpellingServiceClientTest() {}
- virtual ~SpellingServiceClientTest() {}
-
- virtual void SetUp() OVERRIDE {
- }
-
void OnTextCheckComplete(int tag,
bool success,
const string16& text,
@@ -205,6 +200,7 @@ class SpellingServiceClientTest : public testing::Test {
}
protected:
+ content::TestBrowserThreadBundle thread_bundle_;
TestingSpellingServiceClient client_;
TestingProfile profile_;
};
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc
index 1c4a995..8de5c6b 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.cc
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc
@@ -7,13 +7,14 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
+#include "base/run_loop.h"
#include "chrome/browser/sync/test_profile_sync_service.h"
+#include "content/public/test/test_utils.h"
#include "sync/internal_api/public/test/test_user_share.h"
#include "sync/internal_api/public/write_transaction.h"
#include "sync/protocol/sync.pb.h"
#include "sync/util/cryptographer.h"
-using content::BrowserThread;
using syncer::ModelType;
using syncer::UserShare;
@@ -41,10 +42,9 @@ syncer::ImmutableChangeRecordList
}
AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
- : ui_thread_(BrowserThread::UI, &ui_loop_),
- db_thread_(BrowserThread::DB),
- file_thread_(BrowserThread::FILE),
- io_thread_(BrowserThread::IO),
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
+ content::TestBrowserThreadBundle::REAL_FILE_THREAD |
+ content::TestBrowserThreadBundle::REAL_IO_THREAD),
token_service_(NULL),
sync_service_(NULL) {
}
@@ -52,19 +52,14 @@ AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {}
void AbstractProfileSyncServiceTest::SetUp() {
- db_thread_.Start();
- file_thread_.Start();
- io_thread_.StartIOThread();
}
void AbstractProfileSyncServiceTest::TearDown() {
// Pump messages posted by the sync core thread (which may end up
// posting on the IO thread).
- ui_loop_.RunUntilIdle();
- io_thread_.Stop();
- file_thread_.Stop();
- db_thread_.Stop();
- ui_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
+ content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
+ base::RunLoop().RunUntilIdle();
}
bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h
index c3538a2..1ccc810 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.h
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.h
@@ -13,7 +13,7 @@
#include "base/message_loop/message_loop.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/change_record.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -52,11 +52,7 @@ class AbstractProfileSyncServiceTest : public testing::Test {
content::BrowserContext* profile);
protected:
- base::MessageLoopForUI ui_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread file_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
TokenService* token_service_;
TestProfileSyncService* sync_service_;
};
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
index 2660d57..696f5f1 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
@@ -7,7 +7,6 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/sync/glue/autofill_data_type_controller.h"
@@ -24,7 +23,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "sync/api/sync_error.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -153,10 +152,9 @@ class MockWebDataServiceWrapperSyncable : public MockWebDataServiceWrapper {
class SyncAutofillDataTypeControllerTest : public testing::Test {
public:
SyncAutofillDataTypeControllerTest()
- : weak_ptr_factory_(this),
- ui_thread_(BrowserThread::UI, &message_loop_),
- db_thread_(BrowserThread::DB),
- last_start_result_(DataTypeController::OK) {}
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD),
+ last_start_result_(DataTypeController::OK),
+ weak_ptr_factory_(this) {}
virtual ~SyncAutofillDataTypeControllerTest() {}
@@ -174,8 +172,6 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
new AutofillDataTypeController(&profile_sync_factory_,
&profile_,
&service_);
-
- db_thread_.Start();
}
// Passed to AutofillDTC::Start().
@@ -204,10 +200,7 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
}
protected:
- base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_;
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_refptr<NiceMock<SharedChangeProcessorMock> > change_processor_;
ProfileSyncComponentsFactoryMock profile_sync_factory_;
@@ -218,6 +211,7 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
// Stores arguments of most recent call of OnStartFinished().
DataTypeController::StartResult last_start_result_;
syncer::SyncError last_start_error_;
+ base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_;
};
// Load the WDS's database, then start the Autofill DTC. It should
diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
index ec8ba1f..3f95b14 100644
--- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
#include "base/tracked_objects.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -143,7 +144,7 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) {
EXPECT_EQ(DataTypeController::MODEL_LOADED, search_engine_dtc_->state());
// Wait until WebDB is loaded before we shut it down.
- test_util_.BlockTillServiceProcessesRequests();
+ base::RunLoop().RunUntilIdle();
}
TEST_F(SyncSearchEngineDataTypeControllerTest, StartFirstRun) {
@@ -222,7 +223,7 @@ TEST_F(SyncSearchEngineDataTypeControllerTest,
Start();
// This should cause search_engine_dtc_->Stop() to be called.
search_engine_dtc_->OnSingleDatatypeUnrecoverableError(FROM_HERE, "Test");
- test_util_.PumpLoop();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
EXPECT_FALSE(syncable_service_.syncing());
}
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index 5c2f62e5..90eadee 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -20,7 +20,8 @@
#include "chrome/test/base/testing_profile.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
#include "google/cacheinvalidation/include/types.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "sync/internal_api/public/base/model_type.h"
@@ -135,16 +136,13 @@ class FakeSyncManagerFactory : public syncer::SyncManagerFactory {
class SyncBackendHostTest : public testing::Test {
protected:
SyncBackendHostTest()
- : ui_thread_(BrowserThread::UI, &ui_loop_),
- io_thread_(BrowserThread::IO),
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD),
fake_manager_(NULL) {}
virtual ~SyncBackendHostTest() {}
virtual void SetUp() OVERRIDE {
- io_thread_.StartIOThread();
profile_.reset(new TestingProfile());
- profile_->CreateRequestContext();
sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs()));
backend_.reset(new SyncBackendHost(
profile_->GetDebugName(),
@@ -178,10 +176,10 @@ class SyncBackendHostTest : public testing::Test {
profile_.reset();
// Pump messages posted by the sync thread (which may end up
// posting on the IO thread).
- ui_loop_.RunUntilIdle();
- io_thread_.Stop();
+ base::RunLoop().RunUntilIdle();
+ content::RunAllPendingInMessageLoop(BrowserThread::IO);
// Pump any messages posted by the IO thread.
- ui_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
// Synchronously initializes the backend.
@@ -196,9 +194,11 @@ class SyncBackendHostTest : public testing::Test {
&fake_manager_factory_,
&handler_,
NULL);
- ui_loop_.PostDelayedTask(FROM_HERE,
- ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
- ui_loop_.Run();
+ base::RunLoop run_loop;
+ BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
+ run_loop.QuitClosure(),
+ TestTimeouts::action_timeout());
+ run_loop.Run();
// |fake_manager_factory_|'s fake_manager() is set on the sync
// thread, but we can rely on the message loop barriers to
// guarantee that we see the updated value.
@@ -226,9 +226,11 @@ class SyncBackendHostTest : public testing::Test {
base::Unretained(this)),
base::Bind(&SyncBackendHostTest::OnDownloadRetry,
base::Unretained(this)));
- ui_loop_.PostDelayedTask(FROM_HERE,
- ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
- ui_loop_.Run();
+ base::RunLoop run_loop;
+ BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
+ run_loop.QuitClosure(),
+ TestTimeouts::action_timeout());
+ run_loop.Run();
}
void IssueRefreshRequest(syncer::ModelTypeSet types) {
@@ -250,9 +252,7 @@ class SyncBackendHostTest : public testing::Test {
NOTIMPLEMENTED();
}
- base::MessageLoop ui_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
StrictMock<MockSyncFrontend> mock_frontend_;
syncer::SyncCredentials credentials_;
syncer::TestUnrecoverableErrorHandler handler_;
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index 9f18db2..72b6a0e 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -504,7 +504,6 @@ class ProfileSyncServiceAutofillTest
virtual void SetUp() OVERRIDE {
AbstractProfileSyncServiceTest::SetUp();
profile_.reset(new ProfileMock());
- profile_->CreateRequestContext();
web_database_.reset(new WebDatabaseFake(&autofill_table_));
MockWebDataServiceWrapper* wrapper =
static_cast<MockWebDataServiceWrapper*>(
@@ -542,7 +541,6 @@ class ProfileSyncServiceAutofillTest
web_data_service_->ShutdownOnUIThread();
web_data_service_->ShutdownSyncableService();
web_data_service_ = NULL;
- profile_->ResetRequestContext();
// To prevent a leak, fully release TestURLRequestContext to ensure its
// destruction on the IO message loop.
profile_.reset();
diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc
index b9a3fac..17b9523 100644
--- a/chrome/browser/sync/profile_sync_service_password_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc
@@ -154,8 +154,7 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
virtual void SetUp() {
AbstractProfileSyncServiceTest::SetUp();
- profile_.reset(new ProfileMock);
- profile_->CreateRequestContext();
+ profile_.reset(new ProfileMock());
invalidation::InvalidationServiceFactory::GetInstance()->
SetBuildOnlyFakeInvalidatorsForTest(true);
password_store_ = static_cast<MockPasswordStore*>(
@@ -168,7 +167,6 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
password_store_->ShutdownOnUIThread();
ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
profile_.get(), NULL);
- profile_->ResetRequestContext();
profile_.reset();
AbstractProfileSyncServiceTest::TearDown();
}
diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
index 076a7fb..4d57c21 100644
--- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
@@ -124,7 +124,6 @@ class ProfileSyncServicePreferenceTest
virtual void SetUp() {
AbstractProfileSyncServiceTest::SetUp();
profile_.reset(new TestingProfile());
- profile_->CreateRequestContext();
invalidation::InvalidationServiceFactory::GetInstance()->
SetBuildOnlyFakeInvalidatorsForTest(true);
prefs_ = profile_->GetTestingPrefService();
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc
index 6643286..aec8539 100644
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc
@@ -13,7 +13,7 @@
#include "base/guid.h"
#include "base/location.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -48,6 +48,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
+#include "net/url_request/test_url_fetcher_factory.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/change_record.h"
#include "sync/internal_api/public/read_node.h"
@@ -202,8 +203,7 @@ class ProfileSyncServiceSessionTest
public content::NotificationObserver {
public:
ProfileSyncServiceSessionTest()
- : io_thread_(BrowserThread::IO),
- window_bounds_(0, 1, 2, 3),
+ : window_bounds_(0, 1, 2, 3),
notified_of_update_(false),
notified_of_refresh_(false) {}
ProfileSyncService* sync_service() { return sync_service_.get(); }
@@ -222,8 +222,6 @@ class ProfileSyncServiceSessionTest
virtual void SetUp() {
// BrowserWithTestWindowTest implementation.
BrowserWithTestWindowTest::SetUp();
- io_thread_.StartIOThread();
- profile()->CreateRequestContext();
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED,
content::NotificationService::AllSources());
@@ -250,7 +248,6 @@ class ProfileSyncServiceSessionTest
virtual void TearDown() {
sync_service_->Shutdown();
sync_service_.reset();
- profile()->ResetRequestContext();
// We need to destroy the profile before shutting down the threads, because
// some of the ref counted objects in the profile depend on their
@@ -260,9 +257,7 @@ class ProfileSyncServiceSessionTest
// Pump messages posted by the sync core thread (which may end up
// posting on the IO thread).
- base::MessageLoop::current()->RunUntilIdle();
- io_thread_.Stop();
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
BrowserWithTestWindowTest::TearDown();
}
@@ -312,7 +307,6 @@ class ProfileSyncServiceSessionTest
return true;
}
- content::TestBrowserThread io_thread_;
// Path used in testing.
base::ScopedTempDir temp_dir_;
SessionModelAssociator* model_associator_;
@@ -323,6 +317,7 @@ class ProfileSyncServiceSessionTest
bool notified_of_update_;
bool notified_of_refresh_;
content::NotificationRegistrar registrar_;
+ net::TestURLFetcherFactory fetcher_factory_;
};
class CreateRootHelper {
@@ -1222,7 +1217,7 @@ TEST_F(ProfileSyncServiceSessionTest, Favicons) {
// Update associator.
model_associator_->AssociateForeignSpecifics(meta, base::Time());
model_associator_->AssociateForeignSpecifics(tab, base::Time());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_FALSE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
// Now add a favicon.
@@ -1230,7 +1225,7 @@ TEST_F(ProfileSyncServiceSessionTest, Favicons) {
tab.mutable_tab()->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
tab.mutable_tab()->set_favicon("data");
model_associator_->AssociateForeignSpecifics(tab, base::Time());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
ASSERT_TRUE(CompareMemoryToString("data", favicon));
@@ -1241,7 +1236,7 @@ TEST_F(ProfileSyncServiceSessionTest, Favicons) {
tab.mutable_tab()->clear_favicon_type();
tab.mutable_tab()->clear_favicon();
model_associator_->AssociateForeignSpecifics(tab, base::Time());
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model_associator_->GetSyncedFaviconForPageURL(url, &favicon));
}
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index 85b5c88..f1bfd96 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -7,6 +7,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/signin/fake_signin_manager.h"
#include "chrome/browser/signin/oauth2_token_service.h"
@@ -27,7 +28,8 @@
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -71,10 +73,9 @@ class FakeTokenService : public TokenService {
class ProfileSyncServiceStartupTest : public testing::Test {
public:
ProfileSyncServiceStartupTest()
- : ui_thread_(BrowserThread::UI, &ui_loop_),
- db_thread_(BrowserThread::DB),
- file_thread_(BrowserThread::FILE),
- io_thread_(BrowserThread::IO),
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
+ content::TestBrowserThreadBundle::REAL_FILE_THREAD |
+ content::TestBrowserThreadBundle::REAL_IO_THREAD),
profile_(new TestingProfile),
sync_(NULL) {}
@@ -82,9 +83,6 @@ class ProfileSyncServiceStartupTest : public testing::Test {
}
virtual void SetUp() {
- file_thread_.Start();
- io_thread_.StartIOThread();
- profile_->CreateRequestContext();
#if defined(OS_CHROMEOS)
SigninManagerFactory::GetInstance()->SetTestingFactory(
profile_.get(), FakeSigninManagerBase::Build);
@@ -104,10 +102,9 @@ class ProfileSyncServiceStartupTest : public testing::Test {
// Pump messages posted by the sync core thread (which may end up
// posting on the IO thread).
- ui_loop_.RunUntilIdle();
- io_thread_.Stop();
- file_thread_.Stop();
- ui_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
+ content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
+ base::RunLoop().RunUntilIdle();
}
static BrowserContextKeyedService* BuildService(
@@ -139,11 +136,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
return data_type_manager;
}
- base::MessageLoop ui_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread file_thread_;
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
TestProfileSyncService* sync_;
ProfileSyncServiceObserverMock observer_;
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index e933442..2738c10 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -174,8 +174,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
virtual void SetUp() {
AbstractProfileSyncServiceTest::SetUp();
- profile_.reset(new ProfileMock);
- profile_->CreateRequestContext();
+ profile_.reset(new ProfileMock());
invalidation::InvalidationServiceFactory::GetInstance()->
SetBuildOnlyFakeInvalidatorsForTest(true);
history_backend_ = new HistoryBackendMock();
@@ -194,7 +193,6 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
profile_.get(), NULL);
history_thread_.Stop();
- profile_->ResetRequestContext();
profile_.reset();
AbstractProfileSyncServiceTest::TearDown();
}
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 6eb7521..9b22da9 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -6,7 +6,7 @@
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/invalidation/invalidation_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
@@ -21,7 +21,8 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
#include "google/cacheinvalidation/include/types.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/js/js_arg_list.h"
@@ -38,7 +39,6 @@ namespace browser_sync {
namespace {
-using content::BrowserThread;
using testing::_;
using testing::AtLeast;
using testing::AtMost;
@@ -49,18 +49,13 @@ using testing::StrictMock;
class ProfileSyncServiceTestHarness {
public:
ProfileSyncServiceTestHarness()
- : ui_thread_(BrowserThread::UI, &ui_loop_),
- db_thread_(BrowserThread::DB),
- file_thread_(BrowserThread::FILE),
- io_thread_(BrowserThread::IO) {}
-
- ~ProfileSyncServiceTestHarness() {}
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
+ content::TestBrowserThreadBundle::REAL_FILE_THREAD |
+ content::TestBrowserThreadBundle::REAL_IO_THREAD) {
+ }
void SetUp() {
- file_thread_.Start();
- io_thread_.StartIOThread();
profile.reset(new TestingProfile());
- profile->CreateRequestContext();
invalidation::InvalidationServiceFactory::GetInstance()->
SetBuildOnlyFakeInvalidatorsForTest(true);
ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
@@ -76,11 +71,9 @@ class ProfileSyncServiceTestHarness {
profile.reset();
// Pump messages posted by the sync thread (which may end up
// posting on the IO thread).
- ui_loop_.RunUntilIdle();
- io_thread_.Stop();
- file_thread_.Stop();
- // Ensure that the sync objects destruct to avoid memory leaks.
- ui_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
+ content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
+ base::RunLoop().RunUntilIdle();
}
// TODO(akalin): Refactor the StartSyncService*() functions below.
@@ -140,14 +133,7 @@ class ProfileSyncServiceTestHarness {
scoped_ptr<TestingProfile> profile;
private:
- base::MessageLoop ui_loop_;
- // Needed by |service|.
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread db_thread_;
- // Needed by DisableAndEnableSyncTemporarily test case.
- content::TestBrowserThread file_thread_;
- // Needed by |service| and |profile|'s request context.
- content::TestBrowserThread io_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
};
class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver {
diff --git a/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_fake_unittest.cc b/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_fake_unittest.cc
index 6f8431a..a26c2af 100644
--- a/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_fake_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_fake_unittest.cc
@@ -7,8 +7,8 @@
#include <utility>
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/run_loop.h"
#include "chrome/browser/drive/drive_uploader.h"
#include "chrome/browser/drive/fake_drive_service.h"
#include "chrome/browser/extensions/test_extension_service.h"
@@ -28,7 +28,6 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_builder.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/common/id_util.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -216,7 +215,7 @@ class DriveFileSyncServiceFakeTest : public testing::Test {
bool done = false;
metadata_store_->Initialize(base::Bind(&DidInitialize, &done));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
fake_drive_service_->LoadResourceListForWapi(
@@ -241,7 +240,7 @@ class DriveFileSyncServiceFakeTest : public testing::Test {
sync_service_->AddFileStatusObserver(&mock_file_status_observer_);
sync_service_->SetRemoteChangeProcessor(mock_remote_processor());
sync_service_->SetSyncEnabled(enabled);
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
virtual void TearDown() OVERRIDE {
@@ -257,7 +256,7 @@ class DriveFileSyncServiceFakeTest : public testing::Test {
extension_service_ = NULL;
profile_.reset();
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void SetSyncEnabled(bool enabled) {
@@ -284,7 +283,7 @@ class DriveFileSyncServiceFakeTest : public testing::Test {
void UpdateRegisteredOrigins() {
sync_service_->UpdateRegisteredOrigins();
// Wait for completion of uninstalling origin.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void VerifySizeOfRegisteredOrigins(size_t b_size,
@@ -353,7 +352,7 @@ class DriveFileSyncServiceFakeTest : public testing::Test {
sync_service_->ProcessRemoteChange(
base::Bind(&DidProcessRemoteChange, &actual_status, &actual_url));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(expected_status, actual_status);
EXPECT_EQ(expected_url, actual_url);
@@ -446,7 +445,7 @@ void DriveFileSyncServiceFakeTest::TestRegisterNewOrigin() {
sync_service()->RegisterOriginForTrackingChanges(
ExtensionNameToGURL(kExtensionName1),
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
@@ -474,7 +473,7 @@ void DriveFileSyncServiceFakeTest::TestRegisterExistingOrigin() {
sync_service()->RegisterOriginForTrackingChanges(
ExtensionNameToGURL(kExtensionName1),
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
// The origin should be registered as an incremental sync origin.
@@ -494,7 +493,7 @@ void DriveFileSyncServiceFakeTest::TestRegisterOriginWithSyncDisabled() {
sync_service()->RegisterOriginForTrackingChanges(
ExtensionNameToGURL(kExtensionName1),
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
// We must not have started batch sync for the newly registered origin,
@@ -516,7 +515,7 @@ void DriveFileSyncServiceFakeTest::TestUnregisterOrigin() {
sync_service()->UnregisterOriginForTrackingChanges(
ExtensionNameToGURL(kExtensionName1),
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
diff --git a/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_unittest.cc b/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_unittest.cc
index 1b53de2..c107bdd 100644
--- a/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_backend/drive_file_sync_service_unittest.cc
@@ -4,13 +4,13 @@
#include "chrome/browser/sync_file_system/drive_backend/drive_file_sync_service.h"
-#include "base/message_loop/message_loop.h"
+#include "base/bind.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/run_loop.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_metadata_store.h"
#include "chrome/browser/sync_file_system/drive_backend/fake_api_util.h"
#include "chrome/browser/sync_file_system/sync_file_system.pb.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
@@ -60,7 +60,7 @@ class DriveFileSyncServiceTest : public testing::Test {
base_dir_, base::MessageLoopProxy::current().get());
bool done = false;
metadata_store_->Initialize(base::Bind(&DidInitialize, &done));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
metadata_store_->SetSyncRootDirectory(kSyncRootResourceId);
EXPECT_TRUE(done);
@@ -69,14 +69,14 @@ class DriveFileSyncServiceTest : public testing::Test {
base_dir_,
scoped_ptr<APIUtilInterface>(fake_api_util_),
scoped_ptr<DriveMetadataStore>(metadata_store_)).Pass();
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
virtual void TearDown() OVERRIDE {
metadata_store_ = NULL;
fake_api_util_ = NULL;
sync_service_.reset();
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
base_dir_ = base::FilePath();
RevokeSyncableFileSystem();
@@ -172,7 +172,7 @@ TEST_F(DriveFileSyncServiceTest, UninstallOrigin) {
sync_service()->UninstallOrigin(
origin_gurl,
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
// Assert the App's origin folder was marked as deleted.
@@ -194,7 +194,7 @@ TEST_F(DriveFileSyncServiceTest, UninstallOriginWithoutOriginDirectory) {
sync_service()->UninstallOrigin(
origin_gurl,
base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(done);
// Assert the App's origin folder does not exist.
@@ -215,7 +215,7 @@ TEST_F(DriveFileSyncServiceTest, DisableOriginForTrackingChangesPendingOrigin) {
// Pending origins that are disabled are dropped and do not go to disabled.
sync_service()->DisableOriginForTrackingChanges(origin,
base::Bind(&ExpectOkStatus));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(VerifyOriginStatusCount(0u, 0u, 0u));
}
@@ -229,7 +229,7 @@ TEST_F(DriveFileSyncServiceTest,
sync_service()->DisableOriginForTrackingChanges(origin,
base::Bind(&ExpectOkStatus));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(VerifyOriginStatusCount(0u, 0u, 1u));
}
@@ -246,7 +246,7 @@ TEST_F(DriveFileSyncServiceTest, EnableOriginForTrackingChanges) {
// origins > 0.
sync_service()->EnableOriginForTrackingChanges(origin,
base::Bind(&ExpectOkStatus));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
ASSERT_TRUE(VerifyOriginStatusCount(0u, 1u, 0u));
}
diff --git a/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc b/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
index 59722dc..9f19923 100644
--- a/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
+++ b/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
@@ -14,6 +14,9 @@
#include "chrome/browser/sync_file_system/mock_local_change_processor.h"
#include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/file_system_context.h"
@@ -27,6 +30,7 @@
#include "webkit/browser/fileapi/syncable/sync_status_code.h"
#include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
+using content::BrowserThread;
using fileapi::FileSystemURL;
using ::testing::_;
using ::testing::AtLeast;
@@ -95,19 +99,18 @@ class LocalFileSyncServiceTest
: public testing::Test,
public LocalFileSyncService::Observer {
protected:
- LocalFileSyncServiceTest() : num_changes_(0) {}
-
- virtual ~LocalFileSyncServiceTest() {}
+ LocalFileSyncServiceTest()
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
+ content::TestBrowserThreadBundle::REAL_IO_THREAD),
+ num_changes_(0) {}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- thread_helper_.SetUp();
-
file_system_.reset(new CannedSyncableFileSystem(
GURL(kOrigin),
- thread_helper_.io_task_runner(),
- thread_helper_.file_task_runner()));
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
local_service_.reset(new LocalFileSyncService(&profile_));
@@ -132,8 +135,7 @@ class LocalFileSyncServiceTest
local_service_->Shutdown();
file_system_->TearDown();
RevokeSyncableFileSystem();
-
- thread_helper_.TearDown();
+ content::RunAllPendingInMessageLoop(BrowserThread::FILE);
}
// LocalChangeObserver overrides.
@@ -173,11 +175,11 @@ class LocalFileSyncServiceTest
return file_system_->file_system_context()->change_tracker()->num_changes();
}
+ content::TestBrowserThreadBundle thread_bundle_;
+
ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
TestingProfile profile_;
- MultiThreadTestHelper thread_helper_;
-
base::ScopedTempDir temp_dir_;
scoped_ptr<CannedSyncableFileSystem> file_system_;
@@ -277,9 +279,10 @@ TEST_F(LocalFileSyncServiceTest, LocalChangeObserver) {
TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) {
const char kOrigin2[] = "http://foo";
- CannedSyncableFileSystem file_system2(GURL(kOrigin2),
- thread_helper_.io_task_runner(),
- thread_helper_.file_task_runner());
+ CannedSyncableFileSystem file_system2(
+ GURL(kOrigin2),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
file_system2.SetUp();
base::RunLoop run_loop;
diff --git a/chrome/browser/sync_file_system/sync_file_system_service_unittest.cc b/chrome/browser/sync_file_system/sync_file_system_service_unittest.cc
index 6661bb1..7e3c543f 100644
--- a/chrome/browser/sync_file_system/sync_file_system_service_unittest.cc
+++ b/chrome/browser/sync_file_system/sync_file_system_service_unittest.cc
@@ -15,6 +15,9 @@
#include "chrome/browser/sync_file_system/sync_file_system_service.h"
#include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h"
@@ -25,6 +28,7 @@
#include "webkit/browser/fileapi/syncable/sync_status_code.h"
#include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
+using content::BrowserThread;
using fileapi::FileSystemURL;
using fileapi::FileSystemURLSet;
using ::testing::AnyNumber;
@@ -63,11 +67,11 @@ void AssignValueAndQuit(base::RunLoop* run_loop,
}
// This is called on IO thread.
-void VerifyFileError(base::WaitableEvent* event,
+void VerifyFileError(base::RunLoop* run_loop,
base::PlatformFileError error) {
- DCHECK(event);
+ DCHECK(run_loop);
EXPECT_EQ(base::PLATFORM_FILE_OK, error);
- event->Signal();
+ run_loop->Quit();
}
} // namespace
@@ -112,16 +116,15 @@ ACTION_P2(MockSyncFileCallback, status, url) {
class SyncFileSystemServiceTest : public testing::Test {
protected:
- SyncFileSystemServiceTest() {}
- virtual ~SyncFileSystemServiceTest() {}
+ SyncFileSystemServiceTest()
+ : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
+ content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
virtual void SetUp() OVERRIDE {
- thread_helper_.SetUp();
-
file_system_.reset(new CannedSyncableFileSystem(
GURL(kOrigin),
- thread_helper_.io_task_runner(),
- thread_helper_.file_task_runner()));
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
local_service_ = new LocalFileSyncService(&profile_);
remote_service_ = new StrictMock<MockRemoteFileSyncService>;
@@ -150,10 +153,9 @@ class SyncFileSystemServiceTest : public testing::Test {
virtual void TearDown() OVERRIDE {
sync_service_->Shutdown();
-
file_system_->TearDown();
RevokeSyncableFileSystem();
- thread_helper_.TearDown();
+ content::RunAllPendingInMessageLoop(BrowserThread::FILE);
}
void InitializeApp() {
@@ -237,7 +239,7 @@ class SyncFileSystemServiceTest : public testing::Test {
ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
- MultiThreadTestHelper thread_helper_;
+ content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
scoped_ptr<CannedSyncableFileSystem> file_system_;
@@ -392,17 +394,20 @@ TEST_F(SyncFileSystemServiceTest, SimpleSyncFlowWithFileBusy) {
mock_remote_service()->NotifyRemoteChangeQueueUpdated(1);
// Start a local operation on the same file (to make it BUSY).
- base::WaitableEvent event(false, false);
- thread_helper_.io_task_runner()->PostTask(
- FROM_HERE, base::Bind(&CannedSyncableFileSystem::DoCreateFile,
- base::Unretained(file_system_.get()),
- kFile, base::Bind(&VerifyFileError, &event)));
+ base::RunLoop verify_file_error_run_loop;
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoCreateFile,
+ base::Unretained(file_system_.get()),
+ kFile, base::Bind(&VerifyFileError,
+ &verify_file_error_run_loop)));
run_loop.Run();
mock_remote_service()->NotifyRemoteChangeQueueUpdated(0);
- event.Wait();
+ verify_file_error_run_loop.Run();
}
TEST_F(SyncFileSystemServiceTest, GetFileSyncStatus) {
diff --git a/chrome/browser/sync_file_system/sync_file_system_test_util.cc b/chrome/browser/sync_file_system/sync_file_system_test_util.cc
index 1f0c214..ccb5684 100644
--- a/chrome/browser/sync_file_system/sync_file_system_test_util.cc
+++ b/chrome/browser/sync_file_system/sync_file_system_test_util.cc
@@ -9,12 +9,11 @@
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
-#include "content/public/test/test_browser_thread.h"
-#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_utils.h"
#include "webkit/browser/fileapi/syncable/sync_status_code.h"
using content::BrowserThread;
-using content::TestBrowserThread;
namespace sync_file_system {
@@ -35,30 +34,4 @@ AssignAndQuitCallback(base::RunLoop* run_loop, R* result) {
template base::Callback<void(SyncStatusCode)>
AssignAndQuitCallback(base::RunLoop*, SyncStatusCode*);
-MultiThreadTestHelper::MultiThreadTestHelper()
- : thread_bundle_(new content::TestBrowserThreadBundle(
- content::TestBrowserThreadBundle::REAL_FILE_THREAD |
- content::TestBrowserThreadBundle::REAL_IO_THREAD)) {
-}
-
-MultiThreadTestHelper::~MultiThreadTestHelper() {}
-
-void MultiThreadTestHelper::SetUp() {
- ui_task_runner_ =
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
- file_task_runner_ =
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
- io_task_runner_ =
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
-}
-
-void MultiThreadTestHelper::TearDown() {
- // Make sure we give some more time to finish tasks on the FILE thread
- // before stopping IO/FILE threads.
- base::RunLoop run_loop;
- file_task_runner_->PostTaskAndReply(
- FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure());
- run_loop.Run();
-}
-
} // namespace sync_file_system
diff --git a/chrome/browser/sync_file_system/sync_file_system_test_util.h b/chrome/browser/sync_file_system/sync_file_system_test_util.h
index 85152d3..a7c33fa 100644
--- a/chrome/browser/sync_file_system/sync_file_system_test_util.h
+++ b/chrome/browser/sync_file_system/sync_file_system_test_util.h
@@ -5,19 +5,15 @@
#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
+#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
namespace base {
class RunLoop;
class SingleThreadTaskRunner;
}
-namespace content {
-class TestBrowserThreadBundle;
-}
-
namespace sync_file_system {
template <typename R>
@@ -26,36 +22,6 @@ void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result);
template <typename R> base::Callback<void(R)>
AssignAndQuitCallback(base::RunLoop* run_loop, R* result);
-// This sets up FILE, IO and UI browser threads for testing.
-// (UI thread is set to the current thread.)
-class MultiThreadTestHelper {
- public:
- MultiThreadTestHelper();
- ~MultiThreadTestHelper();
-
- void SetUp();
- void TearDown();
-
- base::SingleThreadTaskRunner* ui_task_runner() {
- return ui_task_runner_.get();
- }
-
- base::SingleThreadTaskRunner* file_task_runner() {
- return file_task_runner_.get();
- }
-
- base::SingleThreadTaskRunner* io_task_runner() {
- return io_task_runner_.get();
- }
-
- private:
- scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_;
-
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
-};
-
} // namespace sync_file_system
#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
diff --git a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc
index 81dbb20..ae5c0a0 100644
--- a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc
+++ b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc
@@ -62,11 +62,6 @@ class MockRenderViewContextMenu : public RenderViewContextMenuProxy {
virtual WebContents* GetWebContents() const OVERRIDE;
virtual Profile* GetProfile() const OVERRIDE;
- // Create a testing URL request context.
- void CreateRequestContext() {
- profile_->CreateRequestContext();
- }
-
// Attaches a RenderViewContextMenuObserver to be tested.
void SetObserver(RenderViewContextMenuObserver* observer);
@@ -327,9 +322,6 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kUseSpellingSuggestions);
- // Make sure we can pretend to handle the JSON request.
- menu()->CreateRequestContext();
-
// Force a non-empty locale so SUGGEST is available.
menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en");
EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(),
@@ -370,9 +362,6 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest,
NoMoreSuggestionsNotDisplayed) {
menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
- // Make sure we can pretend to handle the JSON request.
- menu()->CreateRequestContext();
-
// Force a non-empty locale so SPELLCHECK is available.
menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en");
EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(),
@@ -478,7 +467,6 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SuggestionsForceTopSeparator) {
menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kUseSpellingSuggestions);
- menu()->CreateRequestContext();
InitMenu("asdfkj", NULL);
// Should have at least 2 entries. Separator, suggestion.
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc
index 5d73e33..f91430b 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc
@@ -13,7 +13,7 @@
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
@@ -23,7 +23,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
@@ -38,9 +38,7 @@ using extensions::Manifest;
class ChromeLauncherControllerPerBrowserTest : public testing::Test {
protected:
ChromeLauncherControllerPerBrowserTest()
- : ui_thread_(content::BrowserThread::UI, &loop_),
- file_thread_(content::BrowserThread::FILE, &loop_),
- profile_(new TestingProfile()),
+ : profile_(new TestingProfile()),
extension_service_(NULL) {
DictionaryValue manifest;
manifest.SetString("name", "launcher controller test extension");
@@ -81,7 +79,7 @@ class ChromeLauncherControllerPerBrowserTest : public testing::Test {
virtual void TearDown() OVERRIDE {
profile_.reset();
// Execute any pending deletion tasks.
- loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void InsertPrefValue(base::ListValue* pref_value,
@@ -145,9 +143,7 @@ class ChromeLauncherControllerPerBrowserTest : public testing::Test {
}
// Needed for extension service & friends to work.
- base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
#if defined OS_CHROMEOS
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
index 8066568..dbcf723 100644
--- a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
#include "ui/aura/root_window.h"
class TestChromeLauncherControllerPerBrowser :
@@ -39,8 +38,7 @@ class LauncherContextMenuTest : public ash::test::AshTestBase {
}
LauncherContextMenuTest()
- : profile_(new TestingProfile()),
- browser_thread_(content::BrowserThread::UI, message_loop()) {}
+ : profile_(new TestingProfile()) {}
virtual void SetUp() OVERRIDE {
ash::test::AshTestBase::SetUp();
@@ -66,7 +64,6 @@ class LauncherContextMenuTest : public ash::test::AshTestBase {
private:
scoped_ptr<TestingProfile> profile_;
- content::TestBrowserThread browser_thread_;
ash::LauncherModel launcher_model_;
scoped_ptr<ChromeLauncherController> controller_;
diff --git a/chrome/browser/ui/ash/screenshot_taker_unittest.cc b/chrome/browser/ui/ash/screenshot_taker_unittest.cc
index 6eac784..ed8ffd1 100644
--- a/chrome/browser/ui/ash/screenshot_taker_unittest.cc
+++ b/chrome/browser/ui/ash/screenshot_taker_unittest.cc
@@ -18,7 +18,6 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "ui/aura/root_window.h"
#include "ui/message_center/message_center_switches.h"
@@ -30,8 +29,7 @@ class ScreenshotTakerTest : public AshTestBase,
public ScreenshotTakerObserver {
public:
ScreenshotTakerTest()
- : ui_thread_(content::BrowserThread::UI, message_loop()),
- running_(false),
+ : running_(false),
screenshot_complete_(false),
screenshot_result_(ScreenshotTakerObserver::SCREENSHOT_SUCCESS) {
}
@@ -90,7 +88,6 @@ class ScreenshotTakerTest : public AshTestBase,
}
scoped_ptr<ScopedTestingLocalState> local_state_;
- content::TestBrowserThread ui_thread_;
bool running_;
bool screenshot_complete_;
ScreenshotTakerObserver::Result screenshot_result_;
diff --git a/chrome/browser/ui/ash/window_positioner_unittest.cc b/chrome/browser/ui/ash/window_positioner_unittest.cc
index 157678f..3842e2a 100644
--- a/chrome/browser/ui/ash/window_positioner_unittest.cc
+++ b/chrome/browser/ui/ash/window_positioner_unittest.cc
@@ -16,7 +16,6 @@
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/render_view_test.h"
-#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
@@ -59,7 +58,6 @@ TestBrowserWindowAura::~TestBrowserWindowAura() {}
class WindowPositionerTest : public AshTestBase {
public:
WindowPositionerTest();
- virtual ~WindowPositionerTest();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
@@ -80,8 +78,7 @@ class WindowPositionerTest : public AshTestBase {
WindowPositioner* window_positioner_;
// These two need to be deleted after everything else is gone.
- scoped_ptr<content::TestBrowserThread> ui_thread_;
- scoped_ptr<TestingProfile> profile_;
+ TestingProfile profile_;
// These get created for each session.
scoped_ptr<aura::Window> window_;
@@ -99,18 +96,6 @@ class WindowPositionerTest : public AshTestBase {
WindowPositionerTest::WindowPositionerTest()
: grid_size_(WindowPositioner::kMinimumWindowOffset),
window_positioner_(NULL) {
- // Create a message loop.
- base::MessageLoopForUI* ui_loop = message_loop();
- ui_thread_.reset(
- new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
-
- // Create a browser profile.
- profile_.reset(new TestingProfile());
-}
-
-WindowPositionerTest::~WindowPositionerTest() {
- profile_.reset(NULL);
- ui_thread_.reset(NULL);
}
void WindowPositionerTest::SetUp() {
@@ -123,14 +108,14 @@ void WindowPositionerTest::SetUp() {
// Create a browser for the window.
browser_window_.reset(new TestBrowserWindowAura(window_.get()));
- Browser::CreateParams window_params(profile_.get(),
+ Browser::CreateParams window_params(&profile_,
chrome::HOST_DESKTOP_TYPE_ASH);
window_params.window = browser_window_.get();
window_owning_browser_.reset(new Browser(window_params));
// Creating a browser for the popup.
browser_popup_.reset(new TestBrowserWindowAura(popup_.get()));
- Browser::CreateParams popup_params(Browser::TYPE_POPUP, profile_.get(),
+ Browser::CreateParams popup_params(Browser::TYPE_POPUP, &profile_,
chrome::HOST_DESKTOP_TYPE_ASH);
popup_params.window = browser_popup_.get();
popup_owning_browser_.reset(new Browser(popup_params));
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
index 142e7d0..a647868 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
@@ -320,7 +320,6 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
// testing::Test implementation:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
- profile()->CreateRequestContext();
test_bubble_controller_ =
new testing::NiceMock<TestAutofillCreditCardBubbleController>(
@@ -342,7 +341,6 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
void Reset() {
if (controller_)
controller_->ViewClosed();
- profile()->CreateRequestContext();
test_bubble_controller_ =
new testing::NiceMock<TestAutofillCreditCardBubbleController>(
diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm
index 8f4f659..58c279f 100644
--- a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm
@@ -58,7 +58,6 @@ class BalloonControllerTest : public ChromeRenderViewHostTestHarness {
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
CocoaTest::BootstrapCocoa();
- profile()->CreateRequestContext();
Browser::CreateParams native_params(profile(), chrome::GetActiveDesktop());
browser_.reset(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc
index faf842d..c520df9 100644
--- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc
+++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h"
#include "base/compiler_specific.h"
-#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
@@ -14,11 +14,9 @@
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
-using content::BrowserThread;
-
// Dummy implementation that's good enough for the tests; we don't test
// rendering here so all we need is a non-NULL object.
class EmptyTabstripOriginProvider : public TabstripOriginProvider {
@@ -30,11 +28,6 @@ class EmptyTabstripOriginProvider : public TabstripOriginProvider {
class BookmarkBarGtkUnittest : public testing::Test {
protected:
- BookmarkBarGtkUnittest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_) {
- }
-
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
@@ -51,7 +44,7 @@ class BookmarkBarGtkUnittest : public testing::Test {
}
virtual void TearDown() OVERRIDE {
- message_loop_.RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
bookmark_bar_.reset();
origin_provider_.reset();
@@ -61,9 +54,7 @@ class BookmarkBarGtkUnittest : public testing::Test {
BookmarkModel* model_;
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestingProfile> profile_;
scoped_ptr<Browser> browser_;
diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc b/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc
index 374c8fd..0535657 100644
--- a/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc
+++ b/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc
@@ -14,7 +14,7 @@
#include "chrome/common/content_settings.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::HistogramBase;
@@ -136,11 +136,7 @@ private:
class InstantNTPPrerendererTest : public testing::Test {
public:
InstantNTPPrerendererTest()
- : ui_thread_(content::BrowserThread::UI),
- instant_ntp_prerenderer_(new TestableInstantNTPPrerenderer(&profile_)) {
- }
-
- virtual void SetUp() OVERRIDE {
+ : instant_ntp_prerenderer_(new TestableInstantNTPPrerenderer(&profile_)) {
base::StatisticsRecorder::Initialize();
}
@@ -153,7 +149,7 @@ class InstantNTPPrerendererTest : public testing::Test {
}
private:
- content::TestBrowserThread ui_thread_;
+ content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_;
mutable TestingProfile profile_;
};
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc b/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc
index d4c94a8..e0ff981 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/wrench_menu_model_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ui/toolbar/wrench_menu_model.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/global_error/global_error.h"
@@ -13,6 +14,9 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/menu_model_test.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_io_thread_state.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -77,6 +81,27 @@ class WrenchMenuModelTest : public BrowserWithTestWindowTest,
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE { return false; }
+
+ protected:
+ virtual void SetUp() OVERRIDE {
+ prefs_.reset(new TestingPrefServiceSimple());
+ chrome::RegisterLocalState(prefs_->registry());
+
+ TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get());
+ testing_io_thread_state_.reset(new chrome::TestingIOThreadState());
+ BrowserWithTestWindowTest::SetUp();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ BrowserWithTestWindowTest::TearDown();
+ testing_io_thread_state_.reset();
+ TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
+ DestroyBrowserAndProfile();
+ }
+
+ private:
+ scoped_ptr<TestingPrefServiceSimple> prefs_;
+ scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_;
};
// Copies parts of MenuModelTest::Delegate and combines them with the
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
index c1f7053..bb5f2de 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
@@ -113,8 +113,7 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase {
public:
BookmarkBarViewEventTestBase()
: ViewEventTestBase(),
- model_(NULL),
- file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
+ model_(NULL) {}
virtual void SetUp() OVERRIDE {
views::MenuController::TurnOffContextMenuSelectionHoldForTest();
@@ -243,7 +242,6 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase {
scoped_ptr<TestingProfile> profile_;
scoped_ptr<Browser> browser_;
scoped_ptr<ScopedTestingLocalState> local_state_;
- content::TestBrowserThread file_thread_;
ChromeViewsDelegate views_delegate_;
};
diff --git a/chrome/browser/ui/views/frame/browser_view_unittest.cc b/chrome/browser/ui/views/frame/browser_view_unittest.cc
index 8bb3377..d3ad284 100644
--- a/chrome/browser/ui/views/frame/browser_view_unittest.cc
+++ b/chrome/browser/ui/views/frame/browser_view_unittest.cc
@@ -9,6 +9,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
+#include "chrome/browser/predictors/predictor_database.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser_commands.h"
@@ -23,6 +24,8 @@
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_io_thread_state.h"
+#include "content/public/test/test_utils.h"
#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/single_split_view.h"
@@ -80,6 +83,8 @@ class BrowserViewTest : public BrowserWithTestWindowTest {
private:
BrowserView* browser_view_; // Not owned.
scoped_ptr<ScopedTestingLocalState> local_state_;
+ scoped_ptr<predictors::PredictorDatabase> predictor_db_;
+ scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_;
DISALLOW_COPY_AND_ASSIGN(BrowserViewTest);
};
@@ -101,7 +106,10 @@ void BrowserViewTest::TearDown() {
// the Profile.
browser_view_->GetWidget()->CloseNow();
browser_view_ = NULL;
+ content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
BrowserWithTestWindowTest::TearDown();
+ testing_io_thread_state_.reset();
+ predictor_db_.reset();
#if defined(OS_CHROMEOS)
chromeos::input_method::Shutdown();
#endif
@@ -134,7 +142,9 @@ void BrowserViewTest::Init() {
chromeos::input_method::InitializeForTesting(
new chromeos::input_method::MockInputMethodManager);
#endif
+ testing_io_thread_state_.reset(new chrome::TestingIOThreadState());
BrowserWithTestWindowTest::SetUp();
+ predictor_db_.reset(new predictors::PredictorDatabase(GetProfile()));
browser_view_ = static_cast<BrowserView*>(browser()->window());
}
@@ -289,7 +299,6 @@ class BrowserViewIncognitoSwitcherTest : public BrowserViewTest {
BrowserViewIncognitoSwitcherTest()
: browser_view_(NULL) {}
- virtual ~BrowserViewIncognitoSwitcherTest() {}
virtual void SetUp() OVERRIDE {
Init();
diff --git a/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc b/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc
index 2790756..a66d5c9 100644
--- a/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc
+++ b/chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc
@@ -76,32 +76,6 @@ int AlignToGridRoundDown(int location, int grid_size) {
return location / grid_size * grid_size;
}
-// A special test class for use with browser creation - it will create a
-// browser thread and deletes it after all other things have been destroyed.
-class WindowSizerTestWithBrowser : public WindowSizerTest {
- public:
- WindowSizerTestWithBrowser();
- virtual ~WindowSizerTestWithBrowser();
-
- private:
- // Note: It is important to delete the thread after the browser instances got
- // deleted. For this we transfer the thread here.
- scoped_ptr<content::TestBrowserThread> ui_thread_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser);
-};
-
-// The class function definitions from window_sizer_common_unittest.h
-WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() {
- // Set up a UI message thread.
- base::MessageLoopForUI* ui_loop = message_loop();
- ui_thread_.reset(
- new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
-}
-
-WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() {
-}
-
} // namespace
// Test that the window is sized appropriately for the first run experience
@@ -456,7 +430,7 @@ TEST_F(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) {
}
// Test the placement of newly created windows.
-TEST_F(WindowSizerTestWithBrowser, PlaceNewWindows) {
+TEST_F(WindowSizerTest, PlaceNewWindows) {
// Create a dummy window.
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->SetBounds(gfx::Rect(16, 32, 640, 320));
@@ -576,7 +550,7 @@ TEST_F(WindowSizerTestWithBrowser, PlaceNewWindows) {
// Test the placement of newly created windows on an empty desktop.
// This test supplements "PlaceNewWindows" by testing the creation of a newly
// created browser window on an empty desktop.
-TEST_F(WindowSizerTestWithBrowser, PlaceNewBrowserWindowOnEmptyDesktop) {
+TEST_F(WindowSizerTest, PlaceNewBrowserWindowOnEmptyDesktop) {
// Create a browser which we can use to pass into the GetWindowBounds
// function.
scoped_ptr<TestingProfile> profile(new TestingProfile());
@@ -652,7 +626,7 @@ TEST_F(WindowSizerTestWithBrowser, PlaceNewBrowserWindowOnEmptyDesktop) {
#endif
// Test the placement of newly created windows on multiple dislays.
-TEST_F(WindowSizerTestWithBrowser, MAYBE_PlaceNewWindowsOnMultipleDisplays) {
+TEST_F(WindowSizerTest, MAYBE_PlaceNewWindowsOnMultipleDisplays) {
UpdateDisplay("1600x1200,1600x1200");
const gfx::Rect secondary(1600, 0, 1600, 1200);
@@ -741,7 +715,7 @@ TEST_F(WindowSizerTestWithBrowser, MAYBE_PlaceNewWindowsOnMultipleDisplays) {
}
// Test that the show state is properly returned for non default cases.
-TEST_F(WindowSizerTestWithBrowser, TestShowState) {
+TEST_F(WindowSizerTest, TestShowState) {
// Creating a browser & window to play with.
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->SetBounds(gfx::Rect(16, 32, 640, 320));
@@ -846,7 +820,7 @@ TEST_F(WindowSizerTestWithBrowser, TestShowState) {
}
// Test that the default show state override behavior is properly handled.
-TEST_F(WindowSizerTestWithBrowser, TestShowStateDefaults) {
+TEST_F(WindowSizerTest, TestShowStateDefaults) {
// Creating a browser & window to play with.
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->SetBounds(gfx::Rect(16, 32, 640, 320));