| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/local_discovery/privet_url_fetcher.h" | 5 #include "chrome/browser/local_discovery/privet_url_fetcher.h" |
| 6 #include "net/url_request/test_url_fetcher_factory.h" | 6 #include "net/url_request/test_url_fetcher_factory.h" |
| 7 #include "net/url_request/url_request_test_util.h" | 7 #include "net/url_request/url_request_test_util.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 MOCK_METHOD1(OnRawDataInternal, void(std::string data)); | 71 MOCK_METHOD1(OnRawDataInternal, void(std::string data)); |
| 72 | 72 |
| 73 MOCK_METHOD0(OnFileInternal, void()); | 73 MOCK_METHOD0(OnFileInternal, void()); |
| 74 | 74 |
| 75 const base::DictionaryValue* saved_value() { return saved_value_.get(); } | 75 const base::DictionaryValue* saved_value() { return saved_value_.get(); } |
| 76 | 76 |
| 77 void SetRawMode(bool raw_mode) { | 77 void SetRawMode(bool raw_mode) { |
| 78 raw_mode_ = raw_mode; | 78 raw_mode_ = raw_mode; |
| 79 } | 79 } |
| 80 | 80 |
| 81 std::string GetAuthToken() { return "MyAuthToken"; } |
| 82 |
| 81 private: | 83 private: |
| 82 scoped_ptr<base::DictionaryValue> saved_value_; | 84 scoped_ptr<base::DictionaryValue> saved_value_; |
| 83 bool raw_mode_; | 85 bool raw_mode_; |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 class PrivetURLFetcherTest : public ::testing::Test { | 88 class PrivetURLFetcherTest : public ::testing::Test { |
| 87 public: | 89 public: |
| 88 PrivetURLFetcherTest() { | 90 PrivetURLFetcherTest() { |
| 89 request_context_= new net::TestURLRequestContextGetter( | 91 request_context_= new net::TestURLRequestContextGetter( |
| 90 base::MessageLoopProxy::current()); | 92 base::MessageLoopProxy::current()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 fetcher->SetResponseFilePath( | 291 fetcher->SetResponseFilePath( |
| 290 base::FilePath(FILE_PATH_LITERAL("sample/file"))); | 292 base::FilePath(FILE_PATH_LITERAL("sample/file"))); |
| 291 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 293 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 292 net::OK)); | 294 net::OK)); |
| 293 fetcher->set_response_code(200); | 295 fetcher->set_response_code(200); |
| 294 | 296 |
| 295 EXPECT_CALL(delegate_, OnFileInternal()); | 297 EXPECT_CALL(delegate_, OnFileInternal()); |
| 296 fetcher->delegate()->OnURLFetchComplete(fetcher); | 298 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 297 } | 299 } |
| 298 | 300 |
| 301 TEST_F(PrivetURLFetcherTest, V3Mode) { |
| 302 delegate_.SetRawMode(true); |
| 303 privet_urlfetcher_->V3Mode(); |
| 304 privet_urlfetcher_->Start(); |
| 305 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
| 306 ASSERT_TRUE(fetcher != NULL); |
| 307 fetcher->SetResponseFilePath( |
| 308 base::FilePath(FILE_PATH_LITERAL("sample/file"))); |
| 309 net::HttpRequestHeaders headers; |
| 310 fetcher->GetExtraRequestHeaders(&headers); |
| 311 |
| 312 std::string header_token; |
| 313 ASSERT_FALSE(headers.GetHeader("X-Privet-Token", &header_token)); |
| 314 ASSERT_TRUE(headers.GetHeader("X-Privet-Auth", &header_token)); |
| 315 ASSERT_EQ("MyAuthToken", header_token); |
| 316 } |
| 317 |
| 299 } // namespace | 318 } // namespace |
| 300 | 319 |
| 301 } // namespace local_discovery | 320 } // namespace local_discovery |
| OLD | NEW |