Commit 01eff54b authored by Camillo Bruni's avatar Camillo Bruni Committed by Chromium LUCI CQ

[blink] Clean up ModuleScriptCreationParam

Instead of mutating the const ref, we copy the params object in
JSModuleScript::Create when clearing the source text.

Introduce ModuleScriptFetcher::NotifyFetchFinishedError and
ModuleScriptFetcher::NotifyFetchFinishedSuccess to make it clearer which
arguments are used.

Bug: 1154943
Change-Id: I4ed2ca75e56c8cbefb8d49c11e77d1846ce43f16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571877
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837978}
parent 4c50825a
......@@ -37,20 +37,21 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
auto* script_resource = To<ScriptResource>(resource);
HeapVector<Member<ConsoleMessage>> error_messages;
ModuleScriptCreationParams::ModuleType module_type;
if (!WasModuleLoadSuccessful(script_resource, &error_messages,
&module_type)) {
client_->NotifyFetchFinished(base::nullopt, error_messages);
return;
{
HeapVector<Member<ConsoleMessage>> error_messages;
if (!WasModuleLoadSuccessful(script_resource, &error_messages,
&module_type)) {
client_->NotifyFetchFinishedError(error_messages);
return;
}
}
// TODO(crbug.com/1061857): Pass ScriptStreamer to the client here.
ModuleScriptCreationParams params(
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
script_resource->GetResponse().CurrentRequestUrl(), module_type,
script_resource->SourceText(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode(), nullptr,
ScriptStreamer::NotStreamingReason::kStreamingDisabled);
client_->NotifyFetchFinished(params, error_messages);
ScriptStreamer::NotStreamingReason::kStreamingDisabled));
}
void DocumentModuleScriptFetcher::Trace(Visitor* visitor) const {
......
......@@ -46,7 +46,7 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
mojom::ConsoleMessageLevel::kError,
"Failed to load the script unexpectedly",
fetch_params.Url().GetString(), nullptr, 0));
client->NotifyFetchFinished(base::nullopt, error_messages);
client->NotifyFetchFinishedError(error_messages);
return;
}
......@@ -99,16 +99,15 @@ void InstalledServiceWorkerModuleScriptFetcher::Fetch(
mojom::ConsoleMessageLevel::kError,
"Failed to load the script unexpectedly",
fetch_params.Url().GetString(), nullptr, 0));
client->NotifyFetchFinished(base::nullopt, error_messages);
client->NotifyFetchFinishedError(error_messages);
return;
}
ModuleScriptCreationParams params(
client->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
fetch_params.Url(), module_type,
ParkableString(script_data->TakeSourceText().Impl()),
nullptr /* cache_handler */,
fetch_params.GetResourceRequest().GetCredentialsMode());
client->NotifyFetchFinished(params, HeapVector<Member<ConsoleMessage>>());
fetch_params.GetResourceRequest().GetCredentialsMode()));
}
void InstalledServiceWorkerModuleScriptFetcher::Trace(Visitor* visitor) const {
......
......@@ -74,11 +74,10 @@ class ModuleScriptCreationParams {
return source_text_;
}
// TODO(crbug.com/1154943): Make this non-const.
void ClearSourceText() const {
source_text_ = ParkableString();
isolated_source_text_ = String();
is_isolated_ = false;
ModuleScriptCreationParams CopyWithClearedSourceText() const {
return ModuleScriptCreationParams(
source_url_, module_type_, ParkableString(), cache_handler_,
credentials_mode_, script_streamer_, not_streaming_reason_);
}
SingleCachedMetadataHandler* CacheHandler() const { return cache_handler_; }
......
......@@ -21,12 +21,12 @@ ModuleScriptFetcher::ModuleScriptFetcher(
base::PassKey<ModuleScriptLoader> pass_key) {}
void ModuleScriptFetcher::Client::OnFetched(
const base::Optional<ModuleScriptCreationParams>& params) {
NotifyFetchFinished(params, HeapVector<Member<ConsoleMessage>>());
const ModuleScriptCreationParams& params) {
NotifyFetchFinishedSuccess(params);
}
void ModuleScriptFetcher::Client::OnFailed() {
NotifyFetchFinished(base::nullopt, HeapVector<Member<ConsoleMessage>>());
NotifyFetchFinishedError(HeapVector<Member<ConsoleMessage>>());
}
void ModuleScriptFetcher::Trace(Visitor* visitor) const {
......
......@@ -29,13 +29,14 @@ class CORE_EXPORT ModuleScriptFetcher : public ResourceClient {
class CORE_EXPORT Client : public GarbageCollectedMixin {
public:
virtual void NotifyFetchFinished(
const base::Optional<ModuleScriptCreationParams>&,
virtual void NotifyFetchFinishedError(
const HeapVector<Member<ConsoleMessage>>& error_messages) = 0;
virtual void NotifyFetchFinishedSuccess(
const ModuleScriptCreationParams&) = 0;
// These helpers are used only from WorkletModuleResponsesMap.
// TODO(nhiroki): Move these helpers to WorkletModuleResponsesMap.
void OnFetched(const base::Optional<ModuleScriptCreationParams>&);
void OnFetched(const ModuleScriptCreationParams&);
void OnFailed();
};
......
......@@ -224,8 +224,7 @@ void ModuleScriptLoader::FetchInternal(
}
// <specdef href="https://html.spec.whatwg.org/C/#fetch-a-single-module-script">
void ModuleScriptLoader::NotifyFetchFinished(
const base::Optional<ModuleScriptCreationParams>& params,
void ModuleScriptLoader::NotifyFetchFinishedError(
const HeapVector<Member<ConsoleMessage>>& error_messages) {
// [nospec] Abort the steps if the browsing context is discarded.
if (!modulator_->HasValidContext()) {
......@@ -238,11 +237,17 @@ void ModuleScriptLoader::NotifyFetchFinished(
// <spec step="9">If any of the following conditions are met, set
// moduleMap[url] to null, asynchronously complete this algorithm with null,
// and abort these steps: ...</spec>
if (!params.has_value()) {
for (ConsoleMessage* error_message : error_messages) {
ExecutionContext::From(modulator_->GetScriptState())
->AddConsoleMessage(error_message);
}
for (ConsoleMessage* error_message : error_messages) {
ExecutionContext::From(modulator_->GetScriptState())
->AddConsoleMessage(error_message);
}
AdvanceState(State::kFinished);
}
void ModuleScriptLoader::NotifyFetchFinishedSuccess(
const ModuleScriptCreationParams& params) {
// [nospec] Abort the steps if the browsing context is discarded.
if (!modulator_->HasValidContext()) {
AdvanceState(State::kFinished);
return;
}
......@@ -253,7 +258,7 @@ void ModuleScriptLoader::NotifyFetchFinished(
// <spec step="12.2">Set module script to the result of creating a JavaScript
// module script given source text, module map settings object, response's
// url, and options.</spec>
switch (params->GetModuleType()) {
switch (params.GetModuleType()) {
case ModuleScriptCreationParams::ModuleType::kJSONModule:
DCHECK(base::FeatureList::IsEnabled(blink::features::kJSONModules));
module_script_ = ValueWrapperSyntheticModuleScript::
......@@ -264,16 +269,17 @@ void ModuleScriptLoader::NotifyFetchFinished(
module_script_ = ValueWrapperSyntheticModuleScript::
CreateCSSWrapperSyntheticModuleScript(params, modulator_);
break;
case ModuleScriptCreationParams::ModuleType::kJavaScriptModule:
case ModuleScriptCreationParams::ModuleType::kJavaScriptModule: {
// Step 9. "Let source text be the result of UTF-8 decoding response's
// body." [spec text]
// Step 10. "Let module script be the result of creating
// a module script given source text, module map settings object,
// response's url, and options." [spec text]
module_script_ = JSModuleScript::Create(
params.value(), params->SourceURL() /* base URL */,
params, /*base_url=*/params.SourceURL(),
ScriptSourceLocationType::kExternalFile, modulator_, options_);
break;
};
}
AdvanceState(State::kFinished);
......
......@@ -58,8 +58,8 @@ class CORE_EXPORT ModuleScriptLoader final
ModuleScriptLoaderClient*);
// Implements ModuleScriptFetcher::Client.
void NotifyFetchFinished(
const base::Optional<ModuleScriptCreationParams>&,
void NotifyFetchFinishedSuccess(const ModuleScriptCreationParams&) override;
void NotifyFetchFinishedError(
const HeapVector<Member<ConsoleMessage>>& error_messages) override;
bool IsInitialState() const { return state_ == State::kInitial; }
......
......@@ -90,12 +90,14 @@ void WorkerModuleScriptFetcher::NotifyFinished(Resource* resource) {
ClearResource();
auto* script_resource = To<ScriptResource>(resource);
HeapVector<Member<ConsoleMessage>> error_messages;
ModuleScriptCreationParams::ModuleType module_type;
if (!WasModuleLoadSuccessful(script_resource, &error_messages,
&module_type)) {
client_->NotifyFetchFinished(base::nullopt, error_messages);
return;
{
HeapVector<Member<ConsoleMessage>> error_messages;
if (!WasModuleLoadSuccessful(script_resource, &error_messages,
&module_type)) {
client_->NotifyFetchFinishedError(error_messages);
return;
}
}
NotifyClient(resource->Url(), module_type,
......@@ -147,7 +149,7 @@ void WorkerModuleScriptFetcher::NotifyClient(
mojom::ConsoleMessageSource::kSecurity,
mojom::ConsoleMessageLevel::kError,
"Refused to cross-origin redirects of the top-level worker script."));
client_->NotifyFetchFinished(base::nullopt, error_messages);
client_->NotifyFetchFinishedError(error_messages);
return;
}
......@@ -176,13 +178,12 @@ void WorkerModuleScriptFetcher::NotifyClient(
response_origin_trial_tokens.get(), response.AppCacheID());
}
ModuleScriptCreationParams params(response.CurrentRequestUrl(), module_type,
source_text, cache_handler,
credentials_mode);
// <spec step="12.7">Asynchronously complete the perform the fetch steps with
// response.</spec>
client_->NotifyFetchFinished(params, error_messages);
client_->NotifyFetchFinishedSuccess(
ModuleScriptCreationParams(response.CurrentRequestUrl(), module_type,
source_text, cache_handler, credentials_mode));
}
void WorkerModuleScriptFetcher::DidReceiveData(base::span<const char> span) {
......@@ -213,7 +214,7 @@ void WorkerModuleScriptFetcher::OnStartLoadingBody(
resource_response.CurrentRequestUrl().GetString(), /*loader=*/nullptr,
-1));
worker_main_script_loader_->Cancel();
client_->NotifyFetchFinished(base::nullopt, error_messages);
client_->NotifyFetchFinishedError(error_messages);
return;
}
}
......@@ -230,8 +231,7 @@ void WorkerModuleScriptFetcher::OnFinishedLoadingWorkerMainScript() {
}
void WorkerModuleScriptFetcher::OnFailedLoadingWorkerMainScript() {
client_->NotifyFetchFinished(base::nullopt,
HeapVector<Member<ConsoleMessage>>());
client_->NotifyFetchFinishedError(HeapVector<Member<ConsoleMessage>>());
}
} // namespace blink
......@@ -18,7 +18,7 @@ namespace blink {
// <specdef
// href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script">
JSModuleScript* JSModuleScript::Create(
const ModuleScriptCreationParams& params,
const ModuleScriptCreationParams& original_params,
const KURL& base_url,
ScriptSourceLocationType source_location_type,
Modulator* modulator,
......@@ -26,8 +26,10 @@ JSModuleScript* JSModuleScript::Create(
const TextPosition& start_position) {
// <spec step="1">If scripting is disabled for settings's responsible browsing
// context, then set source to the empty string.</spec>
if (modulator->IsScriptingDisabled())
params.ClearSourceText();
const ModuleScriptCreationParams& params =
modulator->IsScriptingDisabled()
? original_params.CopyWithClearedSourceText()
: original_params;
// <spec step="2">Let script be a new module script that this algorithm will
// subsequently initialize.</spec>
......
......@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
namespace blink {
......@@ -116,11 +117,7 @@ class ModuleMapTestModulator final : public DummyModulator {
ModuleScriptFetcher::Client* client) override {
CHECK_EQ(request.GetScriptType(), mojom::blink::ScriptType::kModule);
TestRequest* test_request = MakeGarbageCollected<TestRequest>(
ModuleScriptCreationParams(
request.Url(),
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr,
request.GetResourceRequest().GetCredentialsMode()),
request.Url(), request.GetResourceRequest().GetCredentialsMode(),
client);
modulator_->test_requests_.push_back(test_request);
}
......@@ -150,17 +147,20 @@ class ModuleMapTestModulator final : public DummyModulator {
}
struct TestRequest final : public GarbageCollected<TestRequest> {
TestRequest(const ModuleScriptCreationParams& params,
TestRequest(const KURL& url,
network::mojom::CredentialsMode credential_mode,
ModuleScriptFetcher::Client* client)
: params_(params), client_(client) {}
: url_(url), credential_mode_(credential_mode), client_(client) {}
void NotifyFetchFinished() {
client_->NotifyFetchFinished(*params_,
HeapVector<Member<ConsoleMessage>>());
client_->NotifyFetchFinishedSuccess(ModuleScriptCreationParams(
url_, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(String("").ReleaseImpl()), nullptr, credential_mode_));
}
void Trace(Visitor* visitor) const { visitor->Trace(client_); }
private:
base::Optional<ModuleScriptCreationParams> params_;
const KURL url_;
const network::mojom::CredentialsMode credential_mode_;
Member<ModuleScriptFetcher::Client> client_;
};
HeapVector<Member<TestRequest>> test_requests_;
......
......@@ -464,11 +464,6 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
SecurityPolicy::ReferrerPolicyFromString(
referrerpolicy_attr, kDoNotSupportReferrerPolicyLegacyKeywords,
&referrer_policy);
if (context_window->IsSecureContext() &&
referrer_policy == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(*context_window,
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
}
// Priority Hints is currently a non-standard feature, but we can assume the
......
......@@ -25,7 +25,7 @@ namespace blink {
// https://whatpr.org/html/4898/webappapis.html#creating-a-css-module-script
ValueWrapperSyntheticModuleScript*
ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params,
const ModuleScriptCreationParams& params,
Modulator* settings_object) {
DCHECK(settings_object->HasValidContext());
ScriptState* script_state = settings_object->GetScriptState();
......@@ -40,7 +40,7 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = V8ThrowException::CreateTypeError(
isolate, "Cannot create CSS Module in non-document context");
return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error);
}
CSSStyleSheetInit* init = CSSStyleSheetInit::Create();
......@@ -50,26 +50,26 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error);
}
style_sheet->replaceSync(params->GetSourceText().ToString(), exception_state);
style_sheet->replaceSync(params.GetSourceText().ToString(), exception_state);
if (exception_state.HadException()) {
v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
v8::Local<v8::Value>(), settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error);
}
v8::Local<v8::Value> v8_value_stylesheet = ToV8(style_sheet, script_state);
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
v8_value_stylesheet, settings_object, params->SourceURL(), KURL(),
v8_value_stylesheet, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions());
}
ValueWrapperSyntheticModuleScript*
ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params,
const ModuleScriptCreationParams& params,
Modulator* settings_object) {
DCHECK(settings_object->HasValidContext());
ScriptState::Scope scope(settings_object->GetScriptState());
......@@ -78,7 +78,7 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate);
v8::Local<v8::String> original_json =
V8String(isolate, params->GetSourceText());
V8String(isolate, params.GetSourceText());
v8::Local<v8::Value> parsed_json;
ExceptionState exception_state(isolate, ExceptionState::kExecutionContext,
"ModuleScriptLoader",
......@@ -102,11 +102,11 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError(
parsed_json, settings_object, params->SourceURL(), KURL(),
parsed_json, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions(), error);
} else {
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
parsed_json, settings_object, params->SourceURL(), KURL(),
parsed_json, settings_object, params.SourceURL(), KURL(),
ScriptFetchOptions());
}
}
......
......@@ -26,14 +26,12 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final
: public ModuleScript {
public:
static ValueWrapperSyntheticModuleScript*
CreateCSSWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params,
Modulator* settings_object);
CreateCSSWrapperSyntheticModuleScript(const ModuleScriptCreationParams&,
Modulator* settings_object);
static ValueWrapperSyntheticModuleScript*
CreateJSONWrapperSyntheticModuleScript(
const base::Optional<ModuleScriptCreationParams>& params,
Modulator* settings_object);
CreateJSONWrapperSyntheticModuleScript(const ModuleScriptCreationParams&,
Modulator* settings_object);
static ValueWrapperSyntheticModuleScript* CreateWithDefaultExport(
v8::Local<v8::Value> value,
......@@ -78,4 +76,4 @@ class CORE_EXPORT ValueWrapperSyntheticModuleScript final
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_
\ No newline at end of file
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_
......@@ -47,23 +47,22 @@ class WorkletModuleResponsesMapTest : public testing::Test {
public:
enum class Result { kInitial, kOK, kFailed };
void NotifyFetchFinished(
const base::Optional<ModuleScriptCreationParams>& params,
void NotifyFetchFinishedError(
const HeapVector<Member<ConsoleMessage>>&) override {
ASSERT_EQ(Result::kInitial, result_);
if (params) {
result_ = Result::kOK;
params_.emplace(*params);
} else {
result_ = Result::kFailed;
}
result_ = Result::kFailed;
}
Result GetResult() const { return result_; }
base::Optional<ModuleScriptCreationParams> GetParams() const {
return params_;
void NotifyFetchFinishedSuccess(
const ModuleScriptCreationParams& params) override {
ASSERT_EQ(Result::kInitial, result_);
result_ = Result::kOK;
params_.emplace(std::move(params));
}
Result GetResult() const { return result_; }
bool HasParams() const { return params_.has_value(); }
private:
Result result_ = Result::kInitial;
base::Optional<ModuleScriptCreationParams> params_;
......@@ -108,7 +107,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value());
EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls should wait for the
// completion.
......@@ -125,7 +124,7 @@ TEST_F(WorkletModuleResponsesMapTest, Basic) {
RunUntilIdle();
for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kOK, client->GetResult());
EXPECT_TRUE(client->GetParams().has_value());
EXPECT_TRUE(client->HasParams());
}
}
......@@ -139,7 +138,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value());
EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls should wait for the
// completion.
......@@ -156,7 +155,7 @@ TEST_F(WorkletModuleResponsesMapTest, Failure) {
RunUntilIdle();
for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult());
EXPECT_FALSE(client->GetParams().has_value());
EXPECT_FALSE(client->HasParams());
}
}
......@@ -174,7 +173,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl1, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value());
EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl1| should
// wait for the completion.
......@@ -186,7 +185,7 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl2, clients[2]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult());
EXPECT_FALSE(clients[2]->GetParams().has_value());
EXPECT_FALSE(clients[2]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl2| should
// wait for the completion.
......@@ -201,13 +200,13 @@ TEST_F(WorkletModuleResponsesMapTest, Isolation) {
platform_->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value());
EXPECT_FALSE(clients[0]->HasParams());
EXPECT_EQ(ClientImpl::Result::kFailed, clients[1]->GetResult());
EXPECT_FALSE(clients[1]->GetParams().has_value());
EXPECT_FALSE(clients[1]->HasParams());
EXPECT_EQ(ClientImpl::Result::kOK, clients[2]->GetResult());
EXPECT_TRUE(clients[2]->GetParams().has_value());
EXPECT_TRUE(clients[2]->HasParams());
EXPECT_EQ(ClientImpl::Result::kOK, clients[3]->GetResult());
EXPECT_TRUE(clients[3]->GetParams().has_value());
EXPECT_TRUE(clients[3]->HasParams());
}
TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
......@@ -217,7 +216,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kEmptyURL, client1);
RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client1->GetResult());
EXPECT_FALSE(client1->GetParams().has_value());
EXPECT_FALSE(client1->HasParams());
const KURL kNullURL = NullURL();
ASSERT_TRUE(kNullURL.IsNull());
......@@ -225,7 +224,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kNullURL, client2);
RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client2->GetResult());
EXPECT_FALSE(client2->GetParams().has_value());
EXPECT_FALSE(client2->HasParams());
const KURL kInvalidURL;
ASSERT_FALSE(kInvalidURL.IsValid());
......@@ -233,7 +232,7 @@ TEST_F(WorkletModuleResponsesMapTest, InvalidURL) {
Fetch(kInvalidURL, client3);
RunUntilIdle();
EXPECT_EQ(ClientImpl::Result::kFailed, client3->GetResult());
EXPECT_FALSE(client3->GetParams().has_value());
EXPECT_FALSE(client3->HasParams());
}
TEST_F(WorkletModuleResponsesMapTest, Dispose) {
......@@ -252,7 +251,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl1, clients[0]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[0]->GetResult());
EXPECT_FALSE(clients[0]->GetParams().has_value());
EXPECT_FALSE(clients[0]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl1| should
// wait for the completion.
......@@ -265,7 +264,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
clients.push_back(MakeGarbageCollected<ClientImpl>());
Fetch(kUrl2, clients[2]);
EXPECT_EQ(ClientImpl::Result::kInitial, clients[2]->GetResult());
EXPECT_FALSE(clients[2]->GetParams().has_value());
EXPECT_FALSE(clients[2]->HasParams());
// The entry is now being fetched. Following read calls for |kUrl2| should
// wait for the completion.
......@@ -278,7 +277,7 @@ TEST_F(WorkletModuleResponsesMapTest, Dispose) {
RunUntilIdle();
for (auto client : clients) {
EXPECT_EQ(ClientImpl::Result::kFailed, client->GetResult());
EXPECT_FALSE(client->GetParams().has_value());
EXPECT_FALSE(client->HasParams());
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment