Commit 40b0b565 authored by Ke He's avatar Ke He Committed by Commit Bot

Add service unittest for geolocation-config.

Automated test missing was found when moving geolocation-config related
codes. Add a service unittest against it.

BUG=800633

Change-Id: I99332c942626f8acf2e8ced1387c259024c2a2c3
Reviewed-on: https://chromium-review.googlesource.com/885913Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Ke He <ke.he@intel.com>
Cr-Commit-Position: refs/heads/master@{#534876}
parent 7b8b5b6e
include_rules = [
"+chromeos",
"+net",
]
......@@ -4,6 +4,10 @@
#include "base/run_loop.h"
#include "build/build_config.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/geolocation_handler.h"
#endif
#include "device/geolocation/geolocation_provider_impl.h"
#include "device/geolocation/network_location_request.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
......@@ -11,6 +15,7 @@
#include "services/device/device_service_test_base.h"
#include "services/device/public/interfaces/constants.mojom.h"
#include "services/device/public/interfaces/geolocation.mojom.h"
#include "services/device/public/interfaces/geolocation_config.mojom.h"
#include "services/device/public/interfaces/geolocation_context.mojom.h"
#include "services/device/public/interfaces/geolocation_control.mojom.h"
......@@ -18,6 +23,13 @@ namespace device {
namespace {
void CheckBoolReturnValue(base::OnceClosure quit_closure,
bool expect,
bool result) {
EXPECT_EQ(expect, result);
std::move(quit_closure).Run();
}
// Observer that waits until a TestURLFetcher with the specified fetcher_id
// starts, after which it is made available through .fetcher().
class TestURLFetcherObserver : public net::TestURLFetcher::DelegateForTests {
......@@ -60,6 +72,11 @@ class GeolocationServiceUnitTest : public DeviceServiceTestBase {
void SetUp() override {
DeviceServiceTestBase::SetUp();
#if defined(OS_CHROMEOS)
chromeos::DBusThreadManager::Initialize();
chromeos::NetworkHandler::Initialize();
#endif
connector()->BindInterface(mojom::kServiceName, &geolocation_control_);
geolocation_control_->UserDidOptIntoLocationServices();
......@@ -70,6 +87,11 @@ class GeolocationServiceUnitTest : public DeviceServiceTestBase {
void TearDown() override {
DeviceServiceTestBase::TearDown();
#if defined(OS_CHROMEOS)
chromeos::NetworkHandler::Shutdown();
chromeos::DBusThreadManager::Shutdown();
#endif
// Let the GeolocationImpl destruct earlier than GeolocationProviderImpl to
// make sure the base::CallbackList<> member in GeolocationProviderImpl is
// empty.
......@@ -77,9 +99,14 @@ class GeolocationServiceUnitTest : public DeviceServiceTestBase {
base::RunLoop().RunUntilIdle();
}
void BindGeolocationConfig() {
connector()->BindInterface(mojom::kServiceName, &geolocation_config_);
}
mojom::GeolocationControlPtr geolocation_control_;
mojom::GeolocationContextPtr geolocation_context_;
mojom::GeolocationPtr geolocation_;
mojom::GeolocationConfigPtr geolocation_config_;
DISALLOW_COPY_AND_ASSIGN(GeolocationServiceUnitTest);
};
......@@ -109,6 +136,24 @@ TEST_F(GeolocationServiceUnitTest, UrlWithApiKey) {
}
#endif
TEST_F(GeolocationServiceUnitTest, GeolocationConfig) {
BindGeolocationConfig();
{
base::RunLoop run_loop;
geolocation_config_->IsHighAccuracyLocationBeingCaptured(
base::BindOnce(&CheckBoolReturnValue, run_loop.QuitClosure(), false));
run_loop.Run();
}
geolocation_->SetHighAccuracy(true);
{
base::RunLoop run_loop;
geolocation_config_->IsHighAccuracyLocationBeingCaptured(
base::BindOnce(&CheckBoolReturnValue, run_loop.QuitClosure(), true));
run_loop.Run();
}
}
} // namespace
} // namespace device
......@@ -12,6 +12,7 @@
"device": [
"device:battery_monitor",
"device:generic_sensor",
"device:geolocation_config",
"device:geolocation_control",
"device:geolocation",
"device:hid",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment