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

Side by Side Diff: content/common/cc_messages_unittest.cc

Issue 196423027: Move SoftwareFrameData overflow checks to the IPC code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
« content/common/cc_messages.cc ('K') | « content/common/cc_messages.cc ('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 (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 "content/common/cc_messages.h" 5 #include "content/common/cc_messages.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "cc/output/compositor_frame.h" 11 #include "cc/output/compositor_frame.h"
12 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/khronos/GLES2/gl2ext.h" 14 #include "third_party/khronos/GLES2/gl2ext.h"
15 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
16 16
17 #if defined(OS_POSIX)
18 #include "base/file_descriptor_posix.h"
19 #endif
20
17 using cc::CheckerboardDrawQuad; 21 using cc::CheckerboardDrawQuad;
18 using cc::DelegatedFrameData; 22 using cc::DelegatedFrameData;
19 using cc::DebugBorderDrawQuad; 23 using cc::DebugBorderDrawQuad;
20 using cc::DrawQuad; 24 using cc::DrawQuad;
21 using cc::FilterOperation; 25 using cc::FilterOperation;
22 using cc::FilterOperations; 26 using cc::FilterOperations;
23 using cc::IOSurfaceDrawQuad; 27 using cc::IOSurfaceDrawQuad;
24 using cc::PictureDrawQuad; 28 using cc::PictureDrawQuad;
25 using cc::RenderPass; 29 using cc::RenderPass;
26 using cc::RenderPassDrawQuad; 30 using cc::RenderPassDrawQuad;
27 using cc::ResourceProvider; 31 using cc::ResourceProvider;
28 using cc::SharedQuadState; 32 using cc::SharedQuadState;
33 using cc::SoftwareFrameData;
29 using cc::SolidColorDrawQuad; 34 using cc::SolidColorDrawQuad;
30 using cc::SurfaceDrawQuad; 35 using cc::SurfaceDrawQuad;
31 using cc::TextureDrawQuad; 36 using cc::TextureDrawQuad;
32 using cc::TileDrawQuad; 37 using cc::TileDrawQuad;
33 using cc::TransferableResource; 38 using cc::TransferableResource;
34 using cc::StreamVideoDrawQuad; 39 using cc::StreamVideoDrawQuad;
35 using cc::VideoLayerImpl; 40 using cc::VideoLayerImpl;
36 using cc::YUVVideoDrawQuad; 41 using cc::YUVVideoDrawQuad;
37 using gfx::Transform; 42 using gfx::Transform;
38 43
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 done = true; 740 done = true;
736 } 741 }
737 } 742 }
738 743
739 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever 744 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever
740 // changes, then the ReserveSizeForRenderPassWrite() method needs to be 745 // changes, then the ReserveSizeForRenderPassWrite() method needs to be
741 // updated as well to use the new largest quad. 746 // updated as well to use the new largest quad.
742 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest); 747 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest);
743 } 748 }
744 749
750 TEST_F(CCMessagesTest, SoftwareFrameData) {
751 cc::SoftwareFrameData frame_in;
752 frame_in.id = 3;
753 frame_in.size = gfx::Size(40, 20);
754 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
755 #if defined(OS_WIN)
756 frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
757 #elif defined(OS_POSIX)
758 frame_in.handle = base::FileDescriptor(23, true);
759 #endif
760
761 // Write the frame.
762 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
763 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
764
765 // Read the frame.
766 cc::SoftwareFrameData frame_out;
767 PickleIterator iter(msg);
768 EXPECT_TRUE(
769 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
770 EXPECT_EQ(frame_in.id, frame_out.id);
771 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
772 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
773 EXPECT_EQ(frame_in.handle, frame_out.handle);
774 }
775
776 TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
777 int max = std::numeric_limits<int>::max();
778
779 // The size of the frame will overflow when multiplied together.
780 SoftwareFrameData frame_in;
781 frame_in.id = 3;
782 frame_in.size = gfx::Size(max, max);
783 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
784 #if defined(OS_WIN)
785 frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
786 #elif defined(OS_POSIX)
787 frame_in.handle = base::FileDescriptor(23, true);
788 #endif
789
790 // Write the frame.
791 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
792 IPC::ParamTraits<SoftwareFrameData>::Write(&msg, frame_in);
793
794 // If size_t is larger than int, then int*int*4 can always fit in size_t.
795 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
796
797 // Read the frame.
798 SoftwareFrameData frame_out;
799 PickleIterator iter(msg);
800 EXPECT_EQ(expect_read,
801 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
802 }
803
745 } // namespace 804 } // namespace
746 } // namespace content 805 } // namespace content
OLDNEW
« content/common/cc_messages.cc ('K') | « content/common/cc_messages.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698