By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / ipc / ipc_message_utils_unittest.cc
blob2a49b9a56980d90145cb48fdb9dcef96bb988884
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
3 // found in the LICENSE file.
5 #include "base/file_path.h"
6 #include "ipc/ipc_message.h"
7 #include "ipc/ipc_message_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using namespace IPC;
12 namespace {
14 // Tests nesting of messages as parameters to other messages.
15 TEST(IPCMessageUtilsTest, NestedMessages) {
16 int32 nested_routing = 12;
17 uint32 nested_type = 78;
18 int nested_content = 456789;
19 Message::PriorityValue nested_priority = Message::PRIORITY_HIGH;
20 Message nested_msg(nested_routing, nested_type, nested_priority);
21 nested_msg.set_sync();
22 ParamTraits<int>::Write(&nested_msg, nested_content);
24 // Outer message contains the nested one as its parameter.
25 int32 outer_routing = 91;
26 uint32 outer_type = 88;
27 Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL;
28 Message outer_msg(outer_routing, outer_type, outer_priority);
29 ParamTraits<Message>::Write(&outer_msg, nested_msg);
31 // Read back the nested message.
32 PickleIterator iter(outer_msg);
33 IPC::Message result_msg;
34 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg));
36 // Verify nested message headers.
37 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id());
38 EXPECT_EQ(nested_msg.type(), result_msg.type());
39 EXPECT_EQ(nested_msg.priority(), result_msg.priority());
40 EXPECT_EQ(nested_msg.flags(), result_msg.flags());
42 // Verify nested message content
43 PickleIterator nested_iter(nested_msg);
44 int result_content = 0;
45 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
46 &result_content));
47 EXPECT_EQ(nested_content, result_content);
49 // Try reading past the ends for both messages and make sure it fails.
50 IPC::Message dummy;
51 ASSERT_FALSE(ParamTraits<Message>::Read(&outer_msg, &iter, &dummy));
52 ASSERT_FALSE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
53 &result_content));
56 // Tests that detection of various bad parameters is working correctly.
57 TEST(IPCMessageUtilsTest, ParameterValidation) {
58 IPC::Message message;
59 FilePath::StringType okString(FILE_PATH_LITERAL("hello"), 5);
60 FilePath::StringType badString(FILE_PATH_LITERAL("hel\0o"), 5);
61 FilePath okPath(okString);
62 FilePath badPath(badString);
63 ParamTraits<FilePath>::Write(&message, okPath);
64 ParamTraits<FilePath>::Write(&message, badPath);
66 PickleIterator iter(message);
67 ASSERT_TRUE(ParamTraits<FilePath>::Read(&message, &iter, &okPath));
68 ASSERT_FALSE(ParamTraits<FilePath>::Read(&message, &iter, &badPath));
71 } // namespace