| OLD | NEW |
| 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/launcher/launcher_types.h" | 7 #include "ash/launcher/launcher_types.h" |
| 8 #include "ash/shelf/shelf_model.h" | 8 #include "ash/shelf/shelf_model.h" |
| 9 #include "ash/shelf/shelf_util.h" | 9 #include "ash/shelf/shelf_util.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
| 27 test::AshTestBase::SetUp(); | 27 test::AshTestBase::SetUp(); |
| 28 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model(); | 28 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual void TearDown() OVERRIDE { | 31 virtual void TearDown() OVERRIDE { |
| 32 model_ = NULL; | 32 model_ = NULL; |
| 33 test::AshTestBase::TearDown(); | 33 test::AshTestBase::TearDown(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 ash::LauncherID CreateLauncherItem(aura::Window* window) { | 36 ash::LauncherID CreateShelfItem(aura::Window* window) { |
| 37 LauncherID id = model_->next_id(); | 37 LauncherID id = model_->next_id(); |
| 38 ash::LauncherItemDetails item_details; | 38 ash::LauncherItemDetails item_details; |
| 39 item_details.type = TYPE_PLATFORM_APP; | 39 item_details.type = TYPE_PLATFORM_APP; |
| 40 SetLauncherItemDetailsForWindow(window, item_details); | 40 SetShelfItemDetailsForWindow(window, item_details); |
| 41 return id; | 41 return id; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void UpdateLauncherItem(aura::Window* window) { | 44 void UpdateLauncherItem(aura::Window* window) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 protected: | 47 protected: |
| 48 ShelfModel* model_; | 48 ShelfModel* model_; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); | 51 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveLauncherItem) { | 54 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveLauncherItem) { |
| 55 // ShelfModel only has an APP_LIST item. | 55 // ShelfModel only has an APP_LIST item. |
| 56 EXPECT_EQ(1, model_->item_count()); | 56 EXPECT_EQ(1, model_->item_count()); |
| 57 | 57 |
| 58 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); | 58 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); |
| 59 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); | 59 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); |
| 60 | 60 |
| 61 // Create a LauncherItem for w1. | 61 // Create a LauncherItem for w1. |
| 62 LauncherID id_w1 = CreateLauncherItem(w1.get()); | 62 LauncherID id_w1 = CreateShelfItem(w1.get()); |
| 63 EXPECT_EQ(2, model_->item_count()); | 63 EXPECT_EQ(2, model_->item_count()); |
| 64 | 64 |
| 65 int index_w1 = model_->ItemIndexByID(id_w1); | 65 int index_w1 = model_->ItemIndexByID(id_w1); |
| 66 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); | 66 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); |
| 67 | 67 |
| 68 // Create a LauncherItem for w2. | 68 // Create a LauncherItem for w2. |
| 69 LauncherID id_w2 = CreateLauncherItem(w2.get()); | 69 LauncherID id_w2 = CreateShelfItem(w2.get()); |
| 70 EXPECT_EQ(3, model_->item_count()); | 70 EXPECT_EQ(3, model_->item_count()); |
| 71 | 71 |
| 72 int index_w2 = model_->ItemIndexByID(id_w2); | 72 int index_w2 = model_->ItemIndexByID(id_w2); |
| 73 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); | 73 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); |
| 74 | 74 |
| 75 // LauncherItem is removed when assoicated window is destroyed. | 75 // LauncherItem is removed when assoicated window is destroyed. |
| 76 ClearLauncherItemDetailsForWindow(w1.get()); | 76 ClearLauncherItemDetailsForWindow(w1.get()); |
| 77 EXPECT_EQ(2, model_->item_count()); | 77 EXPECT_EQ(2, model_->item_count()); |
| 78 ClearLauncherItemDetailsForWindow(w2.get()); | 78 ClearLauncherItemDetailsForWindow(w2.get()); |
| 79 EXPECT_EQ(1, model_->item_count()); | 79 EXPECT_EQ(1, model_->item_count()); |
| 80 // Clears twice doesn't do anything. | 80 // Clears twice doesn't do anything. |
| 81 ClearLauncherItemDetailsForWindow(w2.get()); | 81 ClearLauncherItemDetailsForWindow(w2.get()); |
| 82 EXPECT_EQ(1, model_->item_count()); | 82 EXPECT_EQ(1, model_->item_count()); |
| 83 | 83 |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { | 86 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { |
| 87 // ShelfModel only have APP_LIST item. | 87 // ShelfModel only have APP_LIST item. |
| 88 EXPECT_EQ(1, model_->item_count()); | 88 EXPECT_EQ(1, model_->item_count()); |
| 89 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); | 89 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); |
| 90 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); | 90 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); |
| 91 | 91 |
| 92 // Create a LauncherItem for w1. | 92 // Create a LauncherItem for w1. |
| 93 LauncherID id_w1 = CreateLauncherItem(w1.get()); | 93 LauncherID id_w1 = CreateShelfItem(w1.get()); |
| 94 EXPECT_EQ(2, model_->item_count()); | 94 EXPECT_EQ(2, model_->item_count()); |
| 95 int index_w1 = model_->ItemIndexByID(id_w1); | 95 int index_w1 = model_->ItemIndexByID(id_w1); |
| 96 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); | 96 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); |
| 97 | 97 |
| 98 // Create a LauncherItem for w2. | 98 // Create a LauncherItem for w2. |
| 99 LauncherID id_w2 = CreateLauncherItem(w2.get()); | 99 LauncherID id_w2 = CreateShelfItem(w2.get()); |
| 100 EXPECT_EQ(3, model_->item_count()); | 100 EXPECT_EQ(3, model_->item_count()); |
| 101 int index_w2 = model_->ItemIndexByID(id_w2); | 101 int index_w2 = model_->ItemIndexByID(id_w2); |
| 102 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); | 102 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); |
| 103 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); | 103 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); |
| 104 | 104 |
| 105 // LauncherItem for w1 is active when w1 is activated. | 105 // LauncherItem for w1 is active when w1 is activated. |
| 106 wm::ActivateWindow(w1.get()); | 106 wm::ActivateWindow(w1.get()); |
| 107 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); | 107 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); |
| 108 | 108 |
| 109 // LauncherItem for w2 is active state when w2 is activated. | 109 // LauncherItem for w2 is active state when w2 is activated. |
| 110 wm::ActivateWindow(w2.get()); | 110 wm::ActivateWindow(w2.get()); |
| 111 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); | 111 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); |
| 112 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); | 112 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { | 115 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { |
| 116 // ShelfModel only has an APP_LIST item. | 116 // ShelfModel only has an APP_LIST item. |
| 117 EXPECT_EQ(1, model_->item_count()); | 117 EXPECT_EQ(1, model_->item_count()); |
| 118 | 118 |
| 119 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 119 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 120 | 120 |
| 121 // Create a LauncherItem for |window|. | 121 // Create a LauncherItem for |window|. |
| 122 LauncherID id = CreateLauncherItem(window.get()); | 122 LauncherID id = CreateShelfItem(window.get()); |
| 123 EXPECT_EQ(2, model_->item_count()); | 123 EXPECT_EQ(2, model_->item_count()); |
| 124 | 124 |
| 125 int index = model_->ItemIndexByID(id); | 125 int index = model_->ItemIndexByID(id); |
| 126 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); | 126 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 127 | 127 |
| 128 // Update LauncherItem for |window|. | 128 // Update LauncherItem for |window|. |
| 129 LauncherItemDetails details; | 129 LauncherItemDetails details; |
| 130 details.type = TYPE_PLATFORM_APP; | 130 details.type = TYPE_PLATFORM_APP; |
| 131 | 131 |
| 132 SetLauncherItemDetailsForWindow(window.get(), details); | 132 SetShelfItemDetailsForWindow(window.get(), details); |
| 133 // No new item is created after updating a launcher item. | 133 // No new item is created after updating a launcher item. |
| 134 EXPECT_EQ(2, model_->item_count()); | 134 EXPECT_EQ(2, model_->item_count()); |
| 135 // index and id are not changed after updating a launcher item. | 135 // index and id are not changed after updating a launcher item. |
| 136 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 136 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 137 EXPECT_EQ(id, model_->items()[index].id); | 137 EXPECT_EQ(id, model_->items()[index].id); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { | 140 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { |
| 141 // ShelfModel only has an APP_LIST item. | 141 // ShelfModel only has an APP_LIST item. |
| 142 EXPECT_EQ(1, model_->item_count()); | 142 EXPECT_EQ(1, model_->item_count()); |
| 143 | 143 |
| 144 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 144 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 145 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 145 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 146 | 146 |
| 147 // Create a LauncherItem for |window|. | 147 // Create a LauncherItem for |window|. |
| 148 LauncherID id = CreateLauncherItem(window.get()); | 148 LauncherID id = CreateShelfItem(window.get()); |
| 149 EXPECT_EQ(2, model_->item_count()); | 149 EXPECT_EQ(2, model_->item_count()); |
| 150 | 150 |
| 151 int index = model_->ItemIndexByID(id); | 151 int index = model_->ItemIndexByID(id); |
| 152 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); | 152 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 153 | 153 |
| 154 // Maximize window |window|. | 154 // Maximize window |window|. |
| 155 EXPECT_FALSE(window_state->IsMaximized()); | 155 EXPECT_FALSE(window_state->IsMaximized()); |
| 156 window_state->Maximize(); | 156 window_state->Maximize(); |
| 157 EXPECT_TRUE(window_state->IsMaximized()); | 157 EXPECT_TRUE(window_state->IsMaximized()); |
| 158 // No new item is created after maximizing a window |window|. | 158 // No new item is created after maximizing a window |window|. |
| 159 EXPECT_EQ(2, model_->item_count()); | 159 EXPECT_EQ(2, model_->item_count()); |
| 160 // index and id are not changed after maximizing a window |window|. | 160 // index and id are not changed after maximizing a window |window|. |
| 161 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 161 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 162 EXPECT_EQ(id, model_->items()[index].id); | 162 EXPECT_EQ(id, model_->items()[index].id); |
| 163 | 163 |
| 164 // Restore window |window|. | 164 // Restore window |window|. |
| 165 window_state->Restore(); | 165 window_state->Restore(); |
| 166 EXPECT_FALSE(window_state->IsMaximized()); | 166 EXPECT_FALSE(window_state->IsMaximized()); |
| 167 // No new item is created after restoring a window |window|. | 167 // No new item is created after restoring a window |window|. |
| 168 EXPECT_EQ(2, model_->item_count()); | 168 EXPECT_EQ(2, model_->item_count()); |
| 169 // index and id are not changed after maximizing a window |window|. | 169 // index and id are not changed after maximizing a window |window|. |
| 170 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 170 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 171 EXPECT_EQ(id, model_->items()[index].id); | 171 EXPECT_EQ(id, model_->items()[index].id); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace internal | 174 } // namespace internal |
| 175 } // namespace ash | 175 } // namespace ash |
| OLD | NEW |