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
3 // found in the LICENSE file.
5 #include "net/base/net_log_util.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h"
11 #include "net/http/http_cache.h"
12 #include "net/http/http_transaction.h"
13 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
20 // Make sure GetNetConstants doesn't crash.
21 TEST(NetLogUtil, GetNetConstants) {
22 scoped_ptr<base::Value> constants(GetNetConstants());
25 // Make sure GetNetInfo doesn't crash when called on contexts with and without
26 // caches, and they have the same number of elements.
27 TEST(NetLogUtil, GetNetInfo) {
28 TestURLRequestContext context;
29 net::HttpCache* http_cache = context.http_transaction_factory()->GetCache();
31 // Get NetInfo when there's no cache backend (It's only created on first use).
32 EXPECT_FALSE(http_cache->GetCurrentBackend());
33 scoped_ptr<base::DictionaryValue> net_info_without_cache(
34 GetNetInfo(&context, NET_INFO_ALL_SOURCES));
35 EXPECT_FALSE(http_cache->GetCurrentBackend());
36 EXPECT_GT(net_info_without_cache->size(), 0u);
38 // Fore creation of a cache backend, and get NetInfo again.
39 disk_cache::Backend* backend = NULL;
42 context.http_transaction_factory()->GetCache()->GetBackend(
43 &backend, TestCompletionCallback().callback()));
44 EXPECT_TRUE(http_cache->GetCurrentBackend());
45 scoped_ptr<base::DictionaryValue> net_info_with_cache(
46 GetNetInfo(&context, NET_INFO_ALL_SOURCES));
47 EXPECT_GT(net_info_with_cache->size(), 0u);
49 EXPECT_EQ(net_info_without_cache->size(), net_info_with_cache->size());