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

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

Issue 23780002: Actual cancelation of registration when cancel buttons pressed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/local_discovery/privet_http_impl.h" 7 #include "chrome/browser/local_discovery/privet_http_impl.h"
8 #include "net/base/host_port_pair.h" 8 #include "net/base/host_port_pair.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/url_request/test_url_fetcher_factory.h" 10 #include "net/url_request/test_url_fetcher_factory.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 "{ \"error\": \"invalid_x_privet_token\" }"; 68 "{ \"error\": \"invalid_x_privet_token\" }";
69 69
70 const char kSampleRegisterErrorTransient[] = 70 const char kSampleRegisterErrorTransient[] =
71 "{ \"error\": \"device_busy\", \"timeout\": 1}"; 71 "{ \"error\": \"device_busy\", \"timeout\": 1}";
72 72
73 const char kSampleRegisterErrorPermanent[] = 73 const char kSampleRegisterErrorPermanent[] =
74 "{ \"error\": \"user_cancel\" }"; 74 "{ \"error\": \"user_cancel\" }";
75 75
76 const char kSampleInfoResponseBadJson[] = "{"; 76 const char kSampleInfoResponseBadJson[] = "{";
77 77
78 const char kSampleRegisterCancelResponse[] = "{"
79 "\"user\": \"example@google.com\","
80 "\"action\": \"cancel\""
81 "}";
82
78 class MockTestURLFetcherFactoryDelegate 83 class MockTestURLFetcherFactoryDelegate
79 : public net::TestURLFetcher::DelegateForTests { 84 : public net::TestURLFetcher::DelegateForTests {
80 public: 85 public:
81 // Callback issued correspondingly to the call to the |Start()| method. 86 // Callback issued correspondingly to the call to the |Start()| method.
82 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); 87 MOCK_METHOD1(OnRequestStart, void(int fetcher_id));
83 88
84 // Callback issued correspondingly to the call to |AppendChunkToUpload|. 89 // Callback issued correspondingly to the call to |AppendChunkToUpload|.
85 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. 90 // Uploaded chunks can be retrieved with the |upload_chunks()| getter.
86 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); 91 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id));
87 92
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 OnPrivetRegisterErrorInternal( 455 OnPrivetRegisterErrorInternal(
451 "info", 456 "info",
452 PrivetRegisterOperation::FAILURE_NETWORK, 457 PrivetRegisterOperation::FAILURE_NETWORK,
453 -1)); 458 -1));
454 459
455 EXPECT_TRUE(SuccessfulResponseToURL( 460 EXPECT_TRUE(SuccessfulResponseToURL(
456 GURL("http://10.0.0.8:6006/privet/info"), 461 GURL("http://10.0.0.8:6006/privet/info"),
457 kSampleInfoResponseBadJson)); 462 kSampleInfoResponseBadJson));
458 } 463 }
459 464
465
466 TEST_F(PrivetRegisterTest, RegisterCancel) {
467 // Start with info request first to populate XSRF token.
468 info_operation_->Start();
469
470 EXPECT_TRUE(SuccessfulResponseToURL(
471 GURL("http://10.0.0.8:6006/privet/info"),
472 kSampleInfoResponse));
473
474 register_operation_->Start();
475
476 EXPECT_TRUE(SuccessfulResponseToURL(
477 GURL("http://10.0.0.8:6006/privet/register?"
478 "action=start&user=example@google.com"),
479 kSampleRegisterStartResponse));
480
481 register_operation_->Cancel();
482
483 EXPECT_TRUE(SuccessfulResponseToURL(
484 GURL("http://10.0.0.8:6006/privet/register?"
485 "action=cancel&user=example@google.com"),
486 kSampleRegisterCancelResponse));
487
488 // Must keep mocks alive for 3 seconds so the cancelation object can be
489 // deleted.
490 RunFor(base::TimeDelta::FromSeconds(3));
491 }
492
460 } // namespace 493 } // namespace
461 494
462 } // namespace local_discovery 495 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.cc ('k') | chrome/browser/resources/local_discovery/local_discovery.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698