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

Unified Diff: chrome/browser/chrome_process_singleton_win_unittest.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restrict chrome_process_singleton_unittest to WIN for now. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chrome_process_singleton_win_unittest.cc
diff --git a/chrome/browser/process_singleton_win_unittest.cc b/chrome/browser/chrome_process_singleton_win_unittest.cc
similarity index 62%
rename from chrome/browser/process_singleton_win_unittest.cc
rename to chrome/browser/chrome_process_singleton_win_unittest.cc
index 6484de1e9382437526fed209618c3e33a6ee174a..e9d9759a6764992740595a028d7ce0015c66026a 100644
--- a/chrome/browser/process_singleton_win_unittest.cc
+++ b/chrome/browser/chrome_process_singleton_win_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/process_singleton.h"
+#include "chrome/browser/chrome_process_singleton.h"
#include "base/bind.h"
#include "base/command_line.h"
@@ -28,16 +28,19 @@ bool ClientCallback(const CommandLine& command_line,
} // namespace
-TEST(ProcessSingletonWinTest, Basic) {
+TEST(ChromeProcessSingletonTest, Basic) {
base::ScopedTempDir profile_dir;
ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
int callback_count = 0;
- ProcessSingleton ps1(
+ ChromeProcessSingleton ps1(
profile_dir.path(),
base::Bind(&ServerCallback, base::Unretained(&callback_count)));
- ProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ps1.Unlock();
+
+ ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ps2.Unlock();
ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
@@ -50,19 +53,18 @@ TEST(ProcessSingletonWinTest, Basic) {
ASSERT_EQ(1, callback_count);
}
-#if !defined(USE_AURA)
-TEST(ProcessSingletonWinTest, Lock) {
+TEST(ChromeProcessSingletonTest, Lock) {
base::ScopedTempDir profile_dir;
ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
int callback_count = 0;
- ProcessSingleton ps1(
+ ChromeProcessSingleton ps1(
profile_dir.path(),
base::Bind(&ServerCallback, base::Unretained(&callback_count)));
- ps1.Lock(NULL);
- ProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ps2.Unlock();
gab 2013/04/19 15:11:49 ps2 shouldn't need to be unlocked to call NotifyOt
ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
@@ -77,51 +79,53 @@ TEST(ProcessSingletonWinTest, Lock) {
ASSERT_EQ(1, callback_count);
}
-class TestableProcessSingleton : public ProcessSingleton {
- public:
- TestableProcessSingleton(const base::FilePath& user_data_dir,
- const NotificationCallback& notification_callback)
- : ProcessSingleton(user_data_dir, notification_callback),
- called_set_foreground_window_(false) {}
-
- bool called_set_foreground_window() { return called_set_foreground_window_; }
+#if defined(OS_WIN) && !defined(USE_AURA)
+namespace {
- protected:
- virtual void DoSetForegroundWindow(HWND target_window) OVERRIDE {
- called_set_foreground_window_ = true;
- }
+void SetForegroundWindowHandler(bool* flag,
+ gfx::NativeWindow /* target_window */) {
+ *flag = true;
+}
- private:
- bool called_set_foreground_window_;
-};
+} // namespace
-TEST(ProcessSingletonWinTest, LockWithModalDialog) {
+TEST(ChromeProcessSingletonTest, LockWithModalDialog) {
base::ScopedTempDir profile_dir;
ASSERT_TRUE(profile_dir.CreateUniqueTempDir());
int callback_count = 0;
+ bool called_set_foreground_window = false;
- TestableProcessSingleton ps1(
+ ChromeProcessSingleton ps1(
profile_dir.path(),
- base::Bind(&ServerCallback, base::Unretained(&callback_count)));
- ps1.Lock(::GetShellWindow());
+ base::Bind(&ServerCallback, base::Unretained(&callback_count)),
+ base::Bind(&SetForegroundWindowHandler,
+ base::Unretained(&called_set_foreground_window)));
+ ps1.SetActiveModalDialog(::GetShellWindow());
- ProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ChromeProcessSingleton ps2(profile_dir.path(), base::Bind(&ClientCallback));
+ ps2.Unlock();
ProcessSingleton::NotifyResult result = ps1.NotifyOtherProcessOrCreate();
ASSERT_EQ(ProcessSingleton::PROCESS_NONE, result);
ASSERT_EQ(0, callback_count);
- ASSERT_FALSE(ps1.called_set_foreground_window());
+ ASSERT_FALSE(called_set_foreground_window);
result = ps2.NotifyOtherProcessOrCreate();
ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
- ASSERT_TRUE(ps1.called_set_foreground_window());
+ ASSERT_TRUE(called_set_foreground_window);
ASSERT_EQ(0, callback_count);
+ ps1.SetActiveModalDialog(NULL);
ps1.Unlock();
- // When a modal dialog is present, the new command-line invocation is silently
+ // The notification sent while a modal dialog was present was silently
// dropped.
ASSERT_EQ(0, callback_count);
+
+ // But now that the active modal dialog is NULL notifications will be handled.
+ result = ps2.NotifyOtherProcessOrCreate();
+ ASSERT_EQ(ProcessSingleton::PROCESS_NOTIFIED, result);
+ ASSERT_EQ(1, callback_count);
}
-#endif // !defined(USE_AURA)
+#endif // defined(OS_WIN) && !defined(USE_AURA)

Powered by Google App Engine
This is Rietveld 408576698