| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chrome_process_singleton.h" | 5 #include "chrome/browser/chrome_process_singleton.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 TEST(ChromeProcessSingletonTest, Basic) { | 32 TEST(ChromeProcessSingletonTest, Basic) { |
| 33 base::ScopedTempDir profile_dir; | 33 base::ScopedTempDir profile_dir; |
| 34 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); | 34 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); |
| 35 | 35 |
| 36 int callback_count = 0; | 36 int callback_count = 0; |
| 37 | 37 |
| 38 ChromeProcessSingleton ps1( | 38 ChromeProcessSingleton ps1( |
| 39 profile_dir.path(), | 39 profile_dir.GetPath(), |
| 40 base::Bind(&ServerCallback, base::Unretained(&callback_count))); | 40 base::Bind(&ServerCallback, base::Unretained(&callback_count))); |
| 41 ps1.Unlock(); | 41 ps1.Unlock(); |
| 42 | 42 |
| 43 ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback)); | 43 ChromeProcessSingleton ps2(profile_dir.GetPath(), |
| 44 base::Bind(&ClientCallback)); |
| 44 ps2.Unlock(); | 45 ps2.Unlock(); |
| 45 | 46 |
| 46 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); | 47 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); |
| 47 | 48 |
| 48 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); | 49 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); |
| 49 ASSERT_EQ(0, callback_count); | 50 ASSERT_EQ(0, callback_count); |
| 50 | 51 |
| 51 result = ps2.NotifyOtherProcessOrCreate(); | 52 result = ps2.NotifyOtherProcessOrCreate(); |
| 52 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); | 53 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); |
| 53 | 54 |
| 54 ASSERT_EQ(1, callback_count); | 55 ASSERT_EQ(1, callback_count); |
| 55 } | 56 } |
| 56 | 57 |
| 57 TEST(ChromeProcessSingletonTest, Lock) { | 58 TEST(ChromeProcessSingletonTest, Lock) { |
| 58 base::ScopedTempDir profile_dir; | 59 base::ScopedTempDir profile_dir; |
| 59 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); | 60 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); |
| 60 | 61 |
| 61 int callback_count = 0; | 62 int callback_count = 0; |
| 62 | 63 |
| 63 ChromeProcessSingleton ps1( | 64 ChromeProcessSingleton ps1( |
| 64 profile_dir.path(), | 65 profile_dir.GetPath(), |
| 65 base::Bind(&ServerCallback, base::Unretained(&callback_count))); | 66 base::Bind(&ServerCallback, base::Unretained(&callback_count))); |
| 66 | 67 |
| 67 ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback)); | 68 ChromeProcessSingleton ps2(profile_dir.GetPath(), |
| 69 base::Bind(&ClientCallback)); |
| 68 ps2.Unlock(); | 70 ps2.Unlock(); |
| 69 | 71 |
| 70 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); | 72 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); |
| 71 | 73 |
| 72 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); | 74 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); |
| 73 ASSERT_EQ(0, callback_count); | 75 ASSERT_EQ(0, callback_count); |
| 74 | 76 |
| 75 result = ps2.NotifyOtherProcessOrCreate(); | 77 result = ps2.NotifyOtherProcessOrCreate(); |
| 76 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); | 78 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); |
| 77 | 79 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 91 } // namespace | 93 } // namespace |
| 92 | 94 |
| 93 TEST(ChromeProcessSingletonTest, LockWithModalDialog) { | 95 TEST(ChromeProcessSingletonTest, LockWithModalDialog) { |
| 94 base::ScopedTempDir profile_dir; | 96 base::ScopedTempDir profile_dir; |
| 95 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); | 97 ASSERT_TRUE(profile_dir.CreateUniqueTempDir()); |
| 96 | 98 |
| 97 int callback_count = 0; | 99 int callback_count = 0; |
| 98 bool called_set_foreground_window = false; | 100 bool called_set_foreground_window = false; |
| 99 | 101 |
| 100 ChromeProcessSingleton ps1( | 102 ChromeProcessSingleton ps1( |
| 101 profile_dir.path(), | 103 profile_dir.GetPath(), |
| 102 base::Bind(&ServerCallback, base::Unretained(&callback_count)), | 104 base::Bind(&ServerCallback, base::Unretained(&callback_count)), |
| 103 base::Bind(&SetForegroundWindowHandler, | 105 base::Bind(&SetForegroundWindowHandler, |
| 104 base::Unretained(&called_set_foreground_window))); | 106 base::Unretained(&called_set_foreground_window))); |
| 105 ps1.SetActiveModalDialog(::GetShellWindow()); | 107 ps1.SetActiveModalDialog(::GetShellWindow()); |
| 106 | 108 |
| 107 ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback)); | 109 ChromeProcessSingleton ps2(profile_dir.GetPath(), |
| 110 base::Bind(&ClientCallback)); |
| 108 ps2.Unlock(); | 111 ps2.Unlock(); |
| 109 | 112 |
| 110 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); | 113 ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate(); |
| 111 | 114 |
| 112 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); | 115 ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result); |
| 113 ASSERT_EQ(0, callback_count); | 116 ASSERT_EQ(0, callback_count); |
| 114 | 117 |
| 115 ASSERT_FALSE(called_set_foreground_window); | 118 ASSERT_FALSE(called_set_foreground_window); |
| 116 result = ps2.NotifyOtherProcessOrCreate(); | 119 result = ps2.NotifyOtherProcessOrCreate(); |
| 117 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); | 120 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); |
| 118 ASSERT_TRUE(called_set_foreground_window); | 121 ASSERT_TRUE(called_set_foreground_window); |
| 119 | 122 |
| 120 ASSERT_EQ(0, callback_count); | 123 ASSERT_EQ(0, callback_count); |
| 121 ps1.SetActiveModalDialog(NULL); | 124 ps1.SetActiveModalDialog(NULL); |
| 122 ps1.Unlock(); | 125 ps1.Unlock(); |
| 123 // The notification sent while a modal dialog was present was silently | 126 // The notification sent while a modal dialog was present was silently |
| 124 // dropped. | 127 // dropped. |
| 125 ASSERT_EQ(0, callback_count); | 128 ASSERT_EQ(0, callback_count); |
| 126 | 129 |
| 127 // But now that the active modal dialog is NULL notifications will be handled. | 130 // But now that the active modal dialog is NULL notifications will be handled. |
| 128 result = ps2.NotifyOtherProcessOrCreate(); | 131 result = ps2.NotifyOtherProcessOrCreate(); |
| 129 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); | 132 ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result); |
| 130 ASSERT_EQ(1, callback_count); | 133 ASSERT_EQ(1, callback_count); |
| 131 } | 134 } |
| 132 #endif // defined(OS_WIN) && !defined(USE_AURA) | 135 #endif // defined(OS_WIN) && !defined(USE_AURA) |
| OLD | NEW |