Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ash/shelf/shelf_window_watcher_unittest.cc

Issue 2860503002: mash: Replace int ShelfIDs with AppLaunchID strings. (Closed)
Patch Set: Fix struct traits typo. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/shell/window_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_window_watcher.h" 5 #include "ash/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/public/cpp/config.h" 7 #include "ash/public/cpp/config.h"
8 #include "ash/public/cpp/shelf_item.h" 8 #include "ash/public/cpp/shelf_item.h"
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/public/cpp/window_properties.h" 10 #include "ash/public/cpp/window_properties.h"
11 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
12 #include "ash/session/session_controller.h" 12 #include "ash/session/session_controller.h"
13 #include "ash/shelf/shelf_model.h" 13 #include "ash/shelf/shelf_model.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/shell_port.h" 15 #include "ash/shell_port.h"
16 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
17 #include "ash/wm/window_resizer.h" 17 #include "ash/wm/window_resizer.h"
18 #include "ash/wm/window_state.h" 18 #include "ash/wm/window_state.h"
19 #include "ash/wm_window.h" 19 #include "ash/wm_window.h"
20 #include "base/strings/string_number_conversions.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 24
24 namespace ash { 25 namespace ash {
25 26
26 class ShelfWindowWatcherTest : public test::AshTestBase { 27 class ShelfWindowWatcherTest : public test::AshTestBase {
27 public: 28 public:
28 ShelfWindowWatcherTest() : model_(nullptr) {} 29 ShelfWindowWatcherTest() : model_(nullptr) {}
29 ~ShelfWindowWatcherTest() override {} 30 ~ShelfWindowWatcherTest() override {}
30 31
31 void SetUp() override { 32 void SetUp() override {
32 test::AshTestBase::SetUp(); 33 test::AshTestBase::SetUp();
33 model_ = Shell::Get()->shelf_model(); 34 model_ = Shell::Get()->shelf_model();
34 } 35 }
35 36
36 void TearDown() override { 37 void TearDown() override {
37 model_ = nullptr; 38 model_ = nullptr;
38 test::AshTestBase::TearDown(); 39 test::AshTestBase::TearDown();
39 } 40 }
40 41
41 static ShelfID CreateShelfItem(WmWindow* window) { 42 static ShelfID CreateShelfItem(WmWindow* window) {
42 ShelfID id = Shell::Get()->shelf_model()->next_id(); 43 static int id = 0;
44 ShelfID shelf_id(base::IntToString(id++));
45 window->aura_window()->SetProperty(kShelfIDKey, new ShelfID(shelf_id));
43 window->aura_window()->SetProperty(kShelfItemTypeKey, 46 window->aura_window()->SetProperty(kShelfItemTypeKey,
44 static_cast<int32_t>(TYPE_DIALOG)); 47 static_cast<int32_t>(TYPE_DIALOG));
45 return id; 48 return shelf_id;
46 } 49 }
47 50
48 protected: 51 protected:
49 ShelfModel* model_; 52 ShelfModel* model_;
50 53
51 private: 54 private:
52 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 55 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
53 }; 56 };
54 57
55 // Ensure shelf items are added and removed as windows are opened and closed. 58 // Ensure shelf items are added and removed as windows are opened and closed.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (Shell::GetAshConfig() == Config::MASH) 267 if (Shell::GetAshConfig() == Config::MASH)
265 return; 268 return;
266 269
267 // ShelfModel only has an APP_LIST item. 270 // ShelfModel only has an APP_LIST item.
268 EXPECT_EQ(1, model_->item_count()); 271 EXPECT_EQ(1, model_->item_count());
269 272
270 // Adding windows with valid ShelfItemType properties adds shelf items. 273 // Adding windows with valid ShelfItemType properties adds shelf items.
271 std::unique_ptr<views::Widget> widget1 = 274 std::unique_ptr<views::Widget> widget1 =
272 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); 275 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect());
273 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow()); 276 WmWindow* window1 = WmWindow::Get(widget1->GetNativeWindow());
277 window1->aura_window()->SetProperty(kShelfIDKey, new ShelfID("foo"));
274 window1->aura_window()->SetProperty(kShelfItemTypeKey, 278 window1->aura_window()->SetProperty(kShelfItemTypeKey,
275 static_cast<int32_t>(TYPE_APP_PANEL)); 279 static_cast<int32_t>(TYPE_APP_PANEL));
276 EXPECT_EQ(2, model_->item_count()); 280 EXPECT_EQ(2, model_->item_count());
277 std::unique_ptr<views::Widget> widget2 = 281 std::unique_ptr<views::Widget> widget2 =
278 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 282 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
279 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow()); 283 WmWindow* window2 = WmWindow::Get(widget2->GetNativeWindow());
284 window2->aura_window()->SetProperty(kShelfIDKey, new ShelfID("bar"));
280 window2->aura_window()->SetProperty(kShelfItemTypeKey, 285 window2->aura_window()->SetProperty(kShelfItemTypeKey,
281 static_cast<int32_t>(TYPE_APP_PANEL)); 286 static_cast<int32_t>(TYPE_APP_PANEL));
282 EXPECT_EQ(3, model_->item_count()); 287 EXPECT_EQ(3, model_->item_count());
283 288
284 // Create a panel-type widget to mimic Chrome's app panel windows. 289 // Create a panel-type widget to mimic Chrome's app panel windows.
285 views::Widget panel_widget; 290 views::Widget panel_widget;
286 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL); 291 views::Widget::InitParams panel_params(views::Widget::InitParams::TYPE_PANEL);
287 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 292 panel_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
288 ShellPort::Get() 293 ShellPort::Get()
289 ->GetPrimaryRootWindow() 294 ->GetPrimaryRootWindow()
290 ->GetRootWindowController() 295 ->GetRootWindowController()
291 ->ConfigureWidgetInitParamsForContainer( 296 ->ConfigureWidgetInitParamsForContainer(
292 &panel_widget, kShellWindowId_PanelContainer, &panel_params); 297 &panel_widget, kShellWindowId_PanelContainer, &panel_params);
293 panel_widget.Init(panel_params); 298 panel_widget.Init(panel_params);
294 panel_widget.Show(); 299 panel_widget.Show();
295 WmWindow* panel_window = WmWindow::Get(panel_widget.GetNativeWindow()); 300 WmWindow* panel_window = WmWindow::Get(panel_widget.GetNativeWindow());
301 panel_window->aura_window()->SetProperty(kShelfIDKey, new ShelfID("baz"));
296 panel_window->aura_window()->SetProperty( 302 panel_window->aura_window()->SetProperty(
297 kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL)); 303 kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP_PANEL));
298 EXPECT_EQ(4, model_->item_count()); 304 EXPECT_EQ(4, model_->item_count());
299 305
300 // Each ShelfItem is removed when the associated window is destroyed. 306 // Each ShelfItem is removed when the associated window is destroyed.
301 panel_widget.CloseNow(); 307 panel_widget.CloseNow();
302 EXPECT_EQ(3, model_->item_count()); 308 EXPECT_EQ(3, model_->item_count());
303 widget2.reset(); 309 widget2.reset();
304 EXPECT_EQ(2, model_->item_count()); 310 EXPECT_EQ(2, model_->item_count());
305 widget1.reset(); 311 widget1.reset();
306 EXPECT_EQ(1, model_->item_count()); 312 EXPECT_EQ(1, model_->item_count());
307 } 313 }
308 314
309 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { 315 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
310 const int initial_item_count = model_->item_count(); 316 const int initial_item_count = model_->item_count();
311 317
312 std::unique_ptr<aura::Window> window( 318 std::unique_ptr<aura::Window> window(
313 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); 319 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
314 window->Init(ui::LAYER_NOT_DRAWN); 320 window->Init(ui::LAYER_NOT_DRAWN);
321 window->SetProperty(kShelfIDKey, new ShelfID("foo"));
315 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP)); 322 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
316 Shell::GetPrimaryRootWindow() 323 Shell::GetPrimaryRootWindow()
317 ->GetChildById(kShellWindowId_DefaultContainer) 324 ->GetChildById(kShellWindowId_DefaultContainer)
318 ->AddChild(window.get()); 325 ->AddChild(window.get());
319 window->Show(); 326 window->Show();
320 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 327 EXPECT_EQ(initial_item_count + 1, model_->item_count());
321 328
322 std::unique_ptr<aura::Window> child_window( 329 std::unique_ptr<aura::Window> child_window(
323 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); 330 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
324 child_window->Init(ui::LAYER_NOT_DRAWN); 331 child_window->Init(ui::LAYER_NOT_DRAWN);
(...skipping 24 matching lines...) Expand all
349 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); 356 WmWindow* window = WmWindow::Get(widget->GetNativeWindow());
350 ShelfWindowWatcherTest::CreateShelfItem(window); 357 ShelfWindowWatcherTest::CreateShelfItem(window);
351 EXPECT_EQ(1, model->item_count()); 358 EXPECT_EQ(1, model->item_count());
352 359
353 // Start the test user session; ShelfWindowWatcher will find the open window. 360 // Start the test user session; ShelfWindowWatcher will find the open window.
354 SetSessionStarted(true); 361 SetSessionStarted(true);
355 EXPECT_EQ(2, model->item_count()); 362 EXPECT_EQ(2, model->item_count());
356 } 363 }
357 364
358 } // namespace ash 365 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/shell/window_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698