diff --git a/components/brave_vpn/brave_vpn_os_connection_api.cc b/components/brave_vpn/brave_vpn_os_connection_api.cc index 7394871c3e09..8dde6e41a60f 100644 --- a/components/brave_vpn/brave_vpn_os_connection_api.cc +++ b/components/brave_vpn/brave_vpn_os_connection_api.cc @@ -96,8 +96,8 @@ void BraveVPNOSConnectionAPI::Connect(bool ignore_network_state) { if (GetIsSimulation() || connection_info_.IsValid()) { VLOG(2) << __func__ - << " : direct connect as we already have valid connection info."; - ConnectImpl(target_vpn_entry_name_); + << " : Create os vpn entry with cached connection_info."; + CreateVPNConnectionImpl(connection_info_); return; } diff --git a/components/brave_vpn/brave_vpn_unittest.cc b/components/brave_vpn/brave_vpn_unittest.cc index ae23d35cb928..13a087303a75 100644 --- a/components/brave_vpn/brave_vpn_unittest.cc +++ b/components/brave_vpn/brave_vpn_unittest.cc @@ -1092,6 +1092,35 @@ class MockBraveVPNOSConnectionAPI : public BraveVPNOSConnectionAPI { MOCK_METHOD(void, CheckConnectionImpl, (const std::string& name), (override)); }; +// Create os vpn entry with cached connection_info when there is cached +// connection info. +TEST_F(BraveVPNServiceTest, CreateOSVPNEntryWhenConnectTest) { + MockBraveVPNOSConnectionAPI api; + SetMockConnectionAPI(&api); + std::string env = skus::GetDefaultEnvironment(); + SetPurchasedState(env, PurchasedState::PURCHASED); + + // Prepare valid connection info. + OnFetchHostnames("region-a", GetHostnamesData(), true); + prevent_creation() = true; + OnGetProfileCredentials(GetProfileCredentialData(), true); + EXPECT_TRUE(GetConnectionInfo().IsValid()); + + // With cached connection info, connect process starts with + // os vpn entry creation. + EXPECT_CALL(api, CreateVPNConnectionImpl(testing::_)).Times(1); + Connect(); + testing::Mock::VerifyAndClearExpectations(&api); + + // W/o valid connection info, connect will not try to create + // os vpn entry at the beginning. + GetBraveVPNConnectionAPI()->ResetConnectionInfo(); + EXPECT_FALSE(GetConnectionInfo().IsValid()); + EXPECT_CALL(api, CreateVPNConnectionImpl(testing::_)).Times(0); + Connect(); + testing::Mock::VerifyAndClearExpectations(&api); +} + // Test connection check is asked only when purchased state. TEST_F(BraveVPNServiceTest, CheckConnectionStateAfterPurchased) { MockBraveVPNOSConnectionAPI api;