summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate/translate_manager_unittest.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 21:06:36 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 21:06:36 +0000
commitf4da95ff623ea7b7b4bd2c6fe2402437a712b9df (patch)
tree20b3110d52e76a1bd04eb4b2eb6a18871588656a /chrome/browser/translate/translate_manager_unittest.cc
parente9e079909c486a3d7561c1a0433762b395c0f48d (diff)
downloadchromium_src-f4da95ff623ea7b7b4bd2c6fe2402437a712b9df.zip
chromium_src-f4da95ff623ea7b7b4bd2c6fe2402437a712b9df.tar.gz
chromium_src-f4da95ff623ea7b7b4bd2c6fe2402437a712b9df.tar.bz2
Makes sure we don't display several times the translate infobar for a page.
We can get several PAGE_DETERMINED notifications for one page. The user might have closed the translate infobar between these multiple notifications. This CL ensures we don't show the infobar again in such cases. BUG=35919 TEST=See bug. Review URL: http://codereview.chromium.org/613002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate/translate_manager_unittest.cc')
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc38
1 files changed, 37 insertions, 1 deletions
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index e29cc42..34d81f2 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -23,6 +23,12 @@ class TranslateManagerTest : public RenderViewHostTestHarness {
const std::wstring& contents,
const std::string& lang) {
NavigateAndCommit(url);
+ SimulateOnPageContents(url, page_id, contents, lang);
+ }
+
+ void SimulateOnPageContents(const GURL& url, int page_id,
+ const std::wstring& contents,
+ const std::string& lang) {
rvh()->TestOnMessageReceived(ViewHostMsg_PageContents(0, url, page_id,
contents, lang));
}
@@ -121,7 +127,7 @@ TEST_F(TranslateManagerTest, NormalTranslate) {
EXPECT_EQ(new_target_lang, target_lang);
}
-// Test auto-translate on page.
+// Tests auto-translate on page.
TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) {
// Simulate navigating to a page and gettings its language.
SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
@@ -153,3 +159,33 @@ TEST_F(TranslateManagerTest, AutoTranslateOnNavigate) {
// This should not have triggered a translate.
EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
}
+
+// Tests that multiple OnPageContents do not cause multiple infobars.
+TEST_F(TranslateManagerTest, MultipleOnPageContents) {
+ // Simulate navigating to a page and gettings its language.
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+
+ // Simulate clicking 'Nope' (don't translate).
+ ASSERT_EQ(1, contents()->infobar_delegate_count());
+ TranslateInfoBarDelegate* infobar =
+ contents()->GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate();
+ ASSERT_TRUE(infobar != NULL);
+ infobar->TranslationDeclined();
+ contents()->RemoveInfoBar(infobar);
+ EXPECT_EQ(0, contents()->infobar_delegate_count());
+
+ // Send a new PageContents, we should not show an infobar.
+ SimulateOnPageContents(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+ EXPECT_EQ(0, contents()->infobar_delegate_count());
+
+ // Do the same steps but simulate closing the infobar this time.
+ SimulateNavigation(GURL("http://www.youtube.fr"), 1, L"Le YouTube", "fr");
+ ASSERT_EQ(1, contents()->infobar_delegate_count());
+ infobar = contents()->GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate();
+ ASSERT_TRUE(infobar != NULL);
+ infobar->InfoBarDismissed(); // Simulates closing the infobar.
+ contents()->RemoveInfoBar(infobar);
+ EXPECT_EQ(0, contents()->infobar_delegate_count());
+ SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, L"Le YouTube", "fr");
+ EXPECT_EQ(0, contents()->infobar_delegate_count());
+}