Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc

Issue 27369004: Change GetBrowserItemIndex() to GetLauncherItemIndexForType() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix clang error Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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/shell_window.h" 7 #include "apps/shell_window.h"
8 #include "apps/shell_window_registry.h" 8 #include "apps/shell_window_registry.h"
9 #include "apps/ui/native_app_window.h" 9 #include "apps/ui/native_app_window.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_button.h" 13 #include "ash/launcher/launcher_button.h"
14 #include "ash/launcher/launcher_model.h" 14 #include "ash/launcher/launcher_model.h"
15 #include "ash/shelf/shelf_util.h" 15 #include "ash/launcher/launcher_model_util.h"
16 #include "ash/shelf/shelf_view.h" 16 #include "ash/shelf/shelf_view.h"
17 #include "ash/shell.h" 17 #include "ash/shell.h"
18 #include "ash/test/launcher_test_api.h" 18 #include "ash/test/launcher_test_api.h"
19 #include "ash/test/shelf_view_test_api.h" 19 #include "ash/test/shelf_view_test_api.h"
20 #include "ash/test/shell_test_api.h" 20 #include "ash/test/shell_test_api.h"
21 #include "ash/wm/window_state.h" 21 #include "ash/wm/window_state.h"
22 #include "ash/wm/window_util.h" 22 #include "ash/wm/window_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "chrome/browser/apps/app_browsertest_util.h" 25 #include "chrome/browser/apps/app_browsertest_util.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 launcher_->ActivateLauncherItem(id); 261 launcher_->ActivateLauncherItem(id);
262 } 262 }
263 263
264 ash::LauncherID PinFakeApp(const std::string& name) { 264 ash::LauncherID PinFakeApp(const std::string& name) {
265 return controller_->CreateAppShortcutLauncherItem( 265 return controller_->CreateAppShortcutLauncherItem(
266 name, model_->item_count()); 266 name, model_->item_count());
267 } 267 }
268 268
269 // Get the index of an item which has the given type. 269 // Get the index of an item which has the given type.
270 int GetIndexOfLauncherItemType(ash::LauncherItemType type) { 270 int GetIndexOfLauncherItemType(ash::LauncherItemType type) {
271 for (int i = 0; i < model_->item_count(); i++) { 271 return ash::GetLauncherItemIndexForType(type, *model_);
272 if (model_->items()[i].type == type)
273 return i;
274 }
275 return -1;
276 } 272 }
277 273
278 // Try to rip off |item_index|. 274 // Try to rip off |item_index|.
279 void RipOffItemIndex(int index, 275 void RipOffItemIndex(int index,
280 aura::test::EventGenerator* generator, 276 aura::test::EventGenerator* generator,
281 ash::test::ShelfViewTestAPI* test, 277 ash::test::ShelfViewTestAPI* test,
282 RipOffCommand command) { 278 RipOffCommand command) {
283 ash::internal::LauncherButton* button = test->GetButton(index); 279 ash::internal::LauncherButton* button = test->GetButton(index);
284 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); 280 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
285 gfx::Point rip_off_point(0, 0); 281 gfx::Point rip_off_point(0, 0);
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 ui_test_utils::NavigateToURL( 1019 ui_test_utils::NavigateToURL(
1024 browser(), GURL("http://www.example.com/path1/foo.html")); 1020 browser(), GURL("http://www.example.com/path1/foo.html"));
1025 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 1021 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
1026 } 1022 }
1027 1023
1028 // Confirm that a tab can be moved between browsers while maintaining the 1024 // Confirm that a tab can be moved between browsers while maintaining the
1029 // correct running state. 1025 // correct running state.
1030 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, TabDragAndDrop) { 1026 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, TabDragAndDrop) {
1031 TabStripModel* tab_strip_model1 = browser()->tab_strip_model(); 1027 TabStripModel* tab_strip_model1 = browser()->tab_strip_model();
1032 EXPECT_EQ(1, tab_strip_model1->count()); 1028 EXPECT_EQ(1, tab_strip_model1->count());
1033 int browser_index = ash::GetBrowserItemIndex(*model_); 1029 int browser_index = GetIndexOfLauncherItemType(ash::TYPE_BROWSER_SHORTCUT);
1034 EXPECT_TRUE(browser_index >= 0); 1030 EXPECT_TRUE(browser_index >= 0);
1035 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1031 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1036 1032
1037 // Create a shortcut for app1. 1033 // Create a shortcut for app1.
1038 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1034 ash::LauncherID shortcut_id = CreateShortcut("app1");
1039 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1035 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1040 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 1036 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
1041 1037
1042 // Activate app1 and check its item status. 1038 // Activate app1 and check its item status.
1043 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1039 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 WebContents* second_tab = tab_strip->GetActiveWebContents(); 1162 WebContents* second_tab = tab_strip->GetActiveWebContents();
1167 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1163 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1168 EXPECT_NE(first_tab, second_tab); 1164 EXPECT_NE(first_tab, second_tab);
1169 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 1165 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
1170 } 1166 }
1171 1167
1172 // Check the launcher activation state for applications and browser. 1168 // Check the launcher activation state for applications and browser.
1173 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) { 1169 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) {
1174 TabStripModel* tab_strip = browser()->tab_strip_model(); 1170 TabStripModel* tab_strip = browser()->tab_strip_model();
1175 // Get the browser item index 1171 // Get the browser item index
1176 int browser_index = ash::GetBrowserItemIndex(*controller_->model()); 1172 int browser_index = GetIndexOfLauncherItemType(ash::TYPE_BROWSER_SHORTCUT);
1177 EXPECT_TRUE(browser_index >= 0); 1173 EXPECT_TRUE(browser_index >= 0);
1178 1174
1179 // Even though we are just comming up, the browser should be active. 1175 // Even though we are just comming up, the browser should be active.
1180 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1176 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1181 1177
1182 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1178 ash::LauncherID shortcut_id = CreateShortcut("app1");
1183 controller_->SetRefocusURLPatternForTest( 1179 controller_->SetRefocusURLPatternForTest(
1184 shortcut_id, GURL("http://www.example.com/path1/*")); 1180 shortcut_id, GURL("http://www.example.com/path1/*"));
1185 1181
1186 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1182 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1824
1829 // Check that GetIDByWindow() returns |LauncherID| of the active tab. 1825 // Check that GetIDByWindow() returns |LauncherID| of the active tab.
1830 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) { 1826 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) {
1831 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1827 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1832 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1828 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1833 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 1829 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1834 EXPECT_EQ(2, model_->item_count()); 1830 EXPECT_EQ(2, model_->item_count());
1835 1831
1836 aura::Window* window = browser()->window()->GetNativeWindow(); 1832 aura::Window* window = browser()->window()->GetNativeWindow();
1837 1833
1838 int browser_index = ash::GetBrowserItemIndex(*model_); 1834 int browser_index = GetIndexOfLauncherItemType(ash::TYPE_BROWSER_SHORTCUT);
1839 ash::LauncherID browser_id = model_->items()[browser_index].id; 1835 ash::LauncherID browser_id = model_->items()[browser_index].id;
1840 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window)); 1836 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window));
1841 1837
1842 ash::LauncherID app_id = CreateShortcut("app1"); 1838 ash::LauncherID app_id = CreateShortcut("app1");
1843 EXPECT_EQ(3, model_->item_count()); 1839 EXPECT_EQ(3, model_->item_count());
1844 1840
1845 // Creates a new tab for "app1" and checks that GetIDByWindow() returns 1841 // Creates a new tab for "app1" and checks that GetIDByWindow() returns
1846 // |LauncherID| of "app1". 1842 // |LauncherID| of "app1".
1847 ActivateLauncherItem(model_->ItemIndexByID(app_id)); 1843 ActivateLauncherItem(model_->ItemIndexByID(app_id));
1848 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1844 EXPECT_EQ(2, browser()->tab_strip_model()->count());
(...skipping 29 matching lines...) Expand all
1878 // Now show overflow bubble. 1874 // Now show overflow bubble.
1879 test.ShowOverflowBubble(); 1875 test.ShowOverflowBubble();
1880 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); 1876 EXPECT_TRUE(launcher_->IsShowingOverflowBubble());
1881 1877
1882 // Unpin first pinned app and there should be no crash. 1878 // Unpin first pinned app and there should be no crash.
1883 controller_->UnpinAppWithID(std::string("fake_app_0")); 1879 controller_->UnpinAppWithID(std::string("fake_app_0"));
1884 1880
1885 test.RunMessageLoopUntilAnimationsDone(); 1881 test.RunMessageLoopUntilAnimationsDone();
1886 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); 1882 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
1887 } 1883 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698