File: browsing_data_browsertest_utils.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (96 lines) | stat: -rw-r--r-- 3,594 bytes parent folder | download | duplicates (9)
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
// 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.

#ifndef CONTENT_BROWSER_BROWSING_DATA_BROWSING_DATA_BROWSERTEST_UTILS_H_
#define CONTENT_BROWSER_BROWSING_DATA_BROWSING_DATA_BROWSERTEST_UTILS_H_

#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "content/browser/service_worker/service_worker_context_core_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"

namespace blink {
class StorageKey;
}  // namespace blink

namespace content {
class StoragePartition;

namespace browsing_data_browsertest_utils {

// TODO(msramek): A class like this already exists in ServiceWorkerBrowserTest.
// Consider extracting it to a different test utils file.
class ServiceWorkerActivationObserver
    : public ServiceWorkerContextCoreObserver {
 public:
  // |callback| is called when |context| is activated.
  static void SignalActivation(ServiceWorkerContextWrapper* context,
                               base::OnceClosure callback);

 private:
  ServiceWorkerActivationObserver(ServiceWorkerContextWrapper* context,
                                  base::OnceClosure callback);

  ~ServiceWorkerActivationObserver() override;

  // ServiceWorkerContextCoreObserver overrides.
  void OnVersionStateChanged(int64_t version_id,
                             const GURL& scope,
                             const blink::StorageKey& key,
                             ServiceWorkerVersion::Status) override;

  raw_ptr<ServiceWorkerContextWrapper> context_;
  base::ScopedObservation<ServiceWorkerContextWrapper,
                          ServiceWorkerContextCoreObserver>
      scoped_observation_{this};
  base::OnceClosure callback_;
};

// Appends a switch to the |command_line| based on whether the network service
// is enabled. The browser will ignore certificate errors if the network service
// is not enabled.
void SetIgnoreCertificateErrors(base::CommandLine* command_line);

// Adds a service worker for the given |origin|. The EmbeddedTestServer
// |https_server| is required to retrieve a URL to the server based on the
// |origin|. Returns the scope url with port number.
GURL AddServiceWorker(const std::string& origin,
                      StoragePartition* storage_partition,
                      net::EmbeddedTestServer* https_server);

// Retrieves the list of all service workers.
std::vector<StorageUsageInfo> GetServiceWorkers(
    StoragePartition* storage_partition);

// Populates the content and content type fields of a given HTTP |response|
// based on the file extension of the |url| as follows:
//
// For .js:
// Example: "https://localhost/?file=file.js"
// will set the response header as
// Content-Type: application/javascript
//
// For .html:
// Example: "https://localhost/?file=file.html"
// will set the response header as
// Content-Type: text/html
//
// Response content type is only set for .js and .html files.
void SetResponseContent(const GURL& url,
                        std::string* value,
                        net::test_server::BasicHttpResponse* response);

// Sets up a MockCertVerifier with default return value |default_result|.
void SetUpMockCertVerifier(int32_t default_result);

}  // namespace browsing_data_browsertest_utils

}  // namespace content

#endif  // CONTENT_BROWSER_BROWSING_DATA_BROWSING_DATA_BROWSERTEST_UTILS_H_