summaryrefslogtreecommitdiff
path: root/chromium/content/browser/net/network_quality_observer_impl_unittest.cc
blob: 1112635130e774667fd6c02b6b31f4a148e3096f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/net/network_quality_observer_impl.h"

#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/test/histogram_tester.h"
#include "base/time/time.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality_estimator_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
namespace {

TEST(NetworkQualityObserverImplTest, TestObserverNotified) {
  base::MessageLoopForIO message_loop;

  net::TestNetworkQualityEstimator estimator;
  estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(1));

  NetworkQualityObserverImpl observer(&estimator);
  // Give a chance for |observer| to register with the |estimator|.
  base::RunLoop().RunUntilIdle();

  base::HistogramTester histogram_tester;
  estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(500));
  // RTT changed from 1 msec to 500 msec.
  histogram_tester.ExpectBucketCount(
      "NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 1);

  estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(625));
  // RTT changed from 500 msec to 625 msec.
  histogram_tester.ExpectBucketCount(
      "NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 2);

  estimator.SetStartTimeNullHttpRtt(base::TimeDelta::FromMilliseconds(626));
  // RTT changed from 625 msec to 626 msec which is not a meaningful change.
  histogram_tester.ExpectBucketCount(
      "NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 1, 2);
  EXPECT_LE(1, histogram_tester.GetBucketCount(
                   "NQE.ContentObserver.NetworkQualityMeaningfullyChanged", 0));
}

}  // namespace
}  // namespace content