[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / chrome_process_singleton_win_unittest.cc
1 // Copyright (c) 2013 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.
4
5 #include "chrome/browser/chrome_process_singleton.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "build/build_config.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 bool ServerCallback(int* callback_count,
18                     const base::CommandLine& command_line,
19                     const base::FilePath& current_directory) {
20   ++(*callback_count);
21   return true;
22 }
23
24 bool ClientCallback(const base::CommandLine& command_line,
25                     const base::FilePath& current_directory) {
26   ADD_FAILURE();
27   return false;
28 }
29
30 }  // namespace
31
32 TEST(ChromeProcessSingletonTest, Basic) {
33   base::ScopedTempDir profile_dir;
34   ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
35
36   int callback_count = 0;
37
38   ChromeProcessSingleton ps1(
39       profile_dir.GetPath(),
40       base::Bind(&ServerCallback, base::Unretained(&callback_count)));
41   ps1.Unlock();
42
43   ChromeProcessSingleton ps2(profile_dir.GetPath(),
44                              base::Bind(&ClientCallback));
45   ps2.Unlock();
46
47   ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
48
49   ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result);
50   ASSERT_EQ(0, callback_count);
51
52   result = ps2.NotifyOtherProcessOrCreate();
53   ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
54
55   ASSERT_EQ(1, callback_count);
56 }
57
58 TEST(ChromeProcessSingletonTest, Lock) {
59   base::ScopedTempDir profile_dir;
60   ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
61
62   int callback_count = 0;
63
64   ChromeProcessSingleton ps1(
65       profile_dir.GetPath(),
66       base::Bind(&ServerCallback, base::Unretained(&callback_count)));
67
68   ChromeProcessSingleton ps2(profile_dir.GetPath(),
69                              base::Bind(&ClientCallback));
70   ps2.Unlock();
71
72   ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
73
74   ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result);
75   ASSERT_EQ(0, callback_count);
76
77   result = ps2.NotifyOtherProcessOrCreate();
78   ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
79
80   ASSERT_EQ(0, callback_count);
81   ps1.Unlock();
82   ASSERT_EQ(1, callback_count);
83 }
84
85 #if defined(OS_WIN) && !defined(USE_AURA)
86 namespace {
87
88 void ModalNotificationHandler(bool* flag) {
89   *flag = true;
90 }
91
92 }  // namespace
93
94 TEST(ChromeProcessSingletonTest, LockWithModalDialog) {
95   base::ScopedTempDir profile_dir;
96   ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
97
98   int callback_count = 0;
99   bool called_modal_notification_handler = false;
100
101   ChromeProcessSingleton ps1(
102       profile_dir.GetPath(),
103       base::Bind(&ServerCallback, base::Unretained(&callback_count)));
104   ps1.SetModalDialogNotificationHandler(
105       base::Bind(&ModalNotificationHandler,
106                  base::Unretained(&called_modal_notification_handler)));
107
108   ChromeProcessSingleton ps2(profile_dir.GetPath(),
109                              base::Bind(&ClientCallback));
110   ps2.Unlock();
111
112   ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
113
114   ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result);
115   ASSERT_EQ(0, callback_count);
116
117   ASSERT_FALSE(called_modal_notification_handler);
118   result = ps2.NotifyOtherProcessOrCreate();
119   ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
120   ASSERT_TRUE(called_modal_notification_handler);
121
122   ASSERT_EQ(0, callback_count);
123   ps1.SetModalDialogNotificationHandler(base::Closure());
124   ps1.Unlock();
125   // The notifications sent while a modal dialog was open were processed after
126   // unlock.
127   ASSERT_EQ(2, callback_count);
128
129   // And now that the handler was cleared notifications will still be handled.
130   result = ps2.NotifyOtherProcessOrCreate();
131   ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
132   ASSERT_EQ(3, callback_count);
133 }
134 #endif  // defined(OS_WIN) && !defined(USE_AURA)