TestOffscreenCanvas.cpp (1532B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "OffscreenCanvasDisplayHelper.h" 7 #include "gtest/gtest.h" 8 #include "mozilla/dom/CanvasRenderingContextHelper.h" 9 #include "mozilla/dom/WorkerRef.h" 10 11 namespace mozilla::dom { 12 13 // Bug 2004797: Verify UpdateContext preserves ImageContainer. 14 // Recreating ImageContainer on each call discards existing frames, causing 15 // flicker when getContext() is called repeatedly. 16 TEST(OffscreenCanvasDisplayHelper, UpdateContextPreservesImageContainer) 17 { 18 RefPtr<OffscreenCanvasDisplayHelper> helper = 19 MakeRefPtr<OffscreenCanvasDisplayHelper>(nullptr, 100, 100); 20 21 // Initially no ImageContainer 22 EXPECT_EQ(helper->GetImageContainer(), nullptr); 23 24 // First UpdateContext creates an ImageContainer 25 helper->UpdateContext(nullptr, nullptr, CanvasContextType::Canvas2D, 26 Nothing()); 27 RefPtr<layers::ImageContainer> container1 = helper->GetImageContainer(); 28 EXPECT_NE(container1, nullptr); 29 30 // Second UpdateContext should preserve the same ImageContainer 31 helper->UpdateContext(nullptr, nullptr, CanvasContextType::Canvas2D, 32 Nothing()); 33 RefPtr<layers::ImageContainer> container2 = helper->GetImageContainer(); 34 EXPECT_EQ(container1.get(), container2.get()); 35 } 36 37 } // namespace mozilla::dom