Chromium Code Reviews| 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/translate_controller.h" | 5 #import "components/translate/ios/browser/translate_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #import "components/translate/ios/browser/js_translate_manager.h" | 10 #import "components/translate/ios/browser/js_translate_manager.h" |
| 11 #import "ios/web/public/test/fakes/test_web_state.h" | 11 #import "ios/web/public/test/fakes/test_web_state.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 #import "third_party/ocmock/OCMock/OCMock.h" | 13 #import "third_party/ocmock/OCMock/OCMock.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 17 #error "This file requires ARC support." | |
| 18 #endif | |
| 19 | |
| 16 namespace translate { | 20 namespace translate { |
| 17 | 21 |
| 18 class TranslateControllerTest : public PlatformTest, | 22 class TranslateControllerTest : public PlatformTest, |
| 19 public TranslateController::Observer { | 23 public TranslateController::Observer { |
| 20 protected: | 24 protected: |
| 21 TranslateControllerTest() | 25 TranslateControllerTest() |
| 22 : test_web_state_(new web::TestWebState), | 26 : test_web_state_(new web::TestWebState), |
| 23 success_(false), | 27 success_(false), |
| 24 ready_time_(0), | 28 ready_time_(0), |
| 25 load_time_(0), | 29 load_time_(0), |
| 26 translation_time_(0), | 30 translation_time_(0), |
| 27 on_script_ready_called_(false), | 31 on_script_ready_called_(false), |
| 28 on_translate_complete_called_(false) { | 32 on_translate_complete_called_(false) { |
| 29 mock_js_translate_manager_.reset( | 33 mock_js_translate_manager_ = |
| 30 [[OCMockObject niceMockForClass:[JsTranslateManager class]] retain]); | 34 [OCMockObject niceMockForClass:[JsTranslateManager class]]; |
| 31 translate_controller_.reset(new TranslateController( | 35 translate_controller_.reset(new TranslateController( |
|
sdefresne
2017/04/11 07:45:33
ditto, base::MakeUnique
stkhapugin
2017/04/11 15:33:33
Done.
| |
| 32 test_web_state_.get(), mock_js_translate_manager_)); | 36 test_web_state_.get(), mock_js_translate_manager_)); |
| 33 translate_controller_->set_observer(this); | 37 translate_controller_->set_observer(this); |
| 34 } | 38 } |
| 35 | 39 |
| 36 // TranslateController::Observer methods. | 40 // TranslateController::Observer methods. |
| 37 void OnTranslateScriptReady(bool success, | 41 void OnTranslateScriptReady(bool success, |
| 38 double load_time, | 42 double load_time, |
| 39 double ready_time) override { | 43 double ready_time) override { |
| 40 on_script_ready_called_ = true; | 44 on_script_ready_called_ = true; |
| 41 success_ = success; | 45 success_ = success; |
| 42 load_time_ = load_time; | 46 load_time_ = load_time; |
| 43 ready_time_ = ready_time; | 47 ready_time_ = ready_time; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void OnTranslateComplete(bool success, | 50 void OnTranslateComplete(bool success, |
| 47 const std::string& original_language, | 51 const std::string& original_language, |
| 48 double translation_time) override { | 52 double translation_time) override { |
| 49 on_translate_complete_called_ = true; | 53 on_translate_complete_called_ = true; |
| 50 success_ = success; | 54 success_ = success; |
| 51 original_language_ = original_language; | 55 original_language_ = original_language; |
| 52 translation_time_ = translation_time; | 56 translation_time_ = translation_time; |
| 53 } | 57 } |
| 54 | 58 |
| 55 std::unique_ptr<web::TestWebState> test_web_state_; | 59 std::unique_ptr<web::TestWebState> test_web_state_; |
| 56 base::scoped_nsobject<id> mock_js_translate_manager_; | 60 id mock_js_translate_manager_; |
| 57 std::unique_ptr<TranslateController> translate_controller_; | 61 std::unique_ptr<TranslateController> translate_controller_; |
| 58 bool success_; | 62 bool success_; |
| 59 double ready_time_; | 63 double ready_time_; |
| 60 double load_time_; | 64 double load_time_; |
| 61 std::string original_language_; | 65 std::string original_language_; |
| 62 double translation_time_; | 66 double translation_time_; |
| 63 bool on_script_ready_called_; | 67 bool on_script_ready_called_; |
| 64 bool on_translate_complete_called_; | 68 bool on_translate_complete_called_; |
| 65 }; | 69 }; |
| 66 | 70 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 command.SetString("command", "translate.status"); | 139 command.SetString("command", "translate.status"); |
| 136 command.SetBoolean("success", false); | 140 command.SetBoolean("success", false); |
| 137 EXPECT_TRUE(translate_controller_->OnJavascriptCommandReceived( | 141 EXPECT_TRUE(translate_controller_->OnJavascriptCommandReceived( |
| 138 command, GURL("http://google.com"), false)); | 142 command, GURL("http://google.com"), false)); |
| 139 EXPECT_FALSE(on_script_ready_called_); | 143 EXPECT_FALSE(on_script_ready_called_); |
| 140 EXPECT_TRUE(on_translate_complete_called_); | 144 EXPECT_TRUE(on_translate_complete_called_); |
| 141 EXPECT_FALSE(success_); | 145 EXPECT_FALSE(success_); |
| 142 } | 146 } |
| 143 | 147 |
| 144 } // namespace translate | 148 } // namespace translate |
| OLD | NEW |