Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ranker_model_loader.h" | 5 #include "components/translate/core/browser/ranker_model_loader.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <initializer_list> | 8 #include <initializer_list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | |
|
groby-ooo-7-16
2017/04/24 19:12:46
Why does this need ref_counted.h?
Roger McFarlane (Chromium)
2017/04/24 20:31:34
Just something I noticed is used without being exp
| |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
| 19 #include "base/task_scheduler/task_scheduler.h" | 20 #include "base/task_scheduler/task_scheduler.h" |
| 20 #include "base/test/scoped_feature_list.h" | 21 #include "base/test/scoped_feature_list.h" |
| 21 #include "base/test/scoped_task_scheduler.h" | 22 #include "base/test/scoped_task_scheduler.h" |
| 22 #include "base/test/test_simple_task_runner.h" | 23 #include "base/test/test_simple_task_runner.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "components/metrics/proto/translate_event.pb.h" | 25 #include "components/metrics/proto/translate_event.pb.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 return IsEqual(*copy_m1, *copy_m2); | 193 return IsEqual(*copy_m1, *copy_m2); |
| 193 } | 194 } |
| 194 | 195 |
| 195 bool RankerModelLoaderTest::DoLoaderTest(const base::FilePath& model_path, | 196 bool RankerModelLoaderTest::DoLoaderTest(const base::FilePath& model_path, |
| 196 const GURL& model_url) { | 197 const GURL& model_url) { |
| 197 auto loader = base::MakeUnique<RankerModelLoader>( | 198 auto loader = base::MakeUnique<RankerModelLoader>( |
| 198 base::Bind(&RankerModelLoaderTest::ValidateModel, base::Unretained(this)), | 199 base::Bind(&RankerModelLoaderTest::ValidateModel, base::Unretained(this)), |
| 199 base::Bind(&RankerModelLoaderTest::OnModelAvailable, | 200 base::Bind(&RankerModelLoaderTest::OnModelAvailable, |
| 200 base::Unretained(this)), | 201 base::Unretained(this)), |
| 201 model_path, model_url, "RankerModelLoaderTest"); | 202 model_path, model_url, "RankerModelLoaderTest"); |
| 202 | 203 loader->NotifyOfRankerActivity(); |
| 203 loader->Start(); | |
| 204 base::RunLoop().RunUntilIdle(); | 204 base::RunLoop().RunUntilIdle(); |
| 205 | 205 |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void RankerModelLoaderTest::InitRemoteModels() { | 209 void RankerModelLoaderTest::InitRemoteModels() { |
| 210 InitModel(remote_model_url_, base::Time(), base::TimeDelta(), &remote_model_); | 210 InitModel(remote_model_url_, base::Time(), base::TimeDelta(), &remote_model_); |
| 211 url_fetcher_factory_.SetFakeResponse( | 211 url_fetcher_factory_.SetFakeResponse( |
| 212 remote_model_url_, remote_model_.SerializeAsString(), net::HTTP_OK, | 212 remote_model_url_, remote_model_.SerializeAsString(), net::HTTP_OK, |
| 213 net::URLRequestStatus::SUCCESS); | 213 net::URLRequestStatus::SUCCESS); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 validate_model_response_.push_back(RankerModelStatus::OK); | 365 validate_model_response_.push_back(RankerModelStatus::OK); |
| 366 validate_model_response_.push_back(RankerModelStatus::INCOMPATIBLE); | 366 validate_model_response_.push_back(RankerModelStatus::INCOMPATIBLE); |
| 367 | 367 |
| 368 ASSERT_TRUE(DoLoaderTest(expired_model_path_, remote_model_url_)); | 368 ASSERT_TRUE(DoLoaderTest(expired_model_path_, remote_model_url_)); |
| 369 ASSERT_EQ(2U, validated_models_.size()); | 369 ASSERT_EQ(2U, validated_models_.size()); |
| 370 ASSERT_EQ(1U, available_models_.size()); | 370 ASSERT_EQ(1U, available_models_.size()); |
| 371 EXPECT_TRUE(IsEquivalent(*validated_models_[0], local_model_)); | 371 EXPECT_TRUE(IsEquivalent(*validated_models_[0], local_model_)); |
| 372 EXPECT_TRUE(IsEquivalent(*validated_models_[1], remote_model_)); | 372 EXPECT_TRUE(IsEquivalent(*validated_models_[1], remote_model_)); |
| 373 EXPECT_TRUE(IsEquivalent(*available_models_[0], local_model_)); | 373 EXPECT_TRUE(IsEquivalent(*available_models_[0], local_model_)); |
| 374 } | 374 } |
| OLD | NEW |