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

Side by Side Diff: net/http/http_server_properties_manager_unittest.cc

Issue 893403005: Add HttpServerPropertiesManagerTest.UpdateCacheWithPrefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use JSON. Created 5 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
« no previous file with comments | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/http/http_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 EXPECT_EQ(i, port_alternate_protocol.port); 639 EXPECT_EQ(i, port_alternate_protocol.port);
639 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); 640 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
640 } 641 }
641 642
642 // Verify SupportsQuic. 643 // Verify SupportsQuic.
643 IPAddressNumber address; 644 IPAddressNumber address;
644 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 645 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
645 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); 646 EXPECT_EQ("127.0.0.1", IPAddressToString(address));
646 } 647 }
647 648
649 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
650 const HostPortPair server_www("www.google.com", 80);
651 const HostPortPair server_mail("mail.google.com", 80);
652
653 // Set alternate protocol.
654 http_server_props_manager_->SetAlternateProtocol(server_www, 443, NPN_SPDY_3,
655 1.0);
656 http_server_props_manager_->SetAlternateProtocol(server_mail, 444,
657 NPN_SPDY_3_1, 0.2);
658
659 // Set ServerNetworkStats.
660 ServerNetworkStats stats;
661 stats.srtt = base::TimeDelta::FromInternalValue(42);
662 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
663
664 // Set SupportsQuic.
665 IPAddressNumber actual_address;
666 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
667 http_server_props_manager_->SetSupportsQuic(true, actual_address);
668
669 // Update cache.
670 ExpectPrefsUpdate();
671 ExpectCacheUpdate();
672 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
673 base::RunLoop().RunUntilIdle();
674
675 // Verify preferences.
676 const char expected_json[] = "{"
677 "\"servers\":{"
Bence 2015/02/05 14:53:24 This indentation is easier to read, but it is not
Ryan Hamilton 2015/02/05 15:29:13 Either way is fine with me. Your call.
678 "\"mail.google.com:80\":{"
679 "\"alternate_protocol\":{"
680 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\""
681 "},"
682 "\"network_stats\":{"
683 "\"srtt\":42"
684 "}"
685 "},"
686 "\"www.google.com:80\":{"
687 "\"alternate_protocol\":{"
688 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-spdy/3\""
689 "}"
690 "}"
691 "},"
692 "\"supports_quic\":{"
693 "\"address\":\"127.0.0.1\",\"used_quic\":true"
694 "},"
695 "\"version\":3"
696 "}";
697
698 const base::Value* http_server_properties =
699 pref_service_.GetUserPref(kTestHttpServerProperties);
700 ASSERT_NE(nullptr, http_server_properties);
701 std::string preferences_json;
702 EXPECT_TRUE(
703 base::JSONWriter::Write(http_server_properties, &preferences_json));
704 EXPECT_EQ(expected_json, preferences_json);
705 }
706
648 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 707 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
649 // Post an update task to the UI thread. 708 // Post an update task to the UI thread.
650 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 709 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
651 // Shutdown comes before the task is executed. 710 // Shutdown comes before the task is executed.
652 http_server_props_manager_->ShutdownOnPrefThread(); 711 http_server_props_manager_->ShutdownOnPrefThread();
653 http_server_props_manager_.reset(); 712 http_server_props_manager_.reset();
654 // Run the task after shutdown and deletion. 713 // Run the task after shutdown and deletion.
655 base::RunLoop().RunUntilIdle(); 714 base::RunLoop().RunUntilIdle();
656 } 715 }
657 716
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Run the task after shutdown, but before deletion. 772 // Run the task after shutdown, but before deletion.
714 base::RunLoop().RunUntilIdle(); 773 base::RunLoop().RunUntilIdle();
715 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 774 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
716 http_server_props_manager_.reset(); 775 http_server_props_manager_.reset();
717 base::RunLoop().RunUntilIdle(); 776 base::RunLoop().RunUntilIdle();
718 } 777 }
719 778
720 } // namespace 779 } // namespace
721 780
722 } // namespace net 781 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698