Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / chromium / chrome_downloader_impl_unittest.cc
index 3d1cea1..15502f5 100644 (file)
@@ -9,7 +9,10 @@
 #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:
@@ -21,7 +24,7 @@ class ChromeDownloaderImplTest : public testing::Test {
  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);
@@ -32,10 +35,11 @@ class ChromeDownloaderImplTest : public testing::Test {
     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_; }
 
@@ -56,12 +60,14 @@ class ChromeDownloaderImplTest : public testing::Test {
   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());
@@ -70,8 +76,20 @@ TEST_F(ChromeDownloaderImplTest, 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