summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoedow <joedow@chromium.org>2015-07-01 18:39:09 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-02 01:39:48 +0000
commit751a18f30665e8cc19bc5abcd304e550f99fde48 (patch)
treeeac849d5bc7dfa4b0149ba995a0367cf8e86e249
parentb8827395a72e786259c24806fcc0f5827e2a88c5 (diff)
downloadchromium_src-751a18f30665e8cc19bc5abcd304e550f99fde48.zip
chromium_src-751a18f30665e8cc19bc5abcd304e550f99fde48.tar.gz
chromium_src-751a18f30665e8cc19bc5abcd304e550f99fde48.tar.bz2
Adding the ability to release hosts after testing to the app remoting test driver.
This change introduces a new class which will wrap calls to the ReportIssue API. This request will be used to tell the service when we are done with the remote hosts we used for testing so that they can be cleaned up and the test will receive a fresh instance the next time it is launched. I've also moved the logic to create the service urls out into a separate class which can be used by framework and unit test code. Also updates the behavior for 'show-host-availability' so that it can be used when running tests for debugging info purposes. Also cleans up some minor cpplint errors. BUG= Review URL: https://codereview.chromium.org/1219063002 Cr-Commit-Position: refs/heads/master@{#337155}
-rw-r--r--remoting/BUILD.gn7
-rw-r--r--remoting/remoting_test.gypi11
-rw-r--r--remoting/test/app_remoting_connection_helper.cc2
-rw-r--r--remoting/test/app_remoting_report_issue_request.cc82
-rw-r--r--remoting/test/app_remoting_report_issue_request.h62
-rw-r--r--remoting/test/app_remoting_report_issue_request_unittest.cc227
-rw-r--r--remoting/test/app_remoting_service_urls.cc102
-rw-r--r--remoting/test/app_remoting_service_urls.h40
-rw-r--r--remoting/test/app_remoting_test_driver.cc38
-rw-r--r--remoting/test/app_remoting_test_driver_environment.cc82
-rw-r--r--remoting/test/app_remoting_test_driver_environment.h34
-rw-r--r--remoting/test/app_remoting_test_driver_environment_unittest.cc363
-rw-r--r--remoting/test/fake_app_remoting_report_issue_request.cc54
-rw-r--r--remoting/test/fake_app_remoting_report_issue_request.h58
-rw-r--r--remoting/test/mock_access_token_fetcher.h2
-rw-r--r--remoting/test/remote_host_info_fetcher.cc30
-rw-r--r--remoting/test/remote_host_info_fetcher.h23
-rw-r--r--remoting/test/remote_host_info_fetcher_unittest.cc8
18 files changed, 1087 insertions, 138 deletions
diff --git a/remoting/BUILD.gn b/remoting/BUILD.gn
index 314a484..9be8a41 100644
--- a/remoting/BUILD.gn
+++ b/remoting/BUILD.gn
@@ -83,11 +83,17 @@ source_set("test_support") {
"signaling/mock_signal_strategy.h",
"test/access_token_fetcher.cc",
"test/access_token_fetcher.h",
+ "test/app_remoting_report_issue_request.cc",
+ "test/app_remoting_report_issue_request.h",
+ "test/app_remoting_service_urls.cc",
+ "test/app_remoting_service_urls.h",
"test/app_remoting_test_driver_environment.cc",
"test/app_remoting_test_driver_environment.h",
"test/app_remoting_test_driver_environment_app_details.cc",
"test/fake_access_token_fetcher.cc",
"test/fake_access_token_fetcher.h",
+ "test/fake_app_remoting_report_issue_request.cc",
+ "test/fake_app_remoting_report_issue_request.h",
"test/fake_network_dispatcher.cc",
"test/fake_network_dispatcher.h",
"test/fake_network_manager.cc",
@@ -147,6 +153,7 @@ if (!is_mac) {
"signaling/server_log_entry_unittest.cc",
"signaling/server_log_entry_unittest.h",
"test/access_token_fetcher_unittest.cc",
+ "test/app_remoting_report_issue_request_unittest.cc",
"test/app_remoting_test_driver_environment_unittest.cc",
"test/remote_host_info_fetcher_unittest.cc",
"test/test_chromoting_client_unittest.cc",
diff --git a/remoting/remoting_test.gypi b/remoting/remoting_test.gypi
index cc85620..92043c5 100644
--- a/remoting/remoting_test.gypi
+++ b/remoting/remoting_test.gypi
@@ -48,11 +48,17 @@
'signaling/mock_signal_strategy.h',
'test/access_token_fetcher.cc',
'test/access_token_fetcher.h',
+ 'test/app_remoting_report_issue_request.cc',
+ 'test/app_remoting_report_issue_request.h',
+ 'test/app_remoting_service_urls.cc',
+ 'test/app_remoting_service_urls.h',
'test/app_remoting_test_driver_environment.cc',
'test/app_remoting_test_driver_environment_app_details.cc',
'test/app_remoting_test_driver_environment.h',
'test/fake_access_token_fetcher.cc',
'test/fake_access_token_fetcher.h',
+ 'test/fake_app_remoting_report_issue_request.cc',
+ 'test/fake_app_remoting_report_issue_request.h',
'test/fake_network_dispatcher.cc',
'test/fake_network_dispatcher.h',
'test/fake_network_manager.cc',
@@ -151,6 +157,10 @@
'test/app_remoting_connected_client_fixture.h',
'test/app_remoting_connection_helper.cc',
'test/app_remoting_connection_helper.h',
+ 'test/app_remoting_report_issue_request.cc',
+ 'test/app_remoting_report_issue_request.h',
+ 'test/app_remoting_service_urls.cc',
+ 'test/app_remoting_service_urls.h',
'test/app_remoting_test_driver_environment.cc',
'test/app_remoting_test_driver_environment.h',
'test/remote_application_details.h',
@@ -356,6 +366,7 @@
'signaling/xmpp_stream_parser_unittest.cc',
'signaling/xmpp_signal_strategy_unittest.cc',
'test/access_token_fetcher_unittest.cc',
+ 'test/app_remoting_report_issue_request_unittest.cc',
'test/app_remoting_test_driver_environment_unittest.cc',
'test/remote_host_info_fetcher_unittest.cc',
'test/test_chromoting_client_unittest.cc',
diff --git a/remoting/test/app_remoting_connection_helper.cc b/remoting/test/app_remoting_connection_helper.cc
index ca0fa40..6055bcf 100644
--- a/remoting/test/app_remoting_connection_helper.cc
+++ b/remoting/test/app_remoting_connection_helper.cc
@@ -66,6 +66,8 @@ bool AppRemotingConnectionHelper::StartConnection() {
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());
diff --git a/remoting/test/app_remoting_report_issue_request.cc b/remoting/test/app_remoting_report_issue_request.cc
new file mode 100644
index 0000000..9fcbf83
--- /dev/null
+++ b/remoting/test/app_remoting_report_issue_request.cc
@@ -0,0 +1,82 @@
+// 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/thread_task_runner_handle.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_status_code.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() {
+}
+
+AppRemotingReportIssueRequest::~AppRemotingReportIssueRequest() {
+}
+
+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";
+
+ DVLOG(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;
+ }
+ DVLOG(1) << "Using Report Issue service request url: " << service_url;
+
+ request_complete_callback_ = done_callback;
+
+ request_context_getter_ = new remoting::URLRequestContextGetter(
+ base::ThreadTaskRunnerHandle::Get(), // network_runner
+ base::ThreadTaskRunnerHandle::Get()); // file_runner
+
+ std::string upload_data = abandon_host ? "{ 'abandonHost': 'true' }" : "{}";
+
+ request_ =
+ net::URLFetcher::Create(GURL(service_url), net::URLFetcher::POST, this);
+ 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) {
+ DVLOG(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
new file mode 100644
index 0000000..43548e5
--- /dev/null
+++ b/remoting/test/app_remoting_report_issue_request.h
@@ -0,0 +1,62 @@
+// 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 <string>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "remoting/test/app_remoting_service_urls.h"
+
+namespace net {
+class UrlFetcher;
+}
+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.
+ scoped_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
new file mode 100644
index 0000000..8a26322
--- /dev/null
+++ b/remoting/test/app_remoting_report_issue_request_unittest.cc
@@ -0,0 +1,227 @@
+// 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/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::string test_service_environment_url_;
+ std::string staging_service_environment_url_;
+
+ scoped_ptr<base::RunLoop> run_loop_;
+ scoped_ptr<base::Timer> timer_;
+
+ AppRemotingReportIssueRequest app_remoting_report_issue_request_;
+
+ private:
+ net::FakeURLFetcherFactory url_fetcher_factory_;
+ scoped_ptr<base::MessageLoopForIO> message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppRemotingReportIssueRequestTest);
+};
+
+AppRemotingReportIssueRequestTest::AppRemotingReportIssueRequestTest()
+ : url_fetcher_factory_(nullptr), message_loop_(new base::MessageLoopForIO) {
+}
+
+AppRemotingReportIssueRequestTest::~AppRemotingReportIssueRequestTest() {
+}
+
+void AppRemotingReportIssueRequestTest::SetUp() {
+ run_loop_.reset(new base::RunLoop());
+ timer_.reset(new base::Timer(true, false));
+
+ dev_service_environment_url_ =
+ GetReportIssueUrl(kTestApplicationId, kTestHostId, kDeveloperEnvironment);
+ SetFakeResponse(GURL(dev_service_environment_url_), kReportIssueResponse,
+ net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
+
+ test_service_environment_url_ =
+ GetReportIssueUrl(kTestApplicationId, kTestHostId, kTestingEnvironment);
+ SetFakeResponse(GURL(test_service_environment_url_), kReportIssueResponse,
+ net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
+
+ staging_service_environment_url_ =
+ GetReportIssueUrl(kTestApplicationId, kTestHostId, kStagingEnvironment);
+ SetFakeResponse(GURL(staging_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, ReportIssueFromTest) {
+ SetFakeResponse(GURL(test_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, kTestingEnvironment,
+ 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, ReportIssueFromStaging) {
+ SetFakeResponse(GURL(staging_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, kStagingEnvironment,
+ 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, kStagingEnvironment,
+ 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(staging_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, kStagingEnvironment,
+ 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, kStagingEnvironment,
+ 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, kStagingEnvironment,
+ 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_service_urls.cc b/remoting/test/app_remoting_service_urls.cc
new file mode 100644
index 0000000..87432a6
--- /dev/null
+++ b/remoting/test/app_remoting_service_urls.cc
@@ -0,0 +1,102 @@
+// 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";
+const char kAppRemotingTestEndpointQualifier[] = "v1beta1";
+const char kAppRemotingStagingEndpointQualifier[] = "v1beta1_staging";
+
+// 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;
+
+ const char* environment_qualifier = nullptr;
+ switch (service_environment) {
+ case kDeveloperEnvironment:
+ environment_qualifier = kAppRemotingDevEndpointQualifier;
+ break;
+
+ case kTestingEnvironment:
+ environment_qualifier = kAppRemotingTestEndpointQualifier;
+ break;
+
+ case kStagingEnvironment:
+ environment_qualifier = kAppRemotingStagingEndpointQualifier;
+ break;
+
+ default:
+ NOTREACHED();
+ }
+
+ if (environment_qualifier) {
+ base_service_url =
+ base::StringPrintf(kAppRemotingTestEndpointBase, environment_qualifier);
+ }
+
+ 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
new file mode 100644
index 0000000..e532fc6
--- /dev/null
+++ b/remoting/test/app_remoting_service_urls.h
@@ -0,0 +1,40 @@
+// 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,
+ kTestingEnvironment,
+ kStagingEnvironment,
+ 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
index b9360f2..1942284 100644
--- a/remoting/test/app_remoting_test_driver.cc
+++ b/remoting/test/app_remoting_test_driver.cc
@@ -22,11 +22,12 @@ 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 kServiceEnvironmentSwitchName[] = "environment";
const char kShowHostAvailabilitySwitchName[] = "show-host-availability";
const char kSingleProcessTestsSwitchName[] = "single-process-tests";
const char kUserNameSwitchName[] = "username";
-}
+} // namespace switches
namespace {
@@ -81,6 +82,10 @@ void PrintUsage() {
"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);
@@ -198,38 +203,42 @@ int main(int argc, char** argv) {
base::Bind(&NoAtExitBaseTestSuite::RunTestSuite, argc, argv));
}
+ remoting::test::AppRemotingTestDriverEnvironment::EnvironmentOptions options;
+
// Verify we received the required input from the command line.
- std::string user_name(
- command_line->GetSwitchValueASCII(switches::kUserNameSwitchName));
- if (user_name.empty()) {
+ 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;
}
- DVLOG(1) << "Running tests as: " << user_name;
+ DVLOG(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));
- base::FilePath refresh_token_file_path(
- command_line->GetSwitchValuePath(switches::kRefreshTokenFileSwitchName));
+ options.refresh_token_file_path =
+ command_line->GetSwitchValuePath(switches::kRefreshTokenFileSwitchName);
+
+ options.release_hosts_when_done =
+ command_line->HasSwitch(switches::kReleaseHostsAfterTestingSwitchName);
// If the user passed in a service environment, use it, otherwise set a
// default value.
- remoting::test::ServiceEnvironment service_environment;
std::string service_environment_switch(command_line->GetSwitchValueASCII(
switches::kServiceEnvironmentSwitchName));
if (service_environment_switch.empty() ||
service_environment_switch == "dev") {
- service_environment =
+ options.service_environment =
remoting::test::ServiceEnvironment::kDeveloperEnvironment;
} else if (service_environment_switch == "test") {
- service_environment =
+ options.service_environment =
remoting::test::ServiceEnvironment::kTestingEnvironment;
} else if (service_environment_switch == "staging") {
- service_environment =
+ options.service_environment =
remoting::test::ServiceEnvironment::kStagingEnvironment;
} else {
LOG(ERROR) << "Invalid " << switches::kServiceEnvironmentSwitchName
@@ -255,8 +264,7 @@ int main(int argc, char** argv) {
// The GTest framework will own the lifetime of this object once
// it is registered below.
scoped_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data(
- new remoting::test::AppRemotingTestDriverEnvironment(
- user_name, refresh_token_file_path, service_environment));
+ new remoting::test::AppRemotingTestDriverEnvironment(options));
if (!shared_data->Initialize(auth_code)) {
// If we failed to initialize our shared data object, then bail.
@@ -265,9 +273,9 @@ int main(int argc, char** argv) {
if (command_line->HasSwitch(switches::kShowHostAvailabilitySwitchName)) {
// When this flag is specified, we will retrieve connection information
- // for all known applications and report the status. No tests will be run.
+ // for all known applications and report the status. Tests can be skipped
+ // using a gtest_filter flag.
shared_data->ShowHostAvailability();
- return 0;
}
// Since we've successfully set up our shared_data object, we'll assign the
diff --git a/remoting/test/app_remoting_test_driver_environment.cc b/remoting/test/app_remoting_test_driver_environment.cc
index e2716be..8cc8f5c 100644
--- a/remoting/test/app_remoting_test_driver_environment.cc
+++ b/remoting/test/app_remoting_test_driver_environment.cc
@@ -15,6 +15,7 @@
#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"
@@ -23,14 +24,23 @@ namespace test {
AppRemotingTestDriverEnvironment* AppRemotingSharedData;
+AppRemotingTestDriverEnvironment::EnvironmentOptions::EnvironmentOptions()
+ : refresh_token_file_path(base::FilePath()),
+ service_environment(kUnknownEnvironment),
+ release_hosts_when_done(false) {
+}
+
+AppRemotingTestDriverEnvironment::EnvironmentOptions::~EnvironmentOptions() {
+}
+
AppRemotingTestDriverEnvironment::AppRemotingTestDriverEnvironment(
- const std::string& user_name,
- const base::FilePath& refresh_token_file_path,
- ServiceEnvironment service_environment)
- : user_name_(user_name),
- service_environment_(service_environment),
- refresh_token_file_path_(refresh_token_file_path),
+ 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());
@@ -131,6 +141,26 @@ bool AppRemotingTestDriverEnvironment::GetRemoteHostInfoForApplicationId(
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";
@@ -179,6 +209,13 @@ void AppRemotingTestDriverEnvironment::SetAccessTokenFetcherForTest(
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);
@@ -194,6 +231,39 @@ void AppRemotingTestDriverEnvironment::SetRemoteHostInfoFetcherForTest(
}
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.
+ scoped_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;
+ DVLOG(1) << "Releasing hosts for application: " << application_id;
+
+ for (const auto& host_id : kvp.second) {
+ base::RunLoop run_loop;
+
+ DVLOG(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
diff --git a/remoting/test/app_remoting_test_driver_environment.h b/remoting/test/app_remoting_test_driver_environment.h
index 2ff90c77..8f3ca8f 100644
--- a/remoting/test/app_remoting_test_driver_environment.h
+++ b/remoting/test/app_remoting_test_driver_environment.h
@@ -23,6 +23,7 @@ namespace remoting {
namespace test {
class AccessTokenFetcher;
+class AppRemotingReportIssueRequest;
class RefreshTokenStore;
struct RemoteHostInfo;
@@ -31,9 +32,17 @@ struct RemoteHostInfo;
// access tokens and retrieving remote host connection information.
class AppRemotingTestDriverEnvironment : public testing::Environment {
public:
- AppRemotingTestDriverEnvironment(const std::string& user_name,
- const base::FilePath& refresh_token_file,
- ServiceEnvironment service_environment);
+ 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.
@@ -48,6 +57,11 @@ class AppRemotingTestDriverEnvironment : public testing::Environment {
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();
@@ -61,6 +75,8 @@ class AppRemotingTestDriverEnvironment : public testing::Environment {
// 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);
@@ -111,12 +127,20 @@ class AppRemotingTestDriverEnvironment : public testing::Environment {
// 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_;
@@ -126,6 +150,10 @@ class AppRemotingTestDriverEnvironment : public testing::Environment {
// Used for running network request tasks.
scoped_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_;
+
// Contains the names of all supported remote applications.
// Once initialized, this vector is not modified.
std::vector<std::string> application_names_;
diff --git a/remoting/test/app_remoting_test_driver_environment_unittest.cc b/remoting/test/app_remoting_test_driver_environment_unittest.cc
index 484267f..07eb931 100644
--- a/remoting/test/app_remoting_test_driver_environment_unittest.cc
+++ b/remoting/test/app_remoting_test_driver_environment_unittest.cc
@@ -4,8 +4,11 @@
#include "remoting/test/app_remoting_test_driver_environment.h"
+#include <algorithm>
+
#include "base/files/file_path.h"
#include "remoting/test/fake_access_token_fetcher.h"
+#include "remoting/test/fake_app_remoting_report_issue_request.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"
@@ -17,6 +20,10 @@ const char kAuthCodeValue[] = "4/892379827345jkefvkdfbv";
const char kRefreshTokenValue[] = "1/lkjalseLKJlsiJgr45jbv";
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 {
@@ -28,21 +35,12 @@ using testing::_;
// file system dependencies when testing the TestDriverEnvironment.
class FakeRefreshTokenStore : public RefreshTokenStore {
public:
- FakeRefreshTokenStore()
- : refresh_token_value_(kRefreshTokenValue),
- refresh_token_write_succeeded_(true),
- refresh_token_write_attempted_(false) {}
- ~FakeRefreshTokenStore() override {}
-
- std::string FetchRefreshToken() override { return refresh_token_value_; }
+ FakeRefreshTokenStore();
+ ~FakeRefreshTokenStore() override;
- bool StoreRefreshToken(const std::string& refresh_token) override {
- // Record the information passed to us to write.
- refresh_token_write_attempted_ = true;
- stored_refresh_token_value_ = refresh_token;
-
- return refresh_token_write_succeeded_;
- }
+ // RefreshTokenStore interface.
+ std::string FetchRefreshToken() override;
+ bool StoreRefreshToken(const std::string& refresh_token) override;
bool refresh_token_write_attempted() const {
return refresh_token_write_attempted_;
@@ -72,66 +70,112 @@ class FakeRefreshTokenStore : public RefreshTokenStore {
DISALLOW_COPY_AND_ASSIGN(FakeRefreshTokenStore);
};
+FakeRefreshTokenStore::FakeRefreshTokenStore()
+ : refresh_token_value_(kRefreshTokenValue),
+ refresh_token_write_succeeded_(true),
+ refresh_token_write_attempted_(false) {
+}
+
+FakeRefreshTokenStore::~FakeRefreshTokenStore() {
+}
+
+std::string FakeRefreshTokenStore::FetchRefreshToken() {
+ return refresh_token_value_;
+}
+
+bool FakeRefreshTokenStore::StoreRefreshToken(
+ const std::string& refresh_token) {
+ // Record the information passed to us to write.
+ refresh_token_write_attempted_ = true;
+ stored_refresh_token_value_ = refresh_token;
+
+ return refresh_token_write_succeeded_;
+}
+
class AppRemotingTestDriverEnvironmentTest : public ::testing::Test {
public:
- AppRemotingTestDriverEnvironmentTest()
- : fake_access_token_fetcher_(nullptr),
- environment_object_(kUserNameValue,
- base::FilePath(), // refresh_token_file_path
- kDeveloperEnvironment) {}
- ~AppRemotingTestDriverEnvironmentTest() override {}
+ AppRemotingTestDriverEnvironmentTest();
+ ~AppRemotingTestDriverEnvironmentTest() override;
FakeAccessTokenFetcher* fake_access_token_fetcher() const {
return fake_access_token_fetcher_;
}
protected:
- // testing::Test interface.
- void SetUp() override {
- scoped_ptr<FakeAccessTokenFetcher> fake_access_token_fetcher(
- new FakeAccessTokenFetcher());
- fake_access_token_fetcher_ = fake_access_token_fetcher.get();
- mock_access_token_fetcher_.SetAccessTokenFetcher(
- fake_access_token_fetcher.Pass());
-
- environment_object_.SetAccessTokenFetcherForTest(
- &mock_access_token_fetcher_);
- environment_object_.SetRefreshTokenStoreForTest(&fake_token_store_);
- environment_object_.SetRemoteHostInfoFetcherForTest(
- &fake_remote_host_info_fetcher_);
- }
+ 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_;
- FakeAccessTokenFetcher* fake_access_token_fetcher_;
MockAccessTokenFetcher mock_access_token_fetcher_;
- AppRemotingTestDriverEnvironment environment_object_;
+ scoped_ptr<AppRemotingTestDriverEnvironment> environment_object_;
private:
DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironmentTest);
};
+AppRemotingTestDriverEnvironmentTest::AppRemotingTestDriverEnvironmentTest()
+ : fake_access_token_fetcher_(nullptr) {
+}
+
+AppRemotingTestDriverEnvironmentTest::~AppRemotingTestDriverEnvironmentTest() {
+}
+
+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));
+
+ scoped_ptr<FakeAccessTokenFetcher> fake_access_token_fetcher(
+ new FakeAccessTokenFetcher());
+ fake_access_token_fetcher_ = fake_access_token_fetcher.get();
+ mock_access_token_fetcher_.SetAccessTokenFetcher(
+ fake_access_token_fetcher.Pass());
+
+ 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(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(),
+ 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));
+ 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(_, _));
@@ -139,34 +183,55 @@ TEST_F(AppRemotingTestDriverEnvironmentTest,
EXPECT_CALL(mock_access_token_fetcher_, GetAccessTokenFromRefreshToken(_, _))
.Times(0);
- EXPECT_FALSE(environment_object_.Initialize(kAuthCodeValue));
+ 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()));
+ 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(),
+ 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()));
+ 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(_, _));
@@ -175,12 +240,14 @@ TEST_F(AppRemotingTestDriverEnvironmentTest,
.Times(0);
// Pass in an empty auth code since we are using a refresh token.
- EXPECT_FALSE(environment_object_.Initialize(std::string()));
+ 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);
@@ -192,12 +259,14 @@ TEST_F(AppRemotingTestDriverEnvironmentTest,
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(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(_, _))
@@ -206,12 +275,14 @@ TEST_F(AppRemotingTestDriverEnvironmentTest,
// 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_FALSE(environment_object_->Initialize(kAuthCodeValue));
EXPECT_TRUE(fake_token_store_.refresh_token_write_attempted());
}
TEST_F(AppRemotingTestDriverEnvironmentTest,
RefreshAccessTokenAfterUsingAuthCode) {
+ Initialize();
+
{
testing::InSequence call_sequence;
@@ -221,19 +292,21 @@ TEST_F(AppRemotingTestDriverEnvironmentTest,
GetAccessTokenFromRefreshToken(_, _));
}
- EXPECT_TRUE(environment_object_.Initialize(kAuthCodeValue));
+ 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(),
+ 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());
+ EXPECT_TRUE(environment_object_->RefreshAccessToken());
}
TEST_F(AppRemotingTestDriverEnvironmentTest, RefreshAccessTokenFailure) {
+ Initialize();
+
{
testing::InSequence call_sequence;
@@ -245,50 +318,214 @@ TEST_F(AppRemotingTestDriverEnvironmentTest, RefreshAccessTokenFailure) {
GetAccessTokenFromRefreshToken(_, _));
}
- EXPECT_TRUE(environment_object_.Initialize(kAuthCodeValue));
+ 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(),
+ 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);
+ 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()));
+ EXPECT_TRUE(environment_object_->Initialize(std::string()));
RemoteHostInfo remote_host_info;
- EXPECT_TRUE(environment_object_.GetRemoteHostInfoForApplicationId(
+ 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()));
+ 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(
+ EXPECT_FALSE(environment_object_->GetRemoteHostInfoForApplicationId(
kTestApplicationId, &remote_host_info));
}
TEST_F(AppRemotingTestDriverEnvironmentTest,
GetRemoteHostInfoWithoutInitializing) {
+ Initialize();
+
RemoteHostInfo remote_host_info;
- EXPECT_FALSE(environment_object_.GetRemoteHostInfoForApplicationId(
+ 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
new file mode 100644
index 0000000..8d628c9
--- /dev/null
+++ b/remoting/test/fake_app_remoting_report_issue_request.cc
@@ -0,0 +1,54 @@
+// 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/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() {
+}
+
+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
new file mode 100644
index 0000000..2502040
--- /dev/null
+++ b/remoting/test/fake_app_remoting_report_issue_request.h
@@ -0,0 +1,58 @@
+// 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 "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/mock_access_token_fetcher.h b/remoting/test/mock_access_token_fetcher.h
index 61b6f20..9486a36 100644
--- a/remoting/test/mock_access_token_fetcher.h
+++ b/remoting/test/mock_access_token_fetcher.h
@@ -5,6 +5,8 @@
#ifndef REMOTING_TEST_MOCK_ACCESS_TOKEN_FETCHER_H_
#define REMOTING_TEST_MOCK_ACCESS_TOKEN_FETCHER_H_
+#include <string>
+
#include "remoting/test/access_token_fetcher.h"
#include "testing/gmock/include/gmock/gmock.h"
diff --git a/remoting/test/remote_host_info_fetcher.cc b/remoting/test/remote_host_info_fetcher.cc
index cb590b6..f2194c6 100644
--- a/remoting/test/remote_host_info_fetcher.cc
+++ b/remoting/test/remote_host_info_fetcher.cc
@@ -8,7 +8,6 @@
#include "base/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
#include "base/values.h"
@@ -43,30 +42,13 @@ bool RemoteHostInfoFetcher::RetrieveRemoteHostInfo(
DVLOG(2) << "RemoteHostInfoFetcher::RetrieveRemoteHostInfo() called";
- std::string service_url;
- switch (service_environment) {
- case kDeveloperEnvironment:
- DVLOG(1) << "Configuring service request for dev environment";
- service_url = base::StringPrintf(kDevServiceEnvironmentUrlFormat,
- application_id.c_str());
- break;
-
- case kTestingEnvironment:
- DVLOG(1) << "Configuring service request for test environment";
- service_url = base::StringPrintf(kTestServiceEnvironmentUrlFormat,
- application_id.c_str());
- break;
-
- case kStagingEnvironment:
- DVLOG(1) << "Configuring service request for staging environment";
- service_url = base::StringPrintf(kStagingServiceEnvironmentUrlFormat,
- application_id.c_str());
- break;
-
- default:
- LOG(ERROR) << "Unrecognized service type: " << service_environment;
- return false;
+ std::string service_url(
+ GetRunApplicationUrl(application_id, service_environment));
+ if (service_url.empty()) {
+ LOG(ERROR) << "Unrecognized service type: " << service_environment;
+ return false;
}
+ DVLOG(1) << "Using remote host service request url: " << service_url;
remote_host_info_callback_ = callback;
diff --git a/remoting/test/remote_host_info_fetcher.h b/remoting/test/remote_host_info_fetcher.h
index d3af340..984e375 100644
--- a/remoting/test/remote_host_info_fetcher.h
+++ b/remoting/test/remote_host_info_fetcher.h
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.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 net {
@@ -23,28 +24,6 @@ class URLRequestContextGetter;
namespace remoting {
namespace test {
-// Used by the RemoteHostInfoFetcher to make HTTP requests and also by the
-// unittests for this class to set fake response data for these URLs.
-const char kDevServiceEnvironmentUrlFormat[] =
- "https://www-googleapis-test.sandbox.google.com/appremoting/v1beta1_dev/"
- "applications/%s/run";
-const char kTestServiceEnvironmentUrlFormat[] =
- "https://www-googleapis-test.sandbox.google.com/appremoting/v1beta1/"
- "applications/%s/run";
-const char kStagingServiceEnvironmentUrlFormat[] =
- "https://www-googleapis-test.sandbox.google.com/appremoting/"
- "v1beta1_staging/applications/%s/run";
-
-// 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,
- kTestingEnvironment,
- kStagingEnvironment,
- kUnknownEnvironment
-};
-
// 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)>
diff --git a/remoting/test/remote_host_info_fetcher_unittest.cc b/remoting/test/remote_host_info_fetcher_unittest.cc
index 2f6f71c..b4dd9a7 100644
--- a/remoting/test/remote_host_info_fetcher_unittest.cc
+++ b/remoting/test/remote_host_info_fetcher_unittest.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "base/strings/stringprintf.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -88,20 +87,19 @@ void RemoteHostInfoFetcherTest::SetUp() {
message_loop_.reset(new base::MessageLoopForIO);
dev_service_environment_url_ =
- base::StringPrintf(kDevServiceEnvironmentUrlFormat, kTestApplicationId);
+ GetRunApplicationUrl(kTestApplicationId, kDeveloperEnvironment);
SetFakeResponse(GURL(dev_service_environment_url_),
kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
net::URLRequestStatus::FAILED);
test_service_environment_url_ =
- base::StringPrintf(kTestServiceEnvironmentUrlFormat, kTestApplicationId);
+ GetRunApplicationUrl(kTestApplicationId, kTestingEnvironment);
SetFakeResponse(GURL(test_service_environment_url_),
kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
net::URLRequestStatus::FAILED);
staging_service_environment_url_ =
- base::StringPrintf(kStagingServiceEnvironmentUrlFormat,
- kTestApplicationId);
+ GetRunApplicationUrl(kTestApplicationId, kStagingEnvironment);
SetFakeResponse(GURL(staging_service_environment_url_),
kRemoteHostInfoEmptyResponse, net::HTTP_NOT_FOUND,
net::URLRequestStatus::FAILED);