-
Notifications
You must be signed in to change notification settings - Fork 859
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
Disconnect Solana dapps when its permission is revoked #19123
Conversation
@@ -817,22 +817,6 @@ IN_PROC_BROWSER_TEST_F(SolanaProviderRendererTest, Disconnect) { | |||
} | |||
disconnect();)"); | |||
EXPECT_EQ(base::Value(true), result.value); | |||
|
|||
// OnDisconnect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test moved to SolanaProviderTest
because it is not renderer initiated anymore
dca4066
to
0e9fbc7
Compare
base::flat_map<std::string, SignAndSendTransactionCallback> | ||
sign_and_send_tx_callbacks_; | ||
// Pending callback and arg are for waiting user unlock before connect | ||
ConnectCallback pending_connect_callback_; | ||
absl::optional<base::Value::Dict> pending_connect_arg_; | ||
|
||
const raw_ref<HostContentSettingsMap> host_content_settings_map_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: through chromium's code this is typically captured by raw_ptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use raw_ref
here is intentional to enforce that host_content_settings_map_
would never be null.
Same usage is in brave/components/permissions/permission_lifetime_manager.h
written by @goodov
// connect the account | ||
Navigate(GURL("https://brave.com")); | ||
AddSolanaPermission(GetOrigin(), added_account->account_id); | ||
std::string account = Connect(absl::nullopt, nullptr, nullptr); | ||
ASSERT_TRUE(!account.empty()); | ||
ASSERT_TRUE(IsConnected()); | ||
|
||
EXPECT_CALL(*observer_, AccountChangedEvent(testing::_)).Times(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: using testing::_;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and squashed
function registerDisconnect() { | ||
window.braveSolana.on('disconnect', result => { | ||
disconnectEmitted = true | ||
window.domAutomationController.send('result ready') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: at some point in future waiting for 'result ready' message should be refactored to waiting for disconnectEmitted promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is useful when we only want to test the event is emitted but when it is not being emitted there is no obvious way to resolve a different value. If we set a timer to resolve the un-emitted value, the test will be unstable.
@@ -688,21 +677,23 @@ TEST_F(SolanaProviderImplUnitTest, Disconnect) { | |||
ASSERT_TRUE(!account.empty()); | |||
ASSERT_TRUE(IsConnected()); | |||
|
|||
EXPECT_CALL(*observer_, DisconnectEvent()).Times(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik Times(1)
is a noop
or is it just to be explicit and match vs Times(0)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just to explicitly specify one time but I think I can remove it because without WillOnce() nor WillRepeatedly() it would infer just 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and squashed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sec gtg |
`disconnect` event now will be initiated from browser and it won't be emitted when there is no accounts connected
0e9fbc7
to
cdfc282
Compare
disconnect
event now will be initiated from browser and it won't be emitted when there is no accounts connectedResolves brave/brave-browser#24974
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run lint
,npm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
await window.braveSolana.connect()