Removing obsolete app remoting test app and code
This code is unlikely to be used again and I wanted to clear out some
cruft to make the signaling migration work a bit simpler, thus I'm
removing these files.
We should also consider whether to remove the ChromotingTestDriver or to
adapt it for the new signaling solution. I think it could be useful but
that is for another CL in the future.
Change-Id: I9a87b9d413ddf706f8570a7fb294a06361a2f141
Reviewed-on: https://chromium-review.googlesource.com/c/1469526
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Auto-Submit: Joe Downing <joedow@chromium.org>
Reviewed-by: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631831}
diff --git a/remoting/test/BUILD.gn b/remoting/test/BUILD.gn
index 0bb66b9b..2b7d0d7 100644
--- a/remoting/test/BUILD.gn
+++ b/remoting/test/BUILD.gn
@@ -10,10 +10,6 @@
sources = [
"access_token_fetcher.cc",
"access_token_fetcher.h",
- "app_remoting_report_issue_request.cc",
- "app_remoting_report_issue_request.h",
- "app_remoting_service_urls.cc",
- "app_remoting_service_urls.h",
"chromoting_test_driver_environment.cc",
"chromoting_test_driver_environment.h",
"connection_setup_info.cc",
@@ -24,8 +20,6 @@
"cyclic_frame_generator.h",
"fake_access_token_fetcher.cc",
"fake_access_token_fetcher.h",
- "fake_app_remoting_report_issue_request.cc",
- "fake_app_remoting_report_issue_request.h",
"fake_host_list_fetcher.cc",
"fake_host_list_fetcher.h",
"fake_network_dispatcher.cc",
@@ -36,8 +30,6 @@
"fake_port_allocator.h",
"fake_refresh_token_store.cc",
"fake_refresh_token_store.h",
- "fake_remote_host_info_fetcher.cc",
- "fake_remote_host_info_fetcher.h",
"fake_socket_factory.cc",
"fake_socket_factory.h",
"frame_generator_util.cc",
@@ -54,8 +46,6 @@
"remote_connection_observer.h",
"remote_host_info.cc",
"remote_host_info.h",
- "remote_host_info_fetcher.cc",
- "remote_host_info_fetcher.h",
"rgb_value.cc",
"rgb_value.h",
"scroll_frame_generator.cc",
@@ -111,44 +101,6 @@
]
}
-static_library("ar_test_driver_common") {
- testonly = true
-
- sources = [
- "app_remoting_connected_client_fixture.cc",
- "app_remoting_connected_client_fixture.h",
- "app_remoting_connection_helper.cc",
- "app_remoting_connection_helper.h",
- "app_remoting_latency_test_fixture.cc",
- "app_remoting_latency_test_fixture.h",
- "app_remoting_test_driver_environment.cc",
- "app_remoting_test_driver_environment.h",
- ]
-
- deps = [
- ":test_support",
- "//testing/gtest",
- "//third_party/webrtc/modules/desktop_capture",
- ]
-}
-
-# An external version of the test driver tool which includes minimal tests
-executable("ar_sample_test_driver") {
- testonly = true
-
- sources = [
- "app_remoting_sample_test_driver_environment.cc",
- "app_remoting_test_driver.cc",
- ]
-
- deps = [
- ":ar_test_driver_common",
- "//base/test:test_support",
- "//build/win:default_exe_manifest",
- "//testing/gtest",
- ]
-}
-
if (enable_remoting_host && !is_android && !is_chromeos) {
static_library("fake_connection_event_logger") {
testonly = true
@@ -230,18 +182,14 @@
sources = [
"access_token_fetcher_unittest.cc",
- "app_remoting_report_issue_request_unittest.cc",
- "app_remoting_test_driver_environment_unittest.cc",
"chromoting_test_driver_environment_unittest.cc",
"connection_time_observer_unittest.cc",
"host_list_fetcher_unittest.cc",
- "remote_host_info_fetcher_unittest.cc",
"test_chromoting_client_unittest.cc",
"test_video_renderer_unittest.cc",
]
deps = [
- ":ar_test_driver_common",
":test_support",
"//base",
"//net:test_support",
diff --git a/remoting/test/app_remoting_connected_client_fixture.cc b/remoting/test/app_remoting_connected_client_fixture.cc
deleted file mode 100644
index 9e0bad4..0000000
--- a/remoting/test/app_remoting_connected_client_fixture.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_connected_client_fixture.h"
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/callback_helpers.h"
-#include "base/json/json_reader.h"
-#include "base/logging.h"
-#include "base/run_loop.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/timer/timer.h"
-#include "base/values.h"
-#include "remoting/protocol/host_stub.h"
-#include "remoting/test/app_remoting_connection_helper.h"
-#include "remoting/test/app_remoting_test_driver_environment.h"
-#include "remoting/test/remote_application_details.h"
-#include "remoting/test/test_chromoting_client.h"
-
-namespace {
-
-void SimpleHostMessageHandler(
- const std::string& target_message_type,
- const std::string& target_message_data,
- const base::Closure& done_closure,
- bool* message_received,
- const remoting::protocol::ExtensionMessage& message) {
- if (message.type() == target_message_type &&
- message.data() == target_message_data) {
- *message_received = true;
- done_closure.Run();
- }
-}
-} // namespace
-
-namespace remoting {
-namespace test {
-
-AppRemotingConnectedClientFixture::AppRemotingConnectedClientFixture()
- : application_details_(
- AppRemotingSharedData->GetDetailsFromAppName(GetParam())) {}
-
-AppRemotingConnectedClientFixture::~AppRemotingConnectedClientFixture() =
- default;
-
-void AppRemotingConnectedClientFixture::SetUp() {
- connection_helper_.reset(
- new AppRemotingConnectionHelper(application_details_));
- std::unique_ptr<TestChromotingClient> test_chromoting_client(
- new TestChromotingClient());
-
- test_chromoting_client->AddRemoteConnectionObserver(this);
-
- connection_helper_->Initialize(std::move(test_chromoting_client));
- if (!connection_helper_->StartConnection()) {
- LOG(ERROR) << "Remote host connection could not be established.";
- FAIL();
- }
-}
-
-void AppRemotingConnectedClientFixture::TearDown() {
- connection_helper_->test_chromoting_client()->RemoveRemoteConnectionObserver(
- this);
- connection_helper_.reset();
-}
-
-void AppRemotingConnectedClientFixture::HostMessageReceived(
- const protocol::ExtensionMessage& message) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- if (!host_message_received_callback_.is_null()) {
- host_message_received_callback_.Run(message);
- }
-}
-
-bool AppRemotingConnectedClientFixture::VerifyResponseForSimpleHostMessage(
- const std::string& message_request_title,
- const std::string& message_response_title,
- const std::string& message_payload,
- const base::TimeDelta& max_wait_time) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- bool message_received = false;
-
- DCHECK(!run_loop_ || !run_loop_->running());
- run_loop_.reset(new base::RunLoop());
-
- host_message_received_callback_ =
- base::Bind(&SimpleHostMessageHandler, message_response_title,
- message_payload, run_loop_->QuitClosure(), &message_received);
-
- protocol::ExtensionMessage message;
- message.set_type(message_request_title);
- message.set_data(message_payload);
- connection_helper_->host_stub()->DeliverClientMessage(message);
-
- base::OneShotTimer timer;
- timer.Start(FROM_HERE, max_wait_time, run_loop_->QuitClosure());
-
- run_loop_->Run();
- timer.Stop();
- host_message_received_callback_.Reset();
-
- return message_received;
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_connected_client_fixture.h b/remoting/test/app_remoting_connected_client_fixture.h
deleted file mode 100644
index 66f38b16..0000000
--- a/remoting/test/app_remoting_connected_client_fixture.h
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_
-#define REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_
-
-#include <memory>
-#include <string>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/threading/thread_checker.h"
-#include "remoting/test/remote_connection_observer.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-class RunLoop;
-}
-
-namespace remoting {
-namespace test {
-
-struct RemoteApplicationDetails;
-class AppRemotingConnectionHelper;
-
-// Allows for custom handling of ExtensionMessage messages.
-typedef base::Callback<void(const protocol::ExtensionMessage& message)>
- HostMessageReceivedCallback;
-
-// Creates a connection to a remote host which is available for tests to use.
-// All callbacks must occur on the same thread the object was created on.
-class AppRemotingConnectedClientFixture
- : public testing::TestWithParam<const char*>,
- public RemoteConnectionObserver {
- public:
- AppRemotingConnectedClientFixture();
- ~AppRemotingConnectedClientFixture() override;
-
- protected:
- // Sends the request to the host and waits for a reply up to |max_wait_time|.
- // Returns true if we received a response within the maximum time limit.
- bool VerifyResponseForSimpleHostMessage(
- const std::string& message_request_title,
- const std::string& message_response_title,
- const std::string& message_payload,
- const base::TimeDelta& max_wait_time);
-
- private:
- // testing::Test interface.
- void SetUp() override;
- void TearDown() override;
-
- // RemoteConnectionObserver interface.
- void HostMessageReceived(const protocol::ExtensionMessage& message) override;
-
- // Handles messages from the host.
- void HandleOnHostMessage(const remoting::protocol::ExtensionMessage& message);
-
- // Contains the details for the application being tested.
- const RemoteApplicationDetails& application_details_;
-
- // Used to run the thread's message loop.
- std::unique_ptr<base::RunLoop> run_loop_;
-
- // Used to ensure RemoteConnectionObserver methods are called on the same
- // thread.
- base::ThreadChecker thread_checker_;
-
- // Creates and manages the connection to the remote host.
- std::unique_ptr<AppRemotingConnectionHelper> connection_helper_;
-
- // Called when an ExtensionMessage is received from the host.
- HostMessageReceivedCallback host_message_received_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_
diff --git a/remoting/test/app_remoting_connection_helper.cc b/remoting/test/app_remoting_connection_helper.cc
deleted file mode 100644
index 478fb09..0000000
--- a/remoting/test/app_remoting_connection_helper.cc
+++ /dev/null
@@ -1,221 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_connection_helper.h"
-
-#include <utility>
-
-#include "base/json/json_reader.h"
-#include "base/logging.h"
-#include "base/run_loop.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/values.h"
-#include "remoting/protocol/host_stub.h"
-#include "remoting/test/app_remoting_test_driver_environment.h"
-#include "remoting/test/remote_application_details.h"
-#include "remoting/test/test_chromoting_client.h"
-
-namespace {
-const int kDefaultDPI = 96;
-const int kDefaultWidth = 1024;
-const int kDefaultHeight = 768;
-
-const char kHostProcessWindowTitle[] = "Host Process";
-} // namespace
-
-namespace remoting {
-namespace test {
-
-AppRemotingConnectionHelper::AppRemotingConnectionHelper(
- const RemoteApplicationDetails& application_details)
- : application_details_(application_details),
- connection_is_ready_for_tests_(false) {}
-
-AppRemotingConnectionHelper::~AppRemotingConnectionHelper() {
- // |client_| destroys some of its members via DeleteSoon on the message loop's
- // TaskRunner so we need to run the loop until it has no more work to do.
- if (!connection_is_ready_for_tests_) {
- client_->RemoveRemoteConnectionObserver(this);
- }
- client_.reset();
-
- base::RunLoop().RunUntilIdle();
-}
-
-void AppRemotingConnectionHelper::Initialize(
- std::unique_ptr<TestChromotingClient> test_chromoting_client) {
- client_ = std::move(test_chromoting_client);
- client_->AddRemoteConnectionObserver(this);
-}
-
-bool AppRemotingConnectionHelper::StartConnection() {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(client_);
-
- RemoteHostInfo remote_host_info;
- remoting::test::AppRemotingSharedData->GetRemoteHostInfoForApplicationId(
- application_details_.application_id, &remote_host_info);
-
- if (!remote_host_info.IsReadyForConnection()) {
- return false;
- }
- remoting::test::AppRemotingSharedData->AddHostToReleaseList(
- application_details_.application_id, remote_host_info.host_id);
-
- DCHECK(!run_loop_ || !run_loop_->running());
- run_loop_.reset(new base::RunLoop());
-
- // We will wait up to 30 seconds to complete the remote connection and for the
- // main application window to become visible.
- DCHECK(!timer_.IsRunning());
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(30),
- run_loop_->QuitClosure());
-
- client_->StartConnection(
- /*use_test_api_settings=*/false,
- remote_host_info.GenerateConnectionSetupInfo(
- AppRemotingSharedData->access_token(),
- AppRemotingSharedData->user_name()));
-
- run_loop_->Run();
- timer_.Stop();
-
- if (connection_is_ready_for_tests_) {
- return true;
- } else {
- client_->EndConnection();
- return false;
- }
-}
-
-protocol::ClipboardStub* AppRemotingConnectionHelper::clipboard_forwarder() {
- return client_->clipboard_forwarder();
-}
-
-protocol::HostStub* AppRemotingConnectionHelper::host_stub() {
- return client_->host_stub();
-}
-
-protocol::InputStub* AppRemotingConnectionHelper::input_stub() {
- return client_->input_stub();
-}
-
-void AppRemotingConnectionHelper::ConnectionStateChanged(
- protocol::ConnectionToHost::State state,
- protocol::ErrorCode error_code) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- // If the connection is closed or failed then mark the connection as closed
- // and quit the current RunLoop if it exists.
- if (state == protocol::ConnectionToHost::CLOSED ||
- state == protocol::ConnectionToHost::FAILED ||
- error_code != protocol::OK) {
- connection_is_ready_for_tests_ = false;
-
- if (run_loop_) {
- run_loop_->Quit();
- }
- }
-}
-
-void AppRemotingConnectionHelper::ConnectionReady(bool ready) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- if (ready) {
- SendClientConnectionDetailsToHost();
- } else {
- // We will only get called here with a false value for |ready| if the video
- // renderer encounters an error.
- connection_is_ready_for_tests_ = false;
-
- if (run_loop_) {
- run_loop_->Quit();
- }
- }
-}
-
-void AppRemotingConnectionHelper::HostMessageReceived(
- const protocol::ExtensionMessage& message) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- VLOG(2) << "HostMessage received by HostMessageReceived()."
- << " type: " << message.type() << " data: " << message.data();
-
- if (message.type() == "onWindowAdded") {
- HandleOnWindowAddedMessage(message);
- } else {
- VLOG(2) << "HostMessage not handled by HostMessageReceived().";
- }
-}
-
-void AppRemotingConnectionHelper::SendClientConnectionDetailsToHost() {
- // First send an access token which will be used for Google Drive access.
- protocol::ExtensionMessage message;
- message.set_type("accessToken");
- message.set_data(AppRemotingSharedData->access_token());
-
- VLOG(1) << "Sending access token to host";
- client_->host_stub()->DeliverClientMessage(message);
-
- // Next send the host a description of the client screen size.
- protocol::ClientResolution client_resolution;
- client_resolution.set_width_deprecated(kDefaultWidth);
- client_resolution.set_height_deprecated(kDefaultHeight);
- client_resolution.set_x_dpi(kDefaultDPI);
- client_resolution.set_y_dpi(kDefaultDPI);
- client_resolution.set_dips_width(kDefaultWidth);
- client_resolution.set_dips_height(kDefaultHeight);
-
- VLOG(1) << "Sending ClientResolution details to host";
- client_->host_stub()->NotifyClientResolution(client_resolution);
-
- // Finally send a message to start sending us video packets.
- protocol::VideoControl video_control;
- video_control.set_enable(true);
-
- VLOG(1) << "Sending enable VideoControl message to host";
- client_->host_stub()->ControlVideo(video_control);
-}
-
-void AppRemotingConnectionHelper::HandleOnWindowAddedMessage(
- const remoting::protocol::ExtensionMessage& message) {
- DCHECK_EQ(message.type(), "onWindowAdded");
-
- const base::DictionaryValue* message_data = nullptr;
- std::unique_ptr<base::Value> host_message =
- base::JSONReader::Read(message.data());
- if (!host_message.get() || !host_message->GetAsDictionary(&message_data)) {
- LOG(ERROR) << "onWindowAdded message received was not valid JSON.";
- if (run_loop_) {
- run_loop_->Quit();
- }
- return;
- }
-
- std::string current_window_title;
- message_data->GetString("title", ¤t_window_title);
- if (current_window_title == kHostProcessWindowTitle) {
- LOG(ERROR) << "Host Process Window is visible, this likely means that the "
- << "underlying application is in a bad state, YMMV.";
- }
-
- std::string main_window_title = application_details_.main_window_title;
- if (current_window_title.find_first_of(main_window_title) == 0) {
- connection_is_ready_for_tests_ = true;
- client_->RemoveRemoteConnectionObserver(this);
-
- if (timer_.IsRunning()) {
- timer_.Stop();
- }
-
- DCHECK(run_loop_);
- // Now that the main window is visible, give the app some time to settle
- // before signaling that it is ready to run tests.
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(2),
- run_loop_->QuitClosure());
- }
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_connection_helper.h b/remoting/test/app_remoting_connection_helper.h
deleted file mode 100644
index 7820d3a..0000000
--- a/remoting/test/app_remoting_connection_helper.h
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_
-#define REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_
-
-#include <memory>
-#include <string>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/threading/thread_checker.h"
-#include "base/timer/timer.h"
-#include "remoting/test/remote_connection_observer.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-class RunLoop;
-}
-
-namespace remoting {
-namespace test {
-
-struct RemoteApplicationDetails;
-class TestChromotingClient;
-
-// Creates a connection to a remote host which is available for tests to use.
-// A TestChromotingClient is required from caller.
-class AppRemotingConnectionHelper
- : public RemoteConnectionObserver {
- public:
- explicit AppRemotingConnectionHelper(
- const RemoteApplicationDetails& application_details);
- ~AppRemotingConnectionHelper() override;
-
- // Initialize internal structures.
- void Initialize(std::unique_ptr<TestChromotingClient> test_chromoting_client);
-
- // Starts a connection with the remote host.
- // NOTE: Initialize() must be called before calling this method.
- bool StartConnection();
-
- // Stubs used to send messages to the remote host.
- protocol::ClipboardStub* clipboard_forwarder();
- protocol::HostStub* host_stub();
- protocol::InputStub* input_stub();
-
- TestChromotingClient* test_chromoting_client() { return client_.get(); }
-
- // Returns true if connection is ready for tests.
- bool ConnectionIsReadyForTest() { return connection_is_ready_for_tests_; }
-
- private:
- // RemoteConnectionObserver interface.
- void ConnectionStateChanged(protocol::ConnectionToHost::State state,
- protocol::ErrorCode error_code) override;
- void ConnectionReady(bool ready) override;
- void HostMessageReceived(const protocol::ExtensionMessage& message) override;
-
- // Sends client details to the host in order to complete the connection.
- void SendClientConnectionDetailsToHost();
-
- // Handles onWindowAdded messages from the host.
- void HandleOnWindowAddedMessage(
- const remoting::protocol::ExtensionMessage& message);
-
- // Contains the details for the application being tested.
- const RemoteApplicationDetails& application_details_;
-
- // Indicates whether the remote connection is ready to be used for testing.
- // True when a chromoting connection to the remote host has been established
- // and the main application window is visible.
- bool connection_is_ready_for_tests_;
-
- // Used to run the thread's message loop.
- std::unique_ptr<base::RunLoop> run_loop_;
-
- // Used for setting timeouts and delays.
- base::OneShotTimer timer_;
-
- // Used to ensure RemoteConnectionObserver methods are called on the same
- // thread.
- base::ThreadChecker thread_checker_;
-
- // Creates and manages the connection to the remote host.
- std::unique_ptr<TestChromotingClient> client_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_
diff --git a/remoting/test/app_remoting_latency_test_fixture.cc b/remoting/test/app_remoting_latency_test_fixture.cc
deleted file mode 100644
index b011911..0000000
--- a/remoting/test/app_remoting_latency_test_fixture.cc
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_latency_test_fixture.h"
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/run_loop.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "remoting/proto/event.pb.h"
-#include "remoting/protocol/input_stub.h"
-#include "remoting/test/app_remoting_connection_helper.h"
-#include "remoting/test/app_remoting_test_driver_environment.h"
-#include "remoting/test/rgb_value.h"
-#include "remoting/test/test_chromoting_client.h"
-#include "remoting/test/test_video_renderer.h"
-
-namespace remoting {
-namespace test {
-
-AppRemotingLatencyTestFixture::AppRemotingLatencyTestFixture() {
- // NOTE: Derived fixture must initialize application details in constructor.
-}
-
-AppRemotingLatencyTestFixture::~AppRemotingLatencyTestFixture() = default;
-
-void AppRemotingLatencyTestFixture::SetUp() {
- std::unique_ptr<TestVideoRenderer> test_video_renderer(
- new TestVideoRenderer());
- test_video_renderer_ = test_video_renderer->GetWeakPtr();
-
- std::unique_ptr<TestChromotingClient> test_chromoting_client(
- new TestChromotingClient(std::move(test_video_renderer)));
-
- test_chromoting_client->AddRemoteConnectionObserver(this);
-
- connection_helper_.reset(
- new AppRemotingConnectionHelper(GetApplicationDetails()));
- connection_helper_->Initialize(std::move(test_chromoting_client));
-
- if (!connection_helper_->StartConnection()) {
- LOG(ERROR) << "Remote host connection could not be established.";
- FAIL();
- }
-
- if (!PrepareApplicationForTesting()) {
- LOG(ERROR) << "Unable to prepare application for testing.";
- FAIL();
- }
-}
-
-void AppRemotingLatencyTestFixture::TearDown() {
- // Only reset application state when remote host connection is established.
- if (connection_helper_->ConnectionIsReadyForTest()) {
- ResetApplicationState();
- }
-
- connection_helper_->test_chromoting_client()->RemoveRemoteConnectionObserver(
- this);
- connection_helper_.reset();
-}
-
-WaitForImagePatternMatchCallback
-AppRemotingLatencyTestFixture::SetExpectedImagePattern(
- const webrtc::DesktopRect& expected_rect,
- const RGBValue& expected_color) {
- std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop());
-
- test_video_renderer_->ExpectAverageColorInRect(expected_rect, expected_color,
- run_loop->QuitClosure());
-
- return base::Bind(&AppRemotingLatencyTestFixture::WaitForImagePatternMatch,
- base::Unretained(this), base::Passed(&run_loop));
-}
-
-void AppRemotingLatencyTestFixture::SaveFrameDataToDisk(
- bool save_frame_data_to_disk) {
- test_video_renderer_->SaveFrameDataToDisk(save_frame_data_to_disk);
-}
-
-bool AppRemotingLatencyTestFixture::WaitForImagePatternMatch(
- std::unique_ptr<base::RunLoop> run_loop,
- const base::TimeDelta& max_wait_time) {
- DCHECK(run_loop);
- DCHECK(!timer_.IsRunning());
-
- timer_.Start(FROM_HERE, max_wait_time, run_loop->QuitClosure());
-
- run_loop->Run();
-
- // Image pattern is matched if we stopped because of the reply not the timer.
- bool image_pattern_is_matched = (timer_.IsRunning());
- timer_.Stop();
- run_loop.reset();
-
- return image_pattern_is_matched;
-}
-
-void AppRemotingLatencyTestFixture::HostMessageReceived(
- const protocol::ExtensionMessage& message) {
- if (!host_message_received_callback_.is_null()) {
- host_message_received_callback_.Run(message);
- }
-}
-
-void AppRemotingLatencyTestFixture::PressKey(ui::DomCode dom_code,
- bool pressed) {
- remoting::protocol::KeyEvent event;
- event.set_usb_keycode(static_cast<unsigned int>(dom_code));
- event.set_pressed(pressed);
- connection_helper_->input_stub()->InjectKeyEvent(event);
-}
-
-void AppRemotingLatencyTestFixture::PressAndReleaseKey(ui::DomCode dom_code) {
- PressKey(dom_code, true);
- PressKey(dom_code, false);
-}
-
-void AppRemotingLatencyTestFixture::PressAndReleaseKeyCombination(
- const std::vector<ui::DomCode>& dom_codes) {
- for (auto iter = dom_codes.begin(); iter != dom_codes.end(); ++iter) {
- PressKey(*iter, true);
- }
- for (auto iter = dom_codes.rbegin(); iter != dom_codes.rend(); ++iter) {
- PressKey(*iter, false);
- }
-}
-
-void AppRemotingLatencyTestFixture::SetHostMessageReceivedCallback(
- const HostMessageReceivedCallback& host_message_received_callback) {
- host_message_received_callback_ = host_message_received_callback;
-}
-
-void AppRemotingLatencyTestFixture::ResetHostMessageReceivedCallback() {
- host_message_received_callback_.Reset();
-}
-
-void AppRemotingLatencyTestFixture::ResetApplicationState() {
- DCHECK(!timer_.IsRunning());
- DCHECK(!run_loop_ || !run_loop_->running());
-
- // Give the app some time to settle before reseting to initial state.
- run_loop_.reset(new base::RunLoop());
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(1));
- run_loop_->Run();
-
- // Press Alt + F4 and wait for amount of time for the input to be delivered
- // and processed.
- std::vector<ui::DomCode> dom_codes;
- dom_codes.push_back(ui::DomCode::ALT_LEFT);
- dom_codes.push_back(ui::DomCode::F4);
- PressAndReleaseKeyCombination(dom_codes);
-
- run_loop_.reset(new base::RunLoop());
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2));
- run_loop_->Run();
-
- // Press 'N' to choose not save and wait for 1 second for the input to be
- // delivered and processed.
- PressAndReleaseKey(ui::DomCode::US_N);
-
- run_loop_.reset(new base::RunLoop());
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop_->QuitClosure(), base::TimeDelta::FromSeconds(2));
- run_loop_->Run();
- run_loop_.reset();
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_latency_test_fixture.h b/remoting/test/app_remoting_latency_test_fixture.h
deleted file mode 100644
index 9a3df1bb..0000000
--- a/remoting/test/app_remoting_latency_test_fixture.h
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_
-#define REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_
-
-#include <memory>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/timer/timer.h"
-#include "remoting/test/remote_connection_observer.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
-#include "ui/events/keycodes/dom/dom_code.h"
-
-namespace base {
-class RunLoop;
-class TimeDelta;
-}
-
-namespace webrtc {
-class DesktopRect;
-}
-
-namespace remoting {
-namespace test {
-
-struct RemoteApplicationDetails;
-struct RGBValue;
-class AppRemotingConnectionHelper;
-class TestVideoRenderer;
-
-// Allows for custom handling of ExtensionMessage messages.
-typedef base::Callback<void(const protocol::ExtensionMessage& message)>
- HostMessageReceivedCallback;
-
-// Called to wait for expected image pattern to be matched within up to a max
-// wait time.
-typedef base::Callback<bool(const base::TimeDelta& max_wait_time)>
- WaitForImagePatternMatchCallback;
-
-// Creates a connection to a remote host which is available for tests to use.
-// Provides convenient methods to create test cases to measure the input and
-// rendering latency between client and the remote host.
-// NOTE: This is an abstract class. To use it, please derive from this class
-// and implement GetApplicationDetails to specify the application details.
-class AppRemotingLatencyTestFixture : public testing::Test,
- public RemoteConnectionObserver {
- public:
- AppRemotingLatencyTestFixture();
- ~AppRemotingLatencyTestFixture() override;
-
- protected:
- // Set expected image pattern for comparison.
- // A WaitForImagePatternMatchCallback is returned to allow waiting for the
- // expected image pattern to be matched.
- WaitForImagePatternMatchCallback SetExpectedImagePattern(
- const webrtc::DesktopRect& expected_rect,
- const RGBValue& expected_avg_color);
-
- // Turn on/off saving video frames to disk.
- void SaveFrameDataToDisk(bool save_frame_data_to_disk);
-
- // Inject press & release key event.
- void PressAndReleaseKey(ui::DomCode usb_keycode);
-
- // Inject press & release a combination of key events.
- void PressAndReleaseKeyCombination(
- const std::vector<ui::DomCode>& usb_keycodes);
-
- // Setter for |host_message_received_callback_|.
- void SetHostMessageReceivedCallback(
- const HostMessageReceivedCallback& host_message_received_callback);
-
- // Reset |host_message_received_callback_| to null.
- void ResetHostMessageReceivedCallback();
-
- // Get the details of the application to be run.
- virtual const RemoteApplicationDetails& GetApplicationDetails() = 0;
-
- // Used to ensure the application under test is ready for testing.
- virtual bool PrepareApplicationForTesting() = 0;
-
- // Clean up the running application to initial state.
- virtual void ResetApplicationState();
-
- // Creates and manages the connection to the remote host.
- std::unique_ptr<AppRemotingConnectionHelper> connection_helper_;
-
- private:
- // testing::Test interface.
- void SetUp() override;
- void TearDown() override;
-
- // RemoteConnectionObserver interface.
- void HostMessageReceived(const protocol::ExtensionMessage& message) override;
-
- // Inject press key event.
- void PressKey(ui::DomCode usb_keycode, bool pressed);
-
- // Waits for an image pattern matched reply up to |max_wait_time|. Returns
- // true if we received a response within the maximum time limit.
- // NOTE: This method should only be run when as a returned callback by
- // SetExpectedImagePattern.
- bool WaitForImagePatternMatch(std::unique_ptr<base::RunLoop> run_loop,
- const base::TimeDelta& max_wait_time);
-
- // Used to run the thread's message loop.
- std::unique_ptr<base::RunLoop> run_loop_;
-
- // Used for setting timeouts and delays.
- base::OneShotTimer timer_;
-
- // Used to maintain a reference to the TestVideoRenderer instance while it
- // exists.
- base::WeakPtr<TestVideoRenderer> test_video_renderer_;
-
- // Called when an ExtensionMessage is received from the host. Used to
- // override default message handling.
- HostMessageReceivedCallback host_message_received_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingLatencyTestFixture);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_LATENCY_TEST_FIXTURE_H_
diff --git a/remoting/test/app_remoting_report_issue_request.cc b/remoting/test/app_remoting_report_issue_request.cc
deleted file mode 100644
index a3a0eae..0000000
--- a/remoting/test/app_remoting_report_issue_request.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_report_issue_request.h"
-
-#include "base/bind.h"
-#include "base/callback_helpers.h"
-#include "base/logging.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "net/http/http_response_headers.h"
-#include "net/http/http_status_code.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "net/url_request/url_fetcher.h"
-#include "remoting/base/url_request_context_getter.h"
-
-namespace {
-const char kRequestTestOrigin[] =
- "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk";
-}
-
-namespace remoting {
-namespace test {
-
-AppRemotingReportIssueRequest::AppRemotingReportIssueRequest() = default;
-
-AppRemotingReportIssueRequest::~AppRemotingReportIssueRequest() = default;
-
-bool AppRemotingReportIssueRequest::Start(
- const std::string& application_id,
- const std::string& host_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- bool abandon_host,
- base::Closure done_callback) {
- DCHECK(request_complete_callback_.is_null()) << "Request pending";
-
- VLOG(2) << "AppRemotingReportIssueRequest::Start() called";
-
- std::string service_url(
- GetReportIssueUrl(application_id, host_id, service_environment));
- if (service_url.empty()) {
- LOG(ERROR) << "Unrecognized service type: " << service_environment;
- return false;
- }
- VLOG(1) << "Sending Report Issue service request to: " << service_url;
-
- request_complete_callback_ = done_callback;
-
- request_context_getter_ = new remoting::URLRequestContextGetter(
- base::ThreadTaskRunnerHandle::Get());
-
- std::string upload_data = abandon_host ? "{ 'abandonHost': 'true' }" : "{}";
-
- request_ = net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST,
- this, TRAFFIC_ANNOTATION_FOR_TESTS);
- request_->SetRequestContext(request_context_getter_.get());
- request_->AddExtraRequestHeader("Authorization: OAuth " + access_token);
- request_->AddExtraRequestHeader(kRequestTestOrigin);
- request_->SetUploadData("application/json; charset=UTF-8", upload_data);
- request_->Start();
-
- return true;
-}
-
-void AppRemotingReportIssueRequest::OnURLFetchComplete(
- const net::URLFetcher* source) {
- VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL();
-
- int response_code = request_->GetResponseCode();
- if (response_code != net::HTTP_OK && response_code != net::HTTP_NO_CONTENT) {
- LOG(ERROR) << "ReportIssue request failed with error code: "
- << response_code;
- }
-
- base::ResetAndReturn(&request_complete_callback_).Run();
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_report_issue_request.h b/remoting/test/app_remoting_report_issue_request.h
deleted file mode 100644
index 8c41eb4..0000000
--- a/remoting/test/app_remoting_report_issue_request.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
-#define REMOTING_TEST_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
-
-#include <memory>
-#include <string>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "net/url_request/url_fetcher_delegate.h"
-#include "remoting/test/app_remoting_service_urls.h"
-
-namespace remoting {
-class URLRequestContextGetter;
-}
-
-namespace remoting {
-namespace test {
-
-// Calls the App Remoting service API to report an issue. This is typically
-// used to abandon a remote host or to upload crash logs.
-// Must be used from a thread running an IO message loop.
-// The public method is virtual to allow for testing using a fake.
-class AppRemotingReportIssueRequest : public net::URLFetcherDelegate {
- public:
- AppRemotingReportIssueRequest();
- ~AppRemotingReportIssueRequest() override;
-
- // Makes a service call to the ReportIssue API.
- virtual bool Start(const std::string& application_id,
- const std::string& host_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- bool abandon_host,
- base::Closure done_callback);
-
- private:
- // net::URLFetcherDelegate interface.
- void OnURLFetchComplete(const net::URLFetcher* source) override;
-
- // Holds the URLFetcher for the ReportIssue request.
- std::unique_ptr<net::URLFetcher> request_;
-
- // Provides application-specific context for the network request.
- scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_;
-
- // Caller-supplied callback which is signalled when the request is complete.
- base::Closure request_complete_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingReportIssueRequest);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
diff --git a/remoting/test/app_remoting_report_issue_request_unittest.cc b/remoting/test/app_remoting_report_issue_request_unittest.cc
deleted file mode 100644
index 194cf4e4e..0000000
--- a/remoting/test/app_remoting_report_issue_request_unittest.cc
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_report_issue_request.h"
-
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/timer/timer.h"
-#include "net/url_request/test_url_fetcher_factory.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-const char kTestApplicationId[] = "klasdfjlkasdfjklasjfdkljsadf";
-const char kTestHostId[] = "test_host_id_value";
-const char kAccessTokenValue[] = "test_access_token_value";
-const char kReportIssueResponse[] = "{}";
-} // namespace
-
-namespace remoting {
-namespace test {
-
-// Provides base functionality for the AppRemotingReportIssueRequest Tests. The
-// FakeURLFetcherFactory allows us to override the response data and payload for
-// specified URLs. We use this to stub out network calls made by the
-// AppRemotingReportIssueRequest. This fixture also creates an IO MessageLoop,
-// if necessary, for use by the AppRemotingReportIssueRequest class.
-class AppRemotingReportIssueRequestTest : public ::testing::Test {
- public:
- AppRemotingReportIssueRequestTest();
- ~AppRemotingReportIssueRequestTest() override;
-
- protected:
- // testing::Test interface.
- void SetUp() override;
-
- // Sets the HTTP status and data returned for a specified URL.
- void SetFakeResponse(const GURL& url,
- const std::string& data,
- net::HttpStatusCode code,
- net::URLRequestStatus::Status status);
-
- // Used for result verification.
- std::string dev_service_environment_url_;
-
- std::unique_ptr<base::RunLoop> run_loop_;
- base::OneShotTimer timer_;
-
- AppRemotingReportIssueRequest app_remoting_report_issue_request_;
-
- private:
- net::FakeURLFetcherFactory url_fetcher_factory_;
- std::unique_ptr<base::MessageLoopForIO> message_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingReportIssueRequestTest);
-};
-
-AppRemotingReportIssueRequestTest::AppRemotingReportIssueRequestTest()
- : url_fetcher_factory_(nullptr), message_loop_(new base::MessageLoopForIO) {
-}
-
-AppRemotingReportIssueRequestTest::~AppRemotingReportIssueRequestTest() =
- default;
-
-void AppRemotingReportIssueRequestTest::SetUp() {
- run_loop_.reset(new base::RunLoop());
-
- dev_service_environment_url_ =
- GetReportIssueUrl(kTestApplicationId, kTestHostId, kDeveloperEnvironment);
- SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
- net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
-}
-
-void AppRemotingReportIssueRequestTest::SetFakeResponse(
- const GURL& url,
- const std::string& data,
- net::HttpStatusCode code,
- net::URLRequestStatus::Status status) {
- url_fetcher_factory_.SetFakeResponse(url, data, code, status);
-}
-
-TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromDev) {
- SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
- net::HTTP_OK, net::URLRequestStatus::SUCCESS);
-
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
- run_loop_->QuitClosure());
-
- bool request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
- true, run_loop_->QuitClosure());
- EXPECT_TRUE(request_started);
-
- run_loop_->Run();
-
- // Verify we stopped because of the request completing and not the timer.
- EXPECT_TRUE(timer_.IsRunning());
- timer_.Stop();
-}
-
-TEST_F(AppRemotingReportIssueRequestTest, ReportIssueFromInvalidEnvironment) {
- bool request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kUnknownEnvironment,
- true, run_loop_->QuitClosure());
-
- EXPECT_FALSE(request_started);
-}
-
-TEST_F(AppRemotingReportIssueRequestTest, ReportIssueNetworkError) {
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
- run_loop_->QuitClosure());
-
- bool request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
- true, run_loop_->QuitClosure());
- EXPECT_TRUE(request_started);
-
- run_loop_->Run();
-
- // Verify we stopped because of the request completing and not the timer.
- EXPECT_TRUE(timer_.IsRunning());
- timer_.Stop();
-}
-
-TEST_F(AppRemotingReportIssueRequestTest, MultipleRequestsCanBeIssued) {
- SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
- net::HTTP_OK, net::URLRequestStatus::SUCCESS);
-
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
- run_loop_->QuitClosure());
-
- bool request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
- true, run_loop_->QuitClosure());
- EXPECT_TRUE(request_started);
-
- run_loop_->Run();
-
- // Verify we stopped because of the request completing and not the timer.
- EXPECT_TRUE(timer_.IsRunning());
- timer_.Stop();
-
- run_loop_.reset(new base::RunLoop());
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
- run_loop_->QuitClosure());
-
- request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
- true, run_loop_->QuitClosure());
- EXPECT_TRUE(request_started);
-
- run_loop_->Run();
-
- // Verify we stopped because of the request completing and not the timer.
- EXPECT_TRUE(timer_.IsRunning());
- timer_.Stop();
-
- run_loop_.reset(new base::RunLoop());
- timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
- run_loop_->QuitClosure());
-
- request_started = app_remoting_report_issue_request_.Start(
- kTestApplicationId, kTestHostId, kAccessTokenValue, kDeveloperEnvironment,
- true, run_loop_->QuitClosure());
- EXPECT_TRUE(request_started);
-
- run_loop_->Run();
-
- // Verify we stopped because of the request completing and not the timer.
- EXPECT_TRUE(timer_.IsRunning());
- timer_.Stop();
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_sample_test_driver_environment.cc b/remoting/test/app_remoting_sample_test_driver_environment.cc
deleted file mode 100644
index d362eca..0000000
--- a/remoting/test/app_remoting_sample_test_driver_environment.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2015 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 "base/memory/ptr_util.h"
-#include "remoting/test/app_remoting_test_driver_environment.h"
-
-namespace remoting {
-namespace test {
-
-std::unique_ptr<AppRemotingTestDriverEnvironment>
-CreateAppRemotingTestDriverEnvironment(
- const AppRemotingTestDriverEnvironment::EnvironmentOptions& options) {
- return base::WrapUnique<AppRemotingTestDriverEnvironment>(
- new AppRemotingTestDriverEnvironment(options));
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_service_urls.cc b/remoting/test/app_remoting_service_urls.cc
deleted file mode 100644
index a787cfa..0000000
--- a/remoting/test/app_remoting_service_urls.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_service_urls.h"
-
-#include "base/logging.h"
-#include "base/strings/stringprintf.h"
-
-namespace {
-// The placeholder is the environment endpoint qualifier. No trailing slash
-// is added as it will be appended as needed later.
-const char kAppRemotingTestEndpointBase[] =
- "https://www-googleapis-test.sandbox.google.com/appremoting/%s";
-const char kAppRemotingDevEndpointQualifier[] = "v1beta1_dev";
-
-// Placeholder value is for the Application ID.
-const char kRunApplicationApi[] = "applications/%s/run";
-
-// First placeholder value is for the Application ID. Second placeholder is for
-// the Host ID to report the issue for.
-const char kReportIssueApi[] = "applications/%s/hosts/%s/reportIssue";
-} // namespace
-
-namespace remoting {
-namespace test {
-
-bool IsSupportedServiceEnvironment(ServiceEnvironment service_environment) {
- return (service_environment >= 0 &&
- service_environment < kUnknownEnvironment);
-}
-
-std::string GetBaseUrl(ServiceEnvironment service_environment) {
- std::string base_service_url;
-
- if (service_environment == kDeveloperEnvironment) {
- base_service_url = base::StringPrintf(kAppRemotingTestEndpointBase,
- kAppRemotingDevEndpointQualifier);
- }
-
- return base_service_url;
-}
-
-std::string GetRunApplicationUrl(const std::string& extension_id,
- ServiceEnvironment service_environment) {
- std::string service_url;
- if (!IsSupportedServiceEnvironment(service_environment)) {
- return service_url;
- }
-
- service_url = GetBaseUrl(service_environment);
- if (!service_url.empty()) {
- std::string api_string =
- base::StringPrintf(kRunApplicationApi, extension_id.c_str());
- service_url =
- base::StringPrintf("%s/%s", service_url.c_str(), api_string.c_str());
- }
-
- return service_url;
-}
-
-std::string GetReportIssueUrl(const std::string& extension_id,
- const std::string& host_id,
- ServiceEnvironment service_environment) {
- std::string service_url;
- if (!IsSupportedServiceEnvironment(service_environment)) {
- return service_url;
- }
-
- service_url = GetBaseUrl(service_environment);
- if (!service_url.empty()) {
- std::string api_string = base::StringPrintf(
- kReportIssueApi, extension_id.c_str(), host_id.c_str());
- service_url =
- base::StringPrintf("%s/%s", service_url.c_str(), api_string.c_str());
- }
-
- return service_url;
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_service_urls.h b/remoting/test/app_remoting_service_urls.h
deleted file mode 100644
index 7d1226b..0000000
--- a/remoting/test/app_remoting_service_urls.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_SERVICE_URLS_H_
-#define REMOTING_TEST_APP_REMOTING_SERVICE_URLS_H_
-
-#include <string>
-
-namespace remoting {
-namespace test {
-
-// Specifies the service API to call for app remoting host information.
-// Note: When adding new environments, add them before kUnknownEnvironment as
-// the last entry is used for bounds checking.
-enum ServiceEnvironment {
- kDeveloperEnvironment,
- kUnknownEnvironment
-};
-
-// Used to determine if the service_environment is one of the supported values.
-bool IsSupportedServiceEnvironment(ServiceEnvironment service_environment);
-
-// Generates and returns a URL for the specified application and environment to
-// request remote host details.
-std::string GetRunApplicationUrl(const std::string& extension_id,
- ServiceEnvironment service_environment);
-
-// Generates and returns a URL for the specified application and environment to
-// report an issue.
-std::string GetReportIssueUrl(const std::string& extension_id,
- const std::string& host_id,
- ServiceEnvironment service_environment);
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_SERVICE_URLS_H_
diff --git a/remoting/test/app_remoting_test_driver.cc b/remoting/test/app_remoting_test_driver.cc
deleted file mode 100644
index 310ee4a..0000000
--- a/remoting/test/app_remoting_test_driver.cc
+++ /dev/null
@@ -1,269 +0,0 @@
-// Copyright 2015 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 "base/at_exit.h"
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/stringprintf.h"
-#include "base/test/launcher/unit_test_launcher.h"
-#include "base/test/test_suite.h"
-#include "base/test/test_switches.h"
-#include "google_apis/google_api_keys.h"
-#include "net/base/escape.h"
-#include "remoting/test/app_remoting_test_driver_environment.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace switches {
-const char kAuthCodeSwitchName[] = "authcode";
-const char kHelpSwitchName[] = "help";
-const char kLoggingLevelSwitchName[] = "verbosity";
-const char kRefreshTokenFileSwitchName[] = "refresh-token-file";
-const char kReleaseHostsAfterTestingSwitchName[] = "release-hosts-after-tests";
-const char kShowHostAvailabilitySwitchName[] = "show-host-availability";
-const char kSingleProcessTestsSwitchName[] = "single-process-tests";
-const char kUserNameSwitchName[] = "username";
-} // namespace switches
-
-namespace {
-
-// Requested permissions needed for App Remoting tests. The spaces in between
-// scope fragments are necessary and will be escaped properly before use.
-const char kAppRemotingAuthScopeValues[] =
- "https://www.googleapis.com/auth/appremoting.runapplication"
- " https://www.googleapis.com/auth/googletalk"
- " https://www.googleapis.com/auth/userinfo.email"
- " https://docs.google.com/feeds"
- " https://www.googleapis.com/auth/drive";
-
-std::string GetAuthorizationCodeUri() {
- // Replace space characters with a '+' sign when formatting.
- bool use_plus = true;
- return base::StringPrintf(
- "https://accounts.google.com/o/oauth2/auth"
- "?scope=%s"
- "&redirect_uri=https://chromoting-oauth.talkgadget.google.com/"
- "talkgadget/oauth/chrome-remote-desktop/dev"
- "&response_type=code"
- "&client_id=%s"
- "&access_type=offline"
- "&approval_prompt=force",
- net::EscapeUrlEncodedData(kAppRemotingAuthScopeValues, use_plus).c_str(),
- net::EscapeUrlEncodedData(
- google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING),
- use_plus).c_str());
-}
-
-void PrintUsage() {
- printf("\n**************************************\n");
- printf("*** App Remoting Test Driver Usage ***\n");
- printf("**************************************\n");
-
- printf("\nUsage:\n");
- printf(" ar_test_driver --username=<example@gmail.com> [options]\n");
- printf("\nRequired Parameters:\n");
- printf(" %s: Specifies which account to use when running tests\n",
- switches::kUserNameSwitchName);
- printf("\nOptional Parameters:\n");
- printf(" %s: Exchanged for a refresh and access token for authentication\n",
- switches::kAuthCodeSwitchName);
- printf(" %s: Path to a JSON file containing username/refresh_token KVPs\n",
- switches::kRefreshTokenFileSwitchName);
- printf(" %s: Displays additional usage information\n",
- switches::kHelpSwitchName);
- printf(
- " %s: Retrieves and displays the connection status for all known "
- "hosts, no tests will be run\n",
- switches::kShowHostAvailabilitySwitchName);
- printf(
- " %s: Send a message to the service after all tests have been run to "
- "release remote hosts the tool used for testing.\n",
- switches::kReleaseHostsAfterTestingSwitchName);
- printf(
- " %s: Specifies the optional logging level of the tool (0-3)."
- " [default: off]\n",
- switches::kLoggingLevelSwitchName);
-}
-
-void PrintAuthCodeInfo() {
- printf("\n*******************************\n");
- printf("*** Auth Code Example Usage ***\n");
- printf("*******************************\n\n");
-
- printf("If this is the first time you are running the tool,\n");
- printf("you will need to provide an authorization code.\n");
- printf("This code will be exchanged for a long term refresh token which\n");
- printf("will be stored locally and used to acquire a short lived access\n");
- printf("token to connect to the remoting service apis and establish a\n");
- printf("remote host connection.\n\n");
-
- printf("Note: You may need to repeat this step if the stored refresh token");
- printf("\n has been revoked or expired.\n");
- printf(" Passing in the same auth code twice will result in an error\n");
-
- printf(
- "\nFollow these steps to produce an auth code:\n"
- " - Open the Authorization URL link shown below in your browser\n"
- " - Approve the requested permissions for the tool\n"
- " - Copy the 'code' value in the redirected URL\n"
- " - Run the tool and pass in copied auth code as a parameter\n");
-
- printf("\nAuthorization URL:\n");
- printf("%s\n", GetAuthorizationCodeUri().c_str());
-
- printf("\nRedirected URL Example:\n");
- printf(
- "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/"
- "chrome-remote-desktop/dev?code=4/AKtf...\n");
-
- printf("\nTool usage example with the newly created auth code:\n");
- printf("ar_test_driver --%s=example@gmail.com --%s=4/AKtf...\n\n",
- switches::kUserNameSwitchName, switches::kAuthCodeSwitchName);
-}
-
-void PrintJsonFileInfo() {
- printf("\n*****************************************\n");
- printf("*** Refresh Token File Example Usage ***\n");
- printf("****************************************\n\n");
-
- printf("In order to use this option, a valid JSON file must exist, be\n");
- printf("properly formatted, and contain a username/token KVP.\n");
- printf("Contents of example_file.json\n");
- printf("{\n");
- printf(" \"username1@fauxdomain.com\": \"1/3798Gsdf898shksdvfyi8sshad\",\n");
- printf(" \"username2@fauxdomain.com\": \"1/8974sdf87asdgadfgaerhfRsAa\",\n");
- printf("}\n\n");
-
- printf("\nTool usage example:\n");
- printf("ar_test_driver --%s=%s --%s=./example_file.json\n\n",
- switches::kUserNameSwitchName, "username1@fauxdomain.com",
- switches::kRefreshTokenFileSwitchName);
-}
-
-} // namespace
-
-int main(int argc, char** argv) {
- base::TestSuite test_suite(argc, argv);
- base::MessageLoopForIO message_loop;
-
- if (!base::CommandLine::InitializedForCurrentProcess()) {
- if (!base::CommandLine::Init(argc, argv)) {
- LOG(ERROR) << "Failed to initialize command line singleton.";
- return -1;
- }
- }
-
- // The pointer returned here refers to a singleton, since we don't own the
- // lifetime of the object, don't wrap in a scoped_ptr construct or release it.
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- DCHECK(command_line);
-
- // We do not want to retry failures as a failed test should signify an error
- // to be investigated.
- command_line->AppendSwitchASCII(switches::kTestLauncherRetryLimit, "0");
- command_line->AppendSwitchASCII(
- switches::kIsolatedScriptTestLauncherRetryLimit, "0");
-
- // We do not want to run the tests in parallel and we do not want to retry
- // failures. The reason for running in a single process is that some tests
- // may share the same remoting host and they cannot be run concurrently, also
- // the test output gets spammed with test launcher messages which reduces the
- // readability of the results.
- command_line->AppendSwitch(switches::kSingleProcessTestsSwitchName);
-
- // If the user passed in the help flag, then show the help info for this tool
- // and 'run' the tests which will print the gtest specific help and then exit.
- // NOTE: We do this check after updating the switches as otherwise the gtest
- // help is written in parallel with our text and can appear interleaved.
- if (command_line->HasSwitch(switches::kHelpSwitchName)) {
- PrintUsage();
- PrintJsonFileInfo();
- PrintAuthCodeInfo();
-#if defined(OS_IOS)
- return base::LaunchUnitTests(
- argc, argv,
- base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
-#else
- return base::LaunchUnitTestsSerially(
- argc, argv,
- base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
-#endif
- }
-
- remoting::test::AppRemotingTestDriverEnvironment::EnvironmentOptions options;
-
- // Verify we received the required input from the command line.
- options.user_name =
- command_line->GetSwitchValueASCII(switches::kUserNameSwitchName);
- if (options.user_name.empty()) {
- LOG(ERROR) << "No user name passed in, can't authenticate without that!";
- PrintUsage();
- return -1;
- }
- VLOG(1) << "Running tests as: " << options.user_name;
-
- // Check to see if the user passed in a one time use auth_code for
- // refreshing their credentials.
- std::string auth_code(
- command_line->GetSwitchValueASCII(switches::kAuthCodeSwitchName));
-
- options.refresh_token_file_path =
- command_line->GetSwitchValuePath(switches::kRefreshTokenFileSwitchName);
-
- options.release_hosts_when_done =
- command_line->HasSwitch(switches::kReleaseHostsAfterTestingSwitchName);
-
- options.service_environment =
- remoting::test::ServiceEnvironment::kDeveloperEnvironment;
-
- // Update the logging verbosity level is user specified one.
- std::string verbosity_level(
- command_line->GetSwitchValueASCII(switches::kLoggingLevelSwitchName));
- if (!verbosity_level.empty()) {
- // Turn on logging for the test_driver and remoting components.
- // This switch is parsed during logging::InitLogging.
- command_line->AppendSwitchASCII("vmodule",
- "*/remoting/*=" + verbosity_level);
- logging::LoggingSettings logging_settings;
- logging::InitLogging(logging_settings);
- }
-
- // Create and register our global test data object. It will handle
- // retrieving an access token for the user and spinning up VMs.
- // The GTest framework will own the lifetime of this object once
- // it is registered below.
- std::unique_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data(
- remoting::test::CreateAppRemotingTestDriverEnvironment(options));
-
- if (!shared_data->Initialize(auth_code)) {
- // If we failed to initialize our shared data object, then bail.
- return -1;
- }
-
- if (command_line->HasSwitch(switches::kShowHostAvailabilitySwitchName)) {
- // When this flag is specified, we will retrieve connection information
- // for all known applications and report the status. Tests can be skipped
- // using a gtest_filter flag.
- shared_data->ShowHostAvailability();
- }
-
- // Since we've successfully set up our shared_data object, we'll assign the
- // value to our global* and transfer ownership to the framework.
- remoting::test::AppRemotingSharedData = shared_data.release();
- testing::AddGlobalTestEnvironment(remoting::test::AppRemotingSharedData);
-
- // Because many tests may access the same remoting host(s), we need to run
- // the tests sequentially so they do not interfere with each other.
-#if defined(OS_IOS)
- return base::LaunchUnitTests(
- argc, argv,
- base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
-#else
- return base::LaunchUnitTestsSerially(
- argc, argv,
- base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
-#endif
-}
diff --git a/remoting/test/app_remoting_test_driver_environment.cc b/remoting/test/app_remoting_test_driver_environment.cc
deleted file mode 100644
index c88cfa4..0000000
--- a/remoting/test/app_remoting_test_driver_environment.cc
+++ /dev/null
@@ -1,362 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_test_driver_environment.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/callback_forward.h"
-#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_loop_current.h"
-#include "base/run_loop.h"
-#include "base/strings/stringprintf.h"
-#include "remoting/test/access_token_fetcher.h"
-#include "remoting/test/app_remoting_report_issue_request.h"
-#include "remoting/test/refresh_token_store.h"
-#include "remoting/test/remote_host_info.h"
-
-namespace remoting {
-namespace test {
-
-AppRemotingTestDriverEnvironment* AppRemotingSharedData;
-
-AppRemotingTestDriverEnvironment::EnvironmentOptions::EnvironmentOptions()
- : refresh_token_file_path(base::FilePath()),
- service_environment(kUnknownEnvironment),
- release_hosts_when_done(false) {}
-
-AppRemotingTestDriverEnvironment::EnvironmentOptions::~EnvironmentOptions() =
- default;
-
-AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment(
- const EnvironmentOptions& options)
- : user_name_(options.user_name),
- service_environment_(options.service_environment),
- release_hosts_when_done_(options.release_hosts_when_done),
- refresh_token_file_path_(options.refresh_token_file_path),
- test_access_token_fetcher_(nullptr),
- test_app_remoting_report_issue_request_(nullptr),
- test_refresh_token_store_(nullptr),
- test_remote_host_info_fetcher_(nullptr) {
- DCHECK(!user_name_.empty());
- DCHECK(service_environment_ < kUnknownEnvironment);
-}
-
-AppRemotingTestDriverEnvironment::~AppRemotingTestDriverEnvironment() = default;
-
-bool AppRemotingTestDriverEnvironment::Initialize(
- const std::string& auth_code) {
- if (!access_token_.empty()) {
- return true;
- }
-
- if (!base::MessageLoopCurrent::Get()) {
- message_loop_.reset(new base::MessageLoopForIO);
- }
-
- // If a unit test has set |test_refresh_token_store_| then we should use it
- // below. Note that we do not want to destroy the test object.
- std::unique_ptr<RefreshTokenStore> temporary_refresh_token_store;
- RefreshTokenStore* refresh_token_store = test_refresh_token_store_;
- if (!refresh_token_store) {
- temporary_refresh_token_store =
- RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_);
- refresh_token_store = temporary_refresh_token_store.get();
- }
-
- // Check to see if we have a refresh token stored for this user.
- refresh_token_ = refresh_token_store->FetchRefreshToken();
- if (refresh_token_.empty()) {
- // This isn't necessarily an error as this might be a first run scenario.
- VLOG(2) << "No refresh token stored for " << user_name_;
-
- if (auth_code.empty()) {
- // No token and no Auth code means no service connectivity, bail!
- LOG(ERROR) << "Cannot retrieve an access token without a stored refresh"
- << " token on disk or an auth_code passed into the tool";
- return false;
- }
- }
-
- if (!RetrieveAccessToken(auth_code)) {
- // If we cannot retrieve an access token, then nothing is going to work and
- // we should let the caller know that our object is not ready to be used.
- return false;
- }
-
- return true;
-}
-
-bool AppRemotingTestDriverEnvironment::RefreshAccessToken() {
- DCHECK(!refresh_token_.empty());
-
- // Empty auth code is used when refreshing.
- return RetrieveAccessToken(std::string());
-}
-
-bool AppRemotingTestDriverEnvironment::GetRemoteHostInfoForApplicationId(
- const std::string& application_id,
- RemoteHostInfo* remote_host_info) {
- DCHECK(!application_id.empty());
- DCHECK(remote_host_info);
-
- if (access_token_.empty()) {
- LOG(ERROR) << "RemoteHostInfo requested without a valid access token. "
- << "Ensure the environment object has been initialized.";
- return false;
- }
-
- base::RunLoop run_loop;
-
- RemoteHostInfoCallback remote_host_info_fetch_callback = base::Bind(
- &AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure(), remote_host_info);
-
- // If a unit test has set |test_remote_host_info_fetcher_| then we should use
- // it below. Note that we do not want to destroy the test object at the end
- // of the function which is why we have the dance below.
- std::unique_ptr<RemoteHostInfoFetcher> temporary_remote_host_info_fetcher;
- RemoteHostInfoFetcher* remote_host_info_fetcher =
- test_remote_host_info_fetcher_;
- if (!remote_host_info_fetcher) {
- temporary_remote_host_info_fetcher.reset(new RemoteHostInfoFetcher());
- remote_host_info_fetcher = temporary_remote_host_info_fetcher.get();
- }
-
- remote_host_info_fetcher->RetrieveRemoteHostInfo(
- application_id, access_token_, service_environment_,
- remote_host_info_fetch_callback);
-
- run_loop.Run();
-
- return remote_host_info->IsReadyForConnection();
-}
-
-void AppRemotingTestDriverEnvironment::AddHostToReleaseList(
- const std::string& application_id,
- const std::string& host_id) {
- if (!release_hosts_when_done_) {
- return;
- }
-
- auto map_iterator = host_ids_to_release_.find(application_id);
- if (map_iterator == host_ids_to_release_.end()) {
- std::vector<std::string> host_id_list(1, host_id);
- host_ids_to_release_.insert(std::make_pair(application_id, host_id_list));
- } else {
- std::vector<std::string>* host_ids = &map_iterator->second;
- if (std::find(host_ids->begin(), host_ids->end(), host_id) ==
- host_ids->end()) {
- host_ids->push_back(host_id);
- }
- }
-}
-
-void AppRemotingTestDriverEnvironment::ShowHostAvailability() {
- const char kHostAvailabilityFormatString[] = "%-25s%-35s%-10s";
-
- LOG(INFO) << base::StringPrintf(kHostAvailabilityFormatString,
- "Application Name", "Application ID",
- "Status");
-
- for (const auto& application_name : application_names_) {
- const RemoteApplicationDetails& application_details =
- GetDetailsFromAppName(application_name);
-
- RemoteHostInfo remote_host_info;
- GetRemoteHostInfoForApplicationId(application_details.application_id,
- &remote_host_info);
-
- std::string status;
- RemoteHostStatus remote_host_status = remote_host_info.remote_host_status;
- if (remote_host_status == kRemoteHostStatusReady) {
- status = "Ready :)";
- } else if (remote_host_status == kRemoteHostStatusPending) {
- status = "Pending :|";
- } else {
- status = "Unknown :(";
- }
-
- LOG(INFO) << base::StringPrintf(
- kHostAvailabilityFormatString, application_name.c_str(),
- application_details.application_id.c_str(), status.c_str());
- }
-}
-
-const RemoteApplicationDetails&
-AppRemotingTestDriverEnvironment::GetDetailsFromAppName(
- const std::string& application_name) {
- const auto map_pair_iterator =
- application_details_map_.find(application_name);
- DCHECK(map_pair_iterator != application_details_map_.end());
-
- return map_pair_iterator->second;
-}
-
-void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest(
- AccessTokenFetcher* access_token_fetcher) {
- DCHECK(access_token_fetcher);
-
- test_access_token_fetcher_ = access_token_fetcher;
-}
-
-void AppRemotingTestDriverEnvironment::SetAppRemotingReportIssueRequestForTest(
- AppRemotingReportIssueRequest* app_remoting_report_issue_request) {
- DCHECK(app_remoting_report_issue_request);
-
- test_app_remoting_report_issue_request_ = app_remoting_report_issue_request;
-}
-
-void AppRemotingTestDriverEnvironment::SetRefreshTokenStoreForTest(
- RefreshTokenStore* refresh_token_store) {
- DCHECK(refresh_token_store);
-
- test_refresh_token_store_ = refresh_token_store;
-}
-
-void AppRemotingTestDriverEnvironment::SetRemoteHostInfoFetcherForTest(
- RemoteHostInfoFetcher* remote_host_info_fetcher) {
- DCHECK(remote_host_info_fetcher);
-
- test_remote_host_info_fetcher_ = remote_host_info_fetcher;
-}
-
-void AppRemotingTestDriverEnvironment::TearDown() {
- // If a unit test has set |test_app_remoting_report_issue_request_| then we
- // should use it below. Note that we do not want to destroy the test object
- // at the end of the function which is why we have the dance below.
- std::unique_ptr<AppRemotingReportIssueRequest> temporary_report_issue_request;
- AppRemotingReportIssueRequest* report_issue_request =
- test_app_remoting_report_issue_request_;
- if (!report_issue_request) {
- temporary_report_issue_request.reset(new AppRemotingReportIssueRequest());
- report_issue_request = temporary_report_issue_request.get();
- }
-
- for (const auto& kvp : host_ids_to_release_) {
- std::string application_id = kvp.first;
- VLOG(1) << "Releasing hosts for application: " << application_id;
-
- for (const auto& host_id : kvp.second) {
- base::RunLoop run_loop;
-
- VLOG(1) << " Releasing host: " << host_id;
- bool request_started = report_issue_request->Start(
- application_id, host_id, access_token_, service_environment_, true,
- run_loop.QuitClosure());
-
- if (request_started) {
- run_loop.Run();
- } else {
- LOG(ERROR) << "Failed to send ReportIssueRequest for: "
- << application_id << ", " << host_id;
- }
- }
- }
- temporary_report_issue_request.reset();
-
- // Letting the MessageLoop tear down during the test destructor results in
- // errors after test completion, when the MessageLoop dtor touches the
- // registered AtExitManager. The AtExitManager is torn down before the test
- // destructor is executed, so we tear down the MessageLoop here, while it is
- // still valid.
- message_loop_.reset();
-}
-
-bool AppRemotingTestDriverEnvironment::RetrieveAccessToken(
- const std::string& auth_code) {
- base::RunLoop run_loop;
-
- access_token_.clear();
-
- AccessTokenCallback access_token_callback =
- base::Bind(&AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- // If a unit test has set |test_access_token_fetcher_| then we should use it
- // below. Note that we do not want to destroy the test object at the end of
- // the function which is why we have the dance below.
- std::unique_ptr<AccessTokenFetcher> temporary_access_token_fetcher;
- AccessTokenFetcher* access_token_fetcher = test_access_token_fetcher_;
- if (!access_token_fetcher) {
- temporary_access_token_fetcher.reset(new AccessTokenFetcher());
- access_token_fetcher = temporary_access_token_fetcher.get();
- }
-
- if (!auth_code.empty()) {
- // If the user passed in an authcode, then use it to retrieve an
- // updated access/refresh token.
- access_token_fetcher->GetAccessTokenFromAuthCode(auth_code,
- access_token_callback);
- } else {
- DCHECK(!refresh_token_.empty());
-
- access_token_fetcher->GetAccessTokenFromRefreshToken(refresh_token_,
- access_token_callback);
- }
-
- run_loop.Run();
-
- // If we were using an auth_code and received a valid refresh token,
- // then we want to store it locally. If we had an auth code and did not
- // receive a refresh token, then we should let the user know and exit.
- if (!auth_code.empty()) {
- if (!refresh_token_.empty()) {
- // If a unit test has set |test_refresh_token_store_| then we should use
- // it below. Note that we do not want to destroy the test object.
- std::unique_ptr<RefreshTokenStore> temporary_refresh_token_store;
- RefreshTokenStore* refresh_token_store = test_refresh_token_store_;
- if (!refresh_token_store) {
- temporary_refresh_token_store =
- RefreshTokenStore::OnDisk(user_name_, refresh_token_file_path_);
- refresh_token_store = temporary_refresh_token_store.get();
- }
-
- if (!refresh_token_store->StoreRefreshToken(refresh_token_)) {
- // If we failed to persist the refresh token, then we should let the
- // user sort out the issue before continuing.
- return false;
- }
- } else {
- LOG(ERROR) << "Failed to use AUTH CODE to retrieve a refresh token.\n"
- << "Was the one-time use AUTH CODE used more than once?";
- return false;
- }
- }
-
- if (access_token_.empty()) {
- LOG(ERROR) << "Failed to retrieve access token.";
- return false;
- }
-
- return true;
-}
-
-void AppRemotingTestDriverEnvironment::OnAccessTokenRetrieved(
- base::Closure done_closure,
- const std::string& access_token,
- const std::string& refresh_token) {
- access_token_ = access_token;
- refresh_token_ = refresh_token;
-
- done_closure.Run();
-}
-
-void AppRemotingTestDriverEnvironment::OnRemoteHostInfoRetrieved(
- base::Closure done_closure,
- RemoteHostInfo* remote_host_info,
- const RemoteHostInfo& retrieved_remote_host_info) {
- DCHECK(remote_host_info);
-
- *remote_host_info = retrieved_remote_host_info;
-
- done_closure.Run();
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/app_remoting_test_driver_environment.h b/remoting/test/app_remoting_test_driver_environment.h
deleted file mode 100644
index 6bbb43f..0000000
--- a/remoting/test/app_remoting_test_driver_environment.h
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
-#define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "remoting/test/remote_application_details.h"
-#include "remoting/test/remote_host_info_fetcher.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-class MessageLoopForIO;
-}
-
-namespace remoting {
-namespace test {
-
-class AccessTokenFetcher;
-class AppRemotingReportIssueRequest;
-class RefreshTokenStore;
-struct RemoteHostInfo;
-
-// Globally accessible to all test fixtures and cases and has its
-// lifetime managed by the GTest framework. It is responsible for managing
-// access tokens and retrieving remote host connection information.
-class AppRemotingTestDriverEnvironment : public testing::Environment {
- public:
- struct EnvironmentOptions {
- EnvironmentOptions();
- ~EnvironmentOptions();
-
- std::string user_name;
- base::FilePath refresh_token_file_path;
- ServiceEnvironment service_environment;
- bool release_hosts_when_done;
- };
-
- explicit AppRemotingTestDriverEnvironment(const EnvironmentOptions& options);
- ~AppRemotingTestDriverEnvironment() override;
-
- // Returns false if a valid access token cannot be retrieved.
- bool Initialize(const std::string& auth_code);
-
- // Synchronously request a new access token using |refresh_token_|.
- // Returns true if a valid access token has been retrieved.
- bool RefreshAccessToken();
-
- // Synchronously request remote host information for |application_id|.
- // Returns true if the request was successful and |remote_host_info| is valid.
- bool GetRemoteHostInfoForApplicationId(const std::string& application_id,
- RemoteHostInfo* remote_host_info);
-
- // Adds the host_id to the list of hosts that will be released after the tests
- // have all been run.
- void AddHostToReleaseList(const std::string& application_id,
- const std::string& host_id);
-
- // Retrieves connection information for all known applications and displays
- // their availability to STDOUT.
- void ShowHostAvailability();
-
- // Provides the RemoteApplicationDetails for the specified |application_name|.
- const RemoteApplicationDetails& GetDetailsFromAppName(
- const std::string& application_name);
-
- // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests.
- // The caller retains ownership of the supplied objects, and must ensure that
- // they remain valid until the AppRemotingTestDriverEnvironment instance has
- // been destroyed.
- void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
- void SetAppRemotingReportIssueRequestForTest(
- AppRemotingReportIssueRequest* app_remoting_report_issue_request);
- void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
- void SetRemoteHostInfoFetcherForTest(
- RemoteHostInfoFetcher* remote_host_info_fetcher);
-
- // Accessors for fields used by tests.
- const std::string& access_token() const { return access_token_; }
- const std::string& user_name() const { return user_name_; }
-
- protected:
- // Contains the names of all supported remote applications.
- // Once initialized, this vector is not modified.
- std::vector<std::string> application_names_;
-
- // Contains RemoteApplicationDetails for all supported remote applications.
- // Once initialized, this map is not modified.
- std::map<std::string, RemoteApplicationDetails> application_details_map_;
-
- private:
- // testing::Environment interface.
- void TearDown() override;
-
- // Used to retrieve an access token. If |auth_code| is empty, then the stored
- // refresh_token will be used instead of |auth_code|.
- // Returns true if a new, valid access token has been retrieved.
- bool RetrieveAccessToken(const std::string& auth_code);
-
- // Called after the access token fetcher completes.
- // The tokens will be empty on failure.
- void OnAccessTokenRetrieved(base::Closure done_closure,
- const std::string& access_token,
- const std::string& refresh_token);
-
- // Called after the remote host info fetcher completes.
- // |remote_host_info| is modified on failure.
- void OnRemoteHostInfoRetrieved(
- base::Closure done_closure,
- RemoteHostInfo* remote_host_info,
- const RemoteHostInfo& retrieved_remote_host_info);
-
- // Used for authenticating with the app remoting service API.
- std::string access_token_;
-
- // Used to retrieve an access token.
- std::string refresh_token_;
-
- // Used for authentication.
- std::string user_name_;
-
- // Service API to target when retrieving remote host connection information.
- ServiceEnvironment service_environment_;
-
- // Specifies whether to tell the service to release the remote hosts we
- // requested after the tests have completed.
- bool release_hosts_when_done_;
-
- // Path to a JSON file containing refresh tokens.
- base::FilePath refresh_token_file_path_;
-
- // Access token fetcher used by TestDriverEnvironment tests.
- remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
-
- // AppRemotingReportIssueRequest used by TestDriverEnvironment tests.
- remoting::test::AppRemotingReportIssueRequest*
- test_app_remoting_report_issue_request_;
-
- // RefreshTokenStore used by TestDriverEnvironment tests.
- remoting::test::RefreshTokenStore* test_refresh_token_store_;
-
- // RemoteHostInfoFetcher used by TestDriverEnvironment tests.
- remoting::test::RemoteHostInfoFetcher* test_remote_host_info_fetcher_;
-
- // Used for running network request tasks.
- std::unique_ptr<base::MessageLoopForIO> message_loop_;
-
- // Contains the host ids to release when the environment is torn down.
- // The key is the application id and the value is a list of hosts.
- std::map<std::string, std::vector<std::string>> host_ids_to_release_;
-
- DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
-};
-
-// Used to provide application specific instances of the
-// AppRemotingTestDriverEnvironment class.
-extern std::unique_ptr<AppRemotingTestDriverEnvironment>
-CreateAppRemotingTestDriverEnvironment(
- const AppRemotingTestDriverEnvironment::EnvironmentOptions& options);
-
-// Unfortunately a global var is how the GTEST framework handles sharing data
-// between tests and keeping long-lived objects around. Used to share auth
-// tokens and remote host connection information across tests.
-extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
diff --git a/remoting/test/app_remoting_test_driver_environment_unittest.cc b/remoting/test/app_remoting_test_driver_environment_unittest.cc
deleted file mode 100644
index fe84160..0000000
--- a/remoting/test/app_remoting_test_driver_environment_unittest.cc
+++ /dev/null
@@ -1,474 +0,0 @@
-// Copyright 2015 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 "remoting/test/app_remoting_test_driver_environment.h"
-
-#include <stddef.h>
-
-#include <algorithm>
-#include <utility>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "remoting/test/fake_access_token_fetcher.h"
-#include "remoting/test/fake_app_remoting_report_issue_request.h"
-#include "remoting/test/fake_refresh_token_store.h"
-#include "remoting/test/fake_remote_host_info_fetcher.h"
-#include "remoting/test/mock_access_token_fetcher.h"
-#include "remoting/test/refresh_token_store.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv";
-const char kUserNameValue[] = "remoting_user@gmail.com";
-const char kTestApplicationId[] = "sadlkjlsjgadjfgoajdfgagb";
-const char kAnotherTestApplicationId[] = "waklgoisdhfnvjkdsfbljn";
-const char kTestHostId1[] = "awesome_test_host_id";
-const char kTestHostId2[] = "super_awesome_test_host_id";
-const char kTestHostId3[] = "uber_awesome_test_host_id";
-}
-
-namespace remoting {
-namespace test {
-
-using testing::_;
-
-class AppRemotingTestDriverEnvironmentTest : public ::testing::Test {
- public:
- AppRemotingTestDriverEnvironmentTest();
- ~AppRemotingTestDriverEnvironmentTest() override;
-
- FakeAccessTokenFetcher* fake_access_token_fetcher() const {
- return fake_access_token_fetcher_;
- }
-
- protected:
- void Initialize();
- void Initialize(
- const AppRemotingTestDriverEnvironment::EnvironmentOptions& options);
-
- FakeAccessTokenFetcher* fake_access_token_fetcher_;
- FakeAppRemotingReportIssueRequest fake_report_issue_request_;
- FakeRefreshTokenStore fake_token_store_;
- FakeRemoteHostInfoFetcher fake_remote_host_info_fetcher_;
- MockAccessTokenFetcher mock_access_token_fetcher_;
-
- std::unique_ptr<AppRemotingTestDriverEnvironment> environment_object_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironmentTest);
-};
-
-AppRemotingTestDriverEnvironmentTest::AppRemotingTestDriverEnvironmentTest()
- : fake_access_token_fetcher_(nullptr) {
-}
-
-AppRemotingTestDriverEnvironmentTest::~AppRemotingTestDriverEnvironmentTest() =
- default;
-
-void AppRemotingTestDriverEnvironmentTest::Initialize() {
- AppRemotingTestDriverEnvironment::EnvironmentOptions options;
- options.user_name = kUserNameValue;
- options.service_environment = kDeveloperEnvironment;
-
- Initialize(options);
-}
-
-void AppRemotingTestDriverEnvironmentTest::Initialize(
- const AppRemotingTestDriverEnvironment::EnvironmentOptions& options) {
- environment_object_.reset(new AppRemotingTestDriverEnvironment(options));
-
- std::unique_ptr<FakeAccessTokenFetcher> fake_access_token_fetcher(
- new FakeAccessTokenFetcher());
- fake_access_token_fetcher_ = fake_access_token_fetcher.get();
- mock_access_token_fetcher_.SetAccessTokenFetcher(
- std::move(fake_access_token_fetcher));
-
- environment_object_->SetAccessTokenFetcherForTest(
- &mock_access_token_fetcher_);
- environment_object_->SetAppRemotingReportIssueRequestForTest(
- &fake_report_issue_request_);
- environment_object_->SetRefreshTokenStoreForTest(&fake_token_store_);
- environment_object_->SetRemoteHostInfoFetcherForTest(
- &fake_remote_host_info_fetcher_);
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, InitializeObjectWithAuthCode) {
- Initialize();
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _))
- .Times(0);
-
- EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
- EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
- EXPECT_EQ(fake_token_store_.stored_refresh_token_value(),
- kFakeAccessTokenFetcherRefreshTokenValue);
- EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
- EXPECT_EQ(environment_object_->access_token(),
- kFakeAccessTokenFetcherAccessTokenValue);
-
- // Attempt to init again, we should not see any additional calls or errors.
- EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- InitializeObjectWithAuthCodeFailed) {
- Initialize();
-
- fake_access_token_fetcher()->set_fail_access_token_from_auth_code(true);
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _))
- .Times(0);
-
- EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
- EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, InitializeObjectWithRefreshToken) {
- Initialize();
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _))
- .Times(0);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- // We should not write the refresh token a second time if we read from the
- // disk originally.
- EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
-
- // Verify the object was initialized correctly.
- EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
- EXPECT_EQ(environment_object_->access_token(),
- kFakeAccessTokenFetcherAccessTokenValue);
-
- // Attempt to init again, we should not see any additional calls or errors.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, TearDownAfterInitializeSucceeds) {
- Initialize();
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _))
- .Times(0);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- // Note: We are using a static cast here because the TearDown() method is
- // private as it is an interface method that we only want to call
- // directly in tests or by the GTEST framework.
- static_cast<testing::Environment*>(environment_object_.get())->TearDown();
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- InitializeObjectWithRefreshTokenFailed) {
- Initialize();
-
- fake_access_token_fetcher()->set_fail_access_token_from_refresh_token(true);
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _))
- .Times(0);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_FALSE(environment_object_->Initialize(std::string()));
- EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- InitializeObjectNoAuthCodeOrRefreshToken) {
- Initialize();
-
- // Neither method should be called in this scenario.
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _))
- .Times(0);
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _))
- .Times(0);
-
- // Clear out the 'stored' refresh token value.
- fake_token_store_.set_refresh_token_value(std::string());
-
- // With no auth code or refresh token, then the initialization should fail.
- EXPECT_FALSE(environment_object_->Initialize(std::string()));
- EXPECT_FALSE(fake_token_store_.refresh_token_write_attempted());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- InitializeObjectWithAuthCodeWriteFailed) {
- Initialize();
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _))
- .Times(0);
-
- // Simulate a failure writing the token to the disk.
- fake_token_store_.set_refresh_token_write_succeeded(false);
-
- EXPECT_FALSE(environment_object_->Initialize(kAuthCodeValue));
- EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- RefreshAccessTokenAfterUsingAuthCode) {
- Initialize();
-
- {
- testing::InSequence call_sequence;
-
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _));
-
- EXPECT_CALL(mock_access_token_fetcher_,
- GetAccessTokenFromRefreshToken(_, _));
- }
-
- EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
- EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
- EXPECT_EQ(fake_token_store_.stored_refresh_token_value(),
- kFakeAccessTokenFetcherRefreshTokenValue);
- EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
- EXPECT_EQ(environment_object_->access_token(),
- kFakeAccessTokenFetcherAccessTokenValue);
-
- // Attempt to init again, we should not see any additional calls or errors.
- EXPECT_TRUE(environment_object_->RefreshAccessToken());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, RefreshAccessTokenFailure) {
- Initialize();
-
- {
- testing::InSequence call_sequence;
-
- // Mock is set up for this call to succeed.
- EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromAuthCode(_, _));
-
- // Mock is set up for this call to fail.
- EXPECT_CALL(mock_access_token_fetcher_,
- GetAccessTokenFromRefreshToken(_, _));
- }
-
- EXPECT_TRUE(environment_object_->Initialize(kAuthCodeValue));
- EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
- EXPECT_EQ(fake_token_store_.stored_refresh_token_value(),
- kFakeAccessTokenFetcherRefreshTokenValue);
- EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
- EXPECT_EQ(environment_object_->access_token(),
- kFakeAccessTokenFetcherAccessTokenValue);
-
- fake_access_token_fetcher()->set_fail_access_token_from_refresh_token(true);
-
- // We expect the refresh to have failed, the user name to remain valid,
- // and the access token to have been cleared.
- EXPECT_FALSE(environment_object_->RefreshAccessToken());
- EXPECT_TRUE(environment_object_->access_token().empty());
- EXPECT_EQ(environment_object_->user_name(), kUserNameValue);
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, GetRemoteHostInfoSuccess) {
- Initialize();
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
- EXPECT_TRUE(remote_host_info.IsReadyForConnection());
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, GetRemoteHostInfoFailure) {
- Initialize();
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- fake_remote_host_info_fetcher_.set_fail_retrieve_remote_host_info(true);
-
- RemoteHostInfo remote_host_info;
- EXPECT_FALSE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest,
- GetRemoteHostInfoWithoutInitializing) {
- Initialize();
-
- RemoteHostInfo remote_host_info;
- EXPECT_FALSE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, NoRemoteHostsReleasedOnTearDown) {
- // Use the default options as the flag to release the remote hosts is not
- // enabled by default.
- Initialize();
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
- EXPECT_TRUE(remote_host_info.IsReadyForConnection());
-
- EXPECT_EQ(fake_report_issue_request_.get_host_ids_released().size(), 0UL);
-
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId1);
-
- // Note: We are using a static cast here because the TearDown() method is
- // private as it is an interface method that we only want to call
- // directly in tests or by the GTEST framework.
- static_cast<testing::Environment*>(environment_object_.get())->TearDown();
-
- // Verify no hosts were released via a report issue request.
- EXPECT_EQ(fake_report_issue_request_.get_host_ids_released().size(), 0UL);
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, OneRemoteHostReleasedOnTearDown) {
- AppRemotingTestDriverEnvironment::EnvironmentOptions options;
- options.user_name = kUserNameValue;
- options.release_hosts_when_done = true;
- options.service_environment = kDeveloperEnvironment;
- Initialize(options);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
- EXPECT_TRUE(remote_host_info.IsReadyForConnection());
-
- EXPECT_EQ(fake_report_issue_request_.get_host_ids_released().size(), 0UL);
-
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId1);
-
- // Note: We are using a static cast here because the TearDown() method is
- // private as it is an interface method that we only want to call
- // directly in tests or by the GTEST framework.
- static_cast<testing::Environment*>(environment_object_.get())->TearDown();
-
- std::string expected_host(
- MakeFormattedStringForReleasedHost(kTestApplicationId, kTestHostId1));
- std::vector<std::string> actual_host_list =
- fake_report_issue_request_.get_host_ids_released();
-
- EXPECT_EQ(actual_host_list.size(), 1UL);
- EXPECT_EQ(actual_host_list[0], expected_host);
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, RemoteHostsReleasedOnTearDown) {
- AppRemotingTestDriverEnvironment::EnvironmentOptions options;
- options.user_name = kUserNameValue;
- options.release_hosts_when_done = true;
- options.service_environment = kDeveloperEnvironment;
- Initialize(options);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
- EXPECT_TRUE(remote_host_info.IsReadyForConnection());
-
- std::vector<std::string> expected_host_list;
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId1);
- expected_host_list.push_back(
- MakeFormattedStringForReleasedHost(kTestApplicationId, kTestHostId1));
-
- environment_object_->AddHostToReleaseList(kAnotherTestApplicationId,
- kTestHostId2);
- expected_host_list.push_back(MakeFormattedStringForReleasedHost(
- kAnotherTestApplicationId, kTestHostId2));
-
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId3);
- expected_host_list.push_back(
- MakeFormattedStringForReleasedHost(kTestApplicationId, kTestHostId3));
-
- // Note: We are using a static cast here because the TearDown() method is
- // private as it is an interface method that we only want to call
- // directly in tests or by the GTEST framework.
- static_cast<testing::Environment*>(environment_object_.get())->TearDown();
-
- std::vector<std::string> actual_host_list =
- fake_report_issue_request_.get_host_ids_released();
-
- std::sort(actual_host_list.begin(), actual_host_list.end());
- std::sort(expected_host_list.begin(), expected_host_list.end());
-
- EXPECT_EQ(actual_host_list.size(), expected_host_list.size());
- for (size_t i = 0; i < actual_host_list.size(); ++i) {
- EXPECT_EQ(actual_host_list[i], expected_host_list[i]);
- }
-}
-
-TEST_F(AppRemotingTestDriverEnvironmentTest, RemoteHostsReleasedOnce) {
- AppRemotingTestDriverEnvironment::EnvironmentOptions options;
- options.user_name = kUserNameValue;
- options.release_hosts_when_done = true;
- options.service_environment = kDeveloperEnvironment;
- Initialize(options);
-
- // Pass in an empty auth code since we are using a refresh token.
- EXPECT_TRUE(environment_object_->Initialize(std::string()));
-
- RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_->GetRemoteHostInfoForApplicationId(
- kTestApplicationId, &remote_host_info));
- EXPECT_TRUE(remote_host_info.IsReadyForConnection());
-
- std::vector<std::string> expected_host_list;
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId1);
- expected_host_list.push_back(
- MakeFormattedStringForReleasedHost(kTestApplicationId, kTestHostId1));
-
- environment_object_->AddHostToReleaseList(kAnotherTestApplicationId,
- kTestHostId2);
- expected_host_list.push_back(MakeFormattedStringForReleasedHost(
- kAnotherTestApplicationId, kTestHostId2));
-
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId3);
- expected_host_list.push_back(
- MakeFormattedStringForReleasedHost(kTestApplicationId, kTestHostId3));
-
- // Attempt to add the previous hosts again, they should not be added since
- // they will already exist in the list of hosts to release.
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId1);
- environment_object_->AddHostToReleaseList(kAnotherTestApplicationId,
- kTestHostId2);
- environment_object_->AddHostToReleaseList(kTestApplicationId, kTestHostId3);
-
- // Note: We are using a static cast here because the TearDown() method is
- // private as it is an interface method that we only want to call
- // directly in tests or by the GTEST framework.
- static_cast<testing::Environment*>(environment_object_.get())->TearDown();
-
- std::vector<std::string> actual_host_list =
- fake_report_issue_request_.get_host_ids_released();
-
- std::sort(actual_host_list.begin(), actual_host_list.end());
- std::sort(expected_host_list.begin(), expected_host_list.end());
-
- EXPECT_EQ(actual_host_list.size(), expected_host_list.size());
- for (size_t i = 0; i < actual_host_list.size(); ++i) {
- EXPECT_EQ(actual_host_list[i], expected_host_list[i]);
- }
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/fake_app_remoting_report_issue_request.cc b/remoting/test/fake_app_remoting_report_issue_request.cc
deleted file mode 100644
index f2111dd..0000000
--- a/remoting/test/fake_app_remoting_report_issue_request.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2015 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 "remoting/test/fake_app_remoting_report_issue_request.h"
-
-#include "base/location.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/time/time.h"
-
-namespace remoting {
-namespace test {
-
-std::string MakeFormattedStringForReleasedHost(
- const std::string& application_id,
- const std::string& host_id) {
- return application_id + "::" + host_id;
-}
-
-FakeAppRemotingReportIssueRequest::FakeAppRemotingReportIssueRequest()
- : fail_start_request_(false) {
-}
-
-FakeAppRemotingReportIssueRequest::~FakeAppRemotingReportIssueRequest() =
- default;
-
-bool FakeAppRemotingReportIssueRequest::Start(
- const std::string& application_id,
- const std::string& host_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- bool abandon_host,
- base::Closure done_callback) {
- if (fail_start_request_) {
- done_callback.Run();
- return false;
- }
-
- if (abandon_host) {
- std::string host_id_string(application_id + "::" + host_id);
- host_ids_released_.push_back(MakeFormattedStringForReleasedHost(
- application_id, host_id));
- }
-
- scoped_refptr<base::SingleThreadTaskRunner> task_runner =
- base::ThreadTaskRunnerHandle::Get();
- task_runner->PostTask(FROM_HERE, done_callback);
-
- return true;
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/fake_app_remoting_report_issue_request.h b/remoting/test/fake_app_remoting_report_issue_request.h
deleted file mode 100644
index 11ecdccd..0000000
--- a/remoting/test/fake_app_remoting_report_issue_request.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_FAKE_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
-#define REMOTING_TEST_FAKE_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
-
-#include <string>
-#include <vector>
-
-#include "base/macros.h"
-#include "remoting/test/app_remoting_report_issue_request.h"
-
-namespace remoting {
-namespace test {
-
-// Generates a string used to track the 'released' host id by the
-// FakeAppRemotingReportIssueRequest class.
-std::string MakeFormattedStringForReleasedHost(
- const std::string& application_id,
- const std::string& host_id);
-
-// Used for testing classes which rely on the AccessTokenFetcher and want to
-// simulate success and failure scenarios without using the actual class and
-// network connection.
-class FakeAppRemotingReportIssueRequest : public AppRemotingReportIssueRequest {
- public:
- FakeAppRemotingReportIssueRequest();
- ~FakeAppRemotingReportIssueRequest() override;
-
- // AppRemotingReportIssueRequest interface.
- bool Start(const std::string& application_id,
- const std::string& host_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- bool abandon_host,
- base::Closure done_callback) override;
-
- void set_fail_start_request(bool fail) { fail_start_request_ = fail; }
-
- const std::vector<std::string>& get_host_ids_released() {
- return host_ids_released_;
- }
-
- private:
- // True if Start() should fail.
- bool fail_start_request_;
-
- // Contains the set of host ids which have been released, the string contained
- // will be in the form "<application_id>::<host_id>";
- std::vector<std::string> host_ids_released_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeAppRemotingReportIssueRequest);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_FAKE_APP_REMOTING_REPORT_ISSUE_REQUEST_H_
diff --git a/remoting/test/fake_remote_host_info_fetcher.cc b/remoting/test/fake_remote_host_info_fetcher.cc
deleted file mode 100644
index 0cd1a4c..0000000
--- a/remoting/test/fake_remote_host_info_fetcher.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2015 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 "remoting/test/fake_remote_host_info_fetcher.h"
-
-namespace remoting {
-namespace test {
-
-FakeRemoteHostInfoFetcher::FakeRemoteHostInfoFetcher()
- : fail_retrieve_remote_host_info_(false) {
-}
-
-FakeRemoteHostInfoFetcher::~FakeRemoteHostInfoFetcher() = default;
-
-bool FakeRemoteHostInfoFetcher::RetrieveRemoteHostInfo(
- const std::string& application_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- const RemoteHostInfoCallback& callback) {
- RemoteHostInfo remote_host_info;
-
- if (fail_retrieve_remote_host_info_) {
- remote_host_info.remote_host_status = kRemoteHostStatusPending;
- } else {
- remote_host_info.remote_host_status = kRemoteHostStatusReady;
- remote_host_info.application_id = application_id;
- }
-
- callback.Run(remote_host_info);
-
- return !fail_retrieve_remote_host_info_;
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/fake_remote_host_info_fetcher.h b/remoting/test/fake_remote_host_info_fetcher.h
deleted file mode 100644
index bdabbe4..0000000
--- a/remoting/test/fake_remote_host_info_fetcher.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_FAKE_REMOTE_HOST_INFO_FETCHER_H_
-#define REMOTING_TEST_FAKE_REMOTE_HOST_INFO_FETCHER_H_
-
-#include <string>
-
-#include "base/macros.h"
-#include "remoting/test/remote_host_info_fetcher.h"
-
-namespace remoting {
-namespace test {
-
-// Used for testing classes which rely on the RemoteHostInfoFetcher and want to
-// simulate success and failure scenarios without using the actual class and
-// network connection.
-class FakeRemoteHostInfoFetcher : public RemoteHostInfoFetcher {
- public:
- FakeRemoteHostInfoFetcher();
- ~FakeRemoteHostInfoFetcher() override;
-
- // RemoteHostInfoFetcher interface.
- bool RetrieveRemoteHostInfo(const std::string& application_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- const RemoteHostInfoCallback& callback) override;
-
- void set_fail_retrieve_remote_host_info(bool fail) {
- fail_retrieve_remote_host_info_ = fail;
- }
-
- private:
- // True if RetrieveRemoteHostInfo() should fail.
- bool fail_retrieve_remote_host_info_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeRemoteHostInfoFetcher);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_FAKE_REMOTE_HOST_INFO_FETCHER_H_
diff --git a/remoting/test/remote_application_details.h b/remoting/test/remote_application_details.h
deleted file mode 100644
index 711b210..0000000
--- a/remoting/test/remote_application_details.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_REMOTE_APPLICATION_DETAILS_H_
-#define REMOTING_TEST_REMOTE_APPLICATION_DETAILS_H_
-
-#include <string>
-
-namespace remoting {
-namespace test {
-
-// Container for application details used for testing.
-struct RemoteApplicationDetails {
- RemoteApplicationDetails(const std::string& app_id,
- const std::string& window_title)
- : application_id(app_id), main_window_title(window_title) {}
-
- std::string application_id;
- std::string main_window_title;
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_REMOTE_APPLICATION_DETAILS_H_
diff --git a/remoting/test/remote_host_info_fetcher.cc b/remoting/test/remote_host_info_fetcher.cc
deleted file mode 100644
index 8a19223..0000000
--- a/remoting/test/remote_host_info_fetcher.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2015 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 "remoting/test/remote_host_info_fetcher.h"
-
-#include "base/bind.h"
-#include "base/callback_helpers.h"
-#include "base/json/json_reader.h"
-#include "base/logging.h"
-#include "base/strings/stringprintf.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/values.h"
-#include "net/http/http_response_headers.h"
-#include "net/http/http_status_code.h"
-#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
-#include "net/url_request/url_fetcher.h"
-#include "remoting/base/url_request_context_getter.h"
-
-namespace {
-const char kRequestTestOrigin[] =
- "Origin: chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk";
-}
-
-namespace remoting {
-namespace test {
-
-RemoteHostInfoFetcher::RemoteHostInfoFetcher() = default;
-
-RemoteHostInfoFetcher::~RemoteHostInfoFetcher() = default;
-
-bool RemoteHostInfoFetcher::RetrieveRemoteHostInfo(
- const std::string& application_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- const RemoteHostInfoCallback& callback) {
- DCHECK(!application_id.empty());
- DCHECK(!access_token.empty());
- DCHECK(!callback.is_null());
- DCHECK(remote_host_info_callback_.is_null());
-
- VLOG(2) << "RemoteHostInfoFetcher::RetrieveRemoteHostInfo() called";
-
- std::string service_url(
- GetRunApplicationUrl(application_id, service_environment));
- if (service_url.empty()) {
- LOG(ERROR) << "Unrecognized service type: " << service_environment;
- return false;
- }
- VLOG(1) << "Using remote host service request url: " << service_url;
-
- remote_host_info_callback_ = callback;
-
- request_context_getter_ = new remoting::URLRequestContextGetter(
- base::ThreadTaskRunnerHandle::Get());
-
- request_ = net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST,
- this, TRAFFIC_ANNOTATION_FOR_TESTS);
- request_->SetRequestContext(request_context_getter_.get());
- request_->AddExtraRequestHeader("Authorization: OAuth " + access_token);
- request_->AddExtraRequestHeader(kRequestTestOrigin);
- request_->SetUploadData("application/json; charset=UTF-8", "{}");
- request_->Start();
-
- return true;
-}
-
-void RemoteHostInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
- DCHECK(source);
- VLOG(2) << "URL Fetch Completed for: " << source->GetOriginalURL();
-
- RemoteHostInfo remote_host_info;
- int response_code = request_->GetResponseCode();
- if (response_code != net::HTTP_OK) {
- LOG(ERROR) << "RemoteHostInfo request failed with error code: "
- << response_code;
- base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info);
- return;
- }
-
- std::string response_string;
- if (!request_->GetResponseAsString(&response_string)) {
- LOG(ERROR) << "Failed to retrieve RemoteHostInfo response data";
- base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info);
- return;
- }
-
- std::unique_ptr<base::Value> response_value(
- base::JSONReader::Read(response_string));
- if (!response_value || !response_value->is_dict()) {
- LOG(ERROR) << "Failed to parse response string to JSON";
- base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info);
- return;
- }
-
- std::string remote_host_status;
- const base::DictionaryValue* response;
- if (response_value->GetAsDictionary(&response)) {
- response->GetString("status", &remote_host_status);
- } else {
- LOG(ERROR) << "Failed to convert parsed JSON to a dictionary object";
- base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info);
- return;
- }
-
- remote_host_info.SetRemoteHostStatusFromString(remote_host_status);
-
- if (remote_host_info.IsReadyForConnection()) {
- response->GetString("host.applicationId", &remote_host_info.application_id);
- response->GetString("host.hostId", &remote_host_info.host_id);
- response->GetString("hostJid", &remote_host_info.host_jid);
- response->GetString("authorizationCode",
- &remote_host_info.authorization_code);
- response->GetString("sharedSecret", &remote_host_info.shared_secret);
- }
-
- base::ResetAndReturn(&remote_host_info_callback_).Run(remote_host_info);
-}
-
-} // namespace test
-} // namespace remoting
diff --git a/remoting/test/remote_host_info_fetcher.h b/remoting/test/remote_host_info_fetcher.h
deleted file mode 100644
index a5dadf66..0000000
--- a/remoting/test/remote_host_info_fetcher.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2015 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 REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_
-#define REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_
-
-#include <memory>
-#include <string>
-
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "net/url_request/url_fetcher_delegate.h"
-#include "remoting/test/app_remoting_service_urls.h"
-#include "remoting/test/remote_host_info.h"
-
-namespace remoting {
-class URLRequestContextGetter;
-}
-
-namespace remoting {
-namespace test {
-
-// Supplied by the client for each remote host info request and returns a valid,
-// initialized RemoteHostInfo object on success.
-typedef base::Callback<void(const RemoteHostInfo& remote_host_info)>
- RemoteHostInfoCallback;
-
-// Calls the App Remoting service API to request connection info for a remote
-// host. Destroying the RemoteHostInfoFetcher while a request is outstanding
-// will cancel the request. It is safe to delete the fetcher from within a
-// completion callback. Must be used from a thread running an IO message loop.
-// The public method is virtual to allow for mocking and fakes.
-class RemoteHostInfoFetcher : public net::URLFetcherDelegate {
- public:
- RemoteHostInfoFetcher();
- ~RemoteHostInfoFetcher() override;
-
- // Makes a service call to retrieve the details for a remote host. The
- // callback will be called once the HTTP request has completed.
- virtual bool RetrieveRemoteHostInfo(const std::string& application_id,
- const std::string& access_token,
- ServiceEnvironment service_environment,
- const RemoteHostInfoCallback& callback);
-
- private:
- // net::URLFetcherDelegate interface.
- void OnURLFetchComplete(const net::URLFetcher* source) override;
-
- // Holds the URLFetcher for the RemoteHostInfo request.
- std::unique_ptr<net::URLFetcher> request_;
-
- // Provides application-specific context for the network request.
- scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_;
-
- // Caller-supplied callback used to return remote host info on success.
- RemoteHostInfoCallback remote_host_info_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcher);
-};
-
-} // namespace test
-} // namespace remoting
-
-#endif // REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_
diff --git a/remoting/test/remote_host_info_fetcher_unittest.cc b/remoting/test/remote_host_info_fetcher_unittest.cc
deleted file mode 100644
index 5a18fc5..0000000
--- a/remoting/test/remote_host_info_fetcher_unittest.cc
+++ /dev/null
@@ -1,303 +0,0 @@
-// Copyright 2015 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 "remoting/test/remote_host_info_fetcher.h"
-
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "net/url_request/test_url_fetcher_factory.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-const char kTestApplicationId[] = "klasdfjlkasdfjklasjfdkljsadf";
-const char kTestApplicationId2[] = "klasdfjlkasdfjklasjfdkljsadf2";
-const char kAccessTokenValue[] = "test_access_token_value";
-const char kRemoteHostInfoReadyResponse[] =
- "{"
- " \"status\": \"done\","
- " \"host\": {"
- " \"kind\": \"test_kind\","
- " \"applicationId\": \"klasdfjlkasdfjklasjfdkljsadf\","
- " \"hostId\": \"test_host_id\""
- " },"
- " \"hostJid\": \"test_host_jid\","
- " \"authorizationCode\": \"test_authorization_code\","
- " \"sharedSecret\": \"test_shared_secret\""
- "}";
-const char kRemoteHostInfoReadyResponse2[] =
- "{"
- " \"status\": \"done\","
- " \"host\": {"
- " \"kind\": \"test_kind\","
- " \"applicationId\": \"klasdfjlkasdfjklasjfdkljsadf2\","
- " \"hostId\": \"test_host_id\""
- " },"
- " \"hostJid\": \"test_host_jid\","
- " \"authorizationCode\": \"test_authorization_code\","
- " \"sharedSecret\": \"test_shared_secret\""
- "}";
-const char kRemoteHostInfoPendingResponse[] =
- "{"
- " \"status\": \"pending\""
- "}";
-const char kRemoteHostInfoEmptyResponse[] = "{}";
-} // namespace
-
-namespace remoting {
-namespace test {
-
-// Provides base functionality for the RemoteHostInfoFetcher Tests below. The
-// FakeURLFetcherFactory allows us to override the response data and payload for
-// specified URLs. We use this to stub out network calls made by the
-// RemoteHostInfoFetcher. This fixture also creates an IO MessageLoop, if
-// necessary, for use by the RemoteHostInfoFetcher.
-class RemoteHostInfoFetcherTest : public ::testing::Test {
- public:
- RemoteHostInfoFetcherTest() : url_fetcher_factory_(nullptr) {}
- ~RemoteHostInfoFetcherTest() override = default;
-
- // Used as a RemoteHostInfoCallback for testing.
- void OnRemoteHostInfoRetrieved(
- base::Closure done_closure,
- const RemoteHostInfo& retrieved_remote_host_info);
-
- protected:
- // testing::Test interface.
- void SetUp() override;
-
- // Sets the HTTP status and data returned for a specified URL.
- void SetFakeResponse(const GURL& url,
- const std::string& data,
- net::HttpStatusCode code,
- net::URLRequestStatus::Status status);
-
- // Used for result verification.
- RemoteHostInfo remote_host_info_;
-
- std::string dev_service_environment_url_;
- std::string dev_service_environment_url_2_;
-
- private:
- net::FakeURLFetcherFactory url_fetcher_factory_;
- std::unique_ptr<base::MessageLoopForIO> message_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcherTest);
-};
-
-void RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved(
- base::Closure done_closure,
- const RemoteHostInfo& retrieved_remote_host_info) {
- remote_host_info_ = retrieved_remote_host_info;
-
- done_closure.Run();
-}
-
-void RemoteHostInfoFetcherTest::SetUp() {
- DCHECK(!message_loop_);
- message_loop_.reset(new base::MessageLoopForIO);
-
- dev_service_environment_url_ =
- GetRunApplicationUrl(kTestApplicationId, kDeveloperEnvironment);
- SetFakeResponse(GURL(dev_service_environment_url_),
- kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
- net::URLRequestStatus::FAILED);
-
- dev_service_environment_url_2_ =
- GetRunApplicationUrl(kTestApplicationId2, kDeveloperEnvironment);
- SetFakeResponse(GURL(dev_service_environment_url_2_),
- kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
- net::URLRequestStatus::FAILED);
-}
-
-void RemoteHostInfoFetcherTest::SetFakeResponse(
- const GURL& url,
- const std::string& data,
- net::HttpStatusCode code,
- net::URLRequestStatus::Status status) {
- url_fetcher_factory_.SetFakeResponse(url, data, code, status);
-}
-
-TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoFromDev) {
- SetFakeResponse(GURL(dev_service_environment_url_),
- kRemoteHostInfoReadyResponse, net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
-
- base::RunLoop run_loop;
- RemoteHostInfoCallback remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment,
- remote_host_info_callback);
-
- run_loop.Run();
-
- EXPECT_TRUE(request_started);
- EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
- EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
- EXPECT_TRUE(!remote_host_info_.host_id.empty());
- EXPECT_TRUE(!remote_host_info_.host_jid.empty());
- EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
-}
-
-TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoInvalidEnvironment) {
- base::RunLoop run_loop;
- RemoteHostInfoCallback remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kUnknownEnvironment,
- remote_host_info_callback);
-
- EXPECT_FALSE(request_started);
-}
-
-TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoNetworkError) {
- base::RunLoop run_loop;
- RemoteHostInfoCallback remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment,
- remote_host_info_callback);
-
- run_loop.Run();
-
- EXPECT_TRUE(request_started);
- EXPECT_FALSE(remote_host_info_.IsReadyForConnection());
-
- // If there was a network error retrieving the remote host info, then none of
- // the connection details should be populated.
- EXPECT_TRUE(remote_host_info_.application_id.empty());
- EXPECT_TRUE(remote_host_info_.host_id.empty());
- EXPECT_TRUE(remote_host_info_.host_jid.empty());
- EXPECT_TRUE(remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(remote_host_info_.shared_secret.empty());
-}
-
-TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoPendingResponse) {
- SetFakeResponse(GURL(dev_service_environment_url_),
- kRemoteHostInfoPendingResponse, net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
-
- base::RunLoop run_loop;
- RemoteHostInfoCallback remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment,
- remote_host_info_callback);
-
- run_loop.Run();
-
- EXPECT_TRUE(request_started);
- EXPECT_FALSE(remote_host_info_.IsReadyForConnection());
-
- // If the remote host request is pending, then none of the connection details
- // should be populated.
- EXPECT_TRUE(remote_host_info_.application_id.empty());
- EXPECT_TRUE(remote_host_info_.host_id.empty());
- EXPECT_TRUE(remote_host_info_.host_jid.empty());
- EXPECT_TRUE(remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(remote_host_info_.shared_secret.empty());
-}
-
-TEST_F(RemoteHostInfoFetcherTest, RetrieveRemoteHostInfoEmptyResponse) {
- SetFakeResponse(GURL(dev_service_environment_url_),
- kRemoteHostInfoEmptyResponse, net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
-
- base::RunLoop run_loop;
- RemoteHostInfoCallback remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment,
- remote_host_info_callback);
-
- run_loop.Run();
-
- EXPECT_TRUE(request_started);
- EXPECT_FALSE(remote_host_info_.IsReadyForConnection());
-
- // If we received an empty response, then none of the connection details
- // should be populated.
- EXPECT_TRUE(remote_host_info_.application_id.empty());
- EXPECT_TRUE(remote_host_info_.host_id.empty());
- EXPECT_TRUE(remote_host_info_.host_jid.empty());
- EXPECT_TRUE(remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(remote_host_info_.shared_secret.empty());
-}
-
-TEST_F(RemoteHostInfoFetcherTest, MultipleRetrieveRemoteHostInfoRequests) {
- // First, we will fetch info from the development service environment.
- SetFakeResponse(GURL(dev_service_environment_url_),
- kRemoteHostInfoReadyResponse, net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
-
- base::RunLoop dev_run_loop;
- RemoteHostInfoCallback dev_remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), dev_run_loop.QuitClosure());
-
- RemoteHostInfoFetcher remote_host_info_fetcher;
- bool dev_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId, kAccessTokenValue, kDeveloperEnvironment,
- dev_remote_host_info_callback);
-
- dev_run_loop.Run();
-
- EXPECT_TRUE(dev_request_started);
- EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
- EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId), 0);
- EXPECT_TRUE(!remote_host_info_.host_id.empty());
- EXPECT_TRUE(!remote_host_info_.host_jid.empty());
- EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
-
- // Next, we will fetch a different application info block from the dev
- // service environment.
- SetFakeResponse(GURL(dev_service_environment_url_2_),
- kRemoteHostInfoReadyResponse2, net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
-
- base::RunLoop test_run_loop;
- RemoteHostInfoCallback test_remote_host_info_callback =
- base::Bind(&RemoteHostInfoFetcherTest::OnRemoteHostInfoRetrieved,
- base::Unretained(this), test_run_loop.QuitClosure());
-
- // Reset the state of our internal |remote_host_info_| object.
- remote_host_info_ = RemoteHostInfo();
- EXPECT_FALSE(remote_host_info_.IsReadyForConnection());
-
- bool test_request_started = remote_host_info_fetcher.RetrieveRemoteHostInfo(
- kTestApplicationId2, kAccessTokenValue, kDeveloperEnvironment,
- test_remote_host_info_callback);
-
- test_run_loop.Run();
-
- EXPECT_TRUE(test_request_started);
- EXPECT_TRUE(remote_host_info_.IsReadyForConnection());
- EXPECT_EQ(remote_host_info_.application_id.compare(kTestApplicationId2), 0);
- EXPECT_TRUE(!remote_host_info_.host_id.empty());
- EXPECT_TRUE(!remote_host_info_.host_jid.empty());
- EXPECT_TRUE(!remote_host_info_.authorization_code.empty());
- EXPECT_TRUE(!remote_host_info_.shared_secret.empty());
-}
-
-} // namespace test
-} // namespace remoting