OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include <algorithm> | 6 #include <algorithm> |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 InfoBarService* infobar_service() { | 141 InfoBarService* infobar_service() { |
142 return InfoBarService::FromWebContents(web_contents()); | 142 return InfoBarService::FromWebContents(web_contents()); |
143 } | 143 } |
144 | 144 |
145 // Returns the translate infobar if there is 1 infobar and it is a translate | 145 // Returns the translate infobar if there is 1 infobar and it is a translate |
146 // infobar. | 146 // infobar. |
147 TranslateInfoBarDelegate* GetTranslateInfoBar() { | 147 TranslateInfoBarDelegate* GetTranslateInfoBar() { |
148 return (infobar_service()->GetInfoBarCount() == 1) ? | 148 return (infobar_service()->infobar_count() == 1) ? |
149 infobar_service()->GetInfoBarDelegateAt(0)-> | 149 infobar_service()->infobar_at(0)->AsTranslateInfoBarDelegate() : NULL; |
150 AsTranslateInfoBarDelegate() : NULL; | |
151 } | 150 } |
152 | 151 |
153 // If there is 1 infobar and it is a translate infobar, closes it and returns | 152 // If there is 1 infobar and it is a translate infobar, closes it and returns |
154 // true. Returns false otherwise. | 153 // true. Returns false otherwise. |
155 bool CloseTranslateInfoBar() { | 154 bool CloseTranslateInfoBar() { |
156 InfoBarDelegate* infobar = GetTranslateInfoBar(); | 155 InfoBarDelegate* infobar = GetTranslateInfoBar(); |
157 if (!infobar) | 156 if (!infobar) |
158 return false; | 157 return false; |
159 infobar->InfoBarDismissed(); // Simulates closing the infobar. | 158 infobar->InfoBarDismissed(); // Simulates closing the infobar. |
160 infobar_service()->RemoveInfoBar(infobar); | 159 infobar_service()->RemoveInfoBar(infobar); |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 726 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
728 } | 727 } |
729 | 728 |
730 // Tests that multiple OnPageContents do not cause multiple infobars. | 729 // Tests that multiple OnPageContents do not cause multiple infobars. |
731 TEST_F(TranslateManagerBrowserTest, MultipleOnPageContents) { | 730 TEST_F(TranslateManagerBrowserTest, MultipleOnPageContents) { |
732 // Simulate navigating to a page and getting its language. | 731 // Simulate navigating to a page and getting its language. |
733 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 732 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
734 | 733 |
735 // Simulate clicking 'Nope' (don't translate). | 734 // Simulate clicking 'Nope' (don't translate). |
736 EXPECT_TRUE(DenyTranslation()); | 735 EXPECT_TRUE(DenyTranslation()); |
737 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 736 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
738 | 737 |
739 // Send a new PageContents, we should not show an infobar. | 738 // Send a new PageContents, we should not show an infobar. |
740 SimulateOnTranslateLanguageDetermined("fr", true); | 739 SimulateOnTranslateLanguageDetermined("fr", true); |
741 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 740 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
742 | 741 |
743 // Do the same steps but simulate closing the infobar this time. | 742 // Do the same steps but simulate closing the infobar this time. |
744 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); | 743 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); |
745 EXPECT_TRUE(CloseTranslateInfoBar()); | 744 EXPECT_TRUE(CloseTranslateInfoBar()); |
746 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 745 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
747 SimulateOnTranslateLanguageDetermined("fr", true); | 746 SimulateOnTranslateLanguageDetermined("fr", true); |
748 EXPECT_EQ(0U, infobar_service()->GetInfoBarCount()); | 747 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
749 } | 748 } |
750 | 749 |
751 // Test that reloading the page brings back the infobar if the | 750 // Test that reloading the page brings back the infobar if the |
752 // reload succeeded and does not bring it back the reload fails. | 751 // reload succeeded and does not bring it back the reload fails. |
753 TEST_F(TranslateManagerBrowserTest, Reload) { | 752 TEST_F(TranslateManagerBrowserTest, Reload) { |
754 // Simulate navigating to a page and getting its language. | 753 // Simulate navigating to a page and getting its language. |
755 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 754 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
756 | 755 |
757 // Close the infobar. | 756 // Close the infobar. |
758 EXPECT_TRUE(CloseTranslateInfoBar()); | 757 EXPECT_TRUE(CloseTranslateInfoBar()); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, MAYBE_TranslateSessionRestore) { | 1515 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, MAYBE_TranslateSessionRestore) { |
1517 WebContents* current_web_contents = | 1516 WebContents* current_web_contents = |
1518 browser()->tab_strip_model()->GetActiveWebContents(); | 1517 browser()->tab_strip_model()->GetActiveWebContents(); |
1519 content::Source<WebContents> source(current_web_contents); | 1518 content::Source<WebContents> source(current_web_contents); |
1520 | 1519 |
1521 ui_test_utils::WindowedNotificationObserverWithDetails<std::string> | 1520 ui_test_utils::WindowedNotificationObserverWithDetails<std::string> |
1522 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1521 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1523 source); | 1522 source); |
1524 fr_language_detected_signal.Wait(); | 1523 fr_language_detected_signal.Wait(); |
1525 } | 1524 } |
OLD | NEW |