summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/translate/translate_manager.cc5
-rw-r--r--chrome/browser/translate/translate_manager.h8
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc21
3 files changed, 26 insertions, 8 deletions
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 773c066..742f9f0 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -21,6 +21,9 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+// static
+bool TranslateManager::test_enabled_ = false;
+
TranslateManager::~TranslateManager() {
}
@@ -83,7 +86,7 @@ void TranslateManager::Observe(NotificationType type,
}
TranslateManager::TranslateManager() {
- if (TestEnabled() && !TranslationService::IsTranslationEnabled())
+ if (!test_enabled_ && !TranslationService::IsTranslationEnabled())
return;
notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
diff --git a/chrome/browser/translate/translate_manager.h b/chrome/browser/translate/translate_manager.h
index e41fb04..706dd2c 100644
--- a/chrome/browser/translate/translate_manager.h
+++ b/chrome/browser/translate/translate_manager.h
@@ -30,10 +30,10 @@ class TranslateManager : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details);
- protected:
- // Overriden by unit-tests to enable the TranslateManager.
- virtual bool TestEnabled() { return false; }
+ // Used by unit-test to enable the TranslateManager for testing purpose.
+ static void set_test_enabled(bool enabled) { test_enabled_ = enabled; }
+ protected:
TranslateManager();
private:
@@ -58,6 +58,8 @@ class TranslateManager : public NotificationObserver {
typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap;
PrefServiceLanguagesMap accept_languages_;
+ static bool test_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(TranslateManager);
};
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 75420c5..e29cc42 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -13,9 +13,6 @@
class TestTranslateManager : public TranslateManager {
public:
TestTranslateManager() {}
-
- protected:
- virtual bool TestEnabled() { return true; }
};
class TranslateManagerTest : public RenderViewHostTestHarness {
@@ -45,8 +42,24 @@ class TranslateManagerTest : public RenderViewHostTestHarness {
return true;
}
+ protected:
+ virtual void SetUp() {
+ RenderViewHostTestHarness::SetUp();
+
+ TranslateManager::set_test_enabled(true);
+ // This must be created after set_test_enabled() has been called to register
+ // notifications properly.
+ translate_manager_.reset(new TestTranslateManager());
+ }
+
+ virtual void TearDown() {
+ RenderViewHostTestHarness::TearDown();
+
+ TranslateManager::set_test_enabled(false);
+ }
+
private:
- TestTranslateManager translate_manager_;
+ scoped_ptr<TestTranslateManager> translate_manager_;
};
TEST_F(TranslateManagerTest, NormalTranslate) {