| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 TabContentsWrapperTestHarness::TearDown(); | 184 TabContentsWrapperTestHarness::TearDown(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void SimulateTranslateScriptURLFetch(bool success) { | 187 void SimulateTranslateScriptURLFetch(bool success) { |
| 188 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 188 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 189 ASSERT_TRUE(fetcher); | 189 ASSERT_TRUE(fetcher); |
| 190 net::URLRequestStatus status; | 190 net::URLRequestStatus status; |
| 191 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 191 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
| 192 net::URLRequestStatus::FAILED); | 192 net::URLRequestStatus::FAILED); |
| 193 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 193 fetcher->set_url(fetcher->original_url()); |
| 194 status, success ? 200 : 500, | 194 fetcher->set_status(status); |
| 195 net::ResponseCookies(), | 195 fetcher->set_response_code(success ? 200 : 500); |
| 196 std::string()); | 196 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void SimulateSupportedLanguagesURLFetch( | 199 void SimulateSupportedLanguagesURLFetch( |
| 200 bool success, const std::vector<std::string>& languages) { | 200 bool success, const std::vector<std::string>& languages) { |
| 201 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(1); | 201 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(1); |
| 202 ASSERT_TRUE(fetcher); | 202 ASSERT_TRUE(fetcher); |
| 203 net::URLRequestStatus status; | 203 net::URLRequestStatus status; |
| 204 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 204 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
| 205 net::URLRequestStatus::FAILED); | 205 net::URLRequestStatus::FAILED); |
| 206 | 206 |
| 207 std::string data; | 207 std::string data; |
| 208 if (success) { | 208 if (success) { |
| 209 data = base::StringPrintf("%s{'sl': {'bla': 'bla'}, '%s': {", | 209 data = base::StringPrintf("%s{'sl': {'bla': 'bla'}, '%s': {", |
| 210 TranslateManager::kLanguageListCallbackName, | 210 TranslateManager::kLanguageListCallbackName, |
| 211 TranslateManager::kTargetLanguagesKey); | 211 TranslateManager::kTargetLanguagesKey); |
| 212 const char* comma = ""; | 212 const char* comma = ""; |
| 213 for (size_t i = 0; i < languages.size(); ++i) { | 213 for (size_t i = 0; i < languages.size(); ++i) { |
| 214 data += base::StringPrintf( | 214 data += base::StringPrintf( |
| 215 "%s'%s': 'UnusedFullName'", comma, languages[i].c_str()); | 215 "%s'%s': 'UnusedFullName'", comma, languages[i].c_str()); |
| 216 if (i == 0) | 216 if (i == 0) |
| 217 comma = ","; | 217 comma = ","; |
| 218 } | 218 } |
| 219 data += "}})"; | 219 data += "}})"; |
| 220 } | 220 } |
| 221 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 221 fetcher->set_url(fetcher->original_url()); |
| 222 status, success ? 200 : 500, | 222 fetcher->set_status(status); |
| 223 net::ResponseCookies(), | 223 fetcher->set_response_code(success ? 200 : 500); |
| 224 data); | 224 fetcher->SetResponseString(data); |
| 225 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void SetPrefObserverExpectation(const char* path) { | 228 void SetPrefObserverExpectation(const char* path) { |
| 228 EXPECT_CALL( | 229 EXPECT_CALL( |
| 229 pref_observer_, | 230 pref_observer_, |
| 230 Observe(int(chrome::NOTIFICATION_PREF_CHANGED), | 231 Observe(int(chrome::NOTIFICATION_PREF_CHANGED), |
| 231 _, | 232 _, |
| 232 Property(&content::Details<std::string>::ptr, Pointee(path)))); | 233 Property(&content::Details<std::string>::ptr, Pointee(path)))); |
| 233 } | 234 } |
| 234 | 235 |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 NULL); | 1338 NULL); |
| 1338 // Now simulate the URL fetch. | 1339 // Now simulate the URL fetch. |
| 1339 SimulateTranslateScriptURLFetch(true); | 1340 SimulateTranslateScriptURLFetch(true); |
| 1340 // Now the message should have been sent. | 1341 // Now the message should have been sent. |
| 1341 int page_id = 0; | 1342 int page_id = 0; |
| 1342 std::string original_lang, target_lang; | 1343 std::string original_lang, target_lang; |
| 1343 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1344 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1344 EXPECT_EQ("es", original_lang); | 1345 EXPECT_EQ("es", original_lang); |
| 1345 EXPECT_EQ("en", target_lang); | 1346 EXPECT_EQ("en", target_lang); |
| 1346 } | 1347 } |
| OLD | NEW |