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" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/message_loop/message_loop.h" | |
17 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
19 #include "base/task_scheduler/post_task.h" | 18 #include "base/task_scheduler/post_task.h" |
20 #include "base/task_scheduler/task_scheduler.h" | 19 #include "base/task_scheduler/task_scheduler.h" |
21 #include "base/test/scoped_feature_list.h" | 20 #include "base/test/scoped_feature_list.h" |
22 #include "base/test/scoped_task_scheduler.h" | 21 #include "base/test/scoped_task_environment.h" |
23 #include "base/test/test_simple_task_runner.h" | 22 #include "base/test/test_simple_task_runner.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
25 #include "components/metrics/proto/translate_event.pb.h" | 24 #include "components/metrics/proto/translate_event.pb.h" |
26 #include "components/prefs/scoped_user_pref_update.h" | 25 #include "components/prefs/scoped_user_pref_update.h" |
27 #include "components/sync_preferences/testing_pref_service_syncable.h" | 26 #include "components/sync_preferences/testing_pref_service_syncable.h" |
28 #include "components/translate/core/browser/proto/ranker_model.pb.h" | 27 #include "components/translate/core/browser/proto/ranker_model.pb.h" |
29 #include "components/translate/core/browser/proto/translate_ranker_model.pb.h" | 28 #include "components/translate/core/browser/proto/translate_ranker_model.pb.h" |
30 #include "components/translate/core/browser/ranker_model.h" | 29 #include "components/translate/core/browser/ranker_model.h" |
31 #include "components/translate/core/browser/translate_download_manager.h" | 30 #include "components/translate/core/browser/translate_download_manager.h" |
32 #include "components/translate/core/browser/translate_prefs.h" | 31 #include "components/translate/core/browser/translate_prefs.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // InitLocalModels() | 80 // InitLocalModels() |
82 void SaveModel(const RankerModel& model, const base::FilePath& model_path); | 81 void SaveModel(const RankerModel& model, const base::FilePath& model_path); |
83 | 82 |
84 // Implements RankerModelLoader's ValidateModelCallback interface. | 83 // Implements RankerModelLoader's ValidateModelCallback interface. |
85 RankerModelStatus ValidateModel(const RankerModel& model); | 84 RankerModelStatus ValidateModel(const RankerModel& model); |
86 | 85 |
87 // Implements RankerModelLoader's OnModelAvailableCallback interface. | 86 // Implements RankerModelLoader's OnModelAvailableCallback interface. |
88 void OnModelAvailable(std::unique_ptr<RankerModel> model); | 87 void OnModelAvailable(std::unique_ptr<RankerModel> model); |
89 | 88 |
90 // Sets up the task scheduling/task-runner environment for each test. | 89 // Sets up the task scheduling/task-runner environment for each test. |
91 base::test::ScopedTaskScheduler scoped_task_scheduler_; | 90 base::test::ScopedTaskEnvironment scoped_task_environment_; |
92 | 91 |
93 // Override the default URL fetcher to return custom responses for tests. | 92 // Override the default URL fetcher to return custom responses for tests. |
94 net::FakeURLFetcherFactory url_fetcher_factory_; | 93 net::FakeURLFetcherFactory url_fetcher_factory_; |
95 | 94 |
96 // Temporary directory for model files. | 95 // Temporary directory for model files. |
97 base::ScopedTempDir scoped_temp_dir_; | 96 base::ScopedTempDir scoped_temp_dir_; |
98 | 97 |
99 // Cache and reset the application locale for each test. | 98 // Cache and reset the application locale for each test. |
100 std::string locale_; | 99 std::string locale_; |
101 | 100 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 validate_model_response_.push_back(RankerModelStatus::OK); | 364 validate_model_response_.push_back(RankerModelStatus::OK); |
366 validate_model_response_.push_back(RankerModelStatus::INCOMPATIBLE); | 365 validate_model_response_.push_back(RankerModelStatus::INCOMPATIBLE); |
367 | 366 |
368 ASSERT_TRUE(DoLoaderTest(expired_model_path_, remote_model_url_)); | 367 ASSERT_TRUE(DoLoaderTest(expired_model_path_, remote_model_url_)); |
369 ASSERT_EQ(2U, validated_models_.size()); | 368 ASSERT_EQ(2U, validated_models_.size()); |
370 ASSERT_EQ(1U, available_models_.size()); | 369 ASSERT_EQ(1U, available_models_.size()); |
371 EXPECT_TRUE(IsEquivalent(*validated_models_[0], local_model_)); | 370 EXPECT_TRUE(IsEquivalent(*validated_models_[0], local_model_)); |
372 EXPECT_TRUE(IsEquivalent(*validated_models_[1], remote_model_)); | 371 EXPECT_TRUE(IsEquivalent(*validated_models_[1], remote_model_)); |
373 EXPECT_TRUE(IsEquivalent(*available_models_[0], local_model_)); | 372 EXPECT_TRUE(IsEquivalent(*available_models_[0], local_model_)); |
374 } | 373 } |
OLD | NEW |