By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / mach_broker_mac_unittest.cc
blob7bd88a550cffad1d28f3b5c86bd59d2a864e73fe
1 // Copyright (c) 2009 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 "content/browser/mach_broker_mac.h"
7 #include "base/synchronization/lock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace content {
12 class MachBrokerTest : public testing::Test {
13 public:
14 // Helper function to acquire/release locks and call |PlaceholderForPid()|.
15 void AddPlaceholderForPid(base::ProcessHandle pid) {
16 base::AutoLock lock(broker_.GetLock());
17 broker_.AddPlaceholderForPid(pid);
20 // Helper function to acquire/release locks and call |FinalizePid()|.
21 void FinalizePid(base::ProcessHandle pid,
22 const MachBroker::MachInfo& mach_info) {
23 base::AutoLock lock(broker_.GetLock());
24 broker_.FinalizePid(pid, mach_info);
27 protected:
28 MachBroker broker_;
31 TEST_F(MachBrokerTest, Locks) {
32 // Acquire and release the locks. Nothing bad should happen.
33 base::AutoLock lock(broker_.GetLock());
36 TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) {
37 // Add a placeholder for PID 1.
38 AddPlaceholderForPid(1);
39 EXPECT_EQ(0u, broker_.TaskForPid(1));
41 // Finalize PID 1.
42 FinalizePid(1, MachBroker::MachInfo().SetTask(100u));
43 EXPECT_EQ(100u, broker_.TaskForPid(1));
45 // Should be no entry for PID 2.
46 EXPECT_EQ(0u, broker_.TaskForPid(2));
49 TEST_F(MachBrokerTest, Invalidate) {
50 AddPlaceholderForPid(1);
51 FinalizePid(1, MachBroker::MachInfo().SetTask(100u));
53 EXPECT_EQ(100u, broker_.TaskForPid(1));
54 broker_.InvalidatePid(1u);
55 EXPECT_EQ(0u, broker_.TaskForPid(1));
58 TEST_F(MachBrokerTest, FinalizeUnknownPid) {
59 // Finalizing an entry for an unknown pid should not add it to the map.
60 FinalizePid(1u, MachBroker::MachInfo().SetTask(100u));
61 EXPECT_EQ(0u, broker_.TaskForPid(1u));
64 } // namespace content