session_end_watcher_test.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2017 The Crashpad Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "util/win/session_end_watcher.h"
  15. #include "gtest/gtest.h"
  16. #include "test/errors.h"
  17. namespace crashpad {
  18. namespace test {
  19. namespace {
  20. class SessionEndWatcherTest final : public SessionEndWatcher {
  21. public:
  22. SessionEndWatcherTest() : SessionEndWatcher(), called_(false) {}
  23. ~SessionEndWatcherTest() override {}
  24. void Run() {
  25. WaitForStart();
  26. HWND window = GetWindow();
  27. ASSERT_TRUE(window);
  28. EXPECT_TRUE(PostMessage(window, WM_ENDSESSION, 1, 0));
  29. WaitForStop();
  30. EXPECT_TRUE(called_);
  31. }
  32. private:
  33. // SessionEndWatcher:
  34. void SessionEnding() override { called_ = true; }
  35. bool called_;
  36. DISALLOW_COPY_AND_ASSIGN(SessionEndWatcherTest);
  37. };
  38. TEST(SessionEndWatcher, SessionEndWatcher) {
  39. SessionEndWatcherTest test;
  40. test.Run();
  41. }
  42. TEST(SessionEndWatcher, DoNothing) {
  43. SessionEndWatcherTest test;
  44. }
  45. } // namespace
  46. } // namespace test
  47. } // namespace crashpad