Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElementTest.cpp

Issue 2808493002: [blink] Request compositing update when canvas hibernates/wakes up. (Closed)
Patch Set: add test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLCanvasElementTest.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElementTest.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElementTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3690e4ba588bcbb921f64af0b16b22c72f87a039
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElementTest.cpp
@@ -0,0 +1,88 @@
+// Copyright 2017 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.
+
+#include "core/html/HTMLCanvasElement.h"
+
+#include "core/dom/Document.h"
+#include "core/frame/FrameView.h"
+#include "core/frame/Settings.h"
+#include "core/html/canvas/CanvasContextCreationAttributes.h"
+#include "core/layout/LayoutBoxModelObject.h"
+#include "core/page/Page.h"
+#include "core/paint/PaintLayer.h"
+#include "core/testing/DummyPageHolder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class HTMLCanvasElementTest : public testing::Test {
+ protected:
+ HTMLCanvasElementTest() {}
+
+ void SetUp() override;
+
+ Document& document() const { return *m_document; }
+
+ void setHtmlInnerHTML(const char* htmlContent);
+
+ void createContext(HTMLCanvasElement*, OpacityMode);
+
+ std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
+ Persistent<Document> m_document;
+};
+
+void OverrideSettings(Settings& settings) {
+ // Simulate that we allow scripts, so that HTMLCanvasElement uses
+ // LayoutHTMLCanvas.
+ settings.setScriptEnabled(true);
+}
+
+void HTMLCanvasElementTest::SetUp() {
+ m_dummyPageHolder = DummyPageHolder::create(
+ IntSize(800, 600), nullptr, nullptr, &OverrideSettings, nullptr);
+ m_document = &m_dummyPageHolder->document();
+ DCHECK(m_document);
+}
+
+void HTMLCanvasElementTest::setHtmlInnerHTML(const char* htmlContent) {
+ document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent));
+ document().view()->updateAllLifecyclePhases();
+}
+
+void HTMLCanvasElementTest::createContext(HTMLCanvasElement* canvas,
+ OpacityMode opacityMode) {
+ String canvasType("2d");
+ CanvasContextCreationAttributes attributes;
+ attributes.setAlpha(opacityMode == NonOpaque);
+ canvas->getCanvasRenderingContext(canvasType, attributes);
+}
+
+// https://crbug.com/708445: When visibility changes, the compositing reasons
+// for the canvas element may change. Thus, it should request a compositing
+// update.
+TEST_F(HTMLCanvasElementTest, RequestsCompositingUpdateWhenVisibilityChanges) {
+ setHtmlInnerHTML("<canvas id='canvas' width='800' height='600'></canvas>");
+ document().view()->layout();
+
+ auto* element = document().getElementById("canvas");
+ ASSERT_TRUE(element);
+ ASSERT_TRUE(isHTMLCanvasElement(element));
+ HTMLCanvasElement* canvas = toHTMLCanvasElement(element);
+ EXPECT_TRUE(canvas->layoutBoxModelObject());
+ PaintLayer* layer = canvas->layoutBoxModelObject()->layer();
+ EXPECT_TRUE(layer);
+
+ // Create context so that pageVisibilityChanged() doesn't early-out.
+ createContext(canvas, NonOpaque);
+ document().view()->updateAllLifecyclePhases();
+
+ document().page()->setVisibilityState(PageVisibilityStateHidden, false);
+ EXPECT_TRUE(layer->needsCompositingInputsUpdate());
+ document().view()->updateAllLifecyclePhases();
+
+ document().page()->setVisibilityState(PageVisibilityStateVisible, false);
+ EXPECT_TRUE(layer->needsCompositingInputsUpdate());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698