summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-13 02:03:41 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-13 02:03:41 +0000
commit6b12accdb84b02578fbdf5789e6816d1ffc5d19e (patch)
treee98ef8e864f5774f9b07a0e92686ab7dc9b2142a /chrome/browser/translate
parent406c23ac9590b10b009eb3332446bb78cfea98b7 (diff)
downloadchromium_src-6b12accdb84b02578fbdf5789e6816d1ffc5d19e.zip
chromium_src-6b12accdb84b02578fbdf5789e6816d1ffc5d19e.tar.gz
chromium_src-6b12accdb84b02578fbdf5789e6816d1ffc5d19e.tar.bz2
Fix the TranslateManager and unit-tests.
There was a bug that was initialy turning on translate all the time. When fixed it made the unit-tests fail, revealing another bug. The test was calling a virtual method in its constructor, which was bad and not turning on translate for the tests. BUG=None TEST=UI tests, browser tests, unit-tests should pass. Review URL: http://codereview.chromium.org/601069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-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) {