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

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

Issue 2733303004: Removes WmShell::NewWindow() (Closed)
Patch Set: cleanup Created 3 years, 9 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/aura/wm_shell_aura.cc ('k') | ash/common/test/ash_test.cc » ('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/common/shelf/shelf_window_watcher.h" 5 #include "ash/common/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/shelf/shelf_item_types.h" 8 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/shelf/shelf_model.h" 9 #include "ash/common/shelf/shelf_model.h"
10 #include "ash/common/wm/window_resizer.h" 10 #include "ash/common/wm/window_resizer.h"
11 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
13 #include "ash/common/wm_window.h" 13 #include "ash/common/wm_window.h"
14 #include "ash/public/cpp/shell_window_ids.h" 14 #include "ash/public/cpp/shell_window_ids.h"
15 #include "ash/public/cpp/window_properties.h" 15 #include "ash/public/cpp/window_properties.h"
16 #include "ash/root_window_controller.h" 16 #include "ash/root_window_controller.h"
17 #include "ash/test/ash_test_base.h" 17 #include "ash/test/ash_test_base.h"
18 #include "ui/aura/window.h"
18 #include "ui/base/hit_test.h" 19 #include "ui/base/hit_test.h"
20 #include "ui/compositor/layer_type.h"
19 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
20 22
21 namespace ash { 23 namespace ash {
22 24
23 class ShelfWindowWatcherTest : public test::AshTestBase { 25 class ShelfWindowWatcherTest : public test::AshTestBase {
24 public: 26 public:
25 ShelfWindowWatcherTest() : model_(nullptr) {} 27 ShelfWindowWatcherTest() : model_(nullptr) {}
26 ~ShelfWindowWatcherTest() override {} 28 ~ShelfWindowWatcherTest() override {}
27 29
28 void SetUp() override { 30 void SetUp() override {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_EQ(3, model_->item_count()); 340 EXPECT_EQ(3, model_->item_count());
339 widget2.reset(); 341 widget2.reset();
340 EXPECT_EQ(2, model_->item_count()); 342 EXPECT_EQ(2, model_->item_count());
341 widget1.reset(); 343 widget1.reset();
342 EXPECT_EQ(1, model_->item_count()); 344 EXPECT_EQ(1, model_->item_count());
343 } 345 }
344 346
345 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { 347 TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) {
346 const int initial_item_count = model_->item_count(); 348 const int initial_item_count = model_->item_count();
347 349
348 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, 350 std::unique_ptr<aura::Window> window(
349 ui::LAYER_NOT_DRAWN); 351 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
350 window->aura_window()->SetProperty(kShelfItemTypeKey, 352 window->Init(ui::LAYER_NOT_DRAWN);
351 static_cast<int32_t>(TYPE_APP)); 353 window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
352 WmShell::Get() 354 WmShell::Get()
353 ->GetPrimaryRootWindow() 355 ->GetPrimaryRootWindow()
354 ->GetChildByShellWindowId(kShellWindowId_DefaultContainer) 356 ->GetChildByShellWindowId(kShellWindowId_DefaultContainer)
355 ->AddChild(window); 357 ->AddChild(WmWindow::Get(window.get()));
msw 2017/03/08 21:38:24 optional nit: Shell::GetPrimaryRootWindow()->GetCh
sky 2017/03/08 22:58:17 Done.
356 window->Show(); 358 window->Show();
357 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 359 EXPECT_EQ(initial_item_count + 1, model_->item_count());
358 360
359 WmWindow* child_window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, 361 std::unique_ptr<aura::Window> child_window(
360 ui::LAYER_NOT_DRAWN); 362 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL));
361 child_window->aura_window()->SetProperty(kShelfItemTypeKey, 363 child_window->Init(ui::LAYER_NOT_DRAWN);
362 static_cast<int32_t>(TYPE_APP)); 364 child_window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_APP));
363 window->AddChild(child_window); 365 window->AddChild(child_window.get());
364 child_window->Show(); 366 child_window->Show();
365 // |child_window| should not result in adding a new entry. 367 // |child_window| should not result in adding a new entry.
366 EXPECT_EQ(initial_item_count + 1, model_->item_count()); 368 EXPECT_EQ(initial_item_count + 1, model_->item_count());
367 369
368 child_window->Destroy(); 370 child_window.reset();
369 window->Destroy(); 371 window.reset();
370 EXPECT_EQ(initial_item_count, model_->item_count()); 372 EXPECT_EQ(initial_item_count, model_->item_count());
371 } 373 }
372 374
373 // Ensures ShelfWindowWatcher supports windows opened prior to session start. 375 // Ensures ShelfWindowWatcher supports windows opened prior to session start.
374 using ShelfWindowWatcherSessionStartTest = test::NoSessionAshTestBase; 376 using ShelfWindowWatcherSessionStartTest = test::NoSessionAshTestBase;
375 TEST_F(ShelfWindowWatcherSessionStartTest, PreExistingWindow) { 377 TEST_F(ShelfWindowWatcherSessionStartTest, PreExistingWindow) {
376 ShelfModel* model = WmShell::Get()->shelf_model(); 378 ShelfModel* model = WmShell::Get()->shelf_model();
377 ASSERT_FALSE( 379 ASSERT_FALSE(
378 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); 380 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted());
379 381
380 // ShelfModel only has an APP_LIST item. 382 // ShelfModel only has an APP_LIST item.
381 EXPECT_EQ(1, model->item_count()); 383 EXPECT_EQ(1, model->item_count());
382 384
383 // Construct a window that should get a shelf item once the session starts. 385 // Construct a window that should get a shelf item once the session starts.
384 std::unique_ptr<views::Widget> widget = 386 std::unique_ptr<views::Widget> widget =
385 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 387 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
386 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); 388 WmWindow* window = WmWindow::Get(widget->GetNativeWindow());
387 ShelfWindowWatcherTest::CreateShelfItem(window); 389 ShelfWindowWatcherTest::CreateShelfItem(window);
388 EXPECT_EQ(1, model->item_count()); 390 EXPECT_EQ(1, model->item_count());
389 391
390 // Start the test user session; ShelfWindowWatcher will find the open window. 392 // Start the test user session; ShelfWindowWatcher will find the open window.
391 SetSessionStarted(true); 393 SetSessionStarted(true);
392 EXPECT_EQ(2, model->item_count()); 394 EXPECT_EQ(2, model->item_count());
393 } 395 }
394 396
395 } // namespace ash 397 } // namespace ash
OLDNEW
« no previous file with comments | « ash/aura/wm_shell_aura.cc ('k') | ash/common/test/ash_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698