| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/log/file_net_log_observer.h" | 5 #include "net/log/file_net_log_observer.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); | 350 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); |
| 351 | 351 |
| 352 // Check that custom constant was correctly printed. | 352 // Check that custom constant was correctly printed. |
| 353 base::DictionaryValue* dict; | 353 base::DictionaryValue* dict; |
| 354 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 354 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 355 std::string constants_string; | 355 std::string constants_string; |
| 356 ASSERT_TRUE(dict->GetString("constants", &constants_string)); | 356 ASSERT_TRUE(dict->GetString("constants", &constants_string)); |
| 357 ASSERT_EQ(kConstantString, constants_string); | 357 ASSERT_EQ(kConstantString, constants_string); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithContext) { | 360 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) { |
| 361 TestClosure closure; | 361 TestClosure closure; |
| 362 | 362 |
| 363 StartObserving(nullptr, nullptr); | 363 StartObserving(nullptr, nullptr); |
| 364 | 364 |
| 365 // Create unique context. | 365 // Create dummy polled data |
| 366 TestURLRequestContext context(true); | 366 const char kDummyPolledDataPath[] = "dummy_path"; |
| 367 context.set_net_log(&net_log_); | 367 const char kDummyPolledDataString[] = "dummy_info"; |
| 368 const int kDummyParam = 75; | 368 std::unique_ptr<base::DictionaryValue> dummy_polled_data = |
| 369 std::unique_ptr<HttpNetworkSession::Params> params( | 369 base::MakeUnique<base::DictionaryValue>(); |
| 370 new HttpNetworkSession::Params); | 370 dummy_polled_data->SetString(kDummyPolledDataPath, kDummyPolledDataString); |
| 371 params->quic_idle_connection_timeout_seconds = kDummyParam; | |
| 372 context.set_http_network_session_params(std::move(params)); | |
| 373 context.Init(); | |
| 374 | 371 |
| 375 logger_->StopObserving(&context, closure.closure()); | 372 logger_->StopObserving(std::move(dummy_polled_data), closure.closure()); |
| 376 | 373 |
| 377 closure.WaitForResult(); | 374 closure.WaitForResult(); |
| 378 | 375 |
| 379 std::unique_ptr<base::Value> root; | 376 std::unique_ptr<base::Value> root; |
| 380 base::ListValue* events; | 377 base::ListValue* events; |
| 381 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); | 378 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); |
| 382 | 379 |
| 383 // Check that no events were written. | 380 // Check that no events were written. |
| 384 ASSERT_EQ(0u, events->GetSize()); | 381 ASSERT_EQ(0u, events->GetSize()); |
| 385 | 382 |
| 386 // Make sure additional information is present and validate it. | 383 // Make sure additional information is present and validate it. |
| 387 base::DictionaryValue* dict; | 384 base::DictionaryValue* dict; |
| 388 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 385 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 389 base::DictionaryValue* tab_info; | 386 base::DictionaryValue* polled_data; |
| 390 base::DictionaryValue* quic_info; | 387 std::string dummy_string; |
| 391 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); | 388 ASSERT_TRUE(dict->GetDictionary("polledData", &polled_data)); |
| 392 ASSERT_TRUE(tab_info->GetDictionary("quicInfo", &quic_info)); | 389 ASSERT_TRUE(polled_data->GetString(kDummyPolledDataPath, &dummy_string)); |
| 393 base::Value* timeout_value = nullptr; | 390 ASSERT_EQ(dummy_string, kDummyPolledDataString); |
| 394 int timeout; | |
| 395 ASSERT_TRUE( | |
| 396 quic_info->Get("idle_connection_timeout_seconds", &timeout_value)); | |
| 397 ASSERT_TRUE(timeout_value->GetAsInteger(&timeout)); | |
| 398 ASSERT_EQ(timeout, kDummyParam); | |
| 399 } | 391 } |
| 400 | 392 |
| 401 TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithContextWithActiveRequest) { | 393 TEST_P(FileNetLogObserverTest, |
| 394 GeneratesValidJSONWithPolledDataWithActiveRequest) { |
| 402 TestClosure closure; | 395 TestClosure closure; |
| 403 | 396 |
| 404 // Create context, start a request. | 397 // Create context, start a request. |
| 405 TestURLRequestContext context(true); | 398 TestURLRequestContext context(true); |
| 406 context.set_net_log(&net_log_); | 399 context.set_net_log(&net_log_); |
| 407 context.Init(); | 400 context.Init(); |
| 408 TestDelegate delegate; | 401 TestDelegate delegate; |
| 409 delegate.set_quit_on_complete(false); | 402 delegate.set_quit_on_complete(false); |
| 410 | 403 |
| 411 // URL doesn't matter. Requests can't fail synchronously. | 404 // URL doesn't matter. Requests can't fail synchronously. |
| 412 std::unique_ptr<URLRequest> request( | 405 std::unique_ptr<URLRequest> request( |
| 413 context.CreateRequest(GURL("blah:blah"), IDLE, &delegate)); | 406 context.CreateRequest(GURL("blah:blah"), IDLE, &delegate)); |
| 414 request->Start(); | 407 request->Start(); |
| 415 | 408 |
| 416 StartObserving(nullptr, &context); | 409 StartObserving(nullptr, &context); |
| 417 | 410 |
| 418 logger_->StopObserving(&context, closure.closure()); | 411 logger_->StopObserving(net::GetNetInfo(&context, NET_INFO_ALL_SOURCES), |
| 412 closure.closure()); |
| 419 | 413 |
| 420 closure.WaitForResult(); | 414 closure.WaitForResult(); |
| 421 | 415 |
| 422 std::unique_ptr<base::Value> root; | 416 std::unique_ptr<base::Value> root; |
| 423 base::ListValue* events; | 417 base::ListValue* events; |
| 424 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); | 418 ASSERT_TRUE(ReadNetLogFromDisk(&root, &events)); |
| 425 | 419 |
| 426 // Check that 1 event was written | 420 // Check that 1 event was written |
| 427 ASSERT_EQ(1u, events->GetSize()); | 421 ASSERT_EQ(1u, events->GetSize()); |
| 428 | 422 |
| 429 // Make sure additional information is present, but don't validate it. | 423 // Make sure additional information is present, but don't validate it. |
| 430 base::DictionaryValue* dict; | 424 base::DictionaryValue* dict; |
| 431 ASSERT_TRUE(root->GetAsDictionary(&dict)); | 425 ASSERT_TRUE(root->GetAsDictionary(&dict)); |
| 432 base::DictionaryValue* tab_info; | 426 base::DictionaryValue* polled_data; |
| 433 ASSERT_TRUE(dict->GetDictionary("tabInfo", &tab_info)); | 427 ASSERT_TRUE(dict->GetDictionary("polledData", &polled_data)); |
| 434 } | 428 } |
| 435 | 429 |
| 436 // Adds events concurrently from several different threads. The exact order of | 430 // Adds events concurrently from several different threads. The exact order of |
| 437 // events seen by this test is non-deterministic. | 431 // events seen by this test is non-deterministic. |
| 438 TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) { | 432 TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) { |
| 439 const size_t kNumThreads = 10; | 433 const size_t kNumThreads = 10; |
| 440 std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads); | 434 std::vector<std::unique_ptr<base::Thread>> threads(kNumThreads); |
| 441 // Start all the threads. Waiting for them to start is to hopefuly improve | 435 // Start all the threads. Waiting for them to start is to hopefuly improve |
| 442 // the odds of hitting interesting races once events start being added. | 436 // the odds of hitting interesting races once events start being added. |
| 443 for (size_t i = 0; i < threads.size(); ++i) { | 437 for (size_t i = 0; i < threads.size(); ++i) { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 // Check that there are events written to all files. | 827 // Check that there are events written to all files. |
| 834 for (int i = 0; i < kTotalNumFiles; i++) { | 828 for (int i = 0; i < kTotalNumFiles; i++) { |
| 835 ASSERT_GE(GetFileSize(GetEventFilePath(i)), | 829 ASSERT_GE(GetFileSize(GetEventFilePath(i)), |
| 836 static_cast<int64_t>(kEventSize)); | 830 static_cast<int64_t>(kEventSize)); |
| 837 } | 831 } |
| 838 } | 832 } |
| 839 | 833 |
| 840 } // namespace | 834 } // namespace |
| 841 | 835 |
| 842 } // namespace net | 836 } // namespace net |
| OLD | NEW |