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

Side by Side Diff: components/translate/ios/browser/translate_controller_unittest.mm

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

Powered by Google App Engine
This is Rietveld 408576698