| 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/chrome_launcher_controller_per_app.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/launcher/launcher_model.h" | 11 #include "ash/launcher/launcher_model.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
| 21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 22 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 22 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/browser_with_test_window_test.h" | 29 #include "chrome/test/base/browser_with_test_window_test.h" |
| 29 #include "chrome/test/base/testing_pref_service.h" | 30 #include "chrome/test/base/testing_pref_service.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/base/models/menu_model.h" | 34 #include "ui/base/models/menu_model.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 EXPECT_EQ(expected_menu_items, menu->GetItemCount()); | 304 EXPECT_EQ(expected_menu_items, menu->GetItemCount()); |
| 304 EXPECT_FALSE(menu->IsEnabledAt(first_item)); | 305 EXPECT_FALSE(menu->IsEnabledAt(first_item)); |
| 305 if (expected_items) { | 306 if (expected_items) { |
| 306 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | 307 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, |
| 307 menu->GetTypeAt(first_item + 1)); | 308 menu->GetTypeAt(first_item + 1)); |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 | 311 |
| 311 // Check that browsers get reflected correctly in the launcher menu. | 312 // Check that browsers get reflected correctly in the launcher menu. |
| 312 TEST_F(ChromeLauncherControllerPerAppTest, BrowserMenuGeneration) { | 313 TEST_F(ChromeLauncherControllerPerAppTest, BrowserMenuGeneration) { |
| 313 EXPECT_EQ(1U, BrowserList::size()); | 314 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
| 314 chrome::NewTab(browser()); | 315 chrome::NewTab(browser()); |
| 315 | 316 |
| 316 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); | 317 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 317 launcher_controller.Init(); | 318 launcher_controller.Init(); |
| 318 | 319 |
| 319 // Check that the browser list is empty at this time. | 320 // Check that the browser list is empty at this time. |
| 320 ash::LauncherItem item_browser; | 321 ash::LauncherItem item_browser; |
| 321 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; | 322 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; |
| 322 CheckMenuCreation(&launcher_controller, item_browser, 0, NULL); | 323 CheckMenuCreation(&launcher_controller, item_browser, 0, NULL); |
| 323 | 324 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 345 | 346 |
| 346 // Apparently we have to close all tabs we have. | 347 // Apparently we have to close all tabs we have. |
| 347 chrome::CloseTab(browser2.get()); | 348 chrome::CloseTab(browser2.get()); |
| 348 } | 349 } |
| 349 | 350 |
| 350 // Check that V1 apps are correctly reflected in the launcher menu using the | 351 // Check that V1 apps are correctly reflected in the launcher menu using the |
| 351 // refocus logic. | 352 // refocus logic. |
| 352 // Note that the extension matching logic is tested by the extension system | 353 // Note that the extension matching logic is tested by the extension system |
| 353 // and does not need a separate test here. | 354 // and does not need a separate test here. |
| 354 TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuGeneration) { | 355 TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuGeneration) { |
| 355 EXPECT_EQ(1U, BrowserList::size()); | 356 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
| 356 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 357 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 357 chrome::NewTab(browser()); | 358 chrome::NewTab(browser()); |
| 358 BrowserList::SetLastActive(browser()); | 359 BrowserList::SetLastActive(browser()); |
| 359 | 360 |
| 360 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); | 361 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 361 launcher_controller.Init(); | 362 launcher_controller.Init(); |
| 362 | 363 |
| 363 // Model should only contain the browser shortcut and app list items. | 364 // Model should only contain the browser shortcut and app list items. |
| 364 EXPECT_EQ(2, model_.item_count()); | 365 EXPECT_EQ(2, model_.item_count()); |
| 365 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); | 366 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 int first_item = | 466 int first_item = |
| 466 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; | 467 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; |
| 467 menu->ActivatedAt(first_item + 3); | 468 menu->ActivatedAt(first_item + 3); |
| 468 } | 469 } |
| 469 // Now the active tab should be the second item. | 470 // Now the active tab should be the second item. |
| 470 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 471 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 471 } | 472 } |
| 472 | 473 |
| 473 // TODO(skuhne) Add tests for: | 474 // TODO(skuhne) Add tests for: |
| 474 // - V2 apps: create through item in launcher or directly | 475 // - V2 apps: create through item in launcher or directly |
| OLD | NEW |