OLD | NEW |
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 Loading... |
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 // Unable to include render_widget_host_view_mac.h and compile. |
| 957 #if !defined(OS_MACOSX) |
| 958 // Tests setting background transparency. |
957 TEST_F(RenderWidgetHostTest, Background) { | 959 TEST_F(RenderWidgetHostTest, Background) { |
958 #if !defined(OS_MACOSX) | |
959 scoped_ptr<RenderWidgetHostViewBase> view; | 960 scoped_ptr<RenderWidgetHostViewBase> view; |
960 #if defined(USE_AURA) | 961 #if defined(USE_AURA) |
961 view.reset(new RenderWidgetHostViewAura(host_.get())); | 962 view.reset(new RenderWidgetHostViewAura(host_.get())); |
962 // TODO(derat): Call this on all platforms: http://crbug.com/102450. | 963 // TODO(derat): Call this on all platforms: http://crbug.com/102450. |
963 view->InitAsChild(NULL); | 964 view->InitAsChild(NULL); |
964 #elif defined(OS_ANDROID) | 965 #elif defined(OS_ANDROID) |
965 view.reset(new RenderWidgetHostViewAndroid(host_.get(), NULL)); | 966 view.reset(new RenderWidgetHostViewAndroid(host_.get(), NULL)); |
966 #endif | 967 #endif |
967 host_->SetView(view.get()); | 968 host_->SetView(view.get()); |
968 | 969 |
969 // Create a checkerboard background to test with. | 970 EXPECT_TRUE(view->GetBackgroundOpaque()); |
970 gfx::Canvas canvas(gfx::Size(4, 4), 1.0f, true); | 971 view->SetBackgroundOpaque(false); |
971 canvas.FillRect(gfx::Rect(0, 0, 2, 2), SK_ColorBLACK); | 972 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 | 973 |
991 const IPC::Message* set_background = | 974 const IPC::Message* set_background = |
992 process_->sink().GetUniqueMessageMatching(ViewMsg_SetBackground::ID); | 975 process_->sink().GetUniqueMessageMatching( |
| 976 ViewMsg_SetBackgroundOpaque::ID); |
993 ASSERT_TRUE(set_background); | 977 ASSERT_TRUE(set_background); |
994 Tuple1<SkBitmap> sent_background; | 978 Tuple1<bool> sent_background; |
995 ViewMsg_SetBackground::Read(set_background, &sent_background); | 979 ViewMsg_SetBackgroundOpaque::Read(set_background, &sent_background); |
996 EXPECT_EQ(background.getSize(), sent_background.a.getSize()); | 980 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 | 981 |
1005 #if defined(USE_AURA) | 982 #if defined(USE_AURA) |
1006 // See the comment above |InitAsChild(NULL)|. | 983 // See the comment above |InitAsChild(NULL)|. |
1007 host_->SetView(NULL); | 984 host_->SetView(NULL); |
1008 static_cast<RenderWidgetHostViewBase*>(view.release())->Destroy(); | 985 static_cast<RenderWidgetHostViewBase*>(view.release())->Destroy(); |
1009 #endif | 986 #endif |
1010 | 987 } |
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 | 988 #endif |
1015 | 989 |
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 } | |
1020 | |
1021 // Test that we don't paint when we're hidden, but we still send the ACK. Most | 990 // 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. | 991 // of the rest of the painting is tested in the GetBackingStore* ones. |
1023 TEST_F(RenderWidgetHostTest, HiddenPaint) { | 992 TEST_F(RenderWidgetHostTest, HiddenPaint) { |
1024 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | 993 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); |
1025 // Hide the widget, it should have sent out a message to the renderer. | 994 // Hide the widget, it should have sent out a message to the renderer. |
1026 EXPECT_FALSE(host_->is_hidden_); | 995 EXPECT_FALSE(host_->is_hidden_); |
1027 host_->WasHidden(); | 996 host_->WasHidden(); |
1028 EXPECT_TRUE(host_->is_hidden_); | 997 EXPECT_TRUE(host_->is_hidden_); |
1029 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID)); | 998 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID)); |
1030 | 999 |
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2669 | 2638 |
2670 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). | 2639 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). |
2671 PressTouchPoint(0, 1); | 2640 PressTouchPoint(0, 1); |
2672 SendTouchEvent(); | 2641 SendTouchEvent(); |
2673 CheckLatencyInfoComponentInMessage( | 2642 CheckLatencyInfoComponentInMessage( |
2674 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); | 2643 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); |
2675 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 2644 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
2676 } | 2645 } |
2677 | 2646 |
2678 } // namespace content | 2647 } // namespace content |
OLD | NEW |