text: // Copyright 2021 The Chromium Authors. All rights reserved.
  // Use of this source code is governed by a BSD-style license that can be
  // found in the LICENSE file.
  
  #include "ash/public/cpp/ash_features.h"
  #include "ash/public/cpp/capture_mode_test_api.h"
  #include "ash/public/cpp/test/shell_test_api.h"
  #include "base/test/scoped_feature_list.h"
  #include "chrome/browser/ui/browser.h"
  #include "chrome/browser/ui/browser_window.h"
  #include "chrome/test/base/in_process_browser_test.h"
  #include "content/public/test/browser_test.h"
  #include "ui/aura/window.h"
  #include "ui/events/test/event_generator.h"
  
  // Testing class to test CrOS capture mode, which is a feature to take
  // screenshots and record video.
  class CaptureModeBrowserTest : public InProcessBrowserTest {
   public:
    CaptureModeBrowserTest() = default;
    CaptureModeBrowserTest(const CaptureModeBrowserTest&) = delete;
    CaptureModeBrowserTest& operator=(const CaptureModeBrowserTest&) = delete;
    ~CaptureModeBrowserTest() override = default;
  
    // InProcessBrowserTest:
    void SetUp() override {
      scoped_feature_list_.InitAndEnableFeature(ash::features::kCaptureMode);
      InProcessBrowserTest::SetUp();
    }
  
   private:
    base::test::ScopedFeatureList scoped_feature_list_;
  };
  
  IN_PROC_BROWSER_TEST_F(CaptureModeBrowserTest, ContextMenuStaysOpen) {
    // Right click the desktop to open a context menu.
    aura::Window* browser_window = browser()->window()->GetNativeWindow();
    const gfx::Point point_on_desktop(1, 1);
    ASSERT_FALSE(browser_window->bounds().Contains(point_on_desktop));
  
    ui::test::EventGenerator event_generator(browser_window->GetRootWindow(),
                                             point_on_desktop);
    event_generator.ClickRightButton();
  
    ash::ShellTestApi shell_test_api;
    ASSERT_TRUE(shell_test_api.IsContextMenuShown());
  
    ash::CaptureModeTestApi().StartForWindow(/*for_video=*/false);
    EXPECT_TRUE(shell_test_api.IsContextMenuShown());
  }
  