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

Side by Side Diff: Source/web/tests/WebViewTest.cpp

Issue 23483051: Blend background with existing content (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix test in android Created 7 years 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/web/WebSettingsImpl.cpp ('k') | public/web/WebSettings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "WebWidget.h" 51 #include "WebWidget.h"
52 #include "core/dom/Document.h" 52 #include "core/dom/Document.h"
53 #include "core/dom/Element.h" 53 #include "core/dom/Element.h"
54 #include "core/html/HTMLDocument.h" 54 #include "core/html/HTMLDocument.h"
55 #include "core/html/HTMLInputElement.h" 55 #include "core/html/HTMLInputElement.h"
56 #include "core/loader/FrameLoadRequest.h" 56 #include "core/loader/FrameLoadRequest.h"
57 #include "core/frame/FrameView.h" 57 #include "core/frame/FrameView.h"
58 #include "core/page/Chrome.h" 58 #include "core/page/Chrome.h"
59 #include "core/page/Settings.h" 59 #include "core/page/Settings.h"
60 #include "core/platform/chromium/KeyboardCodes.h" 60 #include "core/platform/chromium/KeyboardCodes.h"
61 #include "platform/graphics/Color.h"
61 #include "public/platform/Platform.h" 62 #include "public/platform/Platform.h"
62 #include "public/platform/WebSize.h" 63 #include "public/platform/WebSize.h"
63 #include "public/platform/WebThread.h" 64 #include "public/platform/WebThread.h"
64 #include "public/platform/WebUnitTestSupport.h" 65 #include "public/platform/WebUnitTestSupport.h"
65 #include "public/web/WebWidgetClient.h" 66 #include "public/web/WebWidgetClient.h"
67 #include "third_party/skia/include/core/SkBitmap.h"
68 #include "third_party/skia/include/core/SkBitmapDevice.h"
69 #include "third_party/skia/include/core/SkCanvas.h"
66 70
67 using namespace blink; 71 using namespace blink;
68 using blink::FrameTestHelpers::runPendingTasks; 72 using blink::FrameTestHelpers::runPendingTasks;
69 using blink::URLTestHelpers::toKURL; 73 using blink::URLTestHelpers::toKURL;
70 74
71 namespace { 75 namespace {
72 76
73 enum HorizontalScrollbarState { 77 enum HorizontalScrollbarState {
74 NoHorizontalScrollbar, 78 NoHorizontalScrollbar,
75 VisibleHorizontalScrollbar, 79 VisibleHorizontalScrollbar,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame) 282 TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame)
279 { 283 {
280 const WebColor kBlue = 0xFF0000FF; 284 const WebColor kBlue = 0xFF0000FF;
281 WebView* webView = WebViewImpl::create(0); 285 WebView* webView = WebViewImpl::create(0);
282 EXPECT_NE(kBlue, webView->backgroundColor()); 286 EXPECT_NE(kBlue, webView->backgroundColor());
283 // webView does not have a frame yet, but we should still be able to set the background color. 287 // webView does not have a frame yet, but we should still be able to set the background color.
284 webView->setBaseBackgroundColor(kBlue); 288 webView->setBaseBackgroundColor(kBlue);
285 EXPECT_EQ(kBlue, webView->backgroundColor()); 289 EXPECT_EQ(kBlue, webView->backgroundColor());
286 } 290 }
287 291
292 TEST_F(WebViewTest, SetBaseBackgroundColorAndBlendWithExistingContent)
293 {
294 const WebColor kAlphaRed = 0x80FF0000;
295 const WebColor kAlphaGreen = 0x8000FF00;
296 const int kWidth = 100;
297 const int kHeight = 100;
298
299 // Set WebView background to green with alpha.
300 WebView* webView = m_webViewHelper.initialize();
301 webView->setBaseBackgroundColor(kAlphaGreen);
302 webView->settings()->setShouldClearDocumentBackground(false);
303 webView->resize(WebSize(kWidth, kHeight));
304 webView->layout();
305
306 // Set canvas background to red with alpha.
307 SkBitmap bitmap;
308 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight);
309 bitmap.allocPixels();
310 SkBitmapDevice device(bitmap);
311 SkCanvas canvas(&device);
312 canvas.clear(kAlphaRed);
313 webView->paint(&canvas, WebRect(0, 0, kWidth, kHeight));
314
315 // The result should be a blend of red and green.
316 SkColor color = bitmap.getColor(kWidth / 2, kHeight / 2);
317 EXPECT_TRUE(WebCore::redChannel(color));
318 EXPECT_TRUE(WebCore::greenChannel(color));
319 }
320
288 TEST_F(WebViewTest, FocusIsInactive) 321 TEST_F(WebViewTest, FocusIsInactive)
289 { 322 {
290 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), "visible_iframe.html"); 323 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), "visible_iframe.html");
291 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if rame.html"); 324 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if rame.html");
292 325
293 webView->setFocus(true); 326 webView->setFocus(true);
294 webView->setIsActive(true); 327 webView->setIsActive(true);
295 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); 328 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
296 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); 329 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
297 330
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 EXPECT_STREQ("1970-W01", inputElement->value().utf8().data()); 1402 EXPECT_STREQ("1970-W01", inputElement->value().utf8().data());
1370 1403
1371 openDateTimeChooser(webViewImpl, inputElement); 1404 openDateTimeChooser(webViewImpl, inputElement);
1372 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie t_NaN()); 1405 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie t_NaN());
1373 client.clearChooserCompletion(); 1406 client.clearChooserCompletion();
1374 EXPECT_STREQ("", inputElement->value().utf8().data()); 1407 EXPECT_STREQ("", inputElement->value().utf8().data());
1375 } 1408 }
1376 #endif 1409 #endif
1377 1410
1378 } 1411 }
OLDNEW
« no previous file with comments | « Source/web/WebSettingsImpl.cpp ('k') | public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698