2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
#include "packager/media/base/http_key_fetcher.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
|
|
|
#include "packager/base/strings/string_util.h"
|
|
|
|
#include "packager/media/base/status_test_util.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char kTestUrl[] = "http://packager-test.appspot.com/http_test";
|
|
|
|
const char kTestUrlWithPort[] = "http://packager-test.appspot.com:80/http_test";
|
|
|
|
const char kExpectedGetResponse[] =
|
|
|
|
"<html><head><title>http_test</title></head><body><pre>"
|
|
|
|
"Arguments()</pre></body></html>";
|
|
|
|
const char kPostData[] = "foo=62&type=mp4";
|
|
|
|
const char kExpectedPostResponse[] =
|
|
|
|
"<html><head><title>http_test</title></head><body><pre>"
|
|
|
|
"Arguments([foo]=>62[type]=>mp4)</pre></body></html>";
|
2014-06-18 01:33:07 +00:00
|
|
|
const char kDelayTwoSecs[] = "delay=2"; // This causes host to delay 2 seconds.
|
2013-12-16 17:13:29 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-12-16 17:13:29 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
static void CheckHttpGet(const std::string& url,
|
|
|
|
const std::string& expected_response) {
|
2014-10-07 21:33:08 +00:00
|
|
|
HttpKeyFetcher fetcher;
|
2013-12-16 17:13:29 +00:00
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.Get(url, &response));
|
2014-02-26 23:55:01 +00:00
|
|
|
base::RemoveChars(response, "\r\n\t ", &response);
|
2013-12-16 17:13:29 +00:00
|
|
|
EXPECT_EQ(expected_response, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckHttpPost(const std::string& url, const std::string& data,
|
|
|
|
const std::string& expected_response) {
|
2014-10-07 21:33:08 +00:00
|
|
|
HttpKeyFetcher fetcher;
|
2013-12-16 17:13:29 +00:00
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.Post(url, data, &response));
|
2014-02-26 23:55:01 +00:00
|
|
|
base::RemoveChars(response, "\r\n\t ", &response);
|
2013-12-16 17:13:29 +00:00
|
|
|
EXPECT_EQ(expected_response, response);
|
|
|
|
}
|
|
|
|
|
2014-06-18 01:33:07 +00:00
|
|
|
TEST(DISABLED_HttpFetcherTest, HttpGet) {
|
2013-12-16 17:13:29 +00:00
|
|
|
CheckHttpGet(kTestUrl, kExpectedGetResponse);
|
|
|
|
}
|
|
|
|
|
2014-06-18 01:33:07 +00:00
|
|
|
TEST(DISABLED_HttpFetcherTest, HttpPost) {
|
2013-12-16 17:13:29 +00:00
|
|
|
CheckHttpPost(kTestUrl, kPostData, kExpectedPostResponse);
|
|
|
|
}
|
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
TEST(DISABLED_HttpKeyFetcherTest, HttpFetchKeys) {
|
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.FetchKeys(kTestUrl, kPostData, &response));
|
|
|
|
base::RemoveChars(response, "\r\n\t ", &response);
|
|
|
|
EXPECT_EQ(kExpectedPostResponse, response);
|
|
|
|
}
|
2014-06-18 01:33:07 +00:00
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
TEST(DISABLED_HttpKeyFetcherTest, InvalidUrl) {
|
|
|
|
const char kHttpNotFound[] = "404";
|
|
|
|
HttpKeyFetcher fetcher;
|
2013-12-16 17:13:29 +00:00
|
|
|
std::string response;
|
|
|
|
const std::string invalid_url(kTestUrl, sizeof(kTestUrl) - 2);
|
2014-10-07 21:33:08 +00:00
|
|
|
Status status = fetcher.FetchKeys(invalid_url, kPostData, &response);
|
2013-12-16 17:13:29 +00:00
|
|
|
EXPECT_EQ(error::HTTP_FAILURE, status.error_code());
|
2014-06-18 01:33:07 +00:00
|
|
|
EXPECT_NE(std::string::npos, status.error_message().find(kHttpNotFound));
|
2013-12-16 17:13:29 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
TEST(DISABLED_HttpKeyFetcherTest, UrlWithPort) {
|
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.FetchKeys(kTestUrlWithPort, kPostData, &response));
|
|
|
|
base::RemoveChars(response, "\r\n\t ", &response);
|
|
|
|
EXPECT_EQ(kExpectedPostResponse, response);
|
2013-12-16 17:13:29 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
TEST(DISABLED_HttpKeyFetcherTest, SmallTimeout) {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kTimeoutInSeconds = 1;
|
2014-10-07 21:33:08 +00:00
|
|
|
HttpKeyFetcher fetcher(kTimeoutInSeconds);
|
2014-06-18 01:33:07 +00:00
|
|
|
std::string response;
|
2014-10-07 21:33:08 +00:00
|
|
|
Status status = fetcher.FetchKeys(kTestUrl, kDelayTwoSecs, &response);
|
2014-06-18 01:33:07 +00:00
|
|
|
EXPECT_EQ(error::TIME_OUT, status.error_code());
|
|
|
|
}
|
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
TEST(DISABLED_HttpKeyFetcherTest, BigTimeout) {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kTimeoutInSeconds = 5;
|
2014-10-07 21:33:08 +00:00
|
|
|
HttpKeyFetcher fetcher(kTimeoutInSeconds);
|
2014-06-18 01:33:07 +00:00
|
|
|
std::string response;
|
2014-10-07 21:33:08 +00:00
|
|
|
Status status = fetcher.FetchKeys(kTestUrl, kDelayTwoSecs, &response);
|
2014-06-18 01:33:07 +00:00
|
|
|
EXPECT_OK(status);
|
|
|
|
}
|
|
|
|
|
2013-12-16 17:13:29 +00:00
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-12-16 17:13:29 +00:00
|
|
|
|