Commit 5a6b5571 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Instant Tethering: Rewrite DisconnectTetheringOperation test.

This change also factors out TestTimerFactory to reuse code.

R=khorimoto@chromium.org

Bug: none
Test: DisconnectTetheringOperationTest.*
Change-Id: I5988d6bfdbf145511d9ea5c7451c31b9d929b753
Reviewed-on: https://chromium-review.googlesource.com/c/1357614
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613187}
parent cc2560eb
...@@ -209,6 +209,8 @@ static_library("test_support") { ...@@ -209,6 +209,8 @@ static_library("test_support") {
"mock_tether_host_response_recorder.h", "mock_tether_host_response_recorder.h",
"proto_test_util.cc", "proto_test_util.cc",
"proto_test_util.h", "proto_test_util.h",
"test_timer_factory.cc",
"test_timer_factory.h",
] ]
public_deps = [ public_deps = [
...@@ -217,6 +219,7 @@ static_library("test_support") { ...@@ -217,6 +219,7 @@ static_library("test_support") {
deps = [ deps = [
"//base", "//base",
"//base/test:test_support",
"//chromeos", "//chromeos",
"//chromeos/components/multidevice", "//chromeos/components/multidevice",
"//chromeos/components/multidevice:test_support", "//chromeos/components/multidevice:test_support",
......
...@@ -16,12 +16,11 @@ ...@@ -16,12 +16,11 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/mock_timer.h" #include "base/timer/mock_timer.h"
#include "chromeos/components/multidevice/remote_device_test_util.h" #include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/components/tether/fake_ble_connection_manager.h"
#include "chromeos/components/tether/message_wrapper.h" #include "chromeos/components/tether/message_wrapper.h"
#include "chromeos/components/tether/mock_tether_host_response_recorder.h" #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
#include "chromeos/components/tether/proto/tether.pb.h" #include "chromeos/components/tether/proto/tether.pb.h"
#include "chromeos/components/tether/proto_test_util.h" #include "chromeos/components/tether/proto_test_util.h"
#include "chromeos/components/tether/timer_factory.h" #include "chromeos/components/tether/test_timer_factory.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h" #include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
#include "chromeos/services/secure_channel/ble_constants.h" #include "chromeos/services/secure_channel/ble_constants.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_client_channel.h" #include "chromeos/services/secure_channel/public/cpp/client/fake_client_channel.h"
...@@ -65,28 +64,6 @@ class MockOperationObserver : public ConnectTetheringOperation::Observer { ...@@ -65,28 +64,6 @@ class MockOperationObserver : public ConnectTetheringOperation::Observer {
} // namespace } // namespace
class TestTimerFactory : public TimerFactory {
public:
~TestTimerFactory() override = default;
// TimerFactory:
std::unique_ptr<base::OneShotTimer> CreateOneShotTimer() override {
EXPECT_FALSE(device_id_for_next_timer_.empty());
base::MockOneShotTimer* mock_timer = new base::MockOneShotTimer();
device_id_to_timer_map_[device_id_for_next_timer_] = mock_timer;
return base::WrapUnique(mock_timer);
}
void set_device_id_for_next_timer(
const std::string& device_id_for_next_timer) {
device_id_for_next_timer_ = device_id_for_next_timer;
}
private:
std::string device_id_for_next_timer_;
base::flat_map<std::string, base::MockOneShotTimer*> device_id_to_timer_map_;
};
class ConnectTetheringOperationTest : public testing::Test { class ConnectTetheringOperationTest : public testing::Test {
protected: protected:
ConnectTetheringOperationTest() ConnectTetheringOperationTest()
......
...@@ -74,6 +74,10 @@ class DisconnectTetheringOperation : public MessageTransferOperation { ...@@ -74,6 +74,10 @@ class DisconnectTetheringOperation : public MessageTransferOperation {
private: private:
friend class DisconnectTetheringOperationTest; friend class DisconnectTetheringOperationTest;
FRIEND_TEST_ALL_PREFIXES(DisconnectTetheringOperationTest, TestSuccess);
FRIEND_TEST_ALL_PREFIXES(DisconnectTetheringOperationTest, TestFailure);
FRIEND_TEST_ALL_PREFIXES(DisconnectTetheringOperationTest,
DisconnectRequestSentOnceAuthenticated);
void SetClockForTest(base::Clock* clock_for_test); void SetClockForTest(base::Clock* clock_for_test);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "chromeos/components/multidevice/remote_device_test_util.h" #include "chromeos/components/multidevice/remote_device_test_util.h"
#include "chromeos/components/tether/message_wrapper.h" #include "chromeos/components/tether/message_wrapper.h"
#include "chromeos/components/tether/proto_test_util.h" #include "chromeos/components/tether/proto_test_util.h"
#include "chromeos/components/tether/timer_factory.h" #include "chromeos/components/tether/test_timer_factory.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h" #include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_client_channel.h" #include "chromeos/services/secure_channel/public/cpp/client/fake_client_channel.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_connection_attempt.h" #include "chromeos/services/secure_channel/public/cpp/client/fake_connection_attempt.h"
...@@ -127,36 +127,6 @@ class TestOperation : public MessageTransferOperation { ...@@ -127,36 +127,6 @@ class TestOperation : public MessageTransferOperation {
base::Optional<int> last_sequence_number_; base::Optional<int> last_sequence_number_;
}; };
class TestTimerFactory : public TimerFactory {
public:
~TestTimerFactory() override = default;
// TimerFactory:
std::unique_ptr<base::OneShotTimer> CreateOneShotTimer() override {
EXPECT_FALSE(device_id_for_next_timer_.empty());
base::MockOneShotTimer* mock_timer = new base::MockOneShotTimer();
device_id_to_timer_map_[device_id_for_next_timer_] = mock_timer;
return base::WrapUnique(mock_timer);
}
base::MockOneShotTimer* GetTimerForDeviceId(const std::string& device_id) {
return device_id_to_timer_map_[device_id_for_next_timer_];
}
void ClearTimerForDeviceId(const std::string& device_id) {
device_id_to_timer_map_.erase(device_id_for_next_timer_);
}
void set_device_id_for_next_timer(
const std::string& device_id_for_next_timer) {
device_id_for_next_timer_ = device_id_for_next_timer;
}
private:
std::string device_id_for_next_timer_;
base::flat_map<std::string, base::MockOneShotTimer*> device_id_to_timer_map_;
};
TetherAvailabilityResponse CreateTetherAvailabilityResponse() { TetherAvailabilityResponse CreateTetherAvailabilityResponse() {
TetherAvailabilityResponse response; TetherAvailabilityResponse response;
response.set_response_code( response.set_response_code(
......
// Copyright 2018 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 "chromeos/components/tether/test_timer_factory.h"
#include "base/logging.h"
namespace chromeos {
namespace tether {
TestTimerFactory::TestTimerFactory() = default;
TestTimerFactory::~TestTimerFactory() = default;
std::unique_ptr<base::OneShotTimer> TestTimerFactory::CreateOneShotTimer() {
DCHECK(!device_id_for_next_timer_.empty());
auto mock_timer = std::make_unique<base::MockOneShotTimer>();
device_id_to_timer_map_[device_id_for_next_timer_] = mock_timer.get();
return std::move(mock_timer);
}
} // namespace tether
} // namespace chromeos
\ No newline at end of file
// Copyright 2018 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 CHROMEOS_COMPONENTS_TETHER_TEST_TIMER_FACTORY_H_
#define CHROMEOS_COMPONENTS_TETHER_TEST_TIMER_FACTORY_H_
#include <memory>
#include <string>
#include "base/containers/flat_map.h"
#include "base/timer/mock_timer.h"
#include "base/timer/timer.h"
#include "chromeos/components/tether/timer_factory.h"
namespace chromeos {
namespace tether {
class TestTimerFactory : public TimerFactory {
public:
TestTimerFactory();
~TestTimerFactory() override;
// TimerFactory:
std::unique_ptr<base::OneShotTimer> CreateOneShotTimer() override;
void set_device_id_for_next_timer(
const std::string& device_id_for_next_timer) {
device_id_for_next_timer_ = device_id_for_next_timer;
}
base::MockOneShotTimer* GetTimerForDeviceId(const std::string& device_id) {
return device_id_to_timer_map_[device_id_for_next_timer_];
}
void ClearTimerForDeviceId(const std::string& device_id) {
device_id_to_timer_map_.erase(device_id_for_next_timer_);
}
private:
std::string device_id_for_next_timer_;
base::flat_map<std::string, base::MockOneShotTimer*> device_id_to_timer_map_;
};
} // namespace tether
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_TEST_TIMER_FACTORY_H_
\ No newline at end of file
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