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

Side by Side Diff: net/base/net_log_util_unittest.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/base/net_log_util.cc ('k') | net/base/net_util.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 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/base/net_log_util.h" 5 #include "net/base/net_log_util.h"
6 6
7 #include <set>
8
9 #include "base/files/file_path.h"
7 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/capturing_net_log_observer.h"
9 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
11 #include "net/http/http_cache.h" 15 #include "net/http/http_cache.h"
12 #include "net/http/http_transaction.h" 16 #include "net/http/http_transaction.h"
17 #include "net/test/spawned_test_server/spawned_test_server.h"
13 #include "net/url_request/url_request_test_util.h" 18 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
15 20
16 namespace net { 21 namespace net {
17 22
18 namespace { 23 namespace {
19 24
20 // Make sure GetNetConstants doesn't crash. 25 // Make sure GetNetConstants doesn't crash.
21 TEST(NetLogUtil, GetNetConstants) { 26 TEST(NetLogUtil, GetNetConstants) {
22 scoped_ptr<base::Value> constants(GetNetConstants()); 27 scoped_ptr<base::Value> constants(GetNetConstants());
(...skipping 19 matching lines...) Expand all
42 context.http_transaction_factory()->GetCache()->GetBackend( 47 context.http_transaction_factory()->GetCache()->GetBackend(
43 &backend, TestCompletionCallback().callback())); 48 &backend, TestCompletionCallback().callback()));
44 EXPECT_TRUE(http_cache->GetCurrentBackend()); 49 EXPECT_TRUE(http_cache->GetCurrentBackend());
45 scoped_ptr<base::DictionaryValue> net_info_with_cache( 50 scoped_ptr<base::DictionaryValue> net_info_with_cache(
46 GetNetInfo(&context, NET_INFO_ALL_SOURCES)); 51 GetNetInfo(&context, NET_INFO_ALL_SOURCES));
47 EXPECT_GT(net_info_with_cache->size(), 0u); 52 EXPECT_GT(net_info_with_cache->size(), 0u);
48 53
49 EXPECT_EQ(net_info_without_cache->size(), net_info_with_cache->size()); 54 EXPECT_EQ(net_info_without_cache->size(), net_info_with_cache->size());
50 } 55 }
51 56
57 // Make sure CreateNetLogEntriesForActiveObjects works for requests from a
58 // single URLRequestContext.
59 TEST(NetLogUtil, CreateNetLogEntriesForActiveObjectsOneContext) {
60 // Using same context for each iteration makes sure deleted requests don't
61 // appear in the list, or result in crashes.
62 TestURLRequestContext context(true);
63 NetLog net_log;
64 context.set_net_log(&net_log);
65 context.Init();
66 TestDelegate delegate;
67 for (size_t num_requests = 0; num_requests < 5; ++num_requests) {
68 ScopedVector<URLRequest> requests;
69 for (size_t i = 0; i < num_requests; ++i) {
70 requests.push_back(context.CreateRequest(
71 GURL("about:life"), DEFAULT_PRIORITY, &delegate, nullptr).release());
72 }
73 std::set<URLRequestContext*> contexts;
74 contexts.insert(&context);
75 CapturingNetLogObserver capturing_observer;
76 CreateNetLogEntriesForActiveObjects(contexts, &capturing_observer);
77 CapturedNetLogEntry::List entry_list;
78 capturing_observer.GetEntries(&entry_list);
79 ASSERT_EQ(num_requests, entry_list.size());
80
81 for (size_t i = 0; i < num_requests; ++i) {
82 EXPECT_EQ(entry_list[i].source.id, requests[i]->net_log().source().id);
83 }
84 }
85 }
86
87 // Make sure CreateNetLogEntriesForActiveObjects works with multiple
88 // URLRequestContexts.
89 TEST(NetLogUtil, CreateNetLogEntriesForActiveObjectsMultipleContexts) {
90 TestDelegate delegate;
91 for (size_t num_requests = 0; num_requests < 5; ++num_requests) {
92 ScopedVector<TestURLRequestContext> contexts;
93 ScopedVector<URLRequest> requests;
94 NetLog net_log;
95 std::set<URLRequestContext*> context_set;
96 for (size_t i = 0; i < num_requests; ++i) {
97 contexts.push_back(new TestURLRequestContext(true));
98 contexts[i]->set_net_log(&net_log);
99 contexts[i]->Init();
100 context_set.insert(contexts[i]);
101 requests.push_back(contexts[i]->CreateRequest(
102 GURL("about:hats"), DEFAULT_PRIORITY, &delegate, nullptr).release());
103 }
104 CapturingNetLogObserver capturing_observer;
105 CreateNetLogEntriesForActiveObjects(context_set, &capturing_observer);
106 CapturedNetLogEntry::List entry_list;
107 capturing_observer.GetEntries(&entry_list);
108 ASSERT_EQ(num_requests, entry_list.size());
109
110 for (size_t i = 0; i < num_requests; ++i) {
111 EXPECT_EQ(entry_list[i].source.id, requests[i]->net_log().source().id);
112 }
113 }
114 }
115
52 } // namespace 116 } // namespace
53 117
54 } // namespace net 118 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_log_util.cc ('k') | net/base/net_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698