// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/path_service.h" #include "base/strings/strcat.h" #include "base/test/bind.h" #include "base/test/scoped_feature_list.h" #include "build/build_config.h" #include "content/public/common/content_paths.h" #include "content/public/test/browser_test.h" #include "content/public/test/browser_test_utils.h" #include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test_utils.h" #include "content/public/test/test_navigation_observer.h" #include "content/public/test/url_loader_interceptor.h" #include "content/shell/browser/shell.h" #include "net/base/features.h" #include "net/dns/mock_host_resolver.h" #include "services/network/public/cpp/features.h" namespace content { namespace { bool SupportsSharedWorker() { … } } // namespace enum class WorkerType { … }; class WorkerNetworkIsolationKeyBrowserTest : public ContentBrowserTest { … }; class WorkerImportScriptsAndFetchRequestNetworkIsolationKeyBrowserTest : public WorkerNetworkIsolationKeyBrowserTest, public ::testing::WithParamInterface< std::tuple<bool /* test_same_network_isolation_key */, WorkerType>> { … }; // Test that network isolation key is filled in correctly for service/shared // workers. The test navigates to "a.test" and creates two cross-origin iframes // that each start a worker. The frames/workers may have the same origin, so // worker1 is on "b.test" and worker2 is on either "b.test" or "c.test". The // test checks the cache status of importScripts() and a fetch() request from // the workers to another origin "d.test". When the workers had the same origin // (the same network isolation key), we expect the second importScripts() and // fetch() request to exist in the cache. When the origins are different, we // expect the second requests to not exist in the cache. IN_PROC_BROWSER_TEST_P( WorkerImportScriptsAndFetchRequestNetworkIsolationKeyBrowserTest, ImportScriptsAndFetchRequest) { … } INSTANTIATE_TEST_SUITE_P(…); class ServiceWorkerMainScriptRequestNetworkIsolationKeyBrowserTest : public WorkerNetworkIsolationKeyBrowserTest { … }; // Test that network isolation key is filled in correctly for service worker's // main script request. The test navigates to "a.test" and creates an iframe // having origin "c.test" that registers |worker1|. The test then navigates to // "b.test" and creates an iframe also having origin "c.test". We now want to // test a second register request for |worker1| but just calling register() // would be a no-op since |worker1| is already the current worker. So we // register a new |worker2| and then |worker1| again. // // Note that the second navigation to "c.test" also triggers an update check for // |worker1|. We expect both the second register request for |worker1| and this // update request to exist in the cache. // // Note that it's sufficient not to test the cache miss when subframe origins // are different as in that case the two script urls must be different and it // also won't trigger an update. // // TODO(crbug.com/40053828): Update test to not depend on // kThirdPartyStoragePartitioning being disabled. IN_PROC_BROWSER_TEST_F( ServiceWorkerMainScriptRequestNetworkIsolationKeyBrowserTest, ServiceWorkerMainScriptRequest) { … } SharedWorkerMainScriptRequestNetworkIsolationKeyBrowserTest; // Test that network isolation key is filled in correctly for shared worker's // main script request. The test navigates to "a.test" and creates an iframe // having origin "c.test" that creates |worker1|. The test then navigates to // "b.test" and creates an iframe also having origin "c.test" that creates // |worker1| again. // // We expect the second creation request for |worker1| to not exist in the // cache since the workers should be partitioned by top-level site. // // Note that it's sufficient not to test the cache miss when subframe origins // are different as in that case the two script urls must be different. IN_PROC_BROWSER_TEST_F( SharedWorkerMainScriptRequestNetworkIsolationKeyBrowserTest, SharedWorkerMainScriptRequest) { … } } // namespace content