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

Side by Side Diff: content/child/shared_memory_data_consumer_handle_unittest.cc

Issue 2391513002: Remove lock from SharedMemoryDataConsumerHandle::Context destructor (Closed)
Patch Set: fix Created 4 years, 2 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
« no previous file with comments | « content/child/shared_memory_data_consumer_handle.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/child/shared_memory_data_consumer_handle.h" 5 #include "content/child/shared_memory_data_consumer_handle.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_split.h"
22 #include "base/task_runner.h" 23 #include "base/task_runner.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
25 #include "content/public/child/fixed_received_data.h" 26 #include "content/public/child/fixed_received_data.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 namespace content { 30 namespace content {
30 31
31 namespace { 32 namespace {
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 result = reader->read(buffer, 2, kNone, &size); 968 result = reader->read(buffer, 2, kNone, &size);
968 EXPECT_EQ(kOk, result); 969 EXPECT_EQ(kOk, result);
969 EXPECT_EQ(2u, size); 970 EXPECT_EQ(2u, size);
970 logger->Add("2"); 971 logger->Add("2");
971 writer->Close(); 972 writer->Close();
972 logger->Add("3"); 973 logger->Add("3");
973 handle.reset(); 974 handle.reset();
974 reader.reset(); 975 reader.reset();
975 logger->Add("4"); 976 logger->Add("4");
976 977
977 EXPECT_EQ( 978 std::vector<std::string> log = base::SplitString(
978 "1\n" 979 logger->log(), "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
979 "2\n" 980
980 "3\n" 981 ASSERT_EQ(8u, log.size());
981 "data1 is destructed.\n" 982 EXPECT_EQ("1", log[0]);
982 "data2 is destructed.\n" 983 EXPECT_EQ("2", log[1]);
983 "data3 is destructed.\n" 984 EXPECT_EQ("3", log[2]);
984 "4\n", 985 EXPECT_EQ("4", log[6]);
985 logger->log()); 986 EXPECT_EQ("", log[7]);
987
988 // The destruction order doesn't matter in this case.
989 std::vector<std::string> destruction_entries = {log[3], log[4], log[5]};
990 std::sort(destruction_entries.begin(), destruction_entries.end());
991 EXPECT_EQ(destruction_entries[0], "data1 is destructed.");
992 EXPECT_EQ(destruction_entries[1], "data2 is destructed.");
993 EXPECT_EQ(destruction_entries[2], "data3 is destructed.");
986 } 994 }
987 995
988 TEST(SharedMemoryDataConsumerHandleWithoutBackpressureTest, AddData) { 996 TEST(SharedMemoryDataConsumerHandleWithoutBackpressureTest, AddData) {
989 base::MessageLoop loop; 997 base::MessageLoop loop;
990 std::unique_ptr<Writer> writer; 998 std::unique_ptr<Writer> writer;
991 auto handle = base::MakeUnique<SharedMemoryDataConsumerHandle>( 999 auto handle = base::MakeUnique<SharedMemoryDataConsumerHandle>(
992 kDoNotApplyBackpressure, &writer); 1000 kDoNotApplyBackpressure, &writer);
993 scoped_refptr<Logger> logger(new Logger); 1001 scoped_refptr<Logger> logger(new Logger);
994 1002
995 logger->Add("1"); 1003 logger->Add("1");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 logger->log()); 1059 logger->log());
1052 } 1060 }
1053 1061
1054 INSTANTIATE_TEST_CASE_P(SharedMemoryDataConsumerHandleTest, 1062 INSTANTIATE_TEST_CASE_P(SharedMemoryDataConsumerHandleTest,
1055 SharedMemoryDataConsumerHandleTest, 1063 SharedMemoryDataConsumerHandleTest,
1056 ::testing::Values(kApplyBackpressure, 1064 ::testing::Values(kApplyBackpressure,
1057 kDoNotApplyBackpressure)); 1065 kDoNotApplyBackpressure));
1058 } // namespace 1066 } // namespace
1059 1067
1060 } // namespace content 1068 } // namespace content
OLDNEW
« no previous file with comments | « content/child/shared_memory_data_consumer_handle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698