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

Side by Side Diff: chrome/browser/process_singleton_linux_uitest.cc

Issue 159577: Linux: Adds ACKs to ProcessSingletonLinux. (Closed)
Patch Set: Remove extra header. Created 11 years, 4 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 | « chrome/browser/process_singleton_linux.cc ('k') | chrome/browser/process_singleton_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/process_singleton.h"
6
7 #include <sys/types.h>
8 #include <sys/wait.h>
9 #include <signal.h>
10 #include <unistd.h>
11 #include <vector>
12 #include <string>
13
14 #include "base/path_service.h"
15 #include "base/string_util.h"
16 #include "base/thread.h"
17 #include "chrome/browser/browser.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/test/ui/ui_test.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 class ProcessSingletonLinuxTest : public UITest {
25 protected:
26 // A helper method to call ProcessSingleton::NotifyOtherProcess().
27 // |url| will be added to CommandLine for current process, so that it can be
28 // sent to browser process by ProcessSingleton::NotifyOtherProcess().
29 void NotifyOtherProcess(const std::string& url, bool expect_result) {
30 FilePath user_data_dir;
31 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
32
33 std::vector<std::string> old_argv =
34 CommandLine::ForCurrentProcess()->argv();
35 std::vector<std::string> argv;
36 argv.push_back(old_argv[0]);
37 argv.push_back(url);
38
39 CommandLine::Reset();
40 CommandLine::Init(argv);
41
42 ProcessSingleton process_singleton(user_data_dir);
43
44 if (expect_result)
45 EXPECT_TRUE(process_singleton.NotifyOtherProcess());
46 else
47 EXPECT_FALSE(process_singleton.NotifyOtherProcess());
48 }
49 };
50
51 // Test if the socket file and symbol link created by ProcessSingletonLinux
52 // are valid. When running this test, the ProcessSingleton object is already
53 // initiated by UITest. So we just test against this existing object.
54 TEST_F(ProcessSingletonLinuxTest, CheckSocketFile) {
55 FilePath user_data_dir;
56 FilePath path;
57 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
58
59 path = user_data_dir.Append(chrome::kSingletonSocketFilename);
60
61 struct stat statbuf;
62 ASSERT_EQ(0, lstat(path.value().c_str(), &statbuf));
63 ASSERT_TRUE(S_ISLNK(statbuf.st_mode));
64 char buf[PATH_MAX + 1];
65 ssize_t len = readlink(path.value().c_str(), buf, PATH_MAX);
66 ASSERT_GT(len, 0);
67 buf[len] = '\0';
68
69 path = user_data_dir.Append(buf);
70 ASSERT_EQ(0, lstat(path.value().c_str(), &statbuf));
71 ASSERT_TRUE(S_ISSOCK(statbuf.st_mode));
72 }
73
74 // TODO(james.su@gmail.com): port following tests to Windows.
75 // Test success case of NotifyOtherProcess().
76 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessSuccess) {
77 std::string url("about:blank");
78 int original_tab_count = GetTabCount();
79
80 NotifyOtherProcess(url, true);
81 EXPECT_EQ(original_tab_count + 1, GetTabCount());
82 EXPECT_EQ(url, GetActiveTabURL().spec());
83 }
84
85 // Test failure case of NotifyOtherProcess().
86 TEST_F(ProcessSingletonLinuxTest, NotifyOtherProcessFailure) {
87 // Block the browser process, then it'll be killed by
88 // ProcessSingleton::NotifyOtherProcess().
89 kill(process(), SIGSTOP);
90
91 std::string url("about:blank");
92 NotifyOtherProcess(url, false);
93
94 // Wait for a while to make sure the browser process is actually killed.
95 usleep(10000);
96
97 EXPECT_FALSE(IsBrowserRunning());
98 }
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_linux.cc ('k') | chrome/browser/process_singleton_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698