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

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 1171183002: Use struct AlternativeService in OnAltSvc() and OnSpdyAltSvc() methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <iostream> 6 #include <iostream>
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ++push_promise_frame_count_; 420 ++push_promise_frame_count_;
421 InitHeaderStreaming(PUSH_PROMISE, stream_id); 421 InitHeaderStreaming(PUSH_PROMISE, stream_id);
422 last_push_promise_stream_ = stream_id; 422 last_push_promise_stream_ = stream_id;
423 last_push_promise_promised_stream_ = promised_stream_id; 423 last_push_promise_promised_stream_ = promised_stream_id;
424 } 424 }
425 425
426 void OnContinuation(SpdyStreamId stream_id, bool end) override { 426 void OnContinuation(SpdyStreamId stream_id, bool end) override {
427 ++continuation_count_; 427 ++continuation_count_;
428 } 428 }
429 429
430 void OnAltSvc(SpdyStreamId stream_id, 430 void OnAltSvc(
431 uint32 max_age, 431 SpdyStreamId stream_id,
432 uint16 port, 432 StringPiece origin,
433 StringPiece protocol_id, 433 const SpdyAltSvcWireFormat::AlternativeService& altsvc) override {
434 StringPiece host,
435 StringPiece origin) override {
436 test_altsvc_ir_.set_stream_id(stream_id); 434 test_altsvc_ir_.set_stream_id(stream_id);
437 test_altsvc_ir_.set_max_age(max_age);
438 test_altsvc_ir_.set_port(port);
439 test_altsvc_ir_.set_protocol_id(protocol_id.as_string());
440 test_altsvc_ir_.set_host(host.as_string());
441 if (origin.length() > 0) { 435 if (origin.length() > 0) {
442 test_altsvc_ir_.set_origin(origin.as_string()); 436 test_altsvc_ir_.set_origin(origin.as_string());
443 } 437 }
438 test_altsvc_ir_.set_protocol_id(altsvc.protocol_id);
439 test_altsvc_ir_.set_host(altsvc.host);
440 test_altsvc_ir_.set_port(altsvc.port);
441 test_altsvc_ir_.set_max_age(altsvc.max_age);
442 test_altsvc_ir_.set_p(altsvc.p);
444 ++altsvc_count_; 443 ++altsvc_count_;
445 } 444 }
446 445
447 void OnPriority(SpdyStreamId stream_id, 446 void OnPriority(SpdyStreamId stream_id,
448 SpdyStreamId parent_stream_id, 447 SpdyStreamId parent_stream_id,
449 uint8 weight, 448 uint8 weight,
450 bool exclusive) override { 449 bool exclusive) override {
451 ++priority_count_; 450 ++priority_count_;
452 } 451 }
453 452
(...skipping 5233 matching lines...) Expand 10 before | Expand all | Expand 10 after
5687 if (spdy_version_ <= SPDY3) { 5686 if (spdy_version_ <= SPDY3) {
5688 return; 5687 return;
5689 } 5688 }
5690 5689
5691 const SpdyStreamId kStreamId = 1; 5690 const SpdyStreamId kStreamId = 1;
5692 5691
5693 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5692 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5694 SpdyFramer framer(spdy_version_); 5693 SpdyFramer framer(spdy_version_);
5695 framer.set_visitor(&visitor); 5694 framer.set_visitor(&visitor);
5696 5695
5697 EXPECT_CALL(visitor, OnAltSvc(kStreamId, 5696 SpdyAltSvcWireFormat::AlternativeService altsvc;
5698 10, 5697 altsvc.protocol_id = "p\"=i:d";
5699 443, 5698 altsvc.host = "h_\\o\"st";
5700 StringPiece("pid"), 5699 altsvc.port = 443;
5701 StringPiece("h1"), 5700 altsvc.max_age = 10;
5702 StringPiece("o1"))); 5701 altsvc.p = 1.0;
5702 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc));
5703 5703
5704 SpdyAltSvcIR altsvc_ir(1); 5704 SpdyAltSvcIR altsvc_ir(1);
5705 altsvc_ir.set_max_age(10); 5705 altsvc_ir.set_max_age(10);
5706 altsvc_ir.set_port(443); 5706 altsvc_ir.set_port(443);
5707 altsvc_ir.set_protocol_id("pid"); 5707 altsvc_ir.set_protocol_id("p\"=i:d");
5708 altsvc_ir.set_host("h1"); 5708 altsvc_ir.set_host("h_\\o\"st");
5709 altsvc_ir.set_origin("o1"); 5709 altsvc_ir.set_origin("o_r|g!n");
5710 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); 5710 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir));
5711 framer.ProcessInput(frame->data(), frame->size()); 5711 framer.ProcessInput(frame->data(), frame->size());
5712 5712
5713 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5713 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5714 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5714 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5715 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5715 << SpdyFramer::ErrorCodeToString(framer.error_code());
5716 } 5716 }
5717 5717
5718 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { 5718 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) {
5719 if (spdy_version_ <= SPDY3) { 5719 if (spdy_version_ <= SPDY3) {
5720 return; 5720 return;
5721 } 5721 }
5722 5722
5723 const SpdyStreamId kStreamId = 1; 5723 const SpdyStreamId kStreamId = 1;
5724 5724
5725 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5725 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5726 SpdyFramer framer(spdy_version_); 5726 SpdyFramer framer(spdy_version_);
5727 framer.set_visitor(&visitor); 5727 framer.set_visitor(&visitor);
5728 5728
5729 EXPECT_CALL(visitor, 5729 SpdyAltSvcWireFormat::AlternativeService altsvc;
5730 OnAltSvc(kStreamId, 10, 443, StringPiece("p\"=i:d"), 5730 altsvc.protocol_id = "p\"=i:d";
5731 StringPiece("h_\\o\"st"), StringPiece("o_r|g!n"))); 5731 altsvc.host = "h_\\o\"st";
5732 altsvc.port = 443;
5733 altsvc.max_age = 10;
5734 altsvc.p = 1.0;
5735 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc));
5732 5736
5733 SpdyAltSvcIR altsvc_ir(1); 5737 SpdyAltSvcIR altsvc_ir(1);
5734 altsvc_ir.set_max_age(10); 5738 altsvc_ir.set_max_age(10);
5735 altsvc_ir.set_port(443); 5739 altsvc_ir.set_port(443);
5736 altsvc_ir.set_protocol_id("p\"=i:d"); 5740 altsvc_ir.set_protocol_id("p\"=i:d");
5737 altsvc_ir.set_host("h_\\o\"st"); 5741 altsvc_ir.set_host("h_\\o\"st");
5738 altsvc_ir.set_origin("o_r|g!n");
5739 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); 5742 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir));
5740 framer.ProcessInput(frame->data(), frame->size()); 5743 framer.ProcessInput(frame->data(), frame->size());
5741 5744
5742 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5745 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5743 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5746 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5744 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5747 << SpdyFramer::ErrorCodeToString(framer.error_code());
5745 } 5748 }
5746 5749
5747 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { 5750 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) {
5748 if (spdy_version_ <= SPDY3) { 5751 if (spdy_version_ <= SPDY3) {
(...skipping 23 matching lines...) Expand all
5772 if (spdy_version_ <= SPDY3) { 5775 if (spdy_version_ <= SPDY3) {
5773 return; 5776 return;
5774 } 5777 }
5775 5778
5776 const SpdyStreamId kStreamId = 1; 5779 const SpdyStreamId kStreamId = 1;
5777 5780
5778 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5781 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5779 SpdyFramer framer(spdy_version_); 5782 SpdyFramer framer(spdy_version_);
5780 framer.set_visitor(&visitor); 5783 framer.set_visitor(&visitor);
5781 5784
5782 EXPECT_CALL(visitor, OnAltSvc(kStreamId, 10, 443, StringPiece("pid"), 5785 SpdyAltSvcWireFormat::AlternativeService altsvc;
5783 StringPiece("h1"), StringPiece(""))); 5786 altsvc.protocol_id = "pid";
5787 altsvc.host = "h1";
5788 altsvc.port = 443;
5789 altsvc.max_age = 10;
5790 altsvc.p = 1.0;
5791 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc));
5784 5792
5785 SpdyAltSvcIR altsvc_ir(1); 5793 SpdyAltSvcIR altsvc_ir(1);
5786 altsvc_ir.set_max_age(10); 5794 altsvc_ir.set_max_age(10);
5787 altsvc_ir.set_port(443); 5795 altsvc_ir.set_port(443);
5788 altsvc_ir.set_protocol_id("pid"); 5796 altsvc_ir.set_protocol_id("pid");
5789 altsvc_ir.set_host("h1"); 5797 altsvc_ir.set_host("h1");
5790 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); 5798 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir));
5791 framer.ProcessInput(frame->data(), frame->size()); 5799 framer.ProcessInput(frame->data(), frame->size());
5792 5800
5793 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5801 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
5902 5910
5903 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); 5911 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state());
5904 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 5912 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5905 visitor.framer_.error_code()) 5913 visitor.framer_.error_code())
5906 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); 5914 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code());
5907 } 5915 }
5908 5916
5909 } // namespace test 5917 } // namespace test
5910 5918
5911 } // namespace net 5919 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698