File: shelf_integration_test.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (160 lines) | stat: -rw-r--r-- 6,025 bytes parent folder | download | duplicates (6)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// 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 <memory>

#include "ash/constants/web_app_id_constants.h"
#include "ash/public/cpp/shelf_model.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_app_button.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "base/test/gtest_tags.h"
#include "chrome/browser/ui/ash/shelf/shelf_context_menu.h"
#include "chrome/test/base/chromeos/crosier/ash_integration_test.h"
#include "chrome/test/base/chromeos/crosier/aura_window_title_observer.h"
#include "chromeos/ash/components/file_manager/app_id.h"
#include "components/app_constants/constants.h"
#include "content/public/test/browser_test.h"
#include "ui/aura/env.h"
#include "ui/aura/test/find_window.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/geometry/rect.h"

namespace ash {
namespace {

// The title of a window at the new tab page varies based on branding.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const char16_t kBrowserWindowTitle[] = u"Chrome - New Tab";
#else
const char16_t kBrowserWindowTitle[] = u"Chromium - New Tab";
#endif

class ShelfIntegrationTest : public AshIntegrationTest {
 public:
  ShelfIntegrationTest()
      : zero_duration_scoped_animation_scale_mode_(
            ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) {}

  ~ShelfIntegrationTest() override = default;

 private:
  // Ensure shelf icon positions are stable. This needs to be created before the
  // test starts for the shelf view's bounds animator.
  ui::ScopedAnimationDurationScaleMode
      zero_duration_scoped_animation_scale_mode_;
};

IN_PROC_BROWSER_TEST_F(ShelfIntegrationTest, OpenCloseSwitchApps) {
  base::AddFeatureIdTagToTestResult(
      "screenplay-441c1034-bfff-42c0-ad81-79332c9e2304");

  SetupContextWidget();

  InstallSystemApps();  // For files app.

  // Get the primary display's shelf view.
  Shelf* shelf = Shell::GetPrimaryRootWindowController()->shelf();
  ASSERT_TRUE(shelf);
  ShelfView* shelf_view = shelf->GetShelfViewForTesting();
  ASSERT_TRUE(shelf_view);
  ShelfViewTestAPI test_api(shelf_view);

  // The shelf starts with at least the browser and Files apps pinned. Some
  // builds also have the Discover and Mall apps, but not all.
  ASSERT_GE(test_api.GetButtonCount(), 2u);
  auto* shelf_model = ShelfModel::Get();
  ASSERT_TRUE(shelf_model->IsAppPinned(app_constants::kChromeAppId));
  ASSERT_TRUE(shelf_model->IsAppPinned(file_manager::kFileManagerSwaAppId));

  ShelfAppButton* chrome_button = test_api.GetButton(0);
  ASSERT_TRUE(chrome_button);

  int files_button_index =
      shelf_model->ItemIndexByAppID(file_manager::kFileManagerSwaAppId);
  ASSERT_GT(files_button_index, 0);
  ShelfAppButton* files_app_button = test_api.GetButton(files_button_index);
  ASSERT_TRUE(files_app_button);

  aura::Env* env = aura::Env::GetInstance();
  ASSERT_TRUE(env);

  // Define our own AuraWindowTitleObservers because we wait for window titles
  // more than once, and hence can't use the WaitForWindowWithTitle() helper.
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(AuraWindowTitleObserver,
                                      kBrowserTitleObserver);
  DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(AuraWindowTitleObserver,
                                      kFilesAppTitleObserver);

  RunTestSequence(
      Log("Clicking the chrome shelf button"),
      ObserveState(
          kBrowserTitleObserver,
          std::make_unique<AuraWindowTitleObserver>(env, kBrowserWindowTitle)),
      MoveMouseTo(chrome_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(),

      Log("Waiting for Chrome window to open"),
      WaitForState(kBrowserTitleObserver, true),

      Log("Clicking the files app shelf button"),
      ObserveState(kFilesAppTitleObserver,
                   std::make_unique<AuraWindowTitleObserver>(env, u"Files")),
      MoveMouseTo(files_app_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(),

      Log("Waiting for files app window to open"),
      WaitForState(kFilesAppTitleObserver, true),

      // Wait for files app to move to foreground.

      Log("Clicking the chrome shelf button again"),
      MoveMouseTo(chrome_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(),

      Log("Verifying the browser window is activated"), Check([&]() {
        aura::Window* browser_window =
            aura::test::FindWindowWithTitle(env, kBrowserWindowTitle);
        CHECK(browser_window);
        aura::Window* active_window = window_util::GetActiveWindow();
        CHECK(active_window);
        return browser_window == active_window;
      }),

      Log("Clicking the files app shelf button again"),
      MoveMouseTo(files_app_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(),

      Log("Verifying the files app window is activated"), Check([&]() {
        aura::Window* files_window =
            aura::test::FindWindowWithTitle(env, u"Files");
        CHECK(files_window);
        aura::Window* active_window = window_util::GetActiveWindow();
        CHECK(active_window);
        return files_window == active_window;
      }),

      Log("Closing Chrome via right-click menu"),
      MoveMouseTo(chrome_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(ui_controls::RIGHT), SelectMenuItem(kShelfCloseMenuItem),

      Log("Verifying the browser window is gone"), Check([&]() {
        return !aura::test::FindWindowWithTitle(env, kBrowserWindowTitle);
      }),

      Log("Closing files app via right-click menu"),
      MoveMouseTo(files_app_button->GetBoundsInScreen().CenterPoint()),
      ClickMouse(ui_controls::RIGHT), SelectMenuItem(kShelfCloseMenuItem),

      Log("Verifying the files app window is gone"),
      Check([&]() { return !aura::test::FindWindowWithTitle(env, u"Files"); }),

      Log("Test completed"));
}

}  // namespace
}  // namespace ash