Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2514)

Unified Diff: chrome/browser/translate/translate_manager_unittest.cc

Issue 3011008: Don't crash if the translate server reports a language we don't know (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/translate/translate_manager.cc ('k') | chrome/common/translate_errors.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_manager_unittest.cc
===================================================================
--- chrome/browser/translate/translate_manager_unittest.cc (revision 52843)
+++ chrome/browser/translate/translate_manager_unittest.cc (working copy)
@@ -31,11 +31,6 @@
using testing::Property;
using WebKit::WebContextMenuData;
-class TestTranslateManager : public TranslateManager {
- public:
- TestTranslateManager() {}
-};
-
class TranslateManagerTest : public RenderViewHostTestHarness,
public NotificationObserver {
public:
@@ -193,7 +188,6 @@
private:
NotificationRegistrar notification_registrar_;
- scoped_ptr<TestTranslateManager> translate_manager_;
TestURLFetcherFactory url_fetcher_factory_;
// The list of infobars that have been removed.
@@ -711,7 +705,7 @@
// Tests that no translate infobar is shown when navigating to a page in an
// unsupported language.
-TEST_F(TranslateManagerTest, UnsupportedPageLanguage) {
+TEST_F(TranslateManagerTest, CLDReportsUnsupportedPageLanguage) {
// Simulate navigating to a page and getting an unsupported language.
SimulateNavigation(GURL("http://www.google.com"), 0, "Google", "qbz", true);
@@ -719,6 +713,42 @@
EXPECT_TRUE(GetTranslateInfoBar() == NULL);
}
+// Tests that we deal correctly with unsupported languages returned by the
+// server.
+// The translation server might return a language we don't support.
+TEST_F(TranslateManagerTest, ServerReportsUnsupportedLanguage) {
+ // Simulate navigating to a page and translating it.
+ SimulateNavigation(GURL("http://mail.google.fr"), 0, "Le Google", "fr",
+ true);
+ TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
+ ASSERT_TRUE(infobar != NULL);
+ process()->sink().ClearMessages();
+ infobar->Translate();
+ SimulateURLFetch(true);
+ // Simulate the render notifying the translation has been done, but it
+ // reports a language we don't support.
+ rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "qbz", "en",
+ TranslateErrors::NONE));
+
+ // An error infobar should be showing to report that we don't support this
+ // language.
+ infobar = GetTranslateInfoBar();
+ ASSERT_TRUE(infobar != NULL);
+ EXPECT_EQ(TranslateInfoBarDelegate::kTranslationError, infobar->type());
+
+ // This infobar should have a button (so the string should not be empty).
+ ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty());
+
+ // Pressing the button on that infobar should revert to the original language.
+ process()->sink().ClearMessages();
+ infobar->MessageInfoBarButtonPressed();
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(ViewMsg_RevertTranslation::ID);
+ EXPECT_TRUE(message != NULL);
+ // And it should have removed the infobar.
+ EXPECT_TRUE(GetTranslateInfoBar() == NULL);
+}
+
// Tests that no translate infobar is shown when Chrome is in a language that
// the translate server does not support.
TEST_F(TranslateManagerTest, UnsupportedUILanguage) {
@@ -1088,3 +1118,4 @@
EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
}
+
« no previous file with comments | « chrome/browser/translate/translate_manager.cc ('k') | chrome/common/translate_errors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698