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

Unified Diff: chrome/browser/local_discovery/privet_http_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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/local_discovery/privet_http_unittest.cc
diff --git a/chrome/browser/local_discovery/privet_http_unittest.cc b/chrome/browser/local_discovery/privet_http_unittest.cc
index 1a524feb8f66f039d1912189a30b7559bdc7111b..03db69c433b4712d8efd6c042b649bee83db11d4 100644
--- a/chrome/browser/local_discovery/privet_http_unittest.cc
+++ b/chrome/browser/local_discovery/privet_http_unittest.cc
@@ -202,6 +202,8 @@ class MockTestURLFetcherFactoryDelegate
class PrivetHTTPTest : public ::testing::Test {
public:
PrivetHTTPTest() {
+ PrivetURLFetcher::ResetTokenMapForTests();
+
request_context_= new net::TestURLRequestContextGetter(
base::MessageLoopProxy::current());
privet_client_.reset(new PrivetHTTPClientImpl(
@@ -442,37 +444,6 @@ TEST_F(PrivetInfoTest, SuccessfulInfo) {
EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal());
fetcher->delegate()->OnURLFetchComplete(fetcher);
-
- std::string name;
-
- privet_client_->GetCachedInfo()->GetString("name", &name);
- EXPECT_EQ("Common printer", name);
-};
-
-TEST_F(PrivetInfoTest, InfoSaveToken) {
- info_operation_->Start();
-
- net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
- ASSERT_TRUE(fetcher != NULL);
- fetcher->SetResponseString(kSampleInfoResponse);
- fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
- net::OK));
- fetcher->set_response_code(200);
-
- EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal());
- fetcher->delegate()->OnURLFetchComplete(fetcher);
-
- info_operation_ =
- privet_client_->CreateInfoOperation(info_callback_.callback());
- info_operation_->Start();
-
- fetcher = fetcher_factory_.GetFetcherByID(0);
- ASSERT_TRUE(fetcher != NULL);
- net::HttpRequestHeaders headers;
- fetcher->GetExtraRequestHeaders(&headers);
- std::string header_token;
- ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token));
- EXPECT_EQ("SampleTokenForTesting", header_token);
};
TEST_F(PrivetInfoTest, InfoFailureHTTP) {
@@ -486,7 +457,6 @@ TEST_F(PrivetInfoTest, InfoFailureHTTP) {
EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal());
fetcher->delegate()->OnURLFetchComplete(fetcher);
- EXPECT_EQ(NULL, privet_client_->GetCachedInfo());
};
class PrivetRegisterTest : public PrivetHTTPTest {
@@ -528,15 +498,12 @@ class PrivetRegisterTest : public PrivetHTTPTest {
};
TEST_F(PrivetRegisterTest, RegisterSuccessSimple) {
- // Start with info request first to populate XSRF token.
- info_operation_->Start();
+ register_operation_->Start();
EXPECT_TRUE(SuccessfulResponseToURL(
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponse));
- register_operation_->Start();
-
EXPECT_TRUE(SuccessfulResponseToURL(
GURL("http://10.0.0.8:6006/privet/register?"
"action=start&user=example%40google.com"),
@@ -566,19 +533,6 @@ TEST_F(PrivetRegisterTest, RegisterSuccessSimple) {
kSampleInfoResponseRegistered));
}
-TEST_F(PrivetRegisterTest, RegisterNoInfoCall) {
- register_operation_->Start();
-
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/info"),
- kSampleInfoResponse));
-
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/register?"
- "action=start&user=example%40google.com"),
- kSampleRegisterStartResponse));
-}
-
TEST_F(PrivetRegisterTest, RegisterXSRFFailure) {
register_operation_->Start();
@@ -672,15 +626,12 @@ TEST_F(PrivetRegisterTest, InfoFailure) {
}
TEST_F(PrivetRegisterTest, RegisterCancel) {
- // Start with info request first to populate XSRF token.
- info_operation_->Start();
+ register_operation_->Start();
EXPECT_TRUE(SuccessfulResponseToURL(
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponse));
- register_operation_->Start();
-
EXPECT_TRUE(SuccessfulResponseToURL(
GURL("http://10.0.0.8:6006/privet/register?"
"action=start&user=example%40google.com"),
@@ -786,6 +737,8 @@ class PrivetLocalPrintTest : public PrivetHTTPTest {
virtual ~PrivetLocalPrintTest() {}
virtual void SetUp() OVERRIDE {
+ PrivetURLFetcher::ResetTokenMapForTests();
+
local_print_operation_ = privet_client_->CreateLocalPrintOperation(
&local_print_delegate_);
@@ -817,9 +770,12 @@ TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrint) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponse));
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/capabilities"),
- kSampleCapabilitiesResponse));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
+ EXPECT_TRUE(
+ SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/capabilities"),
+ kSampleCapabilitiesResponse));
EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal());
@@ -843,9 +799,12 @@ TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponse));
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/capabilities"),
- kSampleCapabilitiesResponseWithAnyMimetype));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
+ EXPECT_TRUE(
+ SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/capabilities"),
+ kSampleCapabilitiesResponseWithAnyMimetype));
EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal());
@@ -869,9 +828,12 @@ TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponse));
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/capabilities"),
- kSampleCapabilitiesResponsePWGOnly));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
+ EXPECT_TRUE(
+ SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/capabilities"),
+ kSampleCapabilitiesResponsePWGOnly));
EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal());
@@ -896,9 +858,12 @@ TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponseWithCreatejob));
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/capabilities"),
- kSampleCapabilitiesResponse));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
+ EXPECT_TRUE(
+ SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/capabilities"),
+ kSampleCapabilitiesResponse));
EXPECT_TRUE(SuccessfulResponseToURLAndData(
GURL("http://10.0.0.8:6006/privet/printer/createjob"),
@@ -928,9 +893,12 @@ TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponseWithCreatejob));
- EXPECT_TRUE(SuccessfulResponseToURL(
- GURL("http://10.0.0.8:6006/privet/capabilities"),
- kSampleCapabilitiesResponse));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
+ EXPECT_TRUE(
+ SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/capabilities"),
+ kSampleCapabilitiesResponse));
EXPECT_TRUE(SuccessfulResponseToURLAndData(
GURL("http://10.0.0.8:6006/privet/printer/createjob"),
@@ -967,6 +935,9 @@ TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) {
GURL("http://10.0.0.8:6006/privet/info"),
kSampleInfoResponseWithCreatejob));
+ EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"),
+ kSampleInfoResponse));
+
EXPECT_TRUE(SuccessfulResponseToURL(
GURL("http://10.0.0.8:6006/privet/capabilities"),
kSampleCapabilitiesResponse));
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.cc ('k') | chrome/browser/local_discovery/privet_url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698