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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 InfoBarTabHelper* infobar_tab_helper() { | 103 InfoBarTabHelper* infobar_tab_helper() { |
104 return tab_contents()->infobar_tab_helper(); | 104 return tab_contents()->infobar_tab_helper(); |
105 } | 105 } |
106 | 106 |
107 // Returns the translate infobar if there is 1 infobar and it is a translate | 107 // Returns the translate infobar if there is 1 infobar and it is a translate |
108 // infobar. | 108 // infobar. |
109 TranslateInfoBarDelegate* GetTranslateInfoBar() { | 109 TranslateInfoBarDelegate* GetTranslateInfoBar() { |
110 return (infobar_tab_helper()->infobar_count() == 1) ? | 110 return (infobar_tab_helper()->GetInfoBarCount() == 1) ? |
111 infobar_tab_helper()->GetInfoBarDelegateAt(0)-> | 111 infobar_tab_helper()->GetInfoBarDelegateAt(0)-> |
112 AsTranslateInfoBarDelegate() : NULL; | 112 AsTranslateInfoBarDelegate() : NULL; |
113 } | 113 } |
114 | 114 |
115 // If there is 1 infobar and it is a translate infobar, closes it and returns | 115 // If there is 1 infobar and it is a translate infobar, closes it and returns |
116 // true. Returns false otherwise. | 116 // true. Returns false otherwise. |
117 bool CloseTranslateInfoBar() { | 117 bool CloseTranslateInfoBar() { |
118 InfoBarDelegate* infobar = GetTranslateInfoBar(); | 118 InfoBarDelegate* infobar = GetTranslateInfoBar(); |
119 if (!infobar) | 119 if (!infobar) |
120 return false; | 120 return false; |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 724 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
725 } | 725 } |
726 | 726 |
727 // Tests that multiple OnPageContents do not cause multiple infobars. | 727 // Tests that multiple OnPageContents do not cause multiple infobars. |
728 TEST_F(TranslateManagerTest, MultipleOnPageContents) { | 728 TEST_F(TranslateManagerTest, MultipleOnPageContents) { |
729 // Simulate navigating to a page and getting its language. | 729 // Simulate navigating to a page and getting its language. |
730 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 730 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
731 | 731 |
732 // Simulate clicking 'Nope' (don't translate). | 732 // Simulate clicking 'Nope' (don't translate). |
733 EXPECT_TRUE(DenyTranslation()); | 733 EXPECT_TRUE(DenyTranslation()); |
734 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 734 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
735 | 735 |
736 // Send a new PageContents, we should not show an infobar. | 736 // Send a new PageContents, we should not show an infobar. |
737 SimulateOnTranslateLanguageDetermined("fr", true); | 737 SimulateOnTranslateLanguageDetermined("fr", true); |
738 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 738 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
739 | 739 |
740 // Do the same steps but simulate closing the infobar this time. | 740 // Do the same steps but simulate closing the infobar this time. |
741 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); | 741 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); |
742 EXPECT_TRUE(CloseTranslateInfoBar()); | 742 EXPECT_TRUE(CloseTranslateInfoBar()); |
743 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 743 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
744 SimulateOnTranslateLanguageDetermined("fr", true); | 744 SimulateOnTranslateLanguageDetermined("fr", true); |
745 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 745 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
746 } | 746 } |
747 | 747 |
748 // Test that reloading the page brings back the infobar. | 748 // Test that reloading the page brings back the infobar. |
749 TEST_F(TranslateManagerTest, Reload) { | 749 TEST_F(TranslateManagerTest, Reload) { |
750 // Simulate navigating to a page and getting its language. | 750 // Simulate navigating to a page and getting its language. |
751 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 751 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
752 | 752 |
753 // Close the infobar. | 753 // Close the infobar. |
754 EXPECT_TRUE(CloseTranslateInfoBar()); | 754 EXPECT_TRUE(CloseTranslateInfoBar()); |
755 | 755 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 NULL); | 1459 NULL); |
1460 // Now simulate the URL fetch. | 1460 // Now simulate the URL fetch. |
1461 SimulateTranslateScriptURLFetch(true); | 1461 SimulateTranslateScriptURLFetch(true); |
1462 // Now the message should have been sent. | 1462 // Now the message should have been sent. |
1463 int page_id = 0; | 1463 int page_id = 0; |
1464 std::string original_lang, target_lang; | 1464 std::string original_lang, target_lang; |
1465 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1465 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1466 EXPECT_EQ("es", original_lang); | 1466 EXPECT_EQ("es", original_lang); |
1467 EXPECT_EQ("en", target_lang); | 1467 EXPECT_EQ("en", target_lang); |
1468 } | 1468 } |
OLD | NEW |