summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/loader/frame_resource_fetcher_properties_test.cc
blob: 968851a1b2830e3f4688ccffc9903bba82db4d3f (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
49
50
// Copyright 2019 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 "third_party/blink/renderer/core/loader/frame_resource_fetcher_properties.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"

namespace blink {

class FrameResourceFetcherPropertiesTest : public testing::Test {
 public:
  FrameResourceFetcherPropertiesTest()
      : dummy_page_holder_(std::make_unique<DummyPageHolder>(IntSize(1, 1))),
        properties_(MakeGarbageCollected<FrameResourceFetcherProperties>(
            *dummy_page_holder_->GetDocument().Loader(),
            dummy_page_holder_->GetDocument())) {}

 protected:
  const std::unique_ptr<DummyPageHolder> dummy_page_holder_;
  const Persistent<FrameResourceFetcherProperties> properties_;
};

TEST_F(FrameResourceFetcherPropertiesTest, SubframeDeprioritization) {
  Settings* settings = dummy_page_holder_->GetDocument().GetSettings();
  GetNetworkStateNotifier().SetNetworkConnectionInfoOverride(
      true, WebConnectionType::kWebConnectionTypeCellular3G,
      WebEffectiveConnectionType::kType3G, 1 /* http_rtt_msec */,
      10.0 /* max_bandwidth_mbps */);

  // Experiment is not enabled, expect default values.
  EXPECT_FALSE(properties_->IsSubframeDeprioritizationEnabled());

  // Low priority iframes enabled but network is not slow enough.
  settings->SetLowPriorityIframesThreshold(WebEffectiveConnectionType::kType2G);
  EXPECT_FALSE(properties_->IsSubframeDeprioritizationEnabled());

  // Low priority iframes enabled and network is slow.
  GetNetworkStateNotifier().SetNetworkConnectionInfoOverride(
      true, WebConnectionType::kWebConnectionTypeCellular3G,
      WebEffectiveConnectionType::kType2G, 1 /* http_rtt_msec */,
      10.0 /* max_bandwidth_mbps */);
  EXPECT_TRUE(properties_->IsSubframeDeprioritizationEnabled());
}

}  // namespace blink