1 // Copyright (c) 2015 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.
5 #include "components/browser_watcher/endsession_watcher_window_win.h"
10 #include "base/bind.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace browser_watcher
{
17 class EndSessionWatcherWindowTest
: public testing::Test
{
19 EndSessionWatcherWindowTest()
20 : num_callbacks_(0), last_message_(0), last_lparam_(0) {
23 void OnEndSessionMessage(UINT message
, LPARAM lparam
) {
25 last_message_
= message
;
26 last_lparam_
= lparam
;
29 size_t num_callbacks_
;
34 } // namespace browser_watcher
36 TEST_F(EndSessionWatcherWindowTest
, NoCallbackOnDestruction
) {
38 EndSessionWatcherWindow
watcher_window(
39 base::Bind(&EndSessionWatcherWindowTest::OnEndSessionMessage
,
40 base::Unretained(this)));
43 EXPECT_EQ(num_callbacks_
, 0);
44 EXPECT_EQ(last_lparam_
, 0);
47 TEST_F(EndSessionWatcherWindowTest
, IssuesCallbackOnMessage
) {
48 EndSessionWatcherWindow
watcher_window(
49 base::Bind(&EndSessionWatcherWindowTest::OnEndSessionMessage
,
50 base::Unretained(this)));
52 ::SendMessage(watcher_window
.window(), WM_QUERYENDSESSION
, TRUE
, 0xCAFEBABE);
53 EXPECT_EQ(num_callbacks_
, 1);
54 EXPECT_EQ(last_message_
, WM_QUERYENDSESSION
);
55 EXPECT_EQ(last_lparam_
, 0xCAFEBABE);
57 ::SendMessage(watcher_window
.window(), WM_ENDSESSION
, TRUE
, 0xCAFE);
58 EXPECT_EQ(num_callbacks_
, 2);
59 EXPECT_EQ(last_message_
, WM_ENDSESSION
);
60 EXPECT_EQ(last_lparam_
, 0xCAFE);
62 // Verify that other messages don't pass through.
63 ::SendMessage(watcher_window
.window(), WM_CLOSE
, TRUE
, 0xCAFE);
64 EXPECT_EQ(num_callbacks_
, 2);
67 } // namespace browser_watcher