Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: components/translate/core/browser/translate_manager_unittest.cc

Issue 2822383002: check network connectivity in onPageTranslated callback. (Closed)
Patch Set: add unit tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/translate/core/browser/translate_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/translate/core/browser/translate_manager.h" 5 #include "components/translate/core/browser/translate_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 361
362 // In the online case, InitiateTranslation will proceed past early out tests. 362 // In the online case, InitiateTranslation will proceed past early out tests.
363 network_notifier_.SimulateOnline(); 363 network_notifier_.SimulateOnline();
364 translate_manager_->InitiateTranslation("de"); 364 translate_manager_->InitiateTranslation("de");
365 histogram_tester.ExpectUniqueSample( 365 histogram_tester.ExpectUniqueSample(
366 kMetricName, 366 kMetricName,
367 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS, 367 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS,
368 1); 368 1);
369 } 369 }
370 370
371 TEST_F(TranslateManagerTest, DontTranslateIfOfflineBeforeTranslate) {
372 TranslateManager::SetIgnoreMissingKeyForTesting(true);
373 translate_manager_.reset(new translate::TranslateManager(
374 &mock_translate_client_, &mock_translate_ranker_, kAcceptLanguages));
375 translate_manager_->GetLanguageState().LanguageDetermined("de", true);
376 translate_manager_->InitiateTranslation("de");
377
378 // Trigger translate page.
379 network_notifier_.SimulateOffline();
380 translate_manager_->TranslatePage("de", "en", false);
381
382 // Don't expect calls if network is off.
383 EXPECT_FALSE(driver_.TranslatePage_is_called());
384 }
385
371 // Utility function to set the threshold params 386 // Utility function to set the threshold params
372 void ChangeThresholdInParams( 387 void ChangeThresholdInParams(
373 const char* initiate_translation_confidence_threshold, 388 const char* initiate_translation_confidence_threshold,
374 const char* initiate_translation_probability_threshold, 389 const char* initiate_translation_probability_threshold,
375 const char* target_language_confidence_threshold, 390 const char* target_language_confidence_threshold,
376 const char* target_language_probability_threshold) { 391 const char* target_language_probability_threshold) {
377 ASSERT_TRUE(variations::AssociateVariationParams( 392 ASSERT_TRUE(variations::AssociateVariationParams(
378 kTrialName, "Enabled", 393 kTrialName, "Enabled",
379 {{"initiate_translation_ulp_confidence_threshold", 394 {{"initiate_translation_ulp_confidence_threshold",
380 initiate_translation_confidence_threshold}, 395 initiate_translation_confidence_threshold},
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 _)) 624 _))
610 .WillOnce(Return(true)); 625 .WillOnce(Return(true));
611 SetHasLanguageChanged(false); 626 SetHasLanguageChanged(false);
612 SetLanguageTooOftenDenied("en"); 627 SetLanguageTooOftenDenied("en");
613 EXPECT_FALSE(translate_manager_->ShouldSuppressBubbleUI(false, "en")); 628 EXPECT_FALSE(translate_manager_->ShouldSuppressBubbleUI(false, "en"));
614 } 629 }
615 630
616 } // namespace testing 631 } // namespace testing
617 632
618 } // namespace translate 633 } // namespace translate
OLDNEW
« no previous file with comments | « components/translate/core/browser/translate_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698