Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / metrics / net / net_metrics_log_uploader_unittest.cc
blobc205b42941f9ff91e1a799d6bfc2cc9742234bfd
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
3 // found in the LICENSE file.
5 #include "components/metrics/net/net_metrics_log_uploader.h"
7 #include "base/bind.h"
8 #include "net/url_request/test_url_fetcher_factory.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace metrics {
13 class NetMetricsLogUploaderTest : public testing::Test {
14 public:
15 NetMetricsLogUploaderTest() : on_upload_complete_count_(0) {
18 void CreateAndOnUploadCompleteReuseUploader() {
19 uploader_.reset(new NetMetricsLogUploader(
20 NULL, "http://dummy_server", "dummy_mime",
21 base::Bind(&NetMetricsLogUploaderTest::OnUploadCompleteReuseUploader,
22 base::Unretained(this))));
23 uploader_->UploadLog("initial_dummy_data", "initial_dummy_hash");
26 void OnUploadCompleteReuseUploader(int response_code) {
27 ++on_upload_complete_count_;
28 if (on_upload_complete_count_ == 1)
29 uploader_->UploadLog("dummy_data", "dummy_hash");
32 int on_upload_complete_count() const {
33 return on_upload_complete_count_;
36 private:
37 scoped_ptr<NetMetricsLogUploader> uploader_;
38 int on_upload_complete_count_;
40 DISALLOW_COPY_AND_ASSIGN(NetMetricsLogUploaderTest);
43 TEST_F(NetMetricsLogUploaderTest, OnUploadCompleteReuseUploader) {
44 net::TestURLFetcherFactory factory;
45 CreateAndOnUploadCompleteReuseUploader();
47 // Mimic the initial fetcher callback.
48 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
49 fetcher->delegate()->OnURLFetchComplete(fetcher);
51 // Mimic the second fetcher callback.
52 fetcher = factory.GetFetcherByID(0);
53 fetcher->delegate()->OnURLFetchComplete(fetcher);
55 EXPECT_EQ(on_upload_complete_count(), 2);
58 } // namespace metrics