Commit 595f7529 authored by Michael Hansen's avatar Michael Hansen Committed by Commit Bot

[Nearby] Invalidate surfaces on screen lock changes.

Invalidate send and receive surfaces to make sure we start or stop
advertising based on changes to screen lock state.

Bug: b:166174379
Bug: 1119993
Change-Id: Ie7490d888b42e4c4aac783216b54490476f53aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392703
Commit-Queue: Michael Hansen <hansenmichael@google.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806767}
parent de24e540
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "ash/public/cpp/session/session_controller.h"
#include "base/barrier_closure.h" #include "base/barrier_closure.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file.h" #include "base/files/file.h"
...@@ -43,7 +44,6 @@ ...@@ -43,7 +44,6 @@
#include "crypto/random.h" #include "crypto/random.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/idle/idle.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -230,6 +230,14 @@ NearbySharingServiceImpl::NearbySharingServiceImpl( ...@@ -230,6 +230,14 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
DCHECK(profile_); DCHECK(profile_);
DCHECK(nearby_connections_manager_); DCHECK(nearby_connections_manager_);
#if defined(OS_CHROMEOS)
auto* session_controller = ash::SessionController::Get();
if (session_controller) {
is_screen_locked_ = session_controller->IsScreenLocked();
session_controller->AddObserver(this);
}
#endif // OS_CHROMEOS
nearby_process_observer_.Add(process_manager_); nearby_process_observer_.Add(process_manager_);
settings_.AddSettingsObserver(settings_receiver_.BindNewPipeAndPassRemote()); settings_.AddSettingsObserver(settings_receiver_.BindNewPipeAndPassRemote());
...@@ -282,6 +290,12 @@ void NearbySharingServiceImpl::Shutdown() { ...@@ -282,6 +290,12 @@ void NearbySharingServiceImpl::Shutdown() {
if (bluetooth_adapter_) if (bluetooth_adapter_)
bluetooth_adapter_->RemoveObserver(this); bluetooth_adapter_->RemoveObserver(this);
#if defined(OS_CHROMEOS)
auto* session_controller = ash::SessionController::Get();
if (session_controller)
session_controller->RemoveObserver(this);
#endif // OS_CHROMEOS
foreground_receive_callbacks_.Clear(); foreground_receive_callbacks_.Clear();
background_receive_callbacks_.Clear(); background_receive_callbacks_.Clear();
foreground_send_transfer_callbacks_.Clear(); foreground_send_transfer_callbacks_.Clear();
...@@ -820,6 +834,13 @@ void NearbySharingServiceImpl::OnEndpointLost(const std::string& endpoint_id) { ...@@ -820,6 +834,13 @@ void NearbySharingServiceImpl::OnEndpointLost(const std::string& endpoint_id) {
NS_LOG(VERBOSE) << __func__ << ": Reported onShareTargetLost"; NS_LOG(VERBOSE) << __func__ << ": Reported onShareTargetLost";
} }
void NearbySharingServiceImpl::OnLockStateChanged(bool locked) {
NS_LOG(VERBOSE) << __func__ << ": Screen lock state changed. (" << locked
<< ")";
is_screen_locked_ = locked;
InvalidateSurfaceState();
}
void NearbySharingServiceImpl::OnEnabledChanged(bool enabled) { void NearbySharingServiceImpl::OnEnabledChanged(bool enabled) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (enabled) { if (enabled) {
...@@ -1120,7 +1141,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() { ...@@ -1120,7 +1141,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
} }
// Screen is off. Do no work. // Screen is off. Do no work.
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
StopAdvertising(); StopAdvertising();
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Stopping advertising because the screen is locked."; << ": Stopping advertising because the screen is locked.";
...@@ -1289,7 +1310,7 @@ void NearbySharingServiceImpl::InvalidateScanningState() { ...@@ -1289,7 +1310,7 @@ void NearbySharingServiceImpl::InvalidateScanningState() {
} }
// Screen is off. Do no work. // Screen is off. Do no work.
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
StopScanning(); StopScanning();
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Stopping discovery because the screen is locked."; << ": Stopping discovery because the screen is locked.";
...@@ -1346,7 +1367,7 @@ void NearbySharingServiceImpl::StartScanning() { ...@@ -1346,7 +1367,7 @@ void NearbySharingServiceImpl::StartScanning() {
return; return;
} }
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Failed to scan because the user's screen is locked."; << ": Failed to scan because the user's screen is locked.";
return; return;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ash/public/cpp/session/session_observer.h"
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -57,7 +58,8 @@ class NearbySharingServiceImpl ...@@ -57,7 +58,8 @@ class NearbySharingServiceImpl
public NearbyProcessManager::Observer, public NearbyProcessManager::Observer,
public device::BluetoothAdapter::Observer, public device::BluetoothAdapter::Observer,
public NearbyConnectionsManager::IncomingConnectionListener, public NearbyConnectionsManager::IncomingConnectionListener,
public NearbyConnectionsManager::DiscoveryListener { public NearbyConnectionsManager::DiscoveryListener,
public ash::SessionObserver {
public: public:
explicit NearbySharingServiceImpl( explicit NearbySharingServiceImpl(
PrefService* prefs, PrefService* prefs,
...@@ -132,6 +134,9 @@ class NearbySharingServiceImpl ...@@ -132,6 +134,9 @@ class NearbySharingServiceImpl
void OnEndpointLost(const std::string& endpoint_id) override; void OnEndpointLost(const std::string& endpoint_id) override;
private: private:
// ash::SessionObserver:
void OnLockStateChanged(bool locked) override;
base::ObserverList<TransferUpdateCallback>& GetReceiveCallbacksFromState( base::ObserverList<TransferUpdateCallback>& GetReceiveCallbacksFromState(
ReceiveSurfaceState state); ReceiveSurfaceState state);
bool IsVisibleInBackground(Visibility visibility); bool IsVisibleInBackground(Visibility visibility);
...@@ -316,6 +321,7 @@ class NearbySharingServiceImpl ...@@ -316,6 +321,7 @@ class NearbySharingServiceImpl
std::unique_ptr<NearbyShareCertificateManager> certificate_manager_; std::unique_ptr<NearbyShareCertificateManager> certificate_manager_;
NearbyShareSettings settings_; NearbyShareSettings settings_;
NearbyFileHandler file_handler_; NearbyFileHandler file_handler_;
bool is_screen_locked_ = false;
// A list of service observers. // A list of service observers.
base::ObserverList<NearbySharingService::Observer> observers_; base::ObserverList<NearbySharingService::Observer> observers_;
......
...@@ -59,9 +59,10 @@ ...@@ -59,9 +59,10 @@
#include "net/base/mock_network_change_notifier.h" #include "net/base/mock_network_change_notifier.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/idle/scoped_set_idle_state.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ui/ash/test_session_controller.h"
#include "components/user_manager/scoped_user_manager.h" #include "components/user_manager/scoped_user_manager.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
...@@ -364,6 +365,10 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -364,6 +365,10 @@ class NearbySharingServiceImplTest : public testing::Test {
device::BluetoothAdapterFactory::SetAdapterForTesting( device::BluetoothAdapterFactory::SetAdapterForTesting(
mock_bluetooth_adapter_); mock_bluetooth_adapter_);
#if defined(OS_CHROMEOS)
session_controller_ = std::make_unique<TestSessionController>();
#endif // OS_CHROMEOS
service_ = CreateService(); service_ = CreateService();
SetFakeFastInitiationManagerFactory(/*should_succeed_on_start=*/true); SetFakeFastInitiationManagerFactory(/*should_succeed_on_start=*/true);
...@@ -617,7 +622,6 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -617,7 +622,6 @@ class NearbySharingServiceImplTest : public testing::Test {
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
ShareTarget share_target; ShareTarget share_target;
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_)) EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_))
...@@ -661,7 +665,6 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -661,7 +665,6 @@ class NearbySharingServiceImplTest : public testing::Test {
ShareTarget DiscoverShareTarget( ShareTarget DiscoverShareTarget(
MockTransferUpdateCallback& transfer_callback, MockTransferUpdateCallback& transfer_callback,
MockShareTargetDiscoveredCallback& discovery_callback) { MockShareTargetDiscoveredCallback& discovery_callback) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
// Ensure decoder parses a valid endpoint advertisement. // Ensure decoder parses a valid endpoint advertisement.
...@@ -859,7 +862,6 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -859,7 +862,6 @@ class NearbySharingServiceImplTest : public testing::Test {
// ChromeDownloadManagerDelegate. // ChromeDownloadManagerDelegate.
std::unique_ptr<net::test::MockNetworkChangeNotifier> network_notifier_; std::unique_ptr<net::test::MockNetworkChangeNotifier> network_notifier_;
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
ui::ScopedSetIdleState idle_state_{ui::IDLE_STATE_IDLE};
TestingProfileManager profile_manager_{TestingBrowserProcess::GetGlobal()}; TestingProfileManager profile_manager_{TestingBrowserProcess::GetGlobal()};
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -873,6 +875,9 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -873,6 +875,9 @@ class NearbySharingServiceImplTest : public testing::Test {
FakeNearbyShareCertificateManager::Factory certificate_manager_factory_; FakeNearbyShareCertificateManager::Factory certificate_manager_factory_;
std::unique_ptr<NotificationDisplayServiceTester> notification_tester_; std::unique_ptr<NotificationDisplayServiceTester> notification_tester_;
NiceMock<MockNearbyProcessManager> mock_nearby_process_manager_; NiceMock<MockNearbyProcessManager> mock_nearby_process_manager_;
#if defined(OS_CHROMEOS)
std::unique_ptr<TestSessionController> session_controller_;
#endif // OS_CHROMEOS
std::unique_ptr<NearbySharingServiceImpl> service_; std::unique_ptr<NearbySharingServiceImpl> service_;
std::unique_ptr<base::ScopedDisallowBlocking> disallow_blocking_; std::unique_ptr<base::ScopedDisallowBlocking> disallow_blocking_;
std::unique_ptr<FakeFastInitiationManagerFactory> std::unique_ptr<FakeFastInitiationManagerFactory>
...@@ -886,40 +891,40 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -886,40 +891,40 @@ class NearbySharingServiceImplTest : public testing::Test {
}; };
struct ValidSendSurfaceTestData { struct ValidSendSurfaceTestData {
ui::IdleState idle_state;
bool bluetooth_enabled; bool bluetooth_enabled;
net::NetworkChangeNotifier::ConnectionType connection_type; net::NetworkChangeNotifier::ConnectionType connection_type;
} kValidSendSurfaceTestData[] = { } kValidSendSurfaceTestData[] = {
// No network connection, only bluetooth available // No network connection, only bluetooth available
{ui::IDLE_STATE_IDLE, true, net::NetworkChangeNotifier::CONNECTION_NONE}, {true, net::NetworkChangeNotifier::CONNECTION_NONE},
// Wifi available // Wifi available
{ui::IDLE_STATE_IDLE, true, net::NetworkChangeNotifier::CONNECTION_WIFI}, {true, net::NetworkChangeNotifier::CONNECTION_WIFI},
// Ethernet available // Ethernet available
{ui::IDLE_STATE_IDLE, true, {true, net::NetworkChangeNotifier::CONNECTION_ETHERNET},
net::NetworkChangeNotifier::CONNECTION_ETHERNET},
// 3G available // 3G available
{ui::IDLE_STATE_IDLE, true, net::NetworkChangeNotifier::CONNECTION_3G}, {true, net::NetworkChangeNotifier::CONNECTION_3G},
// Wifi available and no bluetooth // Wifi available and no bluetooth
{ui::IDLE_STATE_IDLE, false, net::NetworkChangeNotifier::CONNECTION_WIFI}, {false, net::NetworkChangeNotifier::CONNECTION_WIFI},
// Ethernet available and no bluetooth // Ethernet available and no bluetooth
{ui::IDLE_STATE_IDLE, false, {false, net::NetworkChangeNotifier::CONNECTION_ETHERNET}};
net::NetworkChangeNotifier::CONNECTION_ETHERNET}};
class NearbySharingServiceImplValidSendTest class NearbySharingServiceImplValidSendTest
: public NearbySharingServiceImplTest, : public NearbySharingServiceImplTest,
public testing::WithParamInterface<ValidSendSurfaceTestData> {}; public testing::WithParamInterface<ValidSendSurfaceTestData> {};
struct InvalidSendSurfaceTestData { struct InvalidSendSurfaceTestData {
ui::IdleState idle_state; bool screen_locked;
bool bluetooth_enabled; bool bluetooth_enabled;
net::NetworkChangeNotifier::ConnectionType connection_type; net::NetworkChangeNotifier::ConnectionType connection_type;
} kInvalidSendSurfaceTestData[] = { } kInvalidSendSurfaceTestData[] = {
#if defined(OS_CHROMEOS)
// Screen locked // Screen locked
{ui::IDLE_STATE_LOCKED, true, net::NetworkChangeNotifier::CONNECTION_WIFI}, {/*screen_locked=*/true, true, net::NetworkChangeNotifier::CONNECTION_WIFI},
#endif // OS_CHROMEOS
// No network connection and no bluetooth // No network connection and no bluetooth
{ui::IDLE_STATE_IDLE, false, net::NetworkChangeNotifier::CONNECTION_NONE}, {/*screen_locked=*/false, false,
net::NetworkChangeNotifier::CONNECTION_NONE},
// 3G available and no bluetooth // 3G available and no bluetooth
{ui::IDLE_STATE_IDLE, false, net::NetworkChangeNotifier::CONNECTION_3G}, {/*screen_locked=*/false, false, net::NetworkChangeNotifier::CONNECTION_3G},
}; };
class NearbySharingServiceImplInvalidSendTest class NearbySharingServiceImplInvalidSendTest
...@@ -979,7 +984,6 @@ TEST_F(NearbySharingServiceImplTest, RemovesNearbyProcessObserver) { ...@@ -979,7 +984,6 @@ TEST_F(NearbySharingServiceImplTest, RemovesNearbyProcessObserver) {
} }
TEST_F(NearbySharingServiceImplTest, DisableNearbyShutdownConnections) { TEST_F(NearbySharingServiceImplTest, DisableNearbyShutdownConnections) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false); prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false);
service_->FlushMojoForTesting(); service_->FlushMojoForTesting();
...@@ -987,7 +991,6 @@ TEST_F(NearbySharingServiceImplTest, DisableNearbyShutdownConnections) { ...@@ -987,7 +991,6 @@ TEST_F(NearbySharingServiceImplTest, DisableNearbyShutdownConnections) {
} }
TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) { TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1007,7 +1010,6 @@ TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) { ...@@ -1007,7 +1010,6 @@ TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertising) {
} }
TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertisingError) { TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertisingError) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
SetFakeFastInitiationManagerFactory(/*should_succeed_on_start=*/false); SetFakeFastInitiationManagerFactory(/*should_succeed_on_start=*/false);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
...@@ -1020,7 +1022,6 @@ TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertisingError) { ...@@ -1020,7 +1022,6 @@ TEST_F(NearbySharingServiceImplTest, StartFastInitiationAdvertisingError) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundStartFastInitiationAdvertisingError) { BackgroundStartFastInitiationAdvertisingError) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1033,7 +1034,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1033,7 +1034,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
StartFastInitiationAdvertising_BluetoothNotPresent) { StartFastInitiationAdvertising_BluetoothNotPresent) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
is_bluetooth_present_ = false; is_bluetooth_present_ = false;
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
...@@ -1046,7 +1046,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1046,7 +1046,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
StartFastInitiationAdvertising_BluetoothNotPowered) { StartFastInitiationAdvertising_BluetoothNotPowered) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
is_bluetooth_powered_ = false; is_bluetooth_powered_ = false;
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
...@@ -1058,7 +1057,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1058,7 +1057,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, StopFastInitiationAdvertising) { TEST_F(NearbySharingServiceImplTest, StopFastInitiationAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1076,7 +1074,6 @@ TEST_F(NearbySharingServiceImplTest, StopFastInitiationAdvertising) { ...@@ -1076,7 +1074,6 @@ TEST_F(NearbySharingServiceImplTest, StopFastInitiationAdvertising) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
StopFastInitiationAdvertising_BluetoothBecomesNotPresent) { StopFastInitiationAdvertising_BluetoothBecomesNotPresent) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1092,7 +1089,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1092,7 +1089,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
StopFastInitiationAdvertising_BluetoothBecomesNotPowered) { StopFastInitiationAdvertising_BluetoothBecomesNotPowered) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1108,7 +1104,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1108,7 +1104,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
RegisterSendSurfaceNoActiveProfilesNotDiscovering) { RegisterSendSurfaceNoActiveProfilesNotDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
ON_CALL(mock_nearby_process_manager_, IsActiveProfile(_)) ON_CALL(mock_nearby_process_manager_, IsActiveProfile(_))
.WillByDefault(Return(false)); .WillByDefault(Return(false));
...@@ -1148,7 +1143,6 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurface_BluetoothNotPowered) { ...@@ -1148,7 +1143,6 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurface_BluetoothNotPowered) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundRegisterSendSurfaceStartsDiscovering) { ForegroundRegisterSendSurfaceStartsDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1161,7 +1155,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1161,7 +1155,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundRegisterSendSurfaceTwiceKeepsDiscovering) { ForegroundRegisterSendSurfaceTwiceKeepsDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1232,7 +1225,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1232,7 +1225,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundRegisterSendSurfaceNotDiscovering) { BackgroundRegisterSendSurfaceNotDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1246,7 +1238,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1246,7 +1238,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
DifferentSurfaceRegisterSendSurfaceTwiceKeepsDiscovering) { DifferentSurfaceRegisterSendSurfaceTwiceKeepsDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1265,7 +1256,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1265,7 +1256,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
RegisterSendSurfaceEndpointFoundDiscoveryCallbackNotified) { RegisterSendSurfaceEndpointFoundDiscoveryCallbackNotified) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
// Ensure decoder parses a valid endpoint advertisement. // Ensure decoder parses a valid endpoint advertisement.
...@@ -1323,7 +1313,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1323,7 +1313,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) { TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
// Ensure decoder parses a valid endpoint advertisement. // Ensure decoder parses a valid endpoint advertisement.
...@@ -1382,7 +1371,6 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) { ...@@ -1382,7 +1371,6 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
TEST_P(NearbySharingServiceImplValidSendTest, TEST_P(NearbySharingServiceImplValidSendTest,
RegisterSendSurfaceIsDiscovering) { RegisterSendSurfaceIsDiscovering) {
ui::ScopedSetIdleState idle_state(GetParam().idle_state);
is_bluetooth_present_ = GetParam().bluetooth_enabled; is_bluetooth_present_ = GetParam().bluetooth_enabled;
SetConnectionType(GetParam().connection_type); SetConnectionType(GetParam().connection_type);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
...@@ -1400,7 +1388,9 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest, ...@@ -1400,7 +1388,9 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest,
TEST_P(NearbySharingServiceImplInvalidSendTest, TEST_P(NearbySharingServiceImplInvalidSendTest,
RegisterSendSurfaceNotDiscovering) { RegisterSendSurfaceNotDiscovering) {
ui::ScopedSetIdleState idle_state(GetParam().idle_state); #if defined(OS_CHROMEOS)
session_controller_->SetScreenLocked(GetParam().screen_locked);
#endif // OS_CHROMEOS
is_bluetooth_present_ = GetParam().bluetooth_enabled; is_bluetooth_present_ = GetParam().bluetooth_enabled;
SetConnectionType(GetParam().connection_type); SetConnectionType(GetParam().connection_type);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
...@@ -1419,7 +1409,6 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest, ...@@ -1419,7 +1409,6 @@ INSTANTIATE_TEST_SUITE_P(NearbySharingServiceImplTest,
testing::ValuesIn(kInvalidSendSurfaceTestData)); testing::ValuesIn(kInvalidSendSurfaceTestData));
TEST_F(NearbySharingServiceImplTest, DisableFeatureSendSurfaceNotDiscovering) { TEST_F(NearbySharingServiceImplTest, DisableFeatureSendSurfaceNotDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false); prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false);
service_->FlushMojoForTesting(); service_->FlushMojoForTesting();
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
...@@ -1435,7 +1424,6 @@ TEST_F(NearbySharingServiceImplTest, DisableFeatureSendSurfaceNotDiscovering) { ...@@ -1435,7 +1424,6 @@ TEST_F(NearbySharingServiceImplTest, DisableFeatureSendSurfaceNotDiscovering) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
DisableFeatureSendSurfaceStopsDiscovering) { DisableFeatureSendSurfaceStopsDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1452,7 +1440,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1452,7 +1440,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) { TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1473,7 +1460,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) { ...@@ -1473,7 +1460,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceStopsDiscovering) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
UnregisterSendSurfaceDifferentCallbackKeepDiscovering) { UnregisterSendSurfaceDifferentCallbackKeepDiscovering) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -1492,7 +1478,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1492,7 +1478,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) { TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
EXPECT_CALL(mock_nearby_process_manager(), StopProcess(profile_)) EXPECT_CALL(mock_nearby_process_manager(), StopProcess(profile_))
...@@ -1507,7 +1492,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) { ...@@ -1507,7 +1492,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterSendSurfaceNeverRegistered) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundRegisterReceiveSurfaceIsAdvertisingAllContacts) { ForegroundRegisterReceiveSurfaceIsAdvertisingAllContacts) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
SetVisibility(nearby_share::mojom::Visibility::kAllContacts); SetVisibility(nearby_share::mojom::Visibility::kAllContacts);
local_device_data_manager()->SetDeviceName(kDeviceName); local_device_data_manager()->SetDeviceName(kDeviceName);
...@@ -1534,7 +1518,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1534,7 +1518,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundRegisterReceiveSurfaceIsAdvertisingNoOne) { ForegroundRegisterReceiveSurfaceIsAdvertisingNoOne) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
SetVisibility(nearby_share::mojom::Visibility::kNoOne); SetVisibility(nearby_share::mojom::Visibility::kNoOne);
local_device_data_manager()->SetDeviceName(kDeviceName); local_device_data_manager()->SetDeviceName(kDeviceName);
...@@ -1563,7 +1546,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1563,7 +1546,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundRegisterReceiveSurfaceIsAdvertisingSelectedContacts) { BackgroundRegisterReceiveSurfaceIsAdvertisingSelectedContacts) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
SetVisibility(nearby_share::mojom::Visibility::kSelectedContacts); SetVisibility(nearby_share::mojom::Visibility::kSelectedContacts);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
...@@ -1591,7 +1573,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1591,7 +1573,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
RegisterReceiveSurfaceTwiceSameCallbackKeepAdvertising) { RegisterReceiveSurfaceTwiceSameCallbackKeepAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1607,7 +1588,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1607,7 +1588,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
RegisterReceiveSurfaceTwiceKeepAdvertising) { RegisterReceiveSurfaceTwiceKeepAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1622,9 +1602,10 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1622,9 +1602,10 @@ TEST_F(NearbySharingServiceImplTest,
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising()); EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
} }
#if defined(OS_CHROMEOS)
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ScreenLockedRegisterReceiveSurfaceNotAdvertising) { ScreenLockedRegisterReceiveSurfaceNotAdvertising) {
ui::ScopedSetIdleState locked(ui::IDLE_STATE_LOCKED); session_controller_->SetScreenLocked(true);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1634,9 +1615,25 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1634,9 +1615,25 @@ TEST_F(NearbySharingServiceImplTest,
EXPECT_FALSE(fake_nearby_connections_manager_->is_shutdown()); EXPECT_FALSE(fake_nearby_connections_manager_->is_shutdown());
} }
TEST_F(NearbySharingServiceImplTest, ScreenLocksDuringAdvertising) {
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback;
EXPECT_EQ(
NearbySharingService::StatusCodes::kOk,
service_->RegisterSendSurface(&transfer_callback, &discovery_callback,
SendSurfaceState::kForeground));
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
session_controller_->SetScreenLocked(true);
EXPECT_FALSE(fake_nearby_connections_manager_->IsDiscovering());
session_controller_->SetScreenLocked(false);
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
}
#endif // OS_CHROMEOS
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
DataUsageChangedRegisterReceiveSurfaceRestartsAdvertising) { DataUsageChangedRegisterReceiveSurfaceRestartsAdvertising) {
ui::ScopedSetIdleState locked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingDataUsageName, prefs_.SetInteger(prefs::kNearbySharingDataUsageName,
...@@ -1660,7 +1657,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1660,7 +1657,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
NoNetworkRegisterReceiveSurfaceIsAdvertising) { NoNetworkRegisterReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
&callback, NearbySharingService::ReceiveSurfaceState::kForeground); &callback, NearbySharingService::ReceiveSurfaceState::kForeground);
...@@ -1671,7 +1667,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1671,7 +1667,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
NoBluetoothNoNetworkRegisterReceiveSurfaceNotAdvertising) { NoBluetoothNoNetworkRegisterReceiveSurfaceNotAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
is_bluetooth_present_ = false; is_bluetooth_present_ = false;
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1682,7 +1677,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1682,7 +1677,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) { TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1693,7 +1687,6 @@ TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) { ...@@ -1693,7 +1687,6 @@ TEST_F(NearbySharingServiceImplTest, WifiRegisterReceiveSurfaceIsAdvertising) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
EthernetRegisterReceiveSurfaceIsAdvertising) { EthernetRegisterReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1704,7 +1697,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1704,7 +1697,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ThreeGRegisterReceiveSurfaceIsAdvertising) { ThreeGRegisterReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_3G); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_3G);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1716,7 +1708,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1716,7 +1708,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
NoBluetoothWifiReceiveSurfaceIsAdvertising) { NoBluetoothWifiReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
is_bluetooth_present_ = false; is_bluetooth_present_ = false;
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
...@@ -1728,7 +1719,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1728,7 +1719,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
NoBluetoothEthernetReceiveSurfaceIsAdvertising) { NoBluetoothEthernetReceiveSurfaceIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
is_bluetooth_present_ = false; is_bluetooth_present_ = false;
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
...@@ -1740,7 +1730,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1740,7 +1730,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
NoBluetoothThreeGReceiveSurfaceNotAdvertising) { NoBluetoothThreeGReceiveSurfaceNotAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
is_bluetooth_present_ = false; is_bluetooth_present_ = false;
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_3G); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_3G);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
...@@ -1753,7 +1742,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1753,7 +1742,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
DisableFeatureReceiveSurfaceNotAdvertising) { DisableFeatureReceiveSurfaceNotAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false); prefs_.SetBoolean(prefs::kNearbySharingEnabledPrefName, false);
service_->FlushMojoForTesting(); service_->FlushMojoForTesting();
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
...@@ -1767,7 +1755,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1767,7 +1755,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
DisableFeatureReceiveSurfaceStopsAdvertising) { DisableFeatureReceiveSurfaceStopsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1783,7 +1770,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1783,7 +1770,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) { ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kNoOne)); static_cast<int>(Visibility::kNoOne));
...@@ -1796,7 +1782,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1796,7 +1782,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundReceiveSurfaceNoOneVisibilityNotAdvertising) { BackgroundReceiveSurfaceNoOneVisibilityNotAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kNoOne)); static_cast<int>(Visibility::kNoOne));
...@@ -1811,7 +1796,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1811,7 +1796,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundReceiveSurfaceVisibilityToNoOneStopsAdvertising) { BackgroundReceiveSurfaceVisibilityToNoOneStopsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kSelectedContacts)); static_cast<int>(Visibility::kSelectedContacts));
...@@ -1831,7 +1815,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1831,7 +1815,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundReceiveSurfaceVisibilityToSelectedStartsAdvertising) { BackgroundReceiveSurfaceVisibilityToSelectedStartsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kNoOne)); static_cast<int>(Visibility::kNoOne));
...@@ -1851,7 +1834,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1851,7 +1834,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) { ForegroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kSelectedContacts)); static_cast<int>(Visibility::kSelectedContacts));
...@@ -1864,7 +1846,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1864,7 +1846,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) { BackgroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kSelectedContacts)); static_cast<int>(Visibility::kSelectedContacts));
...@@ -1877,7 +1858,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1877,7 +1858,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
ForegroundReceiveSurfaceAllContactsVisibilityIsAdvertising) { ForegroundReceiveSurfaceAllContactsVisibilityIsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kAllContacts)); static_cast<int>(Visibility::kAllContacts));
...@@ -1890,7 +1870,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1890,7 +1870,6 @@ TEST_F(NearbySharingServiceImplTest,
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
BackgroundReceiveSurfaceAllContactsVisibilityNotAdvertising) { BackgroundReceiveSurfaceAllContactsVisibilityNotAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName, prefs_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
static_cast<int>(Visibility::kAllContacts)); static_cast<int>(Visibility::kAllContacts));
...@@ -1902,7 +1881,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1902,7 +1881,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) { TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1921,7 +1899,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) { ...@@ -1921,7 +1899,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceStopsAdvertising) {
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
UnregisterReceiveSurfaceDifferentCallbackKeepAdvertising) { UnregisterReceiveSurfaceDifferentCallbackKeepAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -1937,7 +1914,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1937,7 +1914,6 @@ TEST_F(NearbySharingServiceImplTest,
} }
TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceNeverRegistered) { TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceNeverRegistered) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
EXPECT_CALL(mock_nearby_process_manager(), StopProcess(profile_)) EXPECT_CALL(mock_nearby_process_manager(), StopProcess(profile_))
...@@ -1957,7 +1933,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1957,7 +1933,6 @@ TEST_F(NearbySharingServiceImplTest,
SetUpAdvertisementDecoder(kValidV1EndpointInfo, SetUpAdvertisementDecoder(kValidV1EndpointInfo,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_)).Times(0); EXPECT_CALL(callback, OnTransferUpdate(testing::_, testing::_)).Times(0);
...@@ -1985,7 +1960,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1985,7 +1960,6 @@ TEST_F(NearbySharingServiceImplTest,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/true); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/true);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2034,7 +2008,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2034,7 +2008,6 @@ TEST_F(NearbySharingServiceImplTest,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2145,7 +2118,6 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_OutOfStorage) { ...@@ -2145,7 +2118,6 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_OutOfStorage) {
})); }));
connection_.AppendReadableData(std::move(bytes)); connection_.AppendReadableData(std::move(bytes));
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2221,7 +2193,6 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_FileSizeOverflow) { ...@@ -2221,7 +2193,6 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_FileSizeOverflow) {
})); }));
connection_.AppendReadableData(std::move(bytes)); connection_.AppendReadableData(std::move(bytes));
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2262,7 +2233,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2262,7 +2233,6 @@ TEST_F(NearbySharingServiceImplTest,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2844,7 +2814,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2844,7 +2814,6 @@ TEST_F(NearbySharingServiceImplTest,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2897,7 +2866,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2897,7 +2866,6 @@ TEST_F(NearbySharingServiceImplTest,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false); SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -2953,7 +2921,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2953,7 +2921,6 @@ TEST_F(NearbySharingServiceImplTest,
SetUpAdvertisementDecoder(kValidV1EndpointInfo, SetUpAdvertisementDecoder(kValidV1EndpointInfo,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
...@@ -2984,7 +2951,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -2984,7 +2951,6 @@ TEST_F(NearbySharingServiceImplTest,
SetUpAdvertisementDecoder(kValidV1EndpointInfo, SetUpAdvertisementDecoder(kValidV1EndpointInfo,
/*return_empty_advertisement=*/false); /*return_empty_advertisement=*/false);
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
...@@ -3423,7 +3389,6 @@ TEST_F(NearbySharingServiceImplTest, SendFiles_Success) { ...@@ -3423,7 +3389,6 @@ TEST_F(NearbySharingServiceImplTest, SendFiles_Success) {
} }
TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsDiscovery) { TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsDiscovery) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback transfer_callback; MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback; MockShareTargetDiscoveredCallback discovery_callback;
...@@ -3446,7 +3411,6 @@ TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsDiscovery) { ...@@ -3446,7 +3411,6 @@ TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsDiscovery) {
} }
TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsAdvertising) { TEST_F(NearbySharingServiceImplTest, ProfileChangedControlsAdvertising) {
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
MockTransferUpdateCallback callback; MockTransferUpdateCallback callback;
NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface( NearbySharingService::StatusCodes result = service_->RegisterReceiveSurface(
...@@ -3470,7 +3434,6 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -3470,7 +3434,6 @@ TEST_F(NearbySharingServiceImplTest,
RegisterForegroundReceiveSurfaceEntersHighVisibility) { RegisterForegroundReceiveSurfaceEntersHighVisibility) {
TestObserver observer(service_.get()); TestObserver observer(service_.get());
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
ui::ScopedSetIdleState unlocked(ui::IDLE_STATE_IDLE);
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI);
SetVisibility(nearby_share::mojom::Visibility::kAllContacts); SetVisibility(nearby_share::mojom::Visibility::kAllContacts);
......
...@@ -6,9 +6,17 @@ ...@@ -6,9 +6,17 @@
#include <utility> #include <utility>
#include "ash/public/cpp/session/session_observer.h"
TestSessionController::TestSessionController() = default; TestSessionController::TestSessionController() = default;
TestSessionController::~TestSessionController() = default; TestSessionController::~TestSessionController() = default;
void TestSessionController::SetScreenLocked(bool locked) {
is_screen_locked_ = locked;
for (auto& observer : observers_)
observer.OnLockStateChanged(locked);
}
void TestSessionController::SetClient(ash::SessionControllerClient* client) {} void TestSessionController::SetClient(ash::SessionControllerClient* client) {}
void TestSessionController::SetSessionInfo(const ash::SessionInfo& info) { void TestSessionController::SetSessionInfo(const ash::SessionInfo& info) {
...@@ -77,11 +85,14 @@ void TestSessionController::RemoveSessionActivationObserverForAccountId( ...@@ -77,11 +85,14 @@ void TestSessionController::RemoveSessionActivationObserverForAccountId(
const AccountId& account_id, const AccountId& account_id,
ash::SessionActivationObserver* observer) {} ash::SessionActivationObserver* observer) {}
void TestSessionController::AddObserver(ash::SessionObserver* observer) {} void TestSessionController::AddObserver(ash::SessionObserver* observer) {
observers_.AddObserver(observer);
}
void TestSessionController::RemoveObserver(ash::SessionObserver* observer) {} void TestSessionController::RemoveObserver(ash::SessionObserver* observer) {
observers_.RemoveObserver(observer);
}
bool TestSessionController::IsScreenLocked() const { bool TestSessionController::IsScreenLocked() const {
NOTIMPLEMENTED(); return is_screen_locked_;
return false;
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/public/cpp/session/session_controller.h" #include "ash/public/cpp/session/session_controller.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h"
#include "base/optional.h" #include "base/optional.h"
// Test implementation of ash's SessionController interface. // Test implementation of ash's SessionController interface.
...@@ -44,6 +45,8 @@ class TestSessionController : public ash::SessionController { ...@@ -44,6 +45,8 @@ class TestSessionController : public ash::SessionController {
return set_user_session_order_count_; return set_user_session_order_count_;
} }
void SetScreenLocked(bool locked);
// ash::SessionController: // ash::SessionController:
void SetClient(ash::SessionControllerClient* client) override; void SetClient(ash::SessionControllerClient* client) override;
void SetSessionInfo(const ash::SessionInfo& info) override; void SetSessionInfo(const ash::SessionInfo& info) override;
...@@ -82,6 +85,8 @@ class TestSessionController : public ash::SessionController { ...@@ -82,6 +85,8 @@ class TestSessionController : public ash::SessionController {
int update_user_session_count_ = 0; int update_user_session_count_ = 0;
int lock_animation_complete_call_count_ = 0; int lock_animation_complete_call_count_ = 0;
int set_user_session_order_count_ = 0; int set_user_session_order_count_ = 0;
bool is_screen_locked_ = false;
base::ObserverList<ash::SessionObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(TestSessionController); DISALLOW_COPY_AND_ASSIGN(TestSessionController);
}; };
......
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