Skip to content

Commit

Permalink
Migrate chromeos_service_unittests to chromeos_unittests
Browse files Browse the repository at this point in the history
Unit tests are generally preferred and covers all existing test needs.

Bug: None
Test: locally build and run chromeos_unittests
Change-Id: I8cee7e2faf0446899ba6dd76c1c8540df52c6e35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1536764
Reviewed-by: John Budorick <jbudorick@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644887}
  • Loading branch information
Xiaohui Chen authored and Commit Bot committed Mar 27, 2019
1 parent 3384f96 commit ba25ee1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ group("gn_all") {
"//chromeos:chromeos_unittests",
"//chromeos/components:chromeos_components_unittests",
"//chromeos/components/proximity_auth:proximity_auth_unittests",
"//chromeos/services:chromeos_services_unittests",
"//components/session_manager/core",
"//ui/chromeos:ui_chromeos_unittests",
"//ui/keyboard:keyboard_unittests",
Expand Down
12 changes: 1 addition & 11 deletions chromeos/services/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import("//build/config/ui.gni")
import("//chromeos/assistant/assistant.gni")
import("//chromeos/services/ime/public/features.gni")
import("//testing/test.gni")

assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos")
Expand All @@ -20,21 +19,12 @@ source_set("unit_tests") {
testonly = true
deps = [
"//chromeos/services/device_sync:unit_tests",
"//chromeos/services/ime:services_unittests",
"//chromeos/services/ime:unit_tests",
"//chromeos/services/machine_learning/public/cpp:unit_tests",
"//chromeos/services/multidevice_setup:unit_tests",
"//chromeos/services/secure_channel:unit_tests",
]
}

# Use this target for adding new service tests. To add a unit test to this
# target, create a "tests" source_set in your service and add it as a dependency
# here.
test("chromeos_services_unittests") {
deps = [
"//chromeos/services/ime:services_unittests",
"//mojo/core/test:run_all_unittests",
]

if (enable_cros_assistant) {
deps += [ "//chromeos/services/assistant:tests" ]
Expand Down
19 changes: 7 additions & 12 deletions chromeos/services/assistant/service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ class AssistantServiceTest : public testing::Test {
FakePowerManagerClient::Get()->SetTabletMode(
PowerManagerClient::TabletMode::OFF, base::TimeTicks());

shared_url_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&url_loader_factory_);

service_ = std::make_unique<Service>(
test_connector_factory_.RegisterInstance(mojom::kServiceName),
nullptr /* network_connection_tracker */, nullptr /* io_task_runner */);
nullptr /* network_connection_tracker */,
shared_url_loader_factory_->Clone());

mock_task_runner_ = base::MakeRefCounted<base::TestMockTimeTaskRunner>(
base::Time::Now(), base::TimeTicks::Now());
Expand All @@ -188,13 +193,8 @@ class AssistantServiceTest : public testing::Test {
void SetUp() override {
GetPlatform()->Init(fake_assistant_client_.CreateInterfacePtrAndBind(),
fake_device_actions_.CreateInterfacePtrAndBind());
shared_url_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&url_loader_factory_);
platform_.FlushForTesting();
base::RunLoop().RunUntilIdle();

PowerManagerClient::Shutdown();
}

mojom::AssistantPlatform* GetPlatform() {
Expand All @@ -209,10 +209,6 @@ class AssistantServiceTest : public testing::Test {
return fake_assistant_manager_;
}

chromeos::FakePowerManagerClient* power_manager_client() {
return power_manager_client_;
}

base::TestMockTimeTaskRunner* mock_task_runner() {
return mock_task_runner_.get();
}
Expand All @@ -230,7 +226,6 @@ class AssistantServiceTest : public testing::Test {
FakeDeviceActions fake_device_actions_;

FakeAssistantManagerServiceImpl* fake_assistant_manager_;
chromeos::FakePowerManagerClient* power_manager_client_;

network::TestURLLoaderFactory url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_;
Expand Down Expand Up @@ -278,7 +273,7 @@ TEST_F(AssistantServiceTest, RetryRefreshTokenAfterFailure) {

TEST_F(AssistantServiceTest, RetryRefreshTokenAfterDeviceWakeup) {
auto current_count = identity_accessor()->get_access_token_count();
power_manager_client()->SendSuspendDone();
FakePowerManagerClient::Get()->SendSuspendDone();
base::RunLoop().RunUntilIdle();

// Token requested immediately after suspend done.
Expand Down

0 comments on commit ba25ee1

Please sign in to comment.