Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: chrome/browser/local_discovery/privet_url_fetcher_unittest.cc

Issue 166373006: Use persistent map of privet tokens for PrivetURLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/local_discovery/privet_url_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 scoped_ptr<base::DictionaryValue> saved_value_; 82 scoped_ptr<base::DictionaryValue> saved_value_;
83 bool raw_mode_; 83 bool raw_mode_;
84 }; 84 };
85 85
86 class PrivetURLFetcherTest : public ::testing::Test { 86 class PrivetURLFetcherTest : public ::testing::Test {
87 public: 87 public:
88 PrivetURLFetcherTest() { 88 PrivetURLFetcherTest() {
89 request_context_= new net::TestURLRequestContextGetter( 89 request_context_= new net::TestURLRequestContextGetter(
90 base::MessageLoopProxy::current()); 90 base::MessageLoopProxy::current());
91 privet_urlfetcher_.reset(new PrivetURLFetcher( 91 privet_urlfetcher_.reset(new PrivetURLFetcher(
92 kSamplePrivetToken,
93 GURL(kSamplePrivetURL), 92 GURL(kSamplePrivetURL),
94 net::URLFetcher::POST, 93 net::URLFetcher::POST,
95 request_context_.get(), 94 request_context_.get(),
96 &delegate_)); 95 &delegate_));
96
97 PrivetURLFetcher::SetTokenForHost(GURL(kSamplePrivetURL).GetOrigin().spec(),
98 kSamplePrivetToken);
97 } 99 }
98 virtual ~PrivetURLFetcherTest() { 100 virtual ~PrivetURLFetcherTest() {
99 } 101 }
100 102
101 void RunFor(base::TimeDelta time_period) { 103 void RunFor(base::TimeDelta time_period) {
102 base::CancelableCallback<void()> callback(base::Bind( 104 base::CancelableCallback<void()> callback(base::Bind(
103 &PrivetURLFetcherTest::Stop, base::Unretained(this))); 105 &PrivetURLFetcherTest::Stop, base::Unretained(this)));
104 base::MessageLoop::current()->PostDelayedTask( 106 base::MessageLoop::current()->PostDelayedTask(
105 FROM_HERE, callback.callback(), time_period); 107 FROM_HERE, callback.callback(), time_period);
106 108
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ASSERT_TRUE(fetcher != NULL); 199 ASSERT_TRUE(fetcher != NULL);
198 net::HttpRequestHeaders headers; 200 net::HttpRequestHeaders headers;
199 fetcher->GetExtraRequestHeaders(&headers); 201 fetcher->GetExtraRequestHeaders(&headers);
200 202
201 std::string header_token; 203 std::string header_token;
202 ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token)); 204 ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token));
203 EXPECT_EQ(kSamplePrivetToken, header_token); 205 EXPECT_EQ(kSamplePrivetToken, header_token);
204 } 206 }
205 207
206 TEST_F(PrivetURLFetcherTest, Header2) { 208 TEST_F(PrivetURLFetcherTest, Header2) {
207 privet_urlfetcher_.reset(new PrivetURLFetcher( 209 PrivetURLFetcher::SetTokenForHost(GURL(kSamplePrivetURL).GetOrigin().spec(),
208 "", 210 "");
209 GURL(kSamplePrivetURL),
210 net::URLFetcher::POST,
211 request_context_.get(),
212 &delegate_));
213 211
214 privet_urlfetcher_->AllowEmptyPrivetToken(); 212 privet_urlfetcher_->AllowEmptyPrivetToken();
215 privet_urlfetcher_->Start(); 213 privet_urlfetcher_->Start();
216 214
217 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 215 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
218 ASSERT_TRUE(fetcher != NULL); 216 ASSERT_TRUE(fetcher != NULL);
219 net::HttpRequestHeaders headers; 217 net::HttpRequestHeaders headers;
220 fetcher->GetExtraRequestHeaders(&headers); 218 fetcher->GetExtraRequestHeaders(&headers);
221 219
222 std::string header_token; 220 std::string header_token;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 net::OK)); 275 net::OK));
278 fetcher->set_response_code(200); 276 fetcher->set_response_code(200);
279 277
280 EXPECT_CALL(delegate_, OnFileInternal()); 278 EXPECT_CALL(delegate_, OnFileInternal());
281 fetcher->delegate()->OnURLFetchComplete(fetcher); 279 fetcher->delegate()->OnURLFetchComplete(fetcher);
282 } 280 }
283 281
284 } // namespace 282 } // namespace
285 283
286 } // namespace local_discovery 284 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_url_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698