File: arc_vmm_manager_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,010 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/arc/vmm/arc_vmm_manager.h"

#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/constants/ash_switches.h"
#include "base/run_loop.h"
#include "base/task/current_thread.h"
#include "base/test/scoped_mock_clock_override.h"
#include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "chrome/browser/ash/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ash/arc/arc_util.h"
#include "chrome/browser/ash/arc/session/arc_session_manager.h"
#include "chrome/browser/ash/arc/vmm/arc_system_state_observation.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/ash/experiences/arc/arc_features.h"
#include "chromeos/ash/experiences/arc/session/arc_service_manager.h"
#include "chromeos/ash/experiences/arc/test/arc_util_test_support.h"
#include "chromeos/ash/experiences/arc/test/connection_holder_util.h"
#include "chromeos/ash/experiences/arc/test/fake_app_instance.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace arc {

class ArcVmmManagerBrowserTest : public InProcessBrowserTest {
 public:
  ArcVmmManagerBrowserTest() {
    scoped_feature_list_.InitWithFeatures(
        {kVmmSwapPolicy, kVmmSwapKeyboardShortcut}, {});
  }
  ArcVmmManagerBrowserTest(const ArcVmmManagerBrowserTest&) = delete;
  ArcVmmManagerBrowserTest& operator=(const ArcVmmManagerBrowserTest&) = delete;

  // InProcessBrowserTest:
  ~ArcVmmManagerBrowserTest() override = default;

  void SetUpCommandLine(base::CommandLine* command_line) override {
    arc::SetArcAvailableCommandLineForTesting(command_line);
    command_line->AppendSwitch(ash::switches::kEnableArcVm);
  }

  void SetUpInProcessBrowserTestFixture() override {
    arc::ArcSessionManager::SetUiEnabledForTesting(false);
  }

  void SetUpOnMainThread() override {
    base::RunLoop().RunUntilIdle();
    EnableArc();
  }

  void TearDownOnMainThread() override { DisableArc(); }

  // ArcVmmManagerBrowserTest:
  void EnableArc() {
    arc::SetArcPlayStoreEnabledForProfile(browser()->profile(), true);

    arc_app_list_prefs_ = ArcAppListPrefs::Get(browser()->profile());
    DCHECK(arc_app_list_prefs_);

    base::RunLoop run_loop;
    arc_app_list_prefs_->SetDefaultAppsReadyCallback(run_loop.QuitClosure());
    run_loop.Run();

    fake_app_instance_ =
        std::make_unique<arc::FakeAppInstance>(arc_app_list_prefs_);
    arc_app_list_prefs_->app_connection_holder()->SetInstance(
        fake_app_instance_.get());
    WaitForInstanceReady(arc_app_list_prefs_->app_connection_holder());
  }

  void DisableArc() {
    arc_app_list_prefs_->app_connection_holder()->CloseInstance(
        fake_app_instance_.get());
    fake_app_instance_.reset();
    arc::ArcSessionManager::Get()->Shutdown();
    arc_app_list_prefs_ = nullptr;
  }

  ArcVmmManager* vmm_manager() {
    return ArcVmmManager::GetForBrowserContext(browser()->profile());
  }

  bool arc_connected() { return vmm_manager()->arc_connected_; }

  SwapState last_requested_swap_state() {
    return vmm_manager()->latest_swap_state_;
  }
  ArcVmmSwapScheduler* swap_scheduler() {
    return vmm_manager()->scheduler_.get();
  }
  ArcVmmManager::AcceleratorTarget* shortcut_target() {
    return vmm_manager()->accelerator_.get();
  }
  ArcSystemStateObservation* observation() {
    return static_cast<ArcSystemStateObservation*>(
        swap_scheduler()->peace_duration_provider_.get());
  }

 protected:
  std::unique_ptr<FakeAppInstance> fake_app_instance_;

  raw_ptr<ArcAppListPrefs> arc_app_list_prefs_ = nullptr;

 private:
  base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(ArcVmmManagerBrowserTest, Ctor) {
  EXPECT_TRUE(arc_connected());
}

}  // namespace arc