| Index: third_party/WebKit/Source/core/loader/NetworkQuietDetectorTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/loader/NetworkQuietDetectorTest.cpp b/third_party/WebKit/Source/core/loader/NetworkQuietDetectorTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fd4bb67a473fbe9df8049f9717cdf49eceaedd68
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/loader/NetworkQuietDetectorTest.cpp
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2016 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 "core/loader/NetworkQuietDetector.h"
|
| +
|
| +#include "core/testing/DummyPageHolder.h"
|
| +#include "platform/testing/TestingPlatformSupport.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace blink {
|
| +
|
| +class NetworkQuietDetectorTest : public testing::Test {
|
| + protected:
|
| + void SetUp() override {
|
| + platform_->AdvanceClockSeconds(1);
|
| + dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600));
|
| + }
|
| +
|
| + double AdvanceClockAndGetTime() {
|
| + platform_->AdvanceClockSeconds(1);
|
| + return MonotonicallyIncreasingTime();
|
| + }
|
| +
|
| + Document& GetDocument() { return dummy_page_holder_->GetDocument(); }
|
| + NetworkQuietDetector& Detector() {
|
| + return NetworkQuietDetector::From(GetDocument());
|
| + }
|
| +
|
| + void SimulateNetworkStable() {
|
| + GetDocument().SetParsingState(Document::kFinishedParsing);
|
| + Detector().Network2QuietTimerFired(nullptr);
|
| + }
|
| +
|
| + void SimulateNetwork2Quiet() {
|
| + GetDocument().SetParsingState(Document::kFinishedParsing);
|
| + Detector().Network2QuietTimerFired(nullptr);
|
| + }
|
| +
|
| + void SetActiveConnections(int connections) {
|
| + Detector().SetNetworkQuietTimers(connections);
|
| + }
|
| +
|
| + bool IsNetwork2QuietTimerActive() {
|
| + return Detector().network2_quiet_timer_.IsActive();
|
| + }
|
| +
|
| + bool HadNetwork2Quiet() { return Detector().network2_quiet_reached_; }
|
| +
|
| + protected:
|
| + ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
|
| + platform_;
|
| +
|
| + static constexpr double kNetwork2QuietWindowSeconds =
|
| + NetworkQuietDetector::kNetwork2QuietWindowSeconds;
|
| +
|
| + private:
|
| + std::unique_ptr<DummyPageHolder> dummy_page_holder_;
|
| +};
|
| +
|
| +TEST_F(NetworkQuietDetectorTest, Network2QuietTimer) {
|
| + SetActiveConnections(3);
|
| + EXPECT_FALSE(IsNetwork2QuietTimerActive());
|
| +
|
| + SetActiveConnections(2);
|
| + platform_->RunForPeriodSeconds(kNetwork2QuietWindowSeconds - 0.1);
|
| + EXPECT_TRUE(IsNetwork2QuietTimerActive());
|
| + EXPECT_FALSE(HadNetwork2Quiet());
|
| +
|
| + SetActiveConnections(2); // This should reset the 2-quiet timer.
|
| + platform_->RunForPeriodSeconds(kNetwork2QuietWindowSeconds - 0.1);
|
| + EXPECT_TRUE(IsNetwork2QuietTimerActive());
|
| + EXPECT_FALSE(HadNetwork2Quiet());
|
| +
|
| + SetActiveConnections(1); // This should not reset the 2-quiet timer.
|
| + platform_->RunForPeriodSeconds(0.1001);
|
| + EXPECT_TRUE(HadNetwork2Quiet());
|
| +}
|
| +
|
| +} // namespace blink
|
|
|