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/ash/launcher/browser_launcher_item_controller.h" | 5 #include "chrome/browser/ui/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/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" | 15 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.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/activation_delegate.h" | 21 #include "ui/aura/client/activation_delegate.h" |
22 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.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 #include "ui/base/event.h" | 28 #include "ui/base/event.h" |
29 | 29 |
| 30 // TODO(avi): Kill this when TabContents goes away. |
| 31 class BrowserLauncherItemControllerContentsCreator { |
| 32 public: |
| 33 static TabContents* CreateTabContents(content::WebContents* contents) { |
| 34 return TabContents::Factory::CreateTabContents(contents); |
| 35 } |
| 36 }; |
| 37 |
30 namespace { | 38 namespace { |
31 | 39 |
32 // Test implementation of AppTabHelper | 40 // Test implementation of AppTabHelper |
33 class AppTabHelperImpl : public ChromeLauncherController::AppTabHelper { | 41 class AppTabHelperImpl : public ChromeLauncherController::AppTabHelper { |
34 public: | 42 public: |
35 AppTabHelperImpl() {} | 43 AppTabHelperImpl() {} |
36 virtual ~AppTabHelperImpl() {} | 44 virtual ~AppTabHelperImpl() {} |
37 | 45 |
38 // Sets the id for the specified tab. The id is removed if Remove() is | 46 // Sets the id for the specified tab. The id is removed if Remove() is |
39 // invoked. | 47 // invoked. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 content::TestBrowserThread browser_thread_; | 216 content::TestBrowserThread browser_thread_; |
209 std::vector<State*> states; | 217 std::vector<State*> states; |
210 | 218 |
211 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemControllerTest); | 219 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemControllerTest); |
212 }; | 220 }; |
213 | 221 |
214 // Verifies a new launcher item is added for TYPE_TABBED. | 222 // Verifies a new launcher item is added for TYPE_TABBED. |
215 TEST_F(BrowserLauncherItemControllerTest, TabbedSetup) { | 223 TEST_F(BrowserLauncherItemControllerTest, TabbedSetup) { |
216 size_t initial_size = launcher_model_->items().size(); | 224 size_t initial_size = launcher_model_->items().size(); |
217 { | 225 { |
218 TabContents tab_contents(CreateTestWebContents()); | 226 scoped_ptr<TabContents> tab_contents( |
| 227 BrowserLauncherItemControllerContentsCreator::CreateTabContents( |
| 228 CreateTestWebContents())); |
219 State state(this, std::string(), | 229 State state(this, std::string(), |
220 BrowserLauncherItemController::TYPE_TABBED); | 230 BrowserLauncherItemController::TYPE_TABBED); |
221 | 231 |
222 // There should be one more item. | 232 // There should be one more item. |
223 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 233 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
224 // New item should be added at the end. | 234 // New item should be added at the end. |
225 EXPECT_EQ(ash::TYPE_TABBED, state.GetUpdaterItem().type); | 235 EXPECT_EQ(ash::TYPE_TABBED, state.GetUpdaterItem().type); |
226 } | 236 } |
227 | 237 |
228 // Deleting the BrowserLauncherItemController should have removed the item. | 238 // Deleting the BrowserLauncherItemController should have removed the item. |
229 ASSERT_EQ(initial_size, launcher_model_->items().size()); | 239 ASSERT_EQ(initial_size, launcher_model_->items().size()); |
230 | 240 |
231 // Do the same, but this time add the tab first. | 241 // Do the same, but this time add the tab first. |
232 { | 242 { |
233 TabContents tab_contents(CreateTestWebContents()); | 243 scoped_ptr<TabContents> tab_contents( |
| 244 BrowserLauncherItemControllerContentsCreator::CreateTabContents( |
| 245 CreateTestWebContents())); |
234 | 246 |
235 TestTabStripModelDelegate tab_strip_delegate; | 247 TestTabStripModelDelegate tab_strip_delegate; |
236 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 248 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
237 tab_strip.InsertTabContentsAt(0, &tab_contents, TabStripModel::ADD_ACTIVE); | 249 tab_strip.InsertTabContentsAt(0, |
| 250 tab_contents.get(), |
| 251 TabStripModel::ADD_ACTIVE); |
238 aura::Window window(NULL); | 252 aura::Window window(NULL); |
239 window.Init(ui::LAYER_NOT_DRAWN); | 253 window.Init(ui::LAYER_NOT_DRAWN); |
240 root_window()->AddChild(&window); | 254 root_window()->AddChild(&window); |
241 BrowserLauncherItemController updater( | 255 BrowserLauncherItemController updater( |
242 LauncherItemController::TYPE_TABBED, | 256 LauncherItemController::TYPE_TABBED, |
243 &window, &tab_strip, launcher_delegate_.get(), | 257 &window, &tab_strip, launcher_delegate_.get(), |
244 std::string()); | 258 std::string()); |
245 updater.Init(); | 259 updater.Init(); |
246 | 260 |
247 // There should be one more item. | 261 // There should be one more item. |
248 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 262 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
249 // New item should be added at the end. | 263 // New item should be added at the end. |
250 EXPECT_EQ(ash::TYPE_TABBED, GetItem(&updater).type); | 264 EXPECT_EQ(ash::TYPE_TABBED, GetItem(&updater).type); |
251 } | 265 } |
252 } | 266 } |
253 | 267 |
254 // Verifies Panels items work. | 268 // Verifies Panels items work. |
255 TEST_F(BrowserLauncherItemControllerTest, PanelItem) { | 269 TEST_F(BrowserLauncherItemControllerTest, PanelItem) { |
256 size_t initial_size = launcher_model_->items().size(); | 270 size_t initial_size = launcher_model_->items().size(); |
257 | 271 |
258 // Add an App panel. | 272 // Add an App panel. |
259 { | 273 { |
260 aura::Window window(NULL); | 274 aura::Window window(NULL); |
261 TestTabStripModelDelegate tab_strip_delegate; | 275 TestTabStripModelDelegate tab_strip_delegate; |
262 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 276 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
263 TabContents panel_tab(CreateTestWebContents()); | 277 scoped_ptr<TabContents> panel_tab( |
264 app_tab_helper_->SetAppID(&panel_tab, "1"); // Panels are apps. | 278 BrowserLauncherItemControllerContentsCreator::CreateTabContents( |
265 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); | 279 CreateTestWebContents())); |
| 280 app_tab_helper_->SetAppID(panel_tab.get(), "1"); // Panels are apps. |
| 281 tab_strip.InsertTabContentsAt(0, |
| 282 panel_tab.get(), |
| 283 TabStripModel::ADD_ACTIVE); |
266 BrowserLauncherItemController updater( | 284 BrowserLauncherItemController updater( |
267 LauncherItemController::TYPE_APP_PANEL, | 285 LauncherItemController::TYPE_APP_PANEL, |
268 &window, &tab_strip, launcher_delegate_.get(), | 286 &window, &tab_strip, launcher_delegate_.get(), |
269 std::string()); | 287 std::string()); |
270 updater.Init(); | 288 updater.Init(); |
271 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 289 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
272 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); | 290 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); |
273 EXPECT_EQ(static_cast<void*>(NULL), updater.favicon_loader_.get()); | 291 EXPECT_EQ(static_cast<void*>(NULL), updater.favicon_loader_.get()); |
274 } | 292 } |
275 | 293 |
276 // Add an Extension panel. | 294 // Add an Extension panel. |
277 { | 295 { |
278 aura::Window window(NULL); | 296 aura::Window window(NULL); |
279 TestTabStripModelDelegate tab_strip_delegate; | 297 TestTabStripModelDelegate tab_strip_delegate; |
280 TabStripModel tab_strip(&tab_strip_delegate, profile()); | 298 TabStripModel tab_strip(&tab_strip_delegate, profile()); |
281 TabContents panel_tab(CreateTestWebContents()); | 299 scoped_ptr<TabContents> panel_tab( |
282 app_tab_helper_->SetAppID(&panel_tab, "1"); // Panels are apps. | 300 BrowserLauncherItemControllerContentsCreator::CreateTabContents( |
283 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); | 301 CreateTestWebContents())); |
| 302 app_tab_helper_->SetAppID(panel_tab.get(), "1"); // Panels are apps. |
| 303 tab_strip.InsertTabContentsAt(0, |
| 304 panel_tab.get(), |
| 305 TabStripModel::ADD_ACTIVE); |
284 BrowserLauncherItemController updater( | 306 BrowserLauncherItemController updater( |
285 LauncherItemController::TYPE_EXTENSION_PANEL, | 307 LauncherItemController::TYPE_EXTENSION_PANEL, |
286 &window, &tab_strip, launcher_delegate_.get(), | 308 &window, &tab_strip, launcher_delegate_.get(), |
287 std::string()); | 309 std::string()); |
288 updater.Init(); | 310 updater.Init(); |
289 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 311 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
290 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); | 312 EXPECT_EQ(ash::TYPE_APP_PANEL, GetItem(&updater).type); |
291 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get()); | 313 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get()); |
292 } | 314 } |
293 } | 315 } |
294 | 316 |
295 // Verifies pinned apps are persisted and restored. | 317 // Verifies pinned apps are persisted and restored. |
296 TEST_F(BrowserLauncherItemControllerTest, PersistPinned) { | 318 TEST_F(BrowserLauncherItemControllerTest, PersistPinned) { |
297 size_t initial_size = launcher_model_->items().size(); | 319 size_t initial_size = launcher_model_->items().size(); |
298 TabContents tab1(CreateTestWebContents()); | 320 scoped_ptr<TabContents> tab1( |
| 321 BrowserLauncherItemControllerContentsCreator::CreateTabContents( |
| 322 CreateTestWebContents())); |
299 | 323 |
300 app_tab_helper_->SetAppID(&tab1, "1"); | 324 app_tab_helper_->SetAppID(tab1.get(), "1"); |
301 | 325 |
302 app_icon_loader_->GetAndClearFetchCount(); | 326 app_icon_loader_->GetAndClearFetchCount(); |
303 launcher_delegate_->PinAppWithID("1"); | 327 launcher_delegate_->PinAppWithID("1"); |
304 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); | 328 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); |
305 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 329 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
306 launcher_model_->items()[1].type); | 330 launcher_model_->items()[1].type); |
307 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | 331 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
308 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); | 332 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); |
309 EXPECT_EQ(initial_size + 1, launcher_model_->items().size()); | 333 EXPECT_EQ(initial_size + 1, launcher_model_->items().size()); |
310 | 334 |
311 launcher_delegate_.reset( | 335 launcher_delegate_.reset( |
312 new ChromeLauncherController(profile(), launcher_model_.get())); | 336 new ChromeLauncherController(profile(), launcher_model_.get())); |
313 app_tab_helper_ = new AppTabHelperImpl; | 337 app_tab_helper_ = new AppTabHelperImpl; |
314 app_tab_helper_->SetAppID(&tab1, "1"); | 338 app_tab_helper_->SetAppID(tab1.get(), "1"); |
315 ResetAppTabHelper(); | 339 ResetAppTabHelper(); |
316 app_icon_loader_ = new AppIconLoaderImpl; | 340 app_icon_loader_ = new AppIconLoaderImpl; |
317 ResetAppIconLoader(); | 341 ResetAppIconLoader(); |
318 launcher_delegate_->Init(); | 342 launcher_delegate_->Init(); |
319 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); | 343 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); |
320 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | 344 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); |
321 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | 345 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); |
322 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); | 346 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); |
323 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | 347 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, |
324 launcher_model_->items()[1].type); | 348 launcher_model_->items()[1].type); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); | 430 EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); |
407 | 431 |
408 // App window should go to attention state. | 432 // App window should go to attention state. |
409 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); | 433 app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); |
410 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); | 434 EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); |
411 | 435 |
412 // Activating app window should clear attention state. | 436 // Activating app window should clear attention state. |
413 activation_client_->ActivateWindow(&app_state.window); | 437 activation_client_->ActivateWindow(&app_state.window); |
414 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); | 438 EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); |
415 } | 439 } |
OLD | NEW |