| OLD | NEW |
| 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 "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller.
h" | 5 #include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller.
h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" | 14 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" |
| 15 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 22 #include "ui/aura/client/activation_delegate.h" | 22 #include "ui/aura/client/activation_delegate.h" |
| 23 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/test/test_activation_client.h" | 24 #include "ui/aura/test/test_activation_client.h" |
| 25 #include "ui/aura/test/test_window_delegate.h" | 25 #include "ui/aura/test/test_window_delegate.h" |
| 26 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_delegate.h" | 27 #include "ui/aura/window_delegate.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Test implementation of AppIconLoader. | 31 // Test implementation of AppIconLoader. |
| 32 class AppIconLoaderImpl : public ChromeLauncherController::AppIconLoader { | 32 class AppIconLoaderImpl : public ChromeLauncherController::AppIconLoader { |
| 33 public: | 33 public: |
| 34 AppIconLoaderImpl() : fetch_count_(0) {} | 34 AppIconLoaderImpl() : fetch_count_(0) {} |
| 35 virtual ~AppIconLoaderImpl() {} | 35 virtual ~AppIconLoaderImpl() {} |
| 36 | 36 |
| 37 // Sets the id for the specified tab. The id is removed if Remove() is | 37 // Sets the id for the specified tab. The id is removed if Remove() is |
| 38 // invoked. | 38 // invoked. |
| 39 void SetAppID(TabContentsWrapper* tab, const std::string& id) { | 39 void SetAppID(TabContents* tab, const std::string& id) { |
| 40 tab_id_map_[tab] = id; | 40 tab_id_map_[tab] = id; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Returns true if there is an id registered for |tab|. | 43 // Returns true if there is an id registered for |tab|. |
| 44 bool HasAppID(TabContentsWrapper* tab) const { | 44 bool HasAppID(TabContents* tab) const { |
| 45 return tab_id_map_.find(tab) != tab_id_map_.end(); | 45 return tab_id_map_.find(tab) != tab_id_map_.end(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Returns the number of times FetchImage() has been invoked and resets the | 48 // Returns the number of times FetchImage() has been invoked and resets the |
| 49 // count to 0. | 49 // count to 0. |
| 50 int GetAndClearFetchCount() { | 50 int GetAndClearFetchCount() { |
| 51 int value = fetch_count_; | 51 int value = fetch_count_; |
| 52 fetch_count_ = 0; | 52 fetch_count_ = 0; |
| 53 return value; | 53 return value; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // AppIconLoader implementation: | 56 // AppIconLoader implementation: |
| 57 virtual std::string GetAppID(TabContentsWrapper* tab) OVERRIDE { | 57 virtual std::string GetAppID(TabContents* tab) OVERRIDE { |
| 58 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : | 58 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : |
| 59 std::string(); | 59 std::string(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual bool IsValidID(const std::string& id) OVERRIDE { | 62 virtual bool IsValidID(const std::string& id) OVERRIDE { |
| 63 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); | 63 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); |
| 64 i != tab_id_map_.end(); ++i) { | 64 i != tab_id_map_.end(); ++i) { |
| 65 if (i->second == id) | 65 if (i->second == id) |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual void FetchImage(const std::string& id) OVERRIDE { | 71 virtual void FetchImage(const std::string& id) OVERRIDE { |
| 72 fetch_count_++; | 72 fetch_count_++; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 typedef std::map<TabContentsWrapper*, std::string> TabToStringMap; | 76 typedef std::map<TabContents*, std::string> TabToStringMap; |
| 77 | 77 |
| 78 TabToStringMap tab_id_map_; | 78 TabToStringMap tab_id_map_; |
| 79 | 79 |
| 80 int fetch_count_; | 80 int fetch_count_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); | 82 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 content::TestBrowserThread browser_thread_; | 189 content::TestBrowserThread browser_thread_; |
| 190 std::vector<State*> states; | 190 std::vector<State*> states; |
| 191 | 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemControllerTest); | 192 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemControllerTest); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 // Verifies a new launcher item is added for TYPE_TABBED. | 195 // Verifies a new launcher item is added for TYPE_TABBED. |
| 196 TEST_F(BrowserLauncherItemControllerTest, TabbedSetup) { | 196 TEST_F(BrowserLauncherItemControllerTest, TabbedSetup) { |
| 197 size_t initial_size = launcher_model_->items().size(); | 197 size_t initial_size = launcher_model_->items().size(); |
| 198 { | 198 { |
| 199 TabContentsWrapper wrapper(CreateTestWebContents()); | 199 TabContents tab_contents(CreateTestWebContents()); |
| 200 State state(this, std::string(), | 200 State state(this, std::string(), |
| 201 BrowserLauncherItemController::TYPE_TABBED); | 201 BrowserLauncherItemController::TYPE_TABBED); |
| 202 | 202 |
| 203 // There should be one more item. | 203 // There should be one more item. |
| 204 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 204 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 205 // New item should be added at the end. | 205 // New item should be added at the end. |
| 206 EXPECT_EQ(ash::TYPE_TABBED, state.GetUpdaterItem().type); | 206 EXPECT_EQ(ash::TYPE_TABBED, state.GetUpdaterItem().type); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Deleting the BrowserLauncherItemController should have removed the item. | 209 // Deleting the BrowserLauncherItemController should have removed the item. |
| 210 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 210 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
| 211 | 211 |
| 212 // Do the same, but this time add the tab first. | 212 // Do the same, but this time add the tab first. |
| 213 { | 213 { |
| 214 TabContentsWrapper wrapper(CreateTestWebContents()); | 214 TabContents tab_contents(CreateTestWebContents()); |
| 215 | 215 |
| 216 TestTabStripModelDelegate tab_strip_delegate; | 216 TestTabStripModelDelegate tab_strip_delegate; |
| 217 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 217 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
| 218 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); | 218 tab_strip.InsertTabContentsAt(0, &tab_contents, TabStripModel::ADD_ACTIVE); |
| 219 aura::Window window(NULL); | 219 aura::Window window(NULL); |
| 220 window.Init(ui::LAYER_NOT_DRAWN); | 220 window.Init(ui::LAYER_NOT_DRAWN); |
| 221 root_window()->AddChild(&window); | 221 root_window()->AddChild(&window); |
| 222 BrowserLauncherItemController updater( | 222 BrowserLauncherItemController updater( |
| 223 &window, &tab_strip, launcher_delegate_.get(), | 223 &window, &tab_strip, launcher_delegate_.get(), |
| 224 BrowserLauncherItemController::TYPE_TABBED, std::string()); | 224 BrowserLauncherItemController::TYPE_TABBED, std::string()); |
| 225 updater.Init(); | 225 updater.Init(); |
| 226 | 226 |
| 227 // There should be one more item. | 227 // There should be one more item. |
| 228 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 228 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 229 // New item should be added at the end. | 229 // New item should be added at the end. |
| 230 EXPECT_EQ(ash::TYPE_TABBED, GetItem(&updater).type); | 230 EXPECT_EQ(ash::TYPE_TABBED, GetItem(&updater).type); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Verifies Panels items work. | 234 // Verifies Panels items work. |
| 235 TEST_F(BrowserLauncherItemControllerTest, PanelItem) { | 235 TEST_F(BrowserLauncherItemControllerTest, PanelItem) { |
| 236 size_t initial_size = launcher_model_->items().size(); | 236 size_t initial_size = launcher_model_->items().size(); |
| 237 | 237 |
| 238 // Add an App panel. | 238 // Add an App panel. |
| 239 { | 239 { |
| 240 aura::Window window(NULL); | 240 aura::Window window(NULL); |
| 241 TestTabStripModelDelegate tab_strip_delegate; | 241 TestTabStripModelDelegate tab_strip_delegate; |
| 242 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 242 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
| 243 TabContentsWrapper panel_tab(CreateTestWebContents()); | 243 TabContents panel_tab(CreateTestWebContents()); |
| 244 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps. | 244 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps. |
| 245 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); | 245 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); |
| 246 BrowserLauncherItemController updater( | 246 BrowserLauncherItemController updater( |
| 247 &window, &tab_strip, launcher_delegate_.get(), | 247 &window, &tab_strip, launcher_delegate_.get(), |
| 248 BrowserLauncherItemController::TYPE_APP_PANEL, std::string()); | 248 BrowserLauncherItemController::TYPE_APP_PANEL, std::string()); |
| 249 updater.Init(); | 249 updater.Init(); |
| 250 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 250 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 251 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); | 251 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); |
| 252 EXPECT_EQ(static_cast<void*>(NULL), updater.favicon_loader_.get()); | 252 EXPECT_EQ(static_cast<void*>(NULL), updater.favicon_loader_.get()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Add an Extension panel. | 255 // Add an Extension panel. |
| 256 { | 256 { |
| 257 aura::Window window(NULL); | 257 aura::Window window(NULL); |
| 258 TestTabStripModelDelegate tab_strip_delegate; | 258 TestTabStripModelDelegate tab_strip_delegate; |
| 259 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 259 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
| 260 TabContentsWrapper panel_tab(CreateTestWebContents()); | 260 TabContents panel_tab(CreateTestWebContents()); |
| 261 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps. | 261 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps. |
| 262 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); | 262 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); |
| 263 BrowserLauncherItemController updater( | 263 BrowserLauncherItemController updater( |
| 264 &window, &tab_strip, launcher_delegate_.get(), | 264 &window, &tab_strip, launcher_delegate_.get(), |
| 265 BrowserLauncherItemController::TYPE_EXTENSION_PANEL, std::string()); | 265 BrowserLauncherItemController::TYPE_EXTENSION_PANEL, std::string()); |
| 266 updater.Init(); | 266 updater.Init(); |
| 267 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 267 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
| 268 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); | 268 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); |
| 269 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get()); | 269 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get()); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Verifies pinned apps are persisted and restored. | 273 // Verifies pinned apps are persisted and restored. |
| 274 TEST_F(BrowserLauncherItemControllerTest, PersistPinned) { | 274 TEST_F(BrowserLauncherItemControllerTest, PersistPinned) { |
| 275 size_t initial_size = launcher_model_->items().size(); | 275 size_t initial_size = launcher_model_->items().size(); |
| 276 TabContentsWrapper tab1(CreateTestWebContents()); | 276 TabContents tab1(CreateTestWebContents()); |
| 277 | 277 |
| 278 app_icon_loader_->SetAppID(&tab1, "1"); | 278 app_icon_loader_->SetAppID(&tab1, "1"); |
| 279 | 279 |
| 280 app_icon_loader_->GetAndClearFetchCount(); | 280 app_icon_loader_->GetAndClearFetchCount(); |
| 281 launcher_delegate_->PinAppWithID("1"); | 281 launcher_delegate_->PinAppWithID("1"); |
| 282 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); | 282 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); |
| 283 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 283 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
| 284 launcher_model_->items()[1].type); | 284 launcher_model_->items()[1].type); |
| 285 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | 285 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
| 286 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); | 286 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); | 382 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); |
| 383 | 383 |
| 384 // App window should go to attention state. | 384 // App window should go to attention state. |
| 385 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); | 385 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); |
| 386 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); | 386 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); |
| 387 | 387 |
| 388 // Activating app window should clear attention state. | 388 // Activating app window should clear attention state. |
| 389 activation_client_->ActivateWindow(&app_state.window); | 389 activation_client_->ActivateWindow(&app_state.window); |
| 390 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); | 390 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); |
| 391 } | 391 } |
| OLD | NEW |