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

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

Powered by Google App Engine
This is Rietveld 408576698