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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 274453002: Remove RenderWidget::SetBackground, change IPC to pass a bool. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 // deleted. 946 // deleted.
947 host_->SetView(NULL); 947 host_->SetView(NULL);
948 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 948 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
949 EXPECT_FALSE(host_->resize_ack_pending_); 949 EXPECT_FALSE(host_->resize_ack_pending_);
950 EXPECT_EQ(gfx::Size(), host_->last_requested_size_); 950 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
951 951
952 // Reset the view so we can exit the test cleanly. 952 // Reset the view so we can exit the test cleanly.
953 host_->SetView(view_.get()); 953 host_->SetView(view_.get());
954 } 954 }
955 955
956 // Tests setting custom background 956 // Tests setting background transparency.
957 TEST_F(RenderWidgetHostTest, Background) { 957 TEST_F(RenderWidgetHostTest, Background) {
958 #if !defined(OS_MACOSX)
959 scoped_ptr<RenderWidgetHostViewBase> view; 958 scoped_ptr<RenderWidgetHostViewBase> view;
960 #if defined(USE_AURA) 959 #if defined(USE_AURA)
961 view.reset(new RenderWidgetHostViewAura(host_.get())); 960 view.reset(new RenderWidgetHostViewAura(host_.get()));
962 // TODO(derat): Call this on all platforms: http://crbug.com/102450. 961 // TODO(derat): Call this on all platforms: http://crbug.com/102450.
963 view->InitAsChild(NULL); 962 view->InitAsChild(NULL);
964 #elif defined(OS_ANDROID) 963 #elif defined(OS_ANDROID)
965 view.reset(new RenderWidgetHostViewAndroid(host_.get(), NULL)); 964 view.reset(new RenderWidgetHostViewAndroid(host_.get(), NULL));
966 #endif 965 #endif
967 host_->SetView(view.get()); 966 host_->SetView(view.get());
968 967
969 // Create a checkerboard background to test with. 968 EXPECT_TRUE(view->GetBackgroundOpaque());
970 gfx::Canvas canvas(gfx::Size(4, 4), 1.0f, true); 969 view->SetBackgroundOpaque(false);
971 canvas.FillRect(gfx::Rect(0, 0, 2, 2), SK_ColorBLACK); 970 EXPECT_FALSE(view->GetBackgroundOpaque());
972 canvas.FillRect(gfx::Rect(2, 0, 2, 2), SK_ColorWHITE);
973 canvas.FillRect(gfx::Rect(0, 2, 2, 2), SK_ColorWHITE);
974 canvas.FillRect(gfx::Rect(2, 2, 2, 2), SK_ColorBLACK);
975 const SkBitmap& background =
976 canvas.sk_canvas()->getDevice()->accessBitmap(false);
977
978 // Set the background and make sure we get back a copy.
979 view->SetBackground(background);
980 EXPECT_EQ(4, view->GetBackground().width());
981 EXPECT_EQ(4, view->GetBackground().height());
982 EXPECT_EQ(background.getSize(), view->GetBackground().getSize());
983 background.lockPixels();
984 view->GetBackground().lockPixels();
985 EXPECT_TRUE(0 == memcmp(background.getPixels(),
986 view->GetBackground().getPixels(),
987 background.getSize()));
988 view->GetBackground().unlockPixels();
989 background.unlockPixels();
990 971
991 const IPC::Message* set_background = 972 const IPC::Message* set_background =
992 process_->sink().GetUniqueMessageMatching(ViewMsg_SetBackground::ID); 973 process_->sink().GetUniqueMessageMatching(
974 ViewMsg_SetBackgroundOpaque::ID);
993 ASSERT_TRUE(set_background); 975 ASSERT_TRUE(set_background);
994 Tuple1<SkBitmap> sent_background; 976 Tuple1<bool> sent_background;
995 ViewMsg_SetBackground::Read(set_background, &sent_background); 977 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background);
996 EXPECT_EQ(background.getSize(), sent_background.a.getSize()); 978 EXPECT_FALSE(sent_background.a);
997 background.lockPixels();
998 sent_background.a.lockPixels();
999 EXPECT_TRUE(0 == memcmp(background.getPixels(),
1000 sent_background.a.getPixels(),
1001 background.getSize()));
1002 sent_background.a.unlockPixels();
1003 background.unlockPixels();
1004 979
1005 #if defined(USE_AURA) 980 #if defined(USE_AURA)
1006 // See the comment above |InitAsChild(NULL)|. 981 // See the comment above |InitAsChild(NULL)|.
1007 host_->SetView(NULL); 982 host_->SetView(NULL);
1008 static_cast<RenderWidgetHostViewBase*>(view.release())->Destroy(); 983 static_cast<RenderWidgetHostViewBase*>(view.release())->Destroy();
1009 #endif 984 #endif
1010
1011 #else
1012 // TODO(port): Mac does not have gfx::Canvas. Maybe we can just change this
1013 // test to use SkCanvas directly?
1014 #endif
1015
1016 // TODO(aa): It would be nice to factor out the painting logic so that we
1017 // could test that, but it appears that would mean painting everything twice
1018 // since windows HDC structures are opaque.
1019 } 985 }
1020 986
1021 // Test that we don't paint when we're hidden, but we still send the ACK. Most 987 // Test that we don't paint when we're hidden, but we still send the ACK. Most
1022 // of the rest of the painting is tested in the GetBackingStore* ones. 988 // of the rest of the painting is tested in the GetBackingStore* ones.
1023 TEST_F(RenderWidgetHostTest, HiddenPaint) { 989 TEST_F(RenderWidgetHostTest, HiddenPaint) {
1024 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); 990 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current());
1025 // Hide the widget, it should have sent out a message to the renderer. 991 // Hide the widget, it should have sent out a message to the renderer.
1026 EXPECT_FALSE(host_->is_hidden_); 992 EXPECT_FALSE(host_->is_hidden_);
1027 host_->WasHidden(); 993 host_->WasHidden();
1028 EXPECT_TRUE(host_->is_hidden_); 994 EXPECT_TRUE(host_->is_hidden_);
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 2635
2670 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). 2636 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
2671 PressTouchPoint(0, 1); 2637 PressTouchPoint(0, 1);
2672 SendTouchEvent(); 2638 SendTouchEvent();
2673 CheckLatencyInfoComponentInMessage( 2639 CheckLatencyInfoComponentInMessage(
2674 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); 2640 process_, GetLatencyComponentId(), WebInputEvent::TouchStart);
2675 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 2641 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
2676 } 2642 }
2677 2643
2678 } // namespace content 2644 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698