Commit 2f0fc46c authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

[sensors] Round off Ambient Light Sensor readouts to the nearest 50 Lux.

There have been some concerns regarding the precision of readouts from the
Ambient Light Sensor. To decrease the entropy, we are rounding off the
illuminance value to the nearest 50 Lux to mitigate the known attack
vectors as summarized in [1].

[1] https://github.com/w3c/ambient-light/issues/13#issuecomment-302393458

This CL is based on
https://chromium-review.googlesource.com/c/chromium/src/+/1695412 by
Rijubrata Bhaumik and myself.

Bug: 642731, 606766
Change-Id: I85449bdb835e8486b080fc269938b6c96f000c2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834346Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#705486}
parent ed8b3251
...@@ -408,6 +408,9 @@ jumbo_source_set("unit_tests") { ...@@ -408,6 +408,9 @@ jumbo_source_set("unit_tests") {
"push_messaging/push_subscription_test.cc", "push_messaging/push_subscription_test.cc",
"remoteplayback/remote_playback_test.cc", "remoteplayback/remote_playback_test.cc",
"screen_orientation/screen_orientation_controller_impl_test.cc", "screen_orientation/screen_orientation_controller_impl_test.cc",
"sensor/ambient_light_sensor_test.cc",
"sensor/sensor_test_utils.cc",
"sensor/sensor_test_utils.h",
"service_worker/service_worker_container_test.cc", "service_worker/service_worker_container_test.cc",
"service_worker/service_worker_installed_scripts_manager_test.cc", "service_worker/service_worker_installed_scripts_manager_test.cc",
"service_worker/service_worker_timeout_timer_test.cc", "service_worker/service_worker_timeout_timer_test.cc",
......
...@@ -10,3 +10,10 @@ include_rules = [ ...@@ -10,3 +10,10 @@ include_rules = [
"+third_party/blink/renderer/modules/modules_export.h", "+third_party/blink/renderer/modules/modules_export.h",
"+third_party/blink/renderer/modules/sensor", "+third_party/blink/renderer/modules/sensor",
] ]
specific_include_rules = {
"sensor_test_utils\.(cc|h)|.+test\.cc": [
"+base/run_loop.h",
"+services/device/public/cpp/test/fake_sensor_and_provider.h",
],
}
...@@ -12,6 +12,26 @@ using device::mojom::blink::SensorType; ...@@ -12,6 +12,26 @@ using device::mojom::blink::SensorType;
namespace blink { namespace blink {
namespace {
// Even though the underlying value has changed, for ALS we provide readouts to
// JS to the nearest 50 Lux.
constexpr int kAlsRoundingThreshold = 50;
// Decrease precision of ALS readouts.
// Round off to the nearest kAlsRoundingThreshold.
double RoundIlluminance(double value) {
return kAlsRoundingThreshold * std::round(value / kAlsRoundingThreshold);
}
// Value will have to vary by at least half the rounding threshold before it has
// an effect on the output.
bool IsSignificantlyDifferent(double als_old, double als_new) {
return std::fabs(als_old - als_new) >= kAlsRoundingThreshold / 2;
}
} // namespace
// static // static
AmbientLightSensor* AmbientLightSensor::Create( AmbientLightSensor* AmbientLightSensor::Create(
ExecutionContext* execution_context, ExecutionContext* execution_context,
...@@ -39,7 +59,22 @@ AmbientLightSensor::AmbientLightSensor(ExecutionContext* execution_context, ...@@ -39,7 +59,22 @@ AmbientLightSensor::AmbientLightSensor(ExecutionContext* execution_context,
double AmbientLightSensor::illuminance(bool& is_null) const { double AmbientLightSensor::illuminance(bool& is_null) const {
INIT_IS_NULL_AND_RETURN(is_null, 0.0); INIT_IS_NULL_AND_RETURN(is_null, 0.0);
return GetReading().als.value; DCHECK(latest_reading_.has_value());
return RoundIlluminance(*latest_reading_);
}
// When the reading we get does not differ significantly from our current
// value, we discard this reading and do not emit any events. This is a privacy
// measure to avoid giving readings that are too specific.
void AmbientLightSensor::OnSensorReadingChanged() {
const double new_reading = GetReading().als.value;
if (latest_reading_.has_value() &&
!IsSignificantlyDifferent(*latest_reading_, new_reading)) {
return;
}
latest_reading_ = new_reading;
Sensor::OnSensorReadingChanged();
} }
} // namespace blink } // namespace blink
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_AMBIENT_LIGHT_SENSOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_AMBIENT_LIGHT_SENSOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_AMBIENT_LIGHT_SENSOR_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_AMBIENT_LIGHT_SENSOR_H_
#include "base/gtest_prod_util.h"
#include "base/optional.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/sensor/sensor.h" #include "third_party/blink/renderer/modules/sensor/sensor.h"
namespace blink { namespace blink {
class AmbientLightSensor final : public Sensor { class MODULES_EXPORT AmbientLightSensor final : public Sensor {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
...@@ -21,6 +24,13 @@ class AmbientLightSensor final : public Sensor { ...@@ -21,6 +24,13 @@ class AmbientLightSensor final : public Sensor {
AmbientLightSensor(ExecutionContext*, const SensorOptions*, ExceptionState&); AmbientLightSensor(ExecutionContext*, const SensorOptions*, ExceptionState&);
double illuminance(bool& is_null) const; double illuminance(bool& is_null) const;
void OnSensorReadingChanged() override;
private:
base::Optional<double> latest_reading_;
FRIEND_TEST_ALL_PREFIXES(AmbientLightSensorTest, IlluminanceRounding);
}; };
} // namespace blink } // namespace blink
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/sensor/ambient_light_sensor.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/modules/sensor/sensor_provider_proxy.h"
#include "third_party/blink/renderer/modules/sensor/sensor_test_utils.h"
namespace blink {
namespace {
class MockSensorProxyObserver
: public GarbageCollected<MockSensorProxyObserver>,
public SensorProxy::Observer {
USING_GARBAGE_COLLECTED_MIXIN(MockSensorProxyObserver);
public:
virtual ~MockSensorProxyObserver() = default;
// Synchronously waits for OnSensorReadingChanged() to be called.
void WaitForOnSensorReadingChanged() {
run_loop_.emplace();
run_loop_->Run();
}
void OnSensorReadingChanged() override {
DCHECK(run_loop_.has_value() && run_loop_->running());
run_loop_->Quit();
}
private:
base::Optional<base::RunLoop> run_loop_;
};
} // namespace
TEST(AmbientLightSensorTest, IlluminanceInStoppedSensor) {
SensorTestContext context;
NonThrowableExceptionState exception_state;
auto* sensor = AmbientLightSensor::Create(context.GetExecutionContext(),
exception_state);
bool illuminance_is_null;
sensor->illuminance(illuminance_is_null);
EXPECT_TRUE(illuminance_is_null);
EXPECT_FALSE(sensor->hasReading());
}
TEST(AmbientLightSensorTest, IlluminanceInSensorWithoutReading) {
SensorTestContext context;
NonThrowableExceptionState exception_state;
auto* sensor = AmbientLightSensor::Create(context.GetExecutionContext(),
exception_state);
sensor->start();
SensorTestUtils::WaitForEvent(sensor, event_type_names::kActivate);
bool illuminance_is_null;
sensor->illuminance(illuminance_is_null);
EXPECT_TRUE(illuminance_is_null);
EXPECT_FALSE(sensor->hasReading());
}
TEST(AmbientLightSensorTest, IlluminanceRounding) {
SensorTestContext context;
NonThrowableExceptionState exception_state;
auto* sensor = AmbientLightSensor::Create(context.GetExecutionContext(),
exception_state);
sensor->start();
SensorTestUtils::WaitForEvent(sensor, event_type_names::kActivate);
EXPECT_FALSE(sensor->hasReading());
// At this point, we have received an 'activate' event, so the sensor is
// initialized and it is connected to a SensorProxy that we can retrieve
// here. We then attach a new SensorProxy::Observer that we use to
// synchronously wait for OnSensorReadingChanged() to be called. Even though
// the order that each observer is notified is arbitrary, we know that by the
// time we get to the next call here all observers will have been called.
auto* sensor_proxy =
SensorProviderProxy::From(To<Document>(context.GetExecutionContext()))
->GetSensorProxy(device::mojom::blink::SensorType::AMBIENT_LIGHT);
ASSERT_NE(sensor_proxy, nullptr);
auto* mock_observer = MakeGarbageCollected<MockSensorProxyObserver>();
sensor_proxy->AddObserver(mock_observer);
bool illuminance_is_null;
auto* event_counter = MakeGarbageCollected<SensorTestUtils::EventCounter>();
sensor->addEventListener(event_type_names::kReading, event_counter);
// Go from no reading to 24. This will cause a new "reading" event to be
// emitted, and the rounding will cause illuminance() to return 0.
context.sensor_provider()->UpdateAmbientLightSensorData(24);
mock_observer->WaitForOnSensorReadingChanged();
SensorTestUtils::WaitForEvent(sensor, event_type_names::kReading);
EXPECT_EQ(24, sensor->latest_reading_);
EXPECT_EQ(0, sensor->illuminance(illuminance_is_null));
EXPECT_FALSE(illuminance_is_null);
// Go from 24 to 35. The difference is not significant enough, so we will not
// emit any "reading" event or store the new raw reading, as if the new
// reading had never existed.
context.sensor_provider()->UpdateAmbientLightSensorData(35);
mock_observer->WaitForOnSensorReadingChanged();
EXPECT_EQ(24, sensor->latest_reading_);
EXPECT_EQ(0, sensor->illuminance(illuminance_is_null));
EXPECT_FALSE(illuminance_is_null);
// Go from 24 to 49. The difference is significant enough, so we will emit a
// new "reading" event, update our raw reading and return a rounded value of
// 50 in illuminance().
context.sensor_provider()->UpdateAmbientLightSensorData(49);
mock_observer->WaitForOnSensorReadingChanged();
SensorTestUtils::WaitForEvent(sensor, event_type_names::kReading);
EXPECT_EQ(49, sensor->latest_reading_);
EXPECT_EQ(50, sensor->illuminance(illuminance_is_null));
EXPECT_FALSE(illuminance_is_null);
// Go from 49 to 35. The difference is not significant enough, so we will not
// emit any "reading" event or store the new raw reading, as if the new
// reading had never existed.
context.sensor_provider()->UpdateAmbientLightSensorData(35);
mock_observer->WaitForOnSensorReadingChanged();
EXPECT_EQ(49, sensor->latest_reading_);
EXPECT_EQ(50, sensor->illuminance(illuminance_is_null));
EXPECT_FALSE(illuminance_is_null);
// Go from 49 to 24. The difference is significant enough, so we will emit a
// new "reading" event, update our raw reading and return a rounded value of
// 0 in illuminance().
context.sensor_provider()->UpdateAmbientLightSensorData(24);
mock_observer->WaitForOnSensorReadingChanged();
SensorTestUtils::WaitForEvent(sensor, event_type_names::kReading);
EXPECT_EQ(24, sensor->latest_reading_);
EXPECT_EQ(0, sensor->illuminance(illuminance_is_null));
EXPECT_FALSE(illuminance_is_null);
// Make sure there were no stray "reading" events besides those we expected
// above.
EXPECT_EQ(3U, event_counter->event_count());
}
} // namespace blink
...@@ -352,12 +352,13 @@ void Sensor::NotifyActivated() { ...@@ -352,12 +352,13 @@ void Sensor::NotifyActivated() {
state_ = SensorState::kActivated; state_ = SensorState::kActivated;
if (hasReading()) { if (hasReading()) {
// If reading has already arrived, send initial 'reading' notification // If reading has already arrived, process the reading values (a subclass
// right away. // may do some filtering, for example) and then send an initial "reading"
// event right away.
DCHECK(!pending_reading_notification_.IsActive()); DCHECK(!pending_reading_notification_.IsActive());
pending_reading_notification_ = PostCancellableTask( pending_reading_notification_ = PostCancellableTask(
*GetExecutionContext()->GetTaskRunner(TaskType::kSensor), FROM_HERE, *GetExecutionContext()->GetTaskRunner(TaskType::kSensor), FROM_HERE,
WTF::Bind(&Sensor::NotifyReading, WrapWeakPersistent(this))); WTF::Bind(&Sensor::OnSensorReadingChanged, WrapWeakPersistent(this)));
} }
DispatchEvent(*Event::Create(event_type_names::kActivate)); DispatchEvent(*Event::Create(event_type_names::kActivate));
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/frame/platform_event_controller.h" #include "third_party/blink/renderer/core/frame/platform_event_controller.h"
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/sensor/sensor_options.h" #include "third_party/blink/renderer/modules/sensor/sensor_options.h"
#include "third_party/blink/renderer/modules/sensor/sensor_proxy.h" #include "third_party/blink/renderer/modules/sensor/sensor_proxy.h"
#include "third_party/blink/renderer/modules/sensor/spatial_sensor_options.h" #include "third_party/blink/renderer/modules/sensor/spatial_sensor_options.h"
...@@ -26,10 +27,10 @@ class DOMException; ...@@ -26,10 +27,10 @@ class DOMException;
class ExceptionState; class ExceptionState;
class ExecutionContext; class ExecutionContext;
class Sensor : public EventTargetWithInlineData, class MODULES_EXPORT Sensor : public EventTargetWithInlineData,
public ActiveScriptWrappable<Sensor>, public ActiveScriptWrappable<Sensor>,
public ContextLifecycleObserver, public ContextLifecycleObserver,
public SensorProxy::Observer { public SensorProxy::Observer {
USING_GARBAGE_COLLECTED_MIXIN(Sensor); USING_GARBAGE_COLLECTED_MIXIN(Sensor);
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "services/device/public/mojom/sensor.mojom-blink-forward.h" #include "services/device/public/mojom/sensor.mojom-blink-forward.h"
#include "services/device/public/mojom/sensor_provider.mojom-blink.h" #include "services/device/public/mojom/sensor_provider.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
...@@ -19,8 +20,9 @@ class SensorProxy; ...@@ -19,8 +20,9 @@ class SensorProxy;
// This class wraps 'SensorProvider' mojo interface and it manages // This class wraps 'SensorProvider' mojo interface and it manages
// 'SensorProxy' instances. // 'SensorProxy' instances.
class SensorProviderProxy final : public GarbageCollected<SensorProviderProxy>, class MODULES_EXPORT SensorProviderProxy final
public Supplement<Document> { : public GarbageCollected<SensorProviderProxy>,
public Supplement<Document> {
USING_GARBAGE_COLLECTED_MIXIN(SensorProviderProxy); USING_GARBAGE_COLLECTED_MIXIN(SensorProviderProxy);
public: public:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "services/device/public/mojom/sensor_provider.mojom-blink.h" #include "services/device/public/mojom/sensor_provider.mojom-blink.h"
#include "third_party/blink/renderer/core/page/focus_changed_observer.h" #include "third_party/blink/renderer/core/page/focus_changed_observer.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h" #include "third_party/blink/renderer/core/page/page_visibility_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h" #include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
...@@ -21,9 +22,9 @@ class SensorProviderProxy; ...@@ -21,9 +22,9 @@ class SensorProviderProxy;
// This class wraps 'Sensor' mojo interface and used by multiple // This class wraps 'Sensor' mojo interface and used by multiple
// JS sensor instances of the same type (within a single frame). // JS sensor instances of the same type (within a single frame).
class SensorProxy : public GarbageCollected<SensorProxy>, class MODULES_EXPORT SensorProxy : public GarbageCollected<SensorProxy>,
public PageVisibilityObserver, public PageVisibilityObserver,
public FocusChangedObserver { public FocusChangedObserver {
USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); USING_GARBAGE_COLLECTED_MIXIN(SensorProxy);
public: public:
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/callback.h"
#include "base/run_loop.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/dom/events/native_event_listener.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/sensor/sensor_test_utils.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
// An event listener that invokes |invocation_callback| when it is called.
class SyncEventListener final : public NativeEventListener {
public:
SyncEventListener(base::OnceClosure invocation_callback)
: invocation_callback_(std::move(invocation_callback)) {}
void Invoke(ExecutionContext*, Event*) override {
DCHECK(invocation_callback_);
std::move(invocation_callback_).Run();
}
private:
base::OnceClosure invocation_callback_;
};
} // namespace
// SensorTestContext
SensorTestContext::SensorTestContext() {
// Sensor's constructor has a check for this that could be removed in the
// future.
testing_scope_.GetDocument().SetSecureContextStateForTesting(
SecureContextState::kSecure);
// Necessary for SensorProxy::ShouldSuspendUpdates() to work correctly.
testing_scope_.GetPage().GetFocusController().SetFocused(true);
testing_scope_.GetDocument().GetBrowserInterfaceBroker().SetBinderForTesting(
device::mojom::blink::SensorProvider::Name_,
WTF::BindRepeating(&SensorTestContext::BindSensorProviderRequest,
WTF::Unretained(this)));
}
SensorTestContext::~SensorTestContext() {
testing_scope_.GetDocument().GetBrowserInterfaceBroker().SetBinderForTesting(
device::mojom::blink::SensorProvider::Name_, {});
}
ExecutionContext* SensorTestContext::GetExecutionContext() const {
return testing_scope_.GetExecutionContext();
}
void SensorTestContext::BindSensorProviderRequest(
mojo::ScopedMessagePipeHandle handle) {
sensor_provider_.Bind(
device::mojom::SensorProviderRequest(std::move(handle)));
}
// SensorTestUtils
// static
void SensorTestUtils::WaitForEvent(EventTarget* event_target,
const WTF::AtomicString& event_type) {
base::RunLoop run_loop;
auto* event_listener =
MakeGarbageCollected<SyncEventListener>(run_loop.QuitClosure());
event_target->addEventListener(event_type, event_listener);
run_loop.Run();
event_target->removeEventListener(event_type, event_listener);
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_SENSOR_TEST_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_SENSOR_TEST_UTILS_H_
#include "services/device/public/cpp/test/fake_sensor_and_provider.h"
#include "services/device/public/mojom/sensor_provider.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/core/dom/events/native_event_listener.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class EventTarget;
class ExecutionContext;
class SensorTestContext final {
STACK_ALLOCATED();
public:
SensorTestContext();
~SensorTestContext();
ExecutionContext* GetExecutionContext() const;
device::FakeSensorProvider* sensor_provider() { return &sensor_provider_; }
private:
void BindSensorProviderRequest(mojo::ScopedMessagePipeHandle handle);
device::FakeSensorProvider sensor_provider_;
V8TestingScope testing_scope_;
};
class SensorTestUtils final {
public:
// An event listener that can be used to count the number of times a
// particular event has been fired.
//
// Usage:
// auto* event_counter =
// MakeGarbageCollected<SensorTestUtils::EventCounter>();
// my_event_target->addEventListener(..., event_counter);
// [...]
// EXPECT_EQ(42U, event_counter->event_count());
class EventCounter : public NativeEventListener {
public:
void Invoke(ExecutionContext*, Event*) override { event_count_++; }
size_t event_count() const { return event_count_; }
private:
size_t event_count_ = 0;
};
// Synchronously waits for |event_type| to be delivered to |event_target|.
static void WaitForEvent(EventTarget* event_target,
const WTF::AtomicString& event_type);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SENSOR_SENSOR_TEST_UTILS_H_
...@@ -2091,3 +2091,9 @@ crbug.com/870173 virtual/omt-worker-fetch/external/wpt/fetch/metadata/sec-fetch- ...@@ -2091,3 +2091,9 @@ crbug.com/870173 virtual/omt-worker-fetch/external/wpt/fetch/metadata/sec-fetch-
crbug.com/870173 virtual/omt-worker-fetch/external/wpt/resource-timing/cors-preflight.any.html [ WontFix ] crbug.com/870173 virtual/omt-worker-fetch/external/wpt/resource-timing/cors-preflight.any.html [ WontFix ]
crbug.com/870173 virtual/omt-worker-fetch/external/wpt/resource-timing/cors-preflight.any.worker.html [ WontFix ] crbug.com/870173 virtual/omt-worker-fetch/external/wpt/resource-timing/cors-preflight.any.worker.html [ WontFix ]
crbug.com/870173 virtual/omt-worker-fetch/http/tests/workers/worker-redirect.html [ WontFix ] crbug.com/870173 virtual/omt-worker-fetch/http/tests/workers/worker-redirect.html [ WontFix ]
# Blink implements additional privacy measures that cause the regular test in
# WPT to time out.
# There is a version in wpt_internal that performs the same checks but works
# as expected.
external/wpt/ambient-light/AmbientLightSensor.https.html [ WontFix ]
...@@ -246,12 +246,15 @@ function runGenericSensorTests(sensorName, ...@@ -246,12 +246,15 @@ function runGenericSensorTests(sensorName,
assert_true(verificationFunction(expected, sensor2, /*isNull=*/true)); assert_true(verificationFunction(expected, sensor2, /*isNull=*/true));
}, `${sensorName}: sensor reading is correct.`); }, `${sensorName}: sensor reading is correct.`);
sensor_test(async t => { sensor_test(async (t, sensorProvider) => {
assert_true(sensorName in self); assert_true(sensorName in self);
const sensor = new sensorType(); const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]); const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
sensor.start(); sensor.start();
const mockSensor = await sensorProvider.getCreatedSensor(sensorName);
await mockSensor.setSensorReading(readings);
await sensorWatcher.wait_for("reading"); await sensorWatcher.wait_for("reading");
const cachedTimeStamp1 = sensor.timestamp; const cachedTimeStamp1 = sensor.timestamp;
...@@ -392,6 +395,7 @@ function runGenericSensorTests(sensorName, ...@@ -392,6 +395,7 @@ function runGenericSensorTests(sensorName,
fastSensor.start(); fastSensor.start();
const mockSensor = await sensorProvider.getCreatedSensor(sensorName); const mockSensor = await sensorProvider.getCreatedSensor(sensorName);
await mockSensor.setSensorReading(readings);
const fastCounter = await new Promise((resolve, reject) => { const fastCounter = await new Promise((resolve, reject) => {
let fastSensorNotifiedCounter = 0; let fastSensorNotifiedCounter = 0;
......
...@@ -199,6 +199,19 @@ var GenericSensorTest = (() => { ...@@ -199,6 +199,19 @@ var GenericSensorTest = (() => {
this.maxFrequency_ = Math.min(10, this.maxFrequency_); this.maxFrequency_ = Math.min(10, this.maxFrequency_);
} }
// Chromium applies some rounding and other privacy-related measures that
// can cause ALS not to report a reading when it has not changed beyond a
// certain threshold compared to the previous illuminance value. Make
// each reading return a different value that is significantly different
// from the previous one when setSensorReading() is not called by client
// code (e.g. run_generic_sensor_iframe_tests()).
if (type == device.mojom.SensorType.AMBIENT_LIGHT) {
this.activeSensors_.get(type).setSensorReading([
[window.performance.now() * 100],
[(window.performance.now() + 50) * 100]
]);
}
const initParams = new device.mojom.SensorInitParams({ const initParams = new device.mojom.SensorInitParams({
sensor: sensorPtr, sensor: sensorPtr,
clientReceiver: mojo.makeRequest(this.activeSensors_.get(type).client_), clientReceiver: mojo.makeRequest(this.activeSensors_.get(type).client_),
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>AmbientLightSensor Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://www.w3.org/TR/ambient-light/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/generic-sensor/resources/generic-sensor-helpers.js"></script>
<script src="/generic-sensor/generic-sensor-tests.js"></script>
<script>
'use strict';
const kReadings = {
readings: [
// We need to have at least two values here because some tests expect
// at least two readings to be available. If we have one value here,
// the ALS implementation will consider the value has not changed from
// the previous reading and not fire a reading event.
[240],
[110]
],
expectedReadings: [
// Our ALS implementation rounds off raw illuminance values to the
// nearest 50 Lux.
// See kAlsRoundingThreshold in ambient_light_sensor.cc.
[250],
[100]
]
};
runGenericSensorTests(
'AmbientLightSensor',
kReadings,
verifyAlsSensorReading,
['ambient-light-sensor']);
</script>
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