src/net/nqe/network_quality_estimator_util_unittest.cc
TEST(NetworkQualityEstimatorUtilTest,
     ReservedHostUncachedWithNetworkIsolationKey) {
  const url::Origin kOrigin = url::Origin::Create(GURL("https://foo.test/"));
  const net::NetworkIsolationKey kNetworkIsolationKey(kOrigin, kOrigin);

  base::test::ScopedFeatureList feature_list;
  feature_list.InitAndEnableFeature(
      features::kSplitHostCacheByNetworkIsolationKey);

  base::test::TaskEnvironment task_environment;

  MockCachingHostResolver mock_host_resolver;

  scoped_refptr<net::RuleBasedHostResolverProc> rules(
      new net::RuleBasedHostResolverProc(nullptr));

  // Add example3.com resolution to the DNS cache.
  rules->AddRule("example3.com", "127.0.0.3");
  mock_host_resolver.set_rules(rules.get());

  // Not in DNS host cache, so should not be marked as private.
  EXPECT_FALSE(IsPrivateHostForTesting(&mock_host_resolver,
                                       HostPortPair("example3.com", 443),
                                       kNetworkIsolationKey));
  EXPECT_EQ(0u, mock_host_resolver.num_non_local_resolves());

  int rv = mock_host_resolver.LoadIntoCache(
      HostPortPair("example3.com", 443), kNetworkIsolationKey, base::nullopt);
  EXPECT_EQ(OK, rv);
  EXPECT_EQ(1u, mock_host_resolver.num_non_local_resolves());

  EXPECT_TRUE(IsPrivateHostForTesting(&mock_host_resolver,
                                      HostPortPair("example3.com", 443),
                                      kNetworkIsolationKey));

  // IsPrivateHostForTesting() should have queried only the resolver's cache.
  EXPECT_EQ(1u, mock_host_resolver.num_non_local_resolves());

  // IsPrivateHostForTesting should return false when using a different
  // NetworkIsolationKey (in this case, any empty one).
  EXPECT_FALSE(IsPrivateHostForTesting(&mock_host_resolver,
                                       HostPortPair("example3.com", 443),
                                       NetworkIsolationKey()));
}
// Make sure that IsPrivateHostForTesting() uses the NetworkIsolationKey
// provided to it.
Make sure that IsPrivateHostForTesting() uses the NetworkIsolationKey
provided to it.
Make sure that IsPrivateHostForTesting () uses the NetworkIsolationKey provided to it .
TEST(NetworkQualityEstimatorUtilTest,
     ReservedHostUncachedWithNetworkIsolationKey) {
  const url::Origin kOrigin = url::Origin::Create(GURL("https://foo.test/"));
  const net::NetworkIsolationKey kNetworkIsolationKey(kOrigin, kOrigin);
  base::test::ScopedFeatureList feature_list;
  feature_list.InitAndEnableFeature(
      features::kSplitHostCacheByNetworkIsolationKey);
  base::test::TaskEnvironment task_environment;
  MockCachingHostResolver mock_host_resolver;
  scoped_refptr<net::RuleBasedHostResolverProc> rules(
      new net::RuleBasedHostResolverProc(nullptr));
  rules->AddRule("example3.com", "127.0.0.3");
  mock_host_resolver.set_rules(rules.get());
  EXPECT_FALSE(IsPrivateHostForTesting(&mock_host_resolver,
                                       HostPortPair("example3.com", 443),
                                       kNetworkIsolationKey));
  EXPECT_EQ(0u, mock_host_resolver.num_non_local_resolves());
  int rv = mock_host_resolver.LoadIntoCache(
      HostPortPair("example3.com", 443), kNetworkIsolationKey, base::nullopt);
  EXPECT_EQ(OK, rv);
  EXPECT_EQ(1u, mock_host_resolver.num_non_local_resolves());
  EXPECT_TRUE(IsPrivateHostForTesting(&mock_host_resolver,
                                      HostPortPair("example3.com", 443),
                                      kNetworkIsolationKey));
  EXPECT_EQ(1u, mock_host_resolver.num_non_local_resolves());
  EXPECT_FALSE(IsPrivateHostForTesting(&mock_host_resolver,
                                       HostPortPair("example3.com", 443),
                                       NetworkIsolationKey()));
}
TEST ( NetworkQualityEstimatorUtilTest , ReservedHostUncachedWithNetworkIsolationKey ) { const url :: Origin kOrigin = url :: Origin :: Create ( GURL ( " " ) ) ; const net :: NetworkIsolationKey kNetworkIsolationKey ( kOrigin , kOrigin ) ; base :: test :: ScopedFeatureList feature_list ; feature_list . InitAndEnableFeature ( features :: kSplitHostCacheByNetworkIsolationKey ) ; base :: test :: TaskEnvironment task_environment ; MockCachingHostResolver mock_host_resolver ; scoped_refptr < net :: RuleBasedHostResolverProc > rules ( new net :: RuleBasedHostResolverProc ( nullptr ) ) ; rules -> AddRule ( " " , " " ) ; mock_host_resolver . set_rules ( rules . get ( ) ) ; EXPECT_FALSE ( IsPrivateHostForTesting ( & mock_host_resolver , HostPortPair ( " " , 443 ) , kNetworkIsolationKey ) ) ; EXPECT_EQ ( 0u , mock_host_resolver . num_non_local_resolves ( ) ) ; int rv = mock_host_resolver . LoadIntoCache ( HostPortPair ( " " , 443 ) , kNetworkIsolationKey , base :: nullopt ) ; EXPECT_EQ ( OK , rv ) ; EXPECT_EQ ( 1u , mock_host_resolver . num_non_local_resolves ( ) ) ; EXPECT_TRUE ( IsPrivateHostForTesting ( & mock_host_resolver , HostPortPair ( " " , 443 ) , kNetworkIsolationKey ) ) ; EXPECT_EQ ( 1u , mock_host_resolver . num_non_local_resolves ( ) ) ; EXPECT_FALSE ( IsPrivateHostForTesting ( & mock_host_resolver , HostPortPair ( " " , 443 ) , NetworkIsolationKey ( ) ) ) ; }
Make sure that IsPrivateHostForTesting() uses the NetworkIsolationKey
provided to it.
Make sure that IsPrivateHostForTesting () uses the NetworkIsolationKey provided to it .
// Add example3.com resolution to the DNS cache. // Not in DNS host cache, so should not be marked as private. // IsPrivateHostForTesting() should have queried only the resolver's cache. // IsPrivateHostForTesting should return false when using a different // NetworkIsolationKey (in this case, any empty one).