Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigator.getBattery should return constant result #567

Merged
merged 1 commit into from
Oct 13, 2018
Merged

Conversation

jumde
Copy link
Contributor

@jumde jumde commented Oct 4, 2018

fix brave/brave-browser#1398

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

  1. Open Brave and navigate to the Developer Console
  2. Enter: navigator.getBattery()
>navigator.getBattery()
Promise {
<resolved>: BatteryManager}
__proto__: Promise[[PromiseStatus]]: "resolved"
[[PromiseValue]]: BatteryManager
  charging: true
  chargingTime: 0
  dischargingTime: Infinity
  level: 1
  onchargingchange: null
  onchargingtimechange: null
  ondischargingtimechange: null
  onlevelchange: null
  __proto__: BatteryManager
  1. Disconnect the charger from your device and let the battery drain a bit. Invoke getBattery again and verify the values remain the same.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source
@jumde jumde requested a review from bridiver October 4, 2018 03:31
@jumde jumde force-pushed the battery_status branch 2 times, most recently from 40af933 to dc036ef Compare October 4, 2018 04:48
@jumde jumde changed the title WIP: Navigator.getBattery should return constant result Oct 4, 2018
#include "net/proxy_resolution/proxy_resolver_v8.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we still overriding this at all?

}

bool BatteryManager::charging() {
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using this function at all, I picked true as the default value for charging. Shouldn't be hard to change this to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check the values on a fully charged and plugged in laptop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome:

Fully charged:

charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null

89%

charging: false
chargingTime: Infinity
dischargingTime: 5820
level: 0.89
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null

Brave (with fix):

Fully charged:

charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null

89%:

[[PromiseValue]]: BatteryManager
charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null

BatteryManager* BatteryManager::Create(ExecutionContext* context) {
BatteryManager* battery_manager = new BatteryManager(context);
battery_manager->PauseIfNeeded();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to call this here because Pause/Unpause are noops anyway

Copy link
Contributor Author

@jumde jumde Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this a DCHECK is invoked when the BatteryManager destructor is called [30122:775:1005/101814.262486:FATAL:pausable_object.cc(49)] Check failed: pause_if_needed_called_.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) {
if (!battery_property_) {
BatteryStatus* status = new BatteryStatus();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

battery status is never used and this will leak memory for every page

}

void BatteryManager::UnregisterWithDispatcher() {
return;
Copy link
Collaborator

@bridiver bridiver Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upstream sets battery_property_ to null here and I think that might be necessary for GC of the Member property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, wrong method. Happens in ContextDestroyed below which is now correct

@bsclifton bsclifton merged commit 441ea83 into master Oct 13, 2018
@bsclifton bsclifton deleted the battery_status branch October 13, 2018 06:17
bsclifton added a commit that referenced this pull request Oct 13, 2018
Navigator.getBattery should return constant result
bsclifton added a commit that referenced this pull request Oct 13, 2018
Navigator.getBattery should return constant result
@bsclifton
Copy link
Member

master 441ea83
0.56.x 6158801
0.55.x 9a458ee

@bbondy bbondy added this to the 0.55.x - Release milestone Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants