| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/metrics/net/net_metrics_log_uploader.h" | 5 #include "components/metrics/net/net_metrics_log_uploader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace metrics { | 12 namespace metrics { |
| 13 | 13 |
| 14 class NetMetricsLogUploaderTest : public testing::Test { | 14 class NetMetricsLogUploaderTest : public testing::Test { |
| 15 public: | 15 public: |
| 16 NetMetricsLogUploaderTest() : on_upload_complete_count_(0) { | 16 NetMetricsLogUploaderTest() : on_upload_complete_count_(0) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 void CreateAndOnUploadCompleteReuseUploader() { | 19 void CreateAndOnUploadCompleteReuseUploader() { |
| 20 uploader_.reset(new NetMetricsLogUploader( | 20 uploader_.reset(new NetMetricsLogUploader( |
| 21 NULL, "http://dummy_server", "dummy_mime", MetricsLogUploader::UMA, | 21 NULL, "http://dummy_server", "dummy_mime", MetricsLogUploader::UMA, |
| 22 base::Bind(&NetMetricsLogUploaderTest::OnUploadCompleteReuseUploader, | 22 base::Bind(&NetMetricsLogUploaderTest::OnUploadCompleteReuseUploader, |
| 23 base::Unretained(this)))); | 23 base::Unretained(this)))); |
| 24 uploader_->UploadLog("initial_dummy_data", "initial_dummy_hash"); | 24 uploader_->UploadLog("initial_dummy_data", "initial_dummy_hash"); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void OnUploadCompleteReuseUploader(int response_code) { | 27 void OnUploadCompleteReuseUploader(int response_code, int error_code) { |
| 28 ++on_upload_complete_count_; | 28 ++on_upload_complete_count_; |
| 29 if (on_upload_complete_count_ == 1) | 29 if (on_upload_complete_count_ == 1) |
| 30 uploader_->UploadLog("dummy_data", "dummy_hash"); | 30 uploader_->UploadLog("dummy_data", "dummy_hash"); |
| 31 } | 31 } |
| 32 | 32 |
| 33 int on_upload_complete_count() const { | 33 int on_upload_complete_count() const { |
| 34 return on_upload_complete_count_; | 34 return on_upload_complete_count_; |
| 35 } | 35 } |
| 36 | 36 |
| 37 private: | 37 private: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 fetcher->delegate()->OnURLFetchComplete(fetcher); | 50 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 51 | 51 |
| 52 // Mimic the second fetcher callback. | 52 // Mimic the second fetcher callback. |
| 53 fetcher = factory.GetFetcherByID(0); | 53 fetcher = factory.GetFetcherByID(0); |
| 54 fetcher->delegate()->OnURLFetchComplete(fetcher); | 54 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 55 | 55 |
| 56 EXPECT_EQ(on_upload_complete_count(), 2); | 56 EXPECT_EQ(on_upload_complete_count(), 2); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace metrics | 59 } // namespace metrics |
| OLD | NEW |