| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <gflags/gflags.h> | 5 #include <gflags/gflags.h> |
| 6 #include <gtest/gtest.h> | 6 #include <gtest/gtest.h> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cros/chromeos_wm_ipc_enums.h" | 9 #include "cros/chromeos_wm_ipc_enums.h" |
| 10 #include "window_manager/chrome_watchdog.h" | 10 #include "window_manager/chrome_watchdog.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 TEST_F(ChromeWatchdogTest, Basic) { | 28 TEST_F(ChromeWatchdogTest, Basic) { |
| 29 ChromeWatchdog* watchdog = wm_->chrome_watchdog_.get(); | 29 ChromeWatchdog* watchdog = wm_->chrome_watchdog_.get(); |
| 30 | 30 |
| 31 const XWindow kRoot = xconn_->GetRootWindow(); | 31 const XWindow kRoot = xconn_->GetRootWindow(); |
| 32 const XAtom kProtocolsAtom = xconn_->GetAtomOrDie("WM_PROTOCOLS"); | 32 const XAtom kProtocolsAtom = xconn_->GetAtomOrDie("WM_PROTOCOLS"); |
| 33 const XAtom kPingAtom = xconn_->GetAtomOrDie("_NET_WM_PING"); | 33 const XAtom kPingAtom = xconn_->GetAtomOrDie("_NET_WM_PING"); |
| 34 const XAtom kPidAtom = xconn_->GetAtomOrDie("_NET_WM_PID"); | 34 const XAtom kPidAtom = xconn_->GetAtomOrDie("_NET_WM_PID"); |
| 35 const XAtom kClientMachineAtom = xconn_->GetAtomOrDie("WM_CLIENT_MACHINE"); | 35 const XAtom kClientMachineAtom = xconn_->GetAtomOrDie("WM_CLIENT_MACHINE"); |
| 36 const XAtom kCardinalAtom = xconn_->GetAtomOrDie("CARDINAL"); | 36 const XAtom kCardinalAtom = xconn_->GetAtomOrDie("CARDINAL"); |
| 37 | 37 |
| 38 int kPid = 456; | 38 const int kPid = 456; |
| 39 int kTimestamp = 123; | 39 const int kTimestamp = 123; |
| 40 int kTimeoutMs = 5000; | 40 const int kTimeoutMs = 5000; |
| 41 |
| 42 // Make sure that we don't leak any timeouts, either when we get a response |
| 43 // from Chrome or when a timeout fires (http://crosbug.com/10583). |
| 44 const int kInitialNumTimeouts = event_loop_->num_timeouts(); |
| 41 | 45 |
| 42 // We should fail if no windows have been mapped. | 46 // We should fail if no windows have been mapped. |
| 43 EXPECT_FALSE(watchdog->SendPingToChrome(kTimestamp, kTimeoutMs)); | 47 EXPECT_FALSE(watchdog->SendPingToChrome(kTimestamp, kTimeoutMs)); |
| 44 | 48 |
| 45 // Map a single non-Chrome window and check that we don't send a ping | 49 // Map a single non-Chrome window and check that we don't send a ping |
| 46 // message to it. | 50 // message to it. |
| 47 XWindow non_chrome_xid = CreateSimpleWindow(); | 51 XWindow non_chrome_xid = CreateSimpleWindow(); |
| 48 AppendAtomToProperty(non_chrome_xid, kProtocolsAtom, kPingAtom); | 52 AppendAtomToProperty(non_chrome_xid, kProtocolsAtom, kPingAtom); |
| 49 xconn_->SetIntProperty(non_chrome_xid, kPidAtom, kCardinalAtom, kPid); | 53 xconn_->SetIntProperty(non_chrome_xid, kPidAtom, kCardinalAtom, kPid); |
| 50 xconn_->SetStringProperty(non_chrome_xid, kClientMachineAtom, GetHostname()); | 54 xconn_->SetStringProperty(non_chrome_xid, kClientMachineAtom, GetHostname()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 wm_->HandleEvent(&event); | 117 wm_->HandleEvent(&event); |
| 114 EXPECT_TRUE(watchdog->has_outstanding_ping()); | 118 EXPECT_TRUE(watchdog->has_outstanding_ping()); |
| 115 | 119 |
| 116 // We should cancel the ping if we get the proper response. | 120 // We should cancel the ping if we get the proper response. |
| 117 xconn_->InitClientMessageEvent(&event, kRoot, kProtocolsAtom, | 121 xconn_->InitClientMessageEvent(&event, kRoot, kProtocolsAtom, |
| 118 kPingAtom, kTimestamp, toplevel_xid, 0, 0); | 122 kPingAtom, kTimestamp, toplevel_xid, 0, 0); |
| 119 wm_->HandleEvent(&event); | 123 wm_->HandleEvent(&event); |
| 120 EXPECT_FALSE(watchdog->has_outstanding_ping()); | 124 EXPECT_FALSE(watchdog->has_outstanding_ping()); |
| 121 EXPECT_EQ(-1, watchdog->timeout_id_); | 125 EXPECT_EQ(-1, watchdog->timeout_id_); |
| 122 EXPECT_EQ(-1, watchdog->last_killed_pid_); | 126 EXPECT_EQ(-1, watchdog->last_killed_pid_); |
| 127 EXPECT_EQ(kInitialNumTimeouts, event_loop_->num_timeouts()); |
| 123 | 128 |
| 124 // If the timeout is invoked after we send the ping, we should kill | 129 // If the timeout is invoked after we send the ping, we should kill |
| 125 // Chrome (well, not really, since this is a test, but 'last_killed_pid_' | 130 // Chrome (well, not really, since this is a test, but 'last_killed_pid_' |
| 126 // should be set, at least). | 131 // should be set, at least). |
| 127 EXPECT_TRUE(watchdog->SendPingToChrome(kTimestamp, kTimeoutMs)); | 132 EXPECT_TRUE(watchdog->SendPingToChrome(kTimestamp, kTimeoutMs)); |
| 128 watchdog->HandleTimeout(); | 133 watchdog->HandleTimeout(); |
| 129 EXPECT_FALSE(watchdog->has_outstanding_ping()); | 134 EXPECT_FALSE(watchdog->has_outstanding_ping()); |
| 130 EXPECT_EQ(-1, watchdog->timeout_id_); | 135 EXPECT_EQ(-1, watchdog->timeout_id_); |
| 131 EXPECT_EQ(kPid, watchdog->last_killed_pid_); | 136 EXPECT_EQ(kPid, watchdog->last_killed_pid_); |
| 137 EXPECT_EQ(kInitialNumTimeouts, event_loop_->num_timeouts()); |
| 132 } | 138 } |
| 133 | 139 |
| 134 } // namespace window_manager | 140 } // namespace window_manager |
| 135 | 141 |
| 136 int main(int argc, char** argv) { | 142 int main(int argc, char** argv) { |
| 137 // Ensure that we don't really send signals to processes. | 143 // Ensure that we don't really send signals to processes. |
| 138 window_manager::AutoReset<bool> flag_resetter( | 144 window_manager::AutoReset<bool> flag_resetter( |
| 139 &FLAGS_kill_chrome_if_hanging, false); | 145 &FLAGS_kill_chrome_if_hanging, false); |
| 140 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); | 146 return window_manager::InitAndRunTests(&argc, argv, &FLAGS_logtostderr); |
| 141 } | 147 } |
| OLD | NEW |