Commit 275f3166 authored by danakj@chromium.org's avatar danakj@chromium.org

Move TranslateManager unit tests out of the browser_tests target.

These are unit tests so they should be in the unit_tests target. A
TODO says this did not work before, but they appear to pass as unit
tests now, so this is just a code move.

BUG=270918
R=droger@chromium.org, hajimehoshi@chromium.org

Review URL: https://codereview.chromium.org/186063007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255661 0039d316-1c4b-4281-b951-d872f2087c98
parent 867f72e5
......@@ -43,11 +43,26 @@ void TranslateService::Shutdown(bool cleanup_pending_fetcher) {
if (cleanup_pending_fetcher) {
download_manager->Shutdown();
} else {
// This path is only used by tests.
// This path is only used by browser tests.
download_manager->set_request_context(NULL);
}
}
// static
void TranslateService::InitializeForTesting() {
if (!g_translate_service) {
TranslateService::Initialize();
} else {
TranslateDownloadManager::GetInstance()->ResetForTesting();
g_translate_service->OnResourceRequestsAllowed();
}
}
// static
void TranslateService::ShutdownForTesting() {
TranslateDownloadManager::GetInstance()->Shutdown();
}
void TranslateService::OnResourceRequestsAllowed() {
TranslateLanguageList* language_list =
TranslateDownloadManager::GetInstance()->language_list();
......
......@@ -18,6 +18,15 @@ class TranslateService : public ResourceRequestAllowedNotifier::Observer {
// Must be called to shut down the Translate feature.
static void Shutdown(bool cleanup_pending_fetcher);
// Initializes the TranslateService in a way that it can be initialized
// multiple times in a unit test suite (once for each test). Should be paired
// with ShutdownForTesting at the end of the test.
static void InitializeForTesting();
// Shuts down the TranslateService at the end of a test in a way that the next
// test can initialize and use the service.
static void ShutdownForTesting();
// Let the caller decide if and when we should fetch the language list from
// the translate server. This is a NOOP if switches::kDisableTranslate is set
// or if prefs::kEnableTranslate is set to false.
......
......@@ -1420,6 +1420,7 @@
'browser/thumbnails/simple_thumbnail_crop_unittest.cc',
'browser/thumbnails/thumbnail_service_unittest.cc',
'browser/translate/translate_manager_unittest.cc',
'browser/translate/translate_manager_render_view_host_unittest.cc',
'browser/ui/android/tab_model/tab_model_unittest.cc',
'browser/ui/ash/ime_controller_chromeos_unittest.cc',
'browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc',
......@@ -2534,6 +2535,7 @@
'browser/sync/profile_sync_service_session_unittest.cc',
'browser/sync/sessions2/sessions_sync_manager_unittest.cc',
'browser/sync/sync_global_error_unittest.cc',
'browser/translate/translate_manager_render_view_host_unittest.cc',
'browser/ui/autofill/autofill_dialog_controller_unittest.cc',
'browser/ui/browser_instant_controller_unittest.cc',
'browser/ui/bookmarks/bookmark_bubble_sign_in_delegate_unittest.cc',
......
......@@ -118,6 +118,11 @@ void TranslateDownloadManager::ClearTranslateScriptForTesting() {
script_->Clear();
}
void TranslateDownloadManager::ResetForTesting() {
language_list_.reset(new TranslateLanguageList);
script_.reset(new TranslateScript);
}
void TranslateDownloadManager::SetTranslateScriptExpirationDelay(int delay_ms) {
if (script_.get() == NULL) {
NOTREACHED();
......
......@@ -78,6 +78,9 @@ class TranslateDownloadManager {
// Clears the translate script, so it will be fetched next time we translate.
void ClearTranslateScriptForTesting();
// Resets to its initial state as if newly created.
void ResetForTesting();
// Used by unit-tests to override some defaults:
// Delay after which the translate script is fetched again from the
// translation server.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment