Skip to content

Instantly share code, notes, and snippets.

@jeremyroman
Created April 5, 2018 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyroman/2233ed483e0e94365eae28695c50f93f to your computer and use it in GitHub Desktop.
Save jeremyroman/2233ed483e0e94365eae28695c50f93f to your computer and use it in GitHub Desktop.
diff --git a/content/browser/web_package/web_package_context_impl.cc b/content/browser/web_package/web_package_context_impl.cc
index ea3956d77739..86367c49ad54 100644
--- a/content/browser/web_package/web_package_context_impl.cc
+++ b/content/browser/web_package/web_package_context_impl.cc
@@ -4,40 +4,19 @@
#include "content/browser/web_package/web_package_context_impl.h"
-#include "base/bind.h"
-#include "base/single_thread_task_runner.h"
-#include "base/task_scheduler/post_task.h"
-#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/web_package/signed_exchange_handler.h"
#include "content/public/browser/browser_thread.h"
namespace content {
-namespace {
-
-void SetSignedExchangeVerificationTimeForTestingOnIO(
- base::Optional<base::Time> time,
- base::OnceClosure callback,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- SignedExchangeHandler::SetVerificationTimeForTesting(time);
- task_runner_for_callback->PostTask(FROM_HERE, std::move(callback));
-}
-
-} // namespace
-
WebPackageContextImpl::WebPackageContextImpl() = default;
WebPackageContextImpl::~WebPackageContextImpl() = default;
void WebPackageContextImpl::SetSignedExchangeVerificationTimeForTesting(
- base::Optional<base::Time> time,
- base::OnceClosure callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&SetSignedExchangeVerificationTimeForTestingOnIO, time,
- std::move(callback), base::ThreadTaskRunnerHandle::Get()));
+ base::Optional<base::Time> time) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ SignedExchangeHandler::SetVerificationTimeForTesting(time);
}
} // namespace content
diff --git a/content/browser/web_package/web_package_context_impl.h b/content/browser/web_package/web_package_context_impl.h
index 8d4c8e3b6943..b0c198d5fd29 100644
--- a/content/browser/web_package/web_package_context_impl.h
+++ b/content/browser/web_package/web_package_context_impl.h
@@ -16,8 +16,7 @@ class WebPackageContextImpl : public WebPackageContext {
WebPackageContextImpl();
~WebPackageContextImpl() override;
void SetSignedExchangeVerificationTimeForTesting(
- base::Optional<base::Time> time,
- base::OnceClosure callback) override;
+ base::Optional<base::Time> time) override;
};
} // namespace content
diff --git a/content/public/browser/web_package_context.h b/content/public/browser/web_package_context.h
index 087321f202f4..94305626b3d2 100644
--- a/content/public/browser/web_package_context.h
+++ b/content/public/browser/web_package_context.h
@@ -5,7 +5,6 @@
#ifndef CONTENT_PUBLIC_BROWSER_WEB_PACKAGE_CONTEXT_H_
#define CONTENT_PUBLIC_BROWSER_WEB_PACKAGE_CONTEXT_H_
-#include "base/callback.h"
#include "base/optional.h"
#include "base/time/time.h"
@@ -16,13 +15,11 @@ namespace content {
class WebPackageContext {
public:
// Changes the time which will be used to verify SignedHTTPExchange. This
- // method is for testing. Must be called on UI thread. |callback| will be
- // called on the UI thread after changing the time on IO thread.
+ // method is for testing. Must be called on IO thread.
// Need call this method again in the end of the test with nullopt time to
// reset the the verification time overriding.
virtual void SetSignedExchangeVerificationTimeForTesting(
- base::Optional<base::Time> time,
- base::OnceClosure callback) = 0;
+ base::Optional<base::Time> time) = 0;
protected:
WebPackageContext() {}
diff --git a/content/shell/browser/content_shell_browser_manifest_overlay.json b/content/shell/browser/content_shell_browser_manifest_overlay.json
index bd13143a3798..e11cab2c4ce3 100644
--- a/content/shell/browser/content_shell_browser_manifest_overlay.json
+++ b/content/shell/browser/content_shell_browser_manifest_overlay.json
@@ -7,7 +7,8 @@
"content::mojom::LayoutTestBluetoothFakeAdapterSetter",
"content::mojom::MojoLayoutTestHelper",
"content::mojom::FakeBluetoothChooser",
- "bluetooth::mojom::FakeBluetooth"
+ "bluetooth::mojom::FakeBluetooth",
+ "blink::test::mojom::WebPackageInternals"
]
},
"requires": {
@@ -20,8 +21,7 @@
"navigation:frame": {
"provides": {
"renderer": [
- "content::mojom::MojoLayoutTestHelper",
- "blink::test::mojom::WebPackageInternals"
+ "content::mojom::MojoLayoutTestHelper"
]
}
}
diff --git a/content/shell/browser/layout_test/blink_test_controller.cc b/content/shell/browser/layout_test/blink_test_controller.cc
index a230c9929bf2..1d7077b102e0 100644
--- a/content/shell/browser/layout_test/blink_test_controller.cc
+++ b/content/shell/browser/layout_test/blink_test_controller.cc
@@ -849,9 +849,13 @@ void BlinkTestController::OnTestFinished() {
// Resets the SignedHTTPExchange verification time overriding. The time for
// the verification may be changed in the LayoutTest using Mojo JS API.
- storage_partition->GetWebPackageContext()
- ->SetSignedExchangeVerificationTimeForTesting(base::nullopt,
- barrier_closure);
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(
+ &WebPackageContext::SetSignedExchangeVerificationTimeForTesting,
+ base::Unretained(storage_partition->GetWebPackageContext()),
+ base::nullopt),
+ barrier_closure);
}
void BlinkTestController::OnCleanupFinished() {
diff --git a/content/shell/browser/layout_test/layout_test_content_browser_client.cc b/content/shell/browser/layout_test/layout_test_content_browser_client.cc
index 9264eefff30e..2d0f14dce4bb 100644
--- a/content/shell/browser/layout_test/layout_test_content_browser_client.cc
+++ b/content/shell/browser/layout_test/layout_test_content_browser_client.cc
@@ -48,23 +48,21 @@ class WebPackageInternalsImpl : public blink::test::mojom::WebPackageInternals {
: web_package_context_(web_package_context) {}
~WebPackageInternalsImpl() override = default;
- static void Create(blink::test::mojom::WebPackageInternalsRequest request,
- RenderFrameHost* render_frame_host) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- mojo::MakeStrongBinding(std::make_unique<WebPackageInternalsImpl>(
- render_frame_host->GetProcess()
- ->GetStoragePartition()
- ->GetWebPackageContext()),
- std::move(request));
+ static void Create(WebPackageContext* web_package_context,
+ blink::test::mojom::WebPackageInternalsRequest request) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ mojo::MakeStrongBinding(
+ std::make_unique<WebPackageInternalsImpl>(web_package_context),
+ std::move(request));
}
private:
void SetSignedExchangeVerificationTime(
base::Time time,
SetSignedExchangeVerificationTimeCallback callback) override {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- web_package_context_->SetSignedExchangeVerificationTimeForTesting(
- time, std::move(callback));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ web_package_context_->SetSignedExchangeVerificationTimeForTesting(time);
+ std::move(callback).Run();
}
WebPackageContext* web_package_context_;
@@ -147,6 +145,10 @@ void LayoutTestContentBrowserClient::ExposeInterfacesToRenderer(
&LayoutTestContentBrowserClient::CreateFakeBluetoothChooser,
base::Unretained(this)),
ui_task_runner);
+ registry->AddInterface(base::BindRepeating(
+ &WebPackageInternalsImpl::Create,
+ base::Unretained(
+ render_process_host->GetStoragePartition()->GetWebPackageContext())));
registry->AddInterface(base::BindRepeating(&MojoLayoutTestHelper::Create));
}
@@ -236,7 +238,6 @@ void LayoutTestContentBrowserClient::ExposeInterfacesToFrame(
service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>*
registry) {
registry->AddInterface(base::Bind(&BindLayoutTestHelper));
- registry->AddInterface(base::BindRepeating(&WebPackageInternalsImpl::Create));
}
scoped_refptr<LoginDelegate>
diff --git a/third_party/WebKit/LayoutTests/http/tests/loading/htxg/resources/htxg-util.js b/third_party/WebKit/LayoutTests/http/tests/loading/htxg/resources/htxg-util.js
index 6bcc26db3111..f27ff55f527a 100644
--- a/third_party/WebKit/LayoutTests/http/tests/loading/htxg/resources/htxg-util.js
+++ b/third_party/WebKit/LayoutTests/http/tests/loading/htxg/resources/htxg-util.js
@@ -33,7 +33,7 @@ async function setSignedExchangeVerificationTime(time) {
await mojoBindingsLoaded;
const webPackageInternals = new blink.test.mojom.WebPackageInternalsPtr();
Mojo.bindInterface(blink.test.mojom.WebPackageInternals.name,
- mojo.makeRequest(webPackageInternals).handle);
+ mojo.makeRequest(webPackageInternals).handle, 'process');
const windowsEpoch = Date.UTC(1601, 0, 1, 0, 0, 0, 0);
return webPackageInternals.setSignedExchangeVerificationTime({
internalValue: (time - windowsEpoch) * 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment