Make castv2 performance test work.
[chromium-blink-merge.git] / components / browser_watcher / endsession_watcher_window_win_unittest.cc
blobe499b4b5d3b0810e1ae17fbf70c7e884f237cf6d
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"
7 #include <windows.h>
8 #include <vector>
10 #include "base/bind.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace browser_watcher {
15 namespace {
17 class EndSessionWatcherWindowTest : public testing::Test {
18 public:
19 EndSessionWatcherWindowTest()
20 : num_callbacks_(0), last_message_(0), last_lparam_(0) {
23 void OnEndSessionMessage(UINT message, LPARAM lparam) {
24 ++num_callbacks_;
25 last_message_ = message;
26 last_lparam_ = lparam;
29 size_t num_callbacks_;
30 UINT last_message_;
31 UINT last_lparam_;
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