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

Side by Side Diff: Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp

Issue 1242263002: Canvas2d: Fix a bug to update incorrect rect bounds for accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « Source/modules/canvas2d/CanvasRenderingContext2D.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/canvas2d/CanvasRenderingContext2D.h" 6 #include "modules/canvas2d/CanvasRenderingContext2D.h"
7 7
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/Settings.h"
9 #include "core/html/HTMLCanvasElement.h" 10 #include "core/html/HTMLCanvasElement.h"
10 #include "core/html/HTMLDocument.h" 11 #include "core/html/HTMLDocument.h"
11 #include "core/html/ImageData.h" 12 #include "core/html/ImageData.h"
12 #include "core/loader/EmptyClients.h" 13 #include "core/loader/EmptyClients.h"
13 #include "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
15 #include "modules/accessibility/AXObject.h"
16 #include "modules/accessibility/AXObjectCacheImpl.h"
14 #include "modules/canvas2d/CanvasGradient.h" 17 #include "modules/canvas2d/CanvasGradient.h"
15 #include "modules/canvas2d/CanvasPattern.h" 18 #include "modules/canvas2d/CanvasPattern.h"
19 #include "modules/canvas2d/HitRegionOptions.h"
16 #include "modules/webgl/WebGLRenderingContext.h" 20 #include "modules/webgl/WebGLRenderingContext.h"
17 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 21 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
18 #include <gmock/gmock.h> 22 #include <gmock/gmock.h>
19 #include <gtest/gtest.h> 23 #include <gtest/gtest.h>
20 24
21 using ::testing::Mock; 25 using ::testing::Mock;
22 26
23 namespace blink { 27 namespace blink {
24 28
25 class CanvasRenderingContext2DAPITest : public ::testing::Test { 29 class CanvasRenderingContext2DAPITest : public ::testing::Test {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_FALSE(exceptionState.hadException()); 232 EXPECT_FALSE(exceptionState.hadException());
229 ImageData* imgdata4 = context2d()->createImageData(-10, -20, exceptionState) ; 233 ImageData* imgdata4 = context2d()->createImageData(-10, -20, exceptionState) ;
230 EXPECT_FALSE(exceptionState.hadException()); 234 EXPECT_FALSE(exceptionState.hadException());
231 235
232 EXPECT_EQ((unsigned)800, imgdata1->data()->length()); 236 EXPECT_EQ((unsigned)800, imgdata1->data()->length());
233 EXPECT_EQ((unsigned)800, imgdata2->data()->length()); 237 EXPECT_EQ((unsigned)800, imgdata2->data()->length());
234 EXPECT_EQ((unsigned)800, imgdata3->data()->length()); 238 EXPECT_EQ((unsigned)800, imgdata3->data()->length());
235 EXPECT_EQ((unsigned)800, imgdata4->data()->length()); 239 EXPECT_EQ((unsigned)800, imgdata4->data()->length());
236 } 240 }
237 241
242 void resetCanvasForAccessibilityRectTest(HTMLDocument& document)
243 {
244 document.documentElement()->setInnerHTML(
245 "<canvas id='canvas' style='position:absolute; top:0px; left:0px; paddin g:10px; margin:5px;'>"
246 "<button id='button'></button></canvas>", ASSERT_NO_EXCEPTION);
247 document.settings()->setAccessibilityEnabled(true);
248 HTMLCanvasElement* canvas = toHTMLCanvasElement(document.getElementById("can vas"));
249
250 String canvasType("2d");
251 CanvasContextCreationAttributes attributes;
252 attributes.setAlpha(true);
253 canvas->getCanvasRenderingContext(canvasType, attributes);
254
255 EXPECT_NE(nullptr, canvas->renderingContext());
256 EXPECT_TRUE(canvas->renderingContext()->is2d());
257 }
258
259 TEST_F(CanvasRenderingContext2DAPITest, AccessibilityRectTestForAddHitRegion)
260 {
261 resetCanvasForAccessibilityRectTest(document());
262
263 Element* buttonElement = document().getElementById("button");
264 HTMLCanvasElement* canvas = toHTMLCanvasElement(document().getElementById("c anvas"));
265 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->renderingContext());
266
267 NonThrowableExceptionState exceptionState;
268 HitRegionOptions options;
269 options.setControl(buttonElement);
270
271 context->beginPath();
272 context->rect(10, 10, 40, 40);
273 context->addHitRegion(options, exceptionState);
274
275 AXObjectCacheImpl* axObjectCache = toAXObjectCacheImpl(document().existingAX ObjectCache());
276 AXObject* axObject = axObjectCache->getOrCreate(buttonElement);
277
278 EXPECT_EQ(25, axObject->elementRect().x().toInt());
279 EXPECT_EQ(25, axObject->elementRect().y().toInt());
280 EXPECT_EQ(40, axObject->elementRect().width().toInt());
281 EXPECT_EQ(40, axObject->elementRect().height().toInt());
282 }
283
284 TEST_F(CanvasRenderingContext2DAPITest, AccessibilityRectTestForDrawFocusIfNeede d)
285 {
286 resetCanvasForAccessibilityRectTest(document());
287
288 Element* buttonElement = document().getElementById("button");
289 HTMLCanvasElement* canvas = toHTMLCanvasElement(document().getElementById("c anvas"));
290 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->renderingContext());
291
292 document().updateLayoutTreeForNodeIfNeeded(canvas);
293
294 context->beginPath();
295 context->rect(10, 10, 40, 40);
296 context->drawFocusIfNeeded(buttonElement);
297
298 AXObjectCacheImpl* axObjectCache = toAXObjectCacheImpl(document().existingAX ObjectCache());
299 AXObject* axObject = axObjectCache->getOrCreate(buttonElement);
300
301 EXPECT_EQ(25, axObject->elementRect().x().toInt());
302 EXPECT_EQ(25, axObject->elementRect().y().toInt());
303 EXPECT_EQ(40, axObject->elementRect().width().toInt());
304 EXPECT_EQ(40, axObject->elementRect().height().toInt());
305 }
306
238 } // namespace blink 307 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/canvas2d/CanvasRenderingContext2D.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698