Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
Rename to chrome_launcher_controller_browsertest.c
simonhong_
2013/08/19 05:26:11
Done.
| |
| 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.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" |
| 8 #include "apps/shell_window.h" | 8 #include "apps/shell_window.h" |
| 9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_controller.h" | 11 #include "ash/display/display_controller.h" |
| 12 #include "ash/launcher/launcher.h" | 12 #include "ash/launcher/launcher.h" |
| 13 #include "ash/launcher/launcher_model.h" | 13 #include "ash/launcher/launcher_model.h" |
| 14 #include "ash/launcher/launcher_util.h" | 14 #include "ash/launcher/launcher_util.h" |
| 15 #include "ash/launcher/launcher_view.h" | 15 #include "ash/launcher/launcher_view.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/test/launcher_view_test_api.h" | 17 #include "ash/test/launcher_view_test_api.h" |
| 18 #include "ash/test/shell_test_api.h" | 18 #include "ash/test/shell_test_api.h" |
| 19 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 20 #include "base/strings/stringprintf.h" | |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "chrome/browser/apps/app_browsertest_util.h" | 22 #include "chrome/browser/apps/app_browsertest_util.h" |
| 22 #include "chrome/browser/automation/automation_util.h" | 23 #include "chrome/browser/automation/automation_util.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 24 #include "chrome/browser/extensions/extension_apitest.h" | 25 #include "chrome/browser/extensions/extension_apitest.h" |
| 25 #include "chrome/browser/extensions/extension_browsertest.h" | 26 #include "chrome/browser/extensions/extension_browsertest.h" |
| 26 #include "chrome/browser/extensions/extension_function_test_utils.h" | 27 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 27 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 28 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
| 29 #include "chrome/browser/extensions/extension_test_message_listener.h" | 30 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); | 245 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); |
| 245 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 246 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 246 return item.id; | 247 return item.id; |
| 247 } | 248 } |
| 248 | 249 |
| 249 // Activate the launcher item with the given |id|. | 250 // Activate the launcher item with the given |id|. |
| 250 void ActivateLauncherItem(int id) { | 251 void ActivateLauncherItem(int id) { |
| 251 launcher_->ActivateLauncherItem(id); | 252 launcher_->ActivateLauncherItem(id); |
| 252 } | 253 } |
| 253 | 254 |
| 255 ash::LauncherID PinFakeApp(const std::string& name) { | |
| 256 ChromeLauncherController* controller = | |
| 257 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 258 return controller->CreateAppShortcutLauncherItem( | |
| 259 name, model_->item_count()); | |
| 260 } | |
| 261 | |
| 254 ash::Launcher* launcher_; | 262 ash::Launcher* launcher_; |
| 255 ash::LauncherModel* model_; | 263 ash::LauncherModel* model_; |
| 256 | 264 |
| 257 private: | 265 private: |
| 258 | 266 |
| 259 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); | 267 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); |
|
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
Remove the "PerApp" here.
simonhong_
2013/08/19 05:26:11
Done.
| |
| 260 }; | 268 }; |
| 261 | 269 |
| 262 // TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the | 270 // TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the |
| 263 // old launcher gets ripped out. | 271 // old launcher gets ripped out. |
| 264 class LauncherPerAppAppBrowserTestNoDefaultBrowser | 272 class LauncherPerAppAppBrowserTestNoDefaultBrowser |
|
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
Please remove the "PerApp" from this class (and al
simonhong_
2013/08/19 05:26:11
Done.
| |
| 265 : public LauncherPerAppAppBrowserTest { | 273 : public LauncherPerAppAppBrowserTest { |
| 266 protected: | 274 protected: |
| 267 LauncherPerAppAppBrowserTestNoDefaultBrowser() {} | 275 LauncherPerAppAppBrowserTestNoDefaultBrowser() {} |
| 268 virtual ~LauncherPerAppAppBrowserTestNoDefaultBrowser() {} | 276 virtual ~LauncherPerAppAppBrowserTestNoDefaultBrowser() {} |
| 269 | 277 |
| 270 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 278 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 271 LauncherPerAppAppBrowserTest::SetUpCommandLine(command_line); | 279 LauncherPerAppAppBrowserTest::SetUpCommandLine(command_line); |
| 272 command_line->AppendSwitch(switches::kNoStartupWindow); | 280 command_line->AppendSwitch(switches::kNoStartupWindow); |
| 273 } | 281 } |
| 274 | 282 |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1283 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow(); | 1291 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow(); |
| 1284 | 1292 |
| 1285 EXPECT_TRUE(window1a->IsActive()); | 1293 EXPECT_TRUE(window1a->IsActive()); |
| 1286 EXPECT_FALSE(window1->IsActive()); | 1294 EXPECT_FALSE(window1->IsActive()); |
| 1287 ActivateLauncherItem(app_index); | 1295 ActivateLauncherItem(app_index); |
| 1288 EXPECT_TRUE(window1->IsActive()); | 1296 EXPECT_TRUE(window1->IsActive()); |
| 1289 ActivateLauncherItem(app_index); | 1297 ActivateLauncherItem(app_index); |
| 1290 EXPECT_TRUE(window1a->IsActive()); | 1298 EXPECT_TRUE(window1a->IsActive()); |
| 1291 } | 1299 } |
| 1292 | 1300 |
| 1301 // Test that we can launch a platform app panel and get a running item. | |
| 1302 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, | |
| 1303 LaunchPanelWindow) { | |
| 1304 int item_count = launcher_model()->item_count(); | |
| 1305 const Extension* extension = LoadAndLaunchPlatformApp("launch"); | |
| 1306 ShellWindow::CreateParams params; | |
| 1307 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | |
| 1308 params.focused = false; | |
| 1309 ShellWindow* window = CreateShellWindowFromParams(extension, params); | |
| 1310 ++item_count; | |
| 1311 ASSERT_EQ(item_count, launcher_model()->item_count()); | |
| 1312 const ash::LauncherItem& item = GetLastLauncherPanelItem(); | |
| 1313 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | |
| 1314 // Opening a panel does not activate it. | |
| 1315 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | |
| 1316 CloseShellWindow(window); | |
| 1317 --item_count; | |
| 1318 EXPECT_EQ(item_count, launcher_model()->item_count()); | |
| 1319 } | |
| 1320 | |
| 1293 // Checks that the browser Alt "tabbing" is properly done. | 1321 // Checks that the browser Alt "tabbing" is properly done. |
| 1294 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, | 1322 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, |
| 1295 AltNumberBrowserTabbing) { | 1323 AltNumberBrowserTabbing) { |
| 1296 // Get the number of items in the browser menu. | 1324 // Get the number of items in the browser menu. |
| 1297 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); | 1325 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 1298 // The first activation should create a browser. | 1326 // The first activation should create a browser. |
| 1299 launcher_->ActivateLauncherItem(0); | 1327 launcher_->ActivateLauncherItem(0); |
| 1300 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1328 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1301 // A second activation should not create a new instance. | 1329 // A second activation should not create a new instance. |
| 1302 launcher_->ActivateLauncherItem(0); | 1330 launcher_->ActivateLauncherItem(0); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1607 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1635 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1608 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 1636 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 1609 EXPECT_EQ(app_id, controller->GetIDByWindow(window)); | 1637 EXPECT_EQ(app_id, controller->GetIDByWindow(window)); |
| 1610 | 1638 |
| 1611 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow() | 1639 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow() |
| 1612 // returns |LauncherID| of browser shortcut. | 1640 // returns |LauncherID| of browser shortcut. |
| 1613 browser()->tab_strip_model()->ActivateTabAt(0, false); | 1641 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 1614 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 1642 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 1615 EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); | 1643 EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); |
| 1616 } | 1644 } |
| 1645 | |
| 1646 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, OverflowBubble) { | |
|
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
How did this get into this CL?
simonhong_
2013/08/19 05:26:11
This test is moved from (previous)chrome_launcher_
| |
| 1647 // Make sure to have a browser window | |
| 1648 chrome::NewTab(browser()); | |
| 1649 | |
| 1650 // No overflow yet. | |
| 1651 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); | |
| 1652 | |
| 1653 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); | |
| 1654 | |
| 1655 int items_added = 0; | |
| 1656 while (!test.IsOverflowButtonVisible()) { | |
| 1657 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); | |
| 1658 PinFakeApp(fake_app_id); | |
| 1659 | |
| 1660 ++items_added; | |
| 1661 ASSERT_LT(items_added, 10000); | |
| 1662 } | |
| 1663 | |
| 1664 // Now show overflow bubble. | |
| 1665 test.ShowOverflowBubble(); | |
| 1666 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); | |
| 1667 | |
| 1668 // Unpin first pinned app and there should be no crash. | |
| 1669 ChromeLauncherController* controller = | |
| 1670 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1671 controller->UnpinAppsWithID(std::string("fake_app_0")); | |
| 1672 | |
| 1673 test.RunMessageLoopUntilAnimationsDone(); | |
| 1674 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); | |
| 1675 } | |
| 1676 | |
| OLD | NEW |