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

Side by Side Diff: ash/wm/workspace/workspace_manager_unittest.cc

Issue 13008024: Fixes bug where FocusController would stack a layer directly above a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/aura/test/test_window_delegate.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wm/workspace/workspace_manager.h" 5 #include "ash/wm/workspace/workspace_manager.h"
6 6
7 #include <map>
8
7 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
9 #include "ash/screen_ash.h" 11 #include "ash/screen_ash.h"
10 #include "ash/shelf/shelf_layout_manager.h" 12 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 14 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 15 #include "ash/shell_window_ids.h"
14 #include "ash/system/status_area_widget.h" 16 #include "ash/system/status_area_widget.h"
15 #include "ash/test/ash_test_base.h" 17 #include "ash/test/ash_test_base.h"
16 #include "ash/test/shell_test_api.h" 18 #include "ash/test/shell_test_api.h"
(...skipping 15 matching lines...) Expand all
32 #include "ui/compositor/layer.h" 34 #include "ui/compositor/layer.h"
33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
34 #include "ui/gfx/screen.h" 36 #include "ui/gfx/screen.h"
35 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
36 38
37 using aura::Window; 39 using aura::Window;
38 40
39 namespace ash { 41 namespace ash {
40 namespace internal { 42 namespace internal {
41 43
44 // Returns a string containing the names of all the children of |window| (in
45 // order). Each entry is separated by a space.
46 std::string GetWindowNames(const aura::Window* window) {
47 std::string result;
48 for (size_t i = 0; i < window->children().size(); ++i) {
49 if (i != 0)
50 result += " ";
51 result += window->children()[i]->name();
52 }
53 return result;
54 }
55
56 // Returns a string containing the names of windows corresponding to each of the
57 // child layers of |window|'s layer. Any layers that don't correspond to a child
58 // Window of |window| are ignored. The result is ordered based on the layer
59 // ordering.
60 std::string GetLayerNames(const aura::Window* window) {
61 typedef std::map<const ui::Layer*, std::string> LayerToWindowNameMap;
62 LayerToWindowNameMap window_names;
63 for (size_t i = 0; i < window->children().size(); ++i) {
64 window_names[window->children()[i]->layer()] =
65 window->children()[i]->name();
66 }
67
68 std::string result;
69 const std::vector<ui::Layer*>& layers(window->layer()->children());
70 for (size_t i = 0; i < layers.size(); ++i) {
71 LayerToWindowNameMap::iterator layer_i =
72 window_names.find(layers[i]);
73 if (layer_i != window_names.end()) {
74 if (!result.empty())
75 result += " ";
76 result += layer_i->second;
77 }
78 }
79 return result;
80 }
81
42 class WorkspaceManagerTest : public test::AshTestBase { 82 class WorkspaceManagerTest : public test::AshTestBase {
43 public: 83 public:
44 WorkspaceManagerTest() : manager_(NULL) {} 84 WorkspaceManagerTest() : manager_(NULL) {}
45 virtual ~WorkspaceManagerTest() {} 85 virtual ~WorkspaceManagerTest() {}
46 86
47 aura::Window* CreateTestWindowUnparented() { 87 aura::Window* CreateTestWindowUnparented() {
48 aura::Window* window = new aura::Window(NULL); 88 aura::Window* window = new aura::Window(NULL);
49 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 89 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
50 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 90 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
51 window->Init(ui::LAYER_TEXTURED); 91 window->Init(ui::LAYER_TEXTURED);
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 1480
1441 window1->layer()->GetAnimator()->StopAnimating(); 1481 window1->layer()->GetAnimator()->StopAnimating();
1442 window2->layer()->GetAnimator()->StopAnimating(); 1482 window2->layer()->GetAnimator()->StopAnimating();
1443 // |window1| should be flush right and |window2| flush left. 1483 // |window1| should be flush right and |window2| flush left.
1444 EXPECT_EQ(base::IntToString( 1484 EXPECT_EQ(base::IntToString(
1445 desktop_area.width() - window1->bounds().width()) + 1485 desktop_area.width() - window1->bounds().width()) +
1446 ",32 640x320", window1->bounds().ToString()); 1486 ",32 640x320", window1->bounds().ToString());
1447 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); 1487 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
1448 } 1488 }
1449 1489
1490 // This tests simulates a browser and an app and verifies the ordering of the
1491 // windows and layers doesn't get out of sync as various operations occur. Its
1492 // really testing code in FocusController, but easier to simulate here. Just as
1493 // with a real browser the browser here has a transient child window
1494 // (corresponds to the status bubble).
1495 TEST_F(WorkspaceManagerTest, VerifyLayerOrdering) {
1496 aura::test::EventGenerator generator(
1497 Shell::GetPrimaryRootWindow(), gfx::Point());
1498 generator.MoveMouseTo(5, 5);
stevenjb 2013/03/22 18:28:15 Could you document why the initial MoveMouseTo?
sky 2013/03/22 19:30:15 That's not necessary and left over from another te
1499
1500 scoped_ptr<Window> browser(
1501 aura::test::CreateTestWindowWithDelegate(
1502 NULL,
1503 aura::client::WINDOW_TYPE_NORMAL,
1504 gfx::Rect(5, 6, 7, 8),
1505 NULL));
1506 browser->SetName("browser");
1507 SetDefaultParentByPrimaryRootWindow(browser.get());
1508 browser->Show();
1509 wm::ActivateWindow(browser.get());
1510
1511 // |status_bubble| is made a transient child of |browser| and as a result
1512 // owned by |browser|.
1513 aura::test::TestWindowDelegate* status_bubble_delegate =
1514 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
1515 status_bubble_delegate->set_can_focus(false);
1516 Window* status_bubble =
1517 aura::test::CreateTestWindowWithDelegate(
1518 status_bubble_delegate,
1519 aura::client::WINDOW_TYPE_POPUP,
1520 gfx::Rect(5, 6, 7, 8),
1521 NULL);
1522 browser->AddTransientChild(status_bubble);
1523 SetDefaultParentByPrimaryRootWindow(status_bubble);
1524 status_bubble->SetName("status_bubble");
1525
1526 scoped_ptr<Window> app(
1527 aura::test::CreateTestWindowWithDelegate(
1528 NULL,
1529 aura::client::WINDOW_TYPE_NORMAL,
1530 gfx::Rect(5, 6, 7, 8),
1531 NULL));
1532 app->SetName("app");
1533 SetDefaultParentByPrimaryRootWindow(app.get());
1534
1535 aura::Window* parent = browser->parent();
1536
1537 app->Show();
1538 wm::ActivateWindow(app.get());
1539 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1540
1541 // Minimize the app, focus should go the browser.
1542 app->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
stevenjb 2013/03/22 18:28:15 Test that focus does go to the browser here? I kno
sky 2013/03/22 19:30:15 Sure.
1543 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1544
1545 // Minimize the browser.
1546 browser->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
stevenjb 2013/03/22 18:28:15 Mostly out of curiosity, where does focus go here?
sky 2013/03/22 19:30:15 I believe it goes no where, but I think ideally we
1547 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1548
1549 // Show the browser (which should restore it).
stevenjb 2013/03/22 18:28:15 But not focus it, correct?
sky 2013/03/22 19:30:15 Not sure there. The focus rules may implicitly foc
1550 browser->Show();
1551 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1552
1553 // Activate the browser.
1554 ash::wm::ActivateWindow(browser.get());
stevenjb 2013/03/22 18:28:15 Until here, right?
1555 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1556
1557 // Restore the app. This differs from above code for |browser| as internally
1558 // the app code does this.
1559 app->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
stevenjb 2013/03/22 18:28:15 Should we change the App code to use Show() instea
sky 2013/03/22 19:30:15 Yes, but it won't make a difference for this parti
1560 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1561
1562 // Activate the app.
1563 ash::wm::ActivateWindow(app.get());
1564 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent));
1565 }
1566
1450 } // namespace internal 1567 } // namespace internal
1451 } // namespace ash 1568 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/aura/test/test_window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698