Commit b8dc578a authored by cfredric's avatar cfredric Committed by Commit Bot

Add browsertest for canvas toBlob readbacks.

Change-Id: I4edb4c31afbd3d54b2bbe673778a783810312dc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477041
Commit-Queue: Chris Fredrickson <cfredric@google.com>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819393}
parent bbbd5d58
......@@ -12,6 +12,7 @@
#include "components/variations/service/buildflags.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -120,6 +121,50 @@ IN_PROC_BROWSER_TEST_F(PrivacyBudgetBrowserTest, SamplingScreenAPIs) {
}));
}
IN_PROC_BROWSER_TEST_F(PrivacyBudgetBrowserTest, CallsCanvasToBlob) {
ASSERT_TRUE(embedded_test_server()->Start());
content::DOMMessageQueue messages;
base::RunLoop run_loop;
recorder().SetOnAddEntryCallback(ukm::builders::Identifiability::kEntryName,
run_loop.QuitClosure());
ASSERT_TRUE(content::NavigateToURL(
web_contents(), embedded_test_server()->GetURL(
"/privacy_budget/calls_canvas_to_blob.html")));
// The document calls an instrumented method and sends a message
// back to the test. Receipt of the message indicates that the script
// successfully completed. However, we must also wait for the UKM metric to be
// recorded, which happens on a TaskRunner.
std::string blob_type;
ASSERT_TRUE(messages.WaitForMessage(&blob_type));
// Navigating away from the test page causes the document to be unloaded. That
// will cause any buffered metrics to be flushed.
content::NavigateToURLBlockUntilNavigationsComplete(web_contents(),
GURL("about:blank"), 1);
// Wait for the metrics to come down the pipe.
content::RunAllTasksUntilIdle();
run_loop.Run();
auto merged_entries = recorder().GetMergedEntriesByName(
ukm::builders::Identifiability::kEntryName);
// Shouldn't be more than one source here. If this changes, then we'd need to
// adjust this test to deal.
ASSERT_EQ(1u, merged_entries.size());
constexpr uint64_t input_digest = 0;
EXPECT_THAT(merged_entries.begin()->second->metrics,
IsSupersetOf({
Key(blink::IdentifiableSurface::FromTypeAndToken(
blink::IdentifiableSurface::Type::kCanvasReadback,
input_digest)
.ToUkmMetricHash()),
}));
}
#if BUILDFLAG(FIELDTRIAL_TESTING_ENABLED)
namespace {
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Privacy Budget: Test page that calls Canvas.toBlob.</title>
<script src="test_utils.js"></script>
<script src="canvas_to_blob.js"></script>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Gets an image blob from a HTMLCanvasElement and sends it back to the test
// via `sendValueToTest`.
window.addEventListener('load', () => {
document.createElement('canvas').toBlob(function(blob) {
sendValueToTest(JSON.stringify({
'type': blob.type,
}));
});
});
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