Index: chrome/browser/translate/translate_manager_browsertest.cc |
diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc |
index a76421f86cd124206e6b6aea7279a5ed2cdc18d1..73d3e2033f6d855470d71db79907ab9e8b00c1d9 100644 |
--- a/chrome/browser/translate/translate_manager_browsertest.cc |
+++ b/chrome/browser/translate/translate_manager_browsertest.cc |
@@ -14,15 +14,179 @@ |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/ui_test_utils.h" |
+#include "components/translate/core/browser/translate_error_details.h" |
#include "components/translate/core/common/language_detection_details.h" |
#include "content/public/browser/notification_service.h" |
#include "net/url_request/test_url_fetcher_factory.h" |
#include "net/url_request/url_fetcher_delegate.h" |
#include "url/gurl.h" |
+namespace { |
+ |
+static const char kTestValidScript[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return true;" |
+ " }," |
+ " restore : function() {" |
+ " return;" |
+ " }," |
+ " getDetectedLanguage : function() {" |
+ " return \"fr\";" |
+ " }," |
+ " translatePage : function(originalLang, targetLang," |
+ " onTranslateProgress) {" |
+ " var error = (originalLang == 'auto') ? true : false;" |
+ " onTranslateProgress(100, true, error);" |
+ " }" |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptInitializationError[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return error;" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptIdenticalLanguages[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return true;" |
+ " }," |
+ " restore : function() {" |
+ " return;" |
+ " }," |
+ " getDetectedLanguage : function() {" |
+ " return \"en\";" |
+ " }," |
+ " translatePage : function(originalLang, targetLang," |
+ " onTranslateProgress) {" |
+ " onTranslateProgress(100, true, 0);" |
+ " }" |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptTimeout[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return false;" |
+ " }," |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptUnexpectedScriptError[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return true;" |
+ " }," |
+ " restore : function() {" |
+ " return;" |
+ " }," |
+ " getDetectedLanguage : function() {" |
+ " return \"fr\";" |
+ " }," |
+ " translatePage : function(originalLang, targetLang," |
+ " onTranslateProgress) {" |
+ " return error;" |
+ " }" |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptBadOrigin[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return true;" |
+ " }," |
+ " restore : function() {" |
+ " return;" |
+ " }," |
+ " getDetectedLanguage : function() {" |
+ " return \"fr\";" |
+ " }," |
+ " translatePage : function(originalLang, targetLang," |
+ " onTranslateProgress) {" |
+ " var url = \"\";" |
+ " cr.googleTranslate.onLoadJavascript(url);" |
+ " }" |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+static const char kTestScriptLoadError[] = |
+ "var google = {};" |
+ "google.translate = (function() {" |
+ " return {" |
+ " TranslateService: function() {" |
+ " return {" |
+ " isAvailable : function() {" |
+ " return true;" |
+ " }," |
+ " restore : function() {" |
+ " return;" |
+ " }," |
+ " getDetectedLanguage : function() {" |
+ " return \"fr\";" |
+ " }," |
+ " translatePage : function(originalLang, targetLang," |
+ " onTranslateProgress) {" |
+ " var url = \"https://translate.googleapis.com/INVALID\";" |
+ " cr.googleTranslate.onLoadJavascript(url);" |
+ " }" |
+ " };" |
+ " }" |
+ " };" |
+ "})();" |
+ "cr.googleTranslate.onTranslateElementLoad();"; |
+ |
+} // namespace |
+ |
class TranslateManagerBrowserTest : public InProcessBrowserTest { |
public: |
- TranslateManagerBrowserTest() {} |
+ TranslateManagerBrowserTest() { |
+ error_subscription_ = |
+ translate::TranslateManager::RegisterTranslateErrorCallback( |
+ base::Bind(&TranslateManagerBrowserTest::OnTranslateError, |
+ base::Unretained(this))); |
+ } |
~TranslateManagerBrowserTest() override {} |
void WaitUntilLanguageDetected() { language_detected_signal_->Wait(); } |
@@ -37,37 +201,11 @@ class TranslateManagerBrowserTest : public InProcessBrowserTest { |
content::NotificationService::AllSources())); |
} |
- void SimulateURLFetch(bool success) { |
+ void SimulateURLFetch(const std::string& script, bool success) { |
net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
ASSERT_TRUE(fetcher); |
net::Error error = success ? net::OK : net::ERR_FAILED; |
- std::string script = |
- " var google = {};" |
- "google.translate = (function() {" |
- " return {" |
- " TranslateService: function() {" |
- " return {" |
- " isAvailable : function() {" |
- " return true;" |
- " }," |
- " restore : function() {" |
- " return;" |
- " }," |
- " getDetectedLanguage : function() {" |
- " return \"fr\";" |
- " }," |
- " translatePage : function(originalLang, targetLang," |
- " onTranslateProgress) {" |
- " var error = (originalLang == 'auto') ? true : false;" |
- " onTranslateProgress(100, true, error);" |
- " }" |
- " };" |
- " }" |
- " };" |
- "})();" |
- "cr.googleTranslate.onTranslateElementLoad();"; |
- |
fetcher->set_url(fetcher->GetOriginalURL()); |
fetcher->set_status(net::URLRequestStatus::FromError(error)); |
fetcher->set_response_code(success ? 200 : 500); |
@@ -75,6 +213,19 @@ class TranslateManagerBrowserTest : public InProcessBrowserTest { |
fetcher->delegate()->OnURLFetchComplete(fetcher); |
} |
+ void OnTranslateError(const translate::TranslateErrorDetails& details) { |
+ error_type_ = details.error; |
+ } |
+ |
+ translate::TranslateErrors::Type GetPageTranslatedResult() { |
+ return error_type_; |
+ } |
+ |
+ ChromeTranslateClient* GetChromeTranslateClient() { |
+ return ChromeTranslateClient::FromWebContents( |
+ browser()->tab_strip_model()->GetActiveWebContents()); |
+ } |
+ |
protected: |
// InProcessBrowserTest members. |
void SetUp() override { |
@@ -82,11 +233,18 @@ class TranslateManagerBrowserTest : public InProcessBrowserTest { |
} |
void SetUpOnMainThread() override { |
ResetObserver(); |
+ error_type_ = translate::TranslateErrors::NONE; |
} |
private: |
net::TestURLFetcherFactory url_fetcher_factory_; |
+ translate::TranslateErrors::Type error_type_; |
+ |
+ std::unique_ptr< |
+ translate::TranslateManager::TranslateErrorCallbackList::Subscription> |
+ error_subscription_; |
+ |
using LangageDetectionObserver = |
ui_test_utils::WindowedNotificationObserverWithDetails< |
translate::LanguageDetectionDetails>; |
@@ -100,10 +258,8 @@ class TranslateManagerBrowserTest : public InProcessBrowserTest { |
IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageLanguageDetection) { |
ASSERT_TRUE(embedded_test_server()->Start()); |
- content::WebContents* current_web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ChromeTranslateClient* chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
// The InProcessBrowserTest opens a new tab, let's wait for that first. |
// There is a possible race condition, when the language is not yet detected, |
// so we check for that and wait if necessary. |
@@ -117,9 +273,7 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageLanguageDetection) { |
ResetObserver(); |
AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/english_page.html")), |
ui::PAGE_TRANSITION_TYPED); |
- current_web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
- chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ chrome_translate_client = GetChromeTranslateClient(); |
WaitUntilLanguageDetected(); |
EXPECT_EQ("en", |
@@ -139,10 +293,7 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageLanguageDetection) { |
IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationSuccess) { |
ASSERT_TRUE(embedded_test_server()->Start()); |
- content::WebContents* current_web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ChromeTranslateClient* chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
// There is a possible race condition, when the language is not yet detected, |
// so we check for that and wait if necessary. |
@@ -156,9 +307,7 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationSuccess) { |
ResetObserver(); |
AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
ui::PAGE_TRANSITION_TYPED); |
- current_web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
- chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ chrome_translate_client = GetChromeTranslateClient(); |
WaitUntilLanguageDetected(); |
EXPECT_EQ("fr", |
@@ -171,22 +320,20 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationSuccess) { |
chrome_translate_client->GetLanguageState().original_language(), "en", |
true); |
- SimulateURLFetch(true); |
+ SimulateURLFetch(kTestValidScript, true); |
// Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
WaitUntilPageTranslated(); |
EXPECT_FALSE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::NONE, GetPageTranslatedResult()); |
} |
// Test if there was an error during translation. |
IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationError) { |
ASSERT_TRUE(embedded_test_server()->Start()); |
- content::WebContents* current_web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ChromeTranslateClient* chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
// There is a possible race condition, when the language is not yet detected, |
// so we check for that and wait if necessary. |
@@ -199,14 +346,261 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationError) { |
// Open a new tab with about:blank page. |
ResetObserver(); |
AddTabAtIndex(0, GURL("about:blank"), ui::PAGE_TRANSITION_TYPED); |
- current_web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
- chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage( |
+ chrome_translate_client->GetLanguageState().original_language(), "en", |
+ true); |
+ |
+ SimulateURLFetch(kTestValidScript, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::TRANSLATION_ERROR, |
+ GetPageTranslatedResult()); |
+} |
+ |
+// Test if there was an error during translate library initialization. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationInitializationError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage( |
+ chrome_translate_client->GetLanguageState().original_language(), "en", |
+ true); |
+ |
+ SimulateURLFetch(kTestScriptInitializationError, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::INITIALIZATION_ERROR, |
+ GetPageTranslatedResult()); |
+} |
+ |
+// Test the checks translate lib never gets ready and throws timeout. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationTimeoutError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
WaitUntilLanguageDetected(); |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage( |
+ chrome_translate_client->GetLanguageState().original_language(), "en", |
+ true); |
+ |
+ SimulateURLFetch(kTestScriptTimeout, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::TRANSLATION_TIMEOUT, |
+ GetPageTranslatedResult()); |
+} |
+ |
+// Test the checks if both source and target languages mentioned are identical. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationIdenticalLanguagesError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
EXPECT_EQ("und", |
chrome_translate_client->GetLanguageState().original_language()); |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage("aa", "en", true); |
+ |
+ SimulateURLFetch(kTestScriptIdenticalLanguages, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::IDENTICAL_LANGUAGES, |
+ GetPageTranslatedResult()); |
+} |
+ |
+// Test if there was an error during translatePage script execution. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationUnexpectedScriptError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage( |
+ chrome_translate_client->GetLanguageState().original_language(), "en", |
+ true); |
+ |
+ SimulateURLFetch(kTestScriptUnexpectedScriptError, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::UNEXPECTED_SCRIPT_ERROR, |
+ GetPageTranslatedResult()); |
+} |
+ |
+// Test if securityOrigin mentioned in url is valid. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationBadOriginError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Translate the page through TranslateManager. |
+ translate::TranslateManager* manager = |
+ chrome_translate_client->GetTranslateManager(); |
+ manager->TranslatePage( |
+ chrome_translate_client->GetLanguageState().original_language(), "en", |
+ true); |
+ |
+ SimulateURLFetch(kTestScriptBadOrigin, true); |
+ |
+ // Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
+ WaitUntilPageTranslated(); |
+ |
+ EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::BAD_ORIGIN, GetPageTranslatedResult()); |
+} |
+ |
+// Test if there was an error during script load. |
+IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
+ PageTranslationScriptLoadError) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
+ |
+ // There is a possible race condition, when the language is not yet detected, |
+ // so we check for that and wait if necessary. |
+ if (chrome_translate_client->GetLanguageState().original_language().empty()) |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("und", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
+ // Open a new tab with a page in French. |
+ ResetObserver(); |
+ AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), |
+ ui::PAGE_TRANSITION_TYPED); |
+ chrome_translate_client = GetChromeTranslateClient(); |
+ WaitUntilLanguageDetected(); |
+ |
+ EXPECT_EQ("fr", |
+ chrome_translate_client->GetLanguageState().original_language()); |
+ |
// Translate the page through TranslateManager. |
translate::TranslateManager* manager = |
chrome_translate_client->GetTranslateManager(); |
@@ -214,12 +608,14 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationError) { |
chrome_translate_client->GetLanguageState().original_language(), "en", |
true); |
- SimulateURLFetch(true); |
+ SimulateURLFetch(kTestScriptLoadError, true); |
// Wait for NOTIFICATION_PAGE_TRANSLATED notification. |
WaitUntilPageTranslated(); |
EXPECT_TRUE(chrome_translate_client->GetLanguageState().translation_error()); |
+ EXPECT_EQ(translate::TranslateErrors::SCRIPT_LOAD_ERROR, |
+ GetPageTranslatedResult()); |
} |
// Test that session restore restores the translate infobar and other translate |
@@ -229,10 +625,7 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
SessionStartupPref pref(SessionStartupPref::LAST); |
SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
- content::WebContents* current_web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ChromeTranslateClient* chrome_translate_client = |
- ChromeTranslateClient::FromWebContents(current_web_contents); |
+ ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); |
// There is a possible race condition, when the language is not yet detected, |
// so we check for that and wait if necessary. |
@@ -255,10 +648,7 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, |
TranslateSessionRestore) { |
- content::WebContents* active_web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ChromeTranslateClient* active_translate_client = |
- ChromeTranslateClient::FromWebContents(active_web_contents); |
+ ChromeTranslateClient* active_translate_client = GetChromeTranslateClient(); |
if (active_translate_client->GetLanguageState().current_language().empty()) |
WaitUntilLanguageDetected(); |
EXPECT_EQ("und", |