#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-static const char kFakeUrl[] = "http://example.com";
+namespace autofill {
+
+static const char kFakeUrl[] = "https://example.com";
+static const char kFakeInsecureUrl[] = "http://example.com";
class ChromeDownloaderImplTest : public testing::Test {
public:
protected:
// Sets the response for the download.
void SetFakeResponse(const std::string& payload, net::HttpStatusCode code) {
- fake_factory_.SetFakeResponse(GURL(kFakeUrl),
+ fake_factory_.SetFakeResponse(url_,
payload,
code,
net::URLRequestStatus::SUCCESS);
net::TestURLRequestContextGetter* getter =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
ChromeDownloaderImpl impl(getter);
- impl.Download(kFakeUrl, BuildCallback());
+ impl.Download(url_.spec(), BuildCallback());
base::MessageLoop::current()->RunUntilIdle();
}
+ void set_url(const GURL& url) { url_ = url; }
const std::string& data() { return *data_; }
bool success() { return success_; }
base::MessageLoop loop_;
net::URLFetcherImplFactory factory_;
net::FakeURLFetcherFactory fake_factory_;
+ GURL url_;
scoped_ptr<std::string> data_;
bool success_;
};
TEST_F(ChromeDownloaderImplTest, Success) {
const char kFakePayload[] = "ham hock";
+ set_url(GURL(kFakeUrl));
SetFakeResponse(kFakePayload, net::HTTP_OK);
Download();
EXPECT_TRUE(success());
TEST_F(ChromeDownloaderImplTest, Failure) {
const char kFakePayload[] = "ham hock";
+ set_url(GURL(kFakeUrl));
SetFakeResponse(kFakePayload, net::HTTP_INTERNAL_SERVER_ERROR);
Download();
EXPECT_FALSE(success());
EXPECT_EQ(std::string(), data());
}
+
+TEST_F(ChromeDownloaderImplTest, RejectsInsecureScheme) {
+ const char kFakePayload[] = "ham hock";
+ set_url(GURL(kFakeInsecureUrl));
+ SetFakeResponse(kFakePayload, net::HTTP_OK);
+ Download();
+ EXPECT_FALSE(success());
+ EXPECT_EQ(std::string(), data());
+}
+
+} // namespace autofill