File: test_shared_storage_runtime_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 4,542 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_SHARED_STORAGE_TEST_SHARED_STORAGE_RUNTIME_MANAGER_H_
#define CONTENT_BROWSER_SHARED_STORAGE_TEST_SHARED_STORAGE_RUNTIME_MANAGER_H_

#include <cstddef>
#include <map>
#include <memory>
#include <vector>

#include "content/browser/shared_storage/shared_storage_document_service_impl.h"
#include "content/browser/shared_storage/shared_storage_runtime_manager.h"
#include "content/browser/shared_storage/test_shared_storage_worklet_host.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/document_user_data.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/test_select_url_fenced_frame_config_observer.h"
#include "content/test/content_browser_test_utils_internal.h"  // For `ConvertToRenderFrameHost()`
#include "content/test/fenced_frame_test_utils.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "net/base/schemeful_site.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "third_party/blink/public/common/fenced_frame/fenced_frame_utils.h"
#include "third_party/blink/public/mojom/origin_trials/origin_trial_feature.mojom-shared.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
#include "url/origin.h"

namespace content {

class TestSharedStorageRuntimeManager : public SharedStorageRuntimeManager {
 public:
  using SharedStorageRuntimeManager::SharedStorageRuntimeManager;

  explicit TestSharedStorageRuntimeManager(
      StoragePartitionImpl& storage_partition);

  ~TestSharedStorageRuntimeManager() override;

  std::unique_ptr<SharedStorageWorkletHost> CreateWorkletHostHelper(
      SharedStorageDocumentServiceImpl& document_service,
      const url::Origin& frame_origin,
      const url::Origin& data_origin,
      blink::mojom::SharedStorageDataOriginType data_origin_type,
      const GURL& script_source_url,
      network::mojom::CredentialsMode credentials_mode,
      blink::mojom::SharedStorageWorkletCreationMethod creation_method,
      int worklet_ordinal_id,
      const std::vector<blink::mojom::OriginTrialFeature>&
          origin_trial_features,
      mojo::PendingAssociatedReceiver<blink::mojom::SharedStorageWorkletHost>
          worklet_host,
      blink::mojom::SharedStorageDocumentService::CreateWorkletCallback
          callback) override;

  // Precondition: there's only one eligible worklet host.
  TestSharedStorageWorkletHost* GetAttachedWorkletHost();

  std::vector<TestSharedStorageWorkletHost*> GetAttachedWorkletHosts();

  // Precondition: there's only one eligible worklet host.
  TestSharedStorageWorkletHost* GetKeepAliveWorkletHost();

  // Precondition: `frame` is associated with a
  // `SharedStorageDocumentServiceImpl`, and there's a single attached
  // `SharedStorageWorkletHost` for that document service.
  TestSharedStorageWorkletHost* GetAttachedWorkletHostForFrame(
      RenderFrameHost* frame);

  // Gets the host with `script_source_url` that was most recently attached for
  // `frame`'s document service. Returns nullptr if there is no such host.
  TestSharedStorageWorkletHost* GetLastAttachedWorkletHostForFrameWithScriptSrc(
      RenderFrameHost* frame,
      const GURL& script_src_url);

  // Precondition: `frame` is associated with a
  // `SharedStorageDocumentServiceImpl`.
  std::vector<TestSharedStorageWorkletHost*> GetAttachedWorkletHostsForFrame(
      RenderFrameHost* frame);

  // Returns a map of worklet ordinal IDs to worklet DevTools tokens for all of
  // the shared storage worklet hosts created up to that point of the test,
  // regardless of which of these hosts are still attached and/or alive.
  std::map<int, base::UnguessableToken>& GetCachedWorkletHostDevToolsTokens();

  void ConfigureShouldDeferWorkletMessagesOnWorkletHostCreation(
      bool should_defer_worklet_messages);

  size_t GetAttachedWorkletHostsCount();

  size_t GetKeepAliveWorkletHostsCount();

 private:
  bool should_defer_worklet_messages_ = false;

  // A map of worklet ordinal IDs to worklet DevTools Tokens.
  std::map<int, base::UnguessableToken> cached_worklet_host_devtools_tokens_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_SHARED_STORAGE_TEST_SHARED_STORAGE_RUNTIME_MANAGER_H_