| 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 #import "components/translate/ios/browser/language_detection_controller.h" | 5 #import "components/translate/ios/browser/language_detection_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/bind_objc_block.h" | 7 #include "base/mac/bind_objc_block.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/prefs/pref_registry_simple.h" | 10 #include "components/prefs/pref_registry_simple.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 std::unique_ptr<LanguageDetectionController> controller_; | 52 std::unique_ptr<LanguageDetectionController> controller_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 // Tests that OnTextCaptured() correctly handles messages from the JS side and | 57 // Tests that OnTextCaptured() correctly handles messages from the JS side and |
| 58 // informs the driver. | 58 // informs the driver. |
| 59 TEST_F(LanguageDetectionControllerTest, OnTextCaptured) { | 59 TEST_F(LanguageDetectionControllerTest, OnTextCaptured) { |
| 60 const std::string kRootLanguage("en"); | 60 const std::string kRootLanguage("en"); |
| 61 const std::string kContentLanguage("fr"); | 61 const std::string kContentLanguage("fr"); |
| 62 const std::string kUndefined("und"); |
| 62 | 63 |
| 63 __block bool block_was_called = false; | 64 __block bool block_was_called = false; |
| 64 auto subscription = | 65 auto subscription = |
| 65 controller()->RegisterLanguageDetectionCallback(base::BindBlockArc( | 66 controller()->RegisterLanguageDetectionCallback(base::BindBlockArc( |
| 66 ^(const LanguageDetectionController::DetectionDetails& details) { | 67 ^(const LanguageDetectionController::DetectionDetails& details) { |
| 67 block_was_called = true; | 68 block_was_called = true; |
| 68 EXPECT_EQ(kRootLanguage, details.html_root_language); | 69 EXPECT_EQ(kRootLanguage, details.html_root_language); |
| 69 EXPECT_EQ(kContentLanguage, details.content_language); | 70 EXPECT_EQ(kContentLanguage, details.content_language); |
| 71 EXPECT_FALSE(details.is_cld_reliable); |
| 72 EXPECT_EQ(kUndefined, details.cld_language); |
| 70 })); | 73 })); |
| 71 | 74 |
| 72 base::DictionaryValue command; | 75 base::DictionaryValue command; |
| 73 command.SetString("command", "languageDetection.textCaptured"); | 76 command.SetString("command", "languageDetection.textCaptured"); |
| 74 command.SetBoolean("translationAllowed", true); | 77 command.SetBoolean("translationAllowed", true); |
| 75 command.SetInteger("captureTextTime", 10); | 78 command.SetInteger("captureTextTime", 10); |
| 76 command.SetString("htmlLang", kRootLanguage); | 79 command.SetString("htmlLang", kRootLanguage); |
| 77 command.SetString("httpContentLanguage", kContentLanguage); | 80 command.SetString("httpContentLanguage", kContentLanguage); |
| 78 controller()->OnTextCaptured(command, GURL("http://google.com"), false); | 81 controller()->OnTextCaptured(command, GURL("http://google.com"), false); |
| 79 | 82 |
| 80 EXPECT_TRUE(block_was_called); | 83 EXPECT_TRUE(block_was_called); |
| 81 } | 84 } |
| 82 | 85 |
| 83 } // namespace translate | 86 } // namespace translate |
| OLD | NEW |