| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "components/translate/core/common/language_detection_details.h" | 40 #include "components/translate/core/common/language_detection_details.h" |
| 41 #include "components/translate/core/common/translate_pref_names.h" | 41 #include "components/translate/core/common/translate_pref_names.h" |
| 42 #include "content/public/browser/navigation_details.h" | 42 #include "content/public/browser/navigation_details.h" |
| 43 #include "content/public/browser/navigation_entry.h" | 43 #include "content/public/browser/navigation_entry.h" |
| 44 #include "content/public/browser/notification_details.h" | 44 #include "content/public/browser/notification_details.h" |
| 45 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
| 46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 47 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
| 48 #include "content/public/test/mock_render_process_host.h" | 48 #include "content/public/test/mock_render_process_host.h" |
| 49 #include "content/public/test/test_renderer_host.h" | 49 #include "content/public/test/test_renderer_host.h" |
| 50 #include "net/base/net_errors.h" |
| 50 #include "net/url_request/test_url_fetcher_factory.h" | 51 #include "net/url_request/test_url_fetcher_factory.h" |
| 51 #include "net/url_request/url_fetcher_delegate.h" | 52 #include "net/url_request/url_fetcher_delegate.h" |
| 53 #include "net/url_request/url_request_status.h" |
| 52 #include "testing/gmock/include/gmock/gmock.h" | 54 #include "testing/gmock/include/gmock/gmock.h" |
| 53 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 55 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 54 #include "url/gurl.h" | 56 #include "url/gurl.h" |
| 55 | 57 |
| 56 // An observer that keeps track of whether a navigation entry was committed. | 58 // An observer that keeps track of whether a navigation entry was committed. |
| 57 class NavEntryCommittedObserver : public content::NotificationObserver { | 59 class NavEntryCommittedObserver : public content::NotificationObserver { |
| 58 public: | 60 public: |
| 59 explicit NavEntryCommittedObserver(content::WebContents* web_contents) { | 61 explicit NavEntryCommittedObserver(content::WebContents* web_contents) { |
| 60 registrar_.Add(this, | 62 registrar_.Add(this, |
| 61 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 63 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 void SetApplicationLocale(const std::string& locale) { | 286 void SetApplicationLocale(const std::string& locale) { |
| 285 g_browser_process->SetApplicationLocale(locale); | 287 g_browser_process->SetApplicationLocale(locale); |
| 286 translate::TranslateDownloadManager::GetInstance()->set_application_locale( | 288 translate::TranslateDownloadManager::GetInstance()->set_application_locale( |
| 287 g_browser_process->GetApplicationLocale()); | 289 g_browser_process->GetApplicationLocale()); |
| 288 } | 290 } |
| 289 | 291 |
| 290 void SimulateTranslateScriptURLFetch(bool success) { | 292 void SimulateTranslateScriptURLFetch(bool success) { |
| 291 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( | 293 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( |
| 292 translate::TranslateScript::kFetcherId); | 294 translate::TranslateScript::kFetcherId); |
| 293 ASSERT_TRUE(fetcher); | 295 ASSERT_TRUE(fetcher); |
| 294 net::URLRequestStatus status; | 296 int error = success ? net::OK : net::ERR_FAILED; |
| 295 status.set_status(success ? net::URLRequestStatus::SUCCESS | |
| 296 : net::URLRequestStatus::FAILED); | |
| 297 fetcher->set_url(fetcher->GetOriginalURL()); | 297 fetcher->set_url(fetcher->GetOriginalURL()); |
| 298 fetcher->set_status(status); | 298 fetcher->set_status(net::URLRequestStatus::FromError(error)); |
| 299 fetcher->set_response_code(success ? 200 : 500); | 299 fetcher->set_response_code(success ? 200 : 500); |
| 300 fetcher->delegate()->OnURLFetchComplete(fetcher); | 300 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void SimulateSupportedLanguagesURLFetch( | 303 void SimulateSupportedLanguagesURLFetch( |
| 304 bool success, | 304 bool success, |
| 305 const std::vector<std::string>& languages, | 305 const std::vector<std::string>& languages, |
| 306 bool use_alpha_languages, | 306 bool use_alpha_languages, |
| 307 const std::vector<std::string>& alpha_languages) { | 307 const std::vector<std::string>& alpha_languages) { |
| 308 net::URLRequestStatus status; | 308 int error = success ? net::OK : net::ERR_FAILED; |
| 309 status.set_status(success ? net::URLRequestStatus::SUCCESS | |
| 310 : net::URLRequestStatus::FAILED); | |
| 311 | 309 |
| 312 std::string data; | 310 std::string data; |
| 313 if (success) { | 311 if (success) { |
| 314 data = base::StringPrintf( | 312 data = base::StringPrintf( |
| 315 "%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", | 313 "%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", |
| 316 translate::TranslateLanguageList::kLanguageListCallbackName, | 314 translate::TranslateLanguageList::kLanguageListCallbackName, |
| 317 translate::TranslateLanguageList::kTargetLanguagesKey); | 315 translate::TranslateLanguageList::kTargetLanguagesKey); |
| 318 const char* comma = ""; | 316 const char* comma = ""; |
| 319 for (size_t i = 0; i < languages.size(); ++i) { | 317 for (size_t i = 0; i < languages.size(); ++i) { |
| 320 data += base::StringPrintf( | 318 data += base::StringPrintf( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 335 comma = ","; | 333 comma = ","; |
| 336 } | 334 } |
| 337 } | 335 } |
| 338 | 336 |
| 339 data += "}})"; | 337 data += "}})"; |
| 340 } | 338 } |
| 341 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( | 339 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( |
| 342 translate::TranslateLanguageList::kFetcherId); | 340 translate::TranslateLanguageList::kFetcherId); |
| 343 ASSERT_TRUE(fetcher != NULL); | 341 ASSERT_TRUE(fetcher != NULL); |
| 344 fetcher->set_url(fetcher->GetOriginalURL()); | 342 fetcher->set_url(fetcher->GetOriginalURL()); |
| 345 fetcher->set_status(status); | 343 fetcher->set_status(net::URLRequestStatus::FromError(error)); |
| 346 fetcher->set_response_code(success ? 200 : 500); | 344 fetcher->set_response_code(success ? 200 : 500); |
| 347 fetcher->SetResponseString(data); | 345 fetcher->SetResponseString(data); |
| 348 fetcher->delegate()->OnURLFetchComplete(fetcher); | 346 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 349 } | 347 } |
| 350 | 348 |
| 351 void SetPrefObserverExpectation(const char* path) { | 349 void SetPrefObserverExpectation(const char* path) { |
| 352 EXPECT_CALL(*this, OnPreferenceChanged(std::string(path))); | 350 EXPECT_CALL(*this, OnPreferenceChanged(std::string(path))); |
| 353 } | 351 } |
| 354 | 352 |
| 355 PrefChangeRegistrar::NamedChangeCallback pref_callback_; | 353 PrefChangeRegistrar::NamedChangeCallback pref_callback_; |
| (...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 1670 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
| 1673 | 1671 |
| 1674 // Check the bubble exists instead of the infobar. | 1672 // Check the bubble exists instead of the infobar. |
| 1675 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1673 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1676 ASSERT_TRUE(infobar == NULL); | 1674 ASSERT_TRUE(infobar == NULL); |
| 1677 TranslateBubbleModel* bubble = factory->model(); | 1675 TranslateBubbleModel* bubble = factory->model(); |
| 1678 ASSERT_TRUE(bubble != NULL); | 1676 ASSERT_TRUE(bubble != NULL); |
| 1679 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, | 1677 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, |
| 1680 bubble->GetViewState()); | 1678 bubble->GetViewState()); |
| 1681 } | 1679 } |
| OLD | NEW |