OLD | NEW |
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_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "ash/common/ash_switches.h" | 17 #include "ash/common/ash_switches.h" |
| 18 #include "ash/common/shelf/shelf_controller.h" |
18 #include "ash/common/shelf/shelf_model.h" | 19 #include "ash/common/shelf/shelf_model.h" |
19 #include "ash/common/shelf/shelf_model_observer.h" | 20 #include "ash/common/shelf/shelf_model_observer.h" |
20 #include "ash/common/test/test_session_state_delegate.h" | 21 #include "ash/common/test/test_session_state_delegate.h" |
21 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 22 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
22 #include "ash/common/wm_shell.h" | 23 #include "ash/common/wm_shell.h" |
23 #include "ash/display/screen_orientation_controller_chromeos.h" | 24 #include "ash/display/screen_orientation_controller_chromeos.h" |
24 #include "ash/shell.h" | 25 #include "ash/shell.h" |
25 #include "ash/test/ash_test_helper.h" | 26 #include "ash/test/ash_test_helper.h" |
26 #include "ash/test/test_shell_delegate.h" | 27 #include "ash/test/test_shell_delegate.h" |
27 #include "ash/wm/window_util.h" | 28 #include "ash/wm/window_util.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // An extension prefix. | 119 // An extension prefix. |
119 const char kCrxAppPrefix[] = "_crx_"; | 120 const char kCrxAppPrefix[] = "_crx_"; |
120 | 121 |
121 // Dummy app id is used to put at least one pin record to prevent initializing | 122 // Dummy app id is used to put at least one pin record to prevent initializing |
122 // pin model with default apps that can affect some tests. | 123 // pin model with default apps that can affect some tests. |
123 const char kDummyAppId[] = "dummyappid_dummyappid_dummyappid"; | 124 const char kDummyAppId[] = "dummyappid_dummyappid_dummyappid"; |
124 | 125 |
125 // ShelfModelObserver implementation that tracks what messages are invoked. | 126 // ShelfModelObserver implementation that tracks what messages are invoked. |
126 class TestShelfModelObserver : public ash::ShelfModelObserver { | 127 class TestShelfModelObserver : public ash::ShelfModelObserver { |
127 public: | 128 public: |
128 TestShelfModelObserver() | 129 TestShelfModelObserver() {} |
129 : added_(0), | |
130 removed_(0), | |
131 changed_(0) { | |
132 } | |
133 | |
134 ~TestShelfModelObserver() override {} | 130 ~TestShelfModelObserver() override {} |
135 | 131 |
136 // Overridden from ash::ShelfModelObserver: | 132 // Overridden from ash::ShelfModelObserver: |
137 void ShelfItemAdded(int index) override { | 133 void ShelfItemAdded(int index) override { |
138 ++added_; | 134 ++added_; |
139 last_index_ = index; | 135 last_index_ = index; |
140 } | 136 } |
141 | 137 |
142 void ShelfItemRemoved(int index, ash::ShelfID id) override { | 138 void ShelfItemRemoved(int index, ash::ShelfID id) override { |
143 ++removed_; | 139 ++removed_; |
(...skipping 18 matching lines...) Expand all Loading... |
162 changed_ = 0; | 158 changed_ = 0; |
163 last_index_ = 0; | 159 last_index_ = 0; |
164 } | 160 } |
165 | 161 |
166 int added() const { return added_; } | 162 int added() const { return added_; } |
167 int removed() const { return removed_; } | 163 int removed() const { return removed_; } |
168 int changed() const { return changed_; } | 164 int changed() const { return changed_; } |
169 int last_index() const { return last_index_; } | 165 int last_index() const { return last_index_; } |
170 | 166 |
171 private: | 167 private: |
172 int added_; | 168 int added_ = 0; |
173 int removed_; | 169 int removed_ = 0; |
174 int changed_; | 170 int changed_ = 0; |
175 int last_index_; | 171 int last_index_ = 0; |
176 | 172 |
177 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); | 173 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); |
178 }; | 174 }; |
179 | 175 |
180 // Test implementation of AppIconLoader. | 176 // Test implementation of AppIconLoader. |
181 class TestAppIconLoaderImpl : public AppIconLoader { | 177 class TestAppIconLoaderImpl : public AppIconLoader { |
182 public: | 178 public: |
183 TestAppIconLoaderImpl() = default; | 179 TestAppIconLoaderImpl() = default; |
184 ~TestAppIconLoaderImpl() override = default; | 180 ~TestAppIconLoaderImpl() override = default; |
185 | 181 |
186 void AddSupportedApp(const std::string& id) { supported_apps_.insert(id); } | 182 void AddSupportedApp(const std::string& id) { supported_apps_.insert(id); } |
187 | 183 |
188 // AppIconLoader implementation: | 184 // AppIconLoader implementation: |
189 bool CanLoadImageForApp(const std::string& id) override { | 185 bool CanLoadImageForApp(const std::string& id) override { |
190 return supported_apps_.find(id) != supported_apps_.end(); | 186 return supported_apps_.find(id) != supported_apps_.end(); |
191 } | 187 } |
192 | |
193 void FetchImage(const std::string& id) override { ++fetch_count_; } | 188 void FetchImage(const std::string& id) override { ++fetch_count_; } |
194 | |
195 void ClearImage(const std::string& id) override { ++clear_count_; } | 189 void ClearImage(const std::string& id) override { ++clear_count_; } |
196 | |
197 void UpdateImage(const std::string& id) override {} | 190 void UpdateImage(const std::string& id) override {} |
198 | 191 |
199 int fetch_count() const { return fetch_count_; } | 192 int fetch_count() const { return fetch_count_; } |
200 int clear_count() const { return clear_count_; } | 193 int clear_count() const { return clear_count_; } |
201 | 194 |
202 private: | 195 private: |
203 int fetch_count_ = 0; | 196 int fetch_count_ = 0; |
204 int clear_count_ = 0; | 197 int clear_count_ = 0; |
205 std::set<std::string> supported_apps_; | 198 std::set<std::string> supported_apps_; |
206 | 199 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 288 |
296 private: | 289 private: |
297 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | 290 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); |
298 }; | 291 }; |
299 | 292 |
300 } // namespace | 293 } // namespace |
301 | 294 |
302 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { | 295 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { |
303 protected: | 296 protected: |
304 ChromeLauncherControllerImplTest() | 297 ChromeLauncherControllerImplTest() |
305 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false), | 298 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} |
306 test_controller_(NULL), | |
307 extension_service_(NULL) {} | |
308 | 299 |
309 ~ChromeLauncherControllerImplTest() override {} | 300 ~ChromeLauncherControllerImplTest() override {} |
310 | 301 |
311 void SetUp() override { | 302 void SetUp() override { |
312 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 303 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
313 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal); | 304 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal); |
314 command_line->AppendSwitch(ash::switches::kAshEnableTouchViewTesting); | 305 command_line->AppendSwitch(ash::switches::kAshEnableTouchViewTesting); |
315 | 306 |
316 app_list::AppListSyncableServiceFactory::SetUseInTesting(); | 307 app_list::AppListSyncableServiceFactory::SetUseInTesting(); |
317 | 308 |
318 BrowserWithTestWindowTest::SetUp(); | 309 BrowserWithTestWindowTest::SetUp(); |
319 | 310 |
320 if (!profile_manager_) { | 311 if (!profile_manager_) { |
321 profile_manager_.reset( | 312 profile_manager_.reset( |
322 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 313 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
323 ASSERT_TRUE(profile_manager_->SetUp()); | 314 ASSERT_TRUE(profile_manager_->SetUp()); |
324 } | 315 } |
325 | 316 |
326 model_.reset(new ash::ShelfModel); | 317 model_ = ash::WmShell::Get()->shelf_controller()->model(); |
327 model_observer_.reset(new TestShelfModelObserver); | 318 model_observer_.reset(new TestShelfModelObserver); |
328 model_->AddObserver(model_observer_.get()); | 319 model_->AddObserver(model_observer_.get()); |
329 | 320 |
330 base::DictionaryValue manifest; | 321 base::DictionaryValue manifest; |
331 manifest.SetString(extensions::manifest_keys::kName, | 322 manifest.SetString(extensions::manifest_keys::kName, |
332 "launcher controller test extension"); | 323 "launcher controller test extension"); |
333 manifest.SetString(extensions::manifest_keys::kVersion, "1"); | 324 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
334 manifest.SetString(extensions::manifest_keys::kDescription, | 325 manifest.SetString(extensions::manifest_keys::kDescription, |
335 "for testing pinned apps"); | 326 "for testing pinned apps"); |
336 | 327 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 InsertAddPinChange(user_b, 0, extension7_->id()); | 456 InsertAddPinChange(user_b, 0, extension7_->id()); |
466 InsertAddPinChange(user_b, 1, extension8_->id()); | 457 InsertAddPinChange(user_b, 1, extension8_->id()); |
467 InsertAddPinChange(user_b, 2, extension_misc::kChromeAppId); | 458 InsertAddPinChange(user_b, 2, extension_misc::kChromeAppId); |
468 } | 459 } |
469 | 460 |
470 void TearDown() override { | 461 void TearDown() override { |
471 arc_test_.TearDown(); | 462 arc_test_.TearDown(); |
472 model_->RemoveObserver(model_observer_.get()); | 463 model_->RemoveObserver(model_observer_.get()); |
473 model_observer_.reset(); | 464 model_observer_.reset(); |
474 launcher_controller_.reset(); | 465 launcher_controller_.reset(); |
475 | |
476 // |model_| must be deleted after |launch_controller_|, because | |
477 // |launch_controller_| has a map of pointers to the data held by |model_|. | |
478 model_.reset(); | |
479 | |
480 BrowserWithTestWindowTest::TearDown(); | 466 BrowserWithTestWindowTest::TearDown(); |
481 } | 467 } |
482 | 468 |
483 BrowserWindow* CreateBrowserWindow() override { | 469 BrowserWindow* CreateBrowserWindow() override { |
484 return CreateTestBrowserWindowAura(); | 470 return CreateTestBrowserWindowAura(); |
485 } | 471 } |
486 | 472 |
487 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile( | 473 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile( |
488 Profile* profile) { | 474 Profile* profile) { |
489 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura(); | 475 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura(); |
490 new TestBrowserWindowOwner(browser_window); | 476 new TestBrowserWindowOwner(browser_window); |
491 return base::WrapUnique( | 477 return base::WrapUnique( |
492 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window)); | 478 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window)); |
493 } | 479 } |
494 | 480 |
495 void AddAppListLauncherItem() { | 481 void AddAppListLauncherItem() { |
496 ash::ShelfItem app_list; | 482 ash::ShelfItem app_list; |
497 app_list.type = ash::TYPE_APP_LIST; | 483 app_list.type = ash::TYPE_APP_LIST; |
498 model_->Add(app_list); | 484 model_->Add(app_list); |
499 } | 485 } |
500 | 486 |
501 void InitLauncherController() { | 487 void InitLauncherController() { |
502 AddAppListLauncherItem(); | |
503 launcher_controller_.reset( | 488 launcher_controller_.reset( |
504 new ChromeLauncherControllerImpl(profile(), model_.get())); | 489 new ChromeLauncherControllerImpl(profile(), model_)); |
505 // TODO(crbug.com/654622): Some tests break with a non-null static instance. | 490 // TODO(crbug.com/654622): Some tests break with a non-null static instance. |
506 ChromeLauncherControllerImpl::set_instance_for_test(nullptr); | 491 ChromeLauncherControllerImpl::set_instance_for_test(nullptr); |
507 launcher_controller_->Init(); | 492 launcher_controller_->Init(); |
508 } | 493 } |
509 | 494 |
510 void InitLauncherControllerWithBrowser() { | 495 void InitLauncherControllerWithBrowser() { |
511 InitLauncherController(); | 496 InitLauncherController(); |
512 chrome::NewTab(browser()); | 497 chrome::NewTab(browser()); |
513 browser()->window()->Show(); | 498 browser()->window()->Show(); |
514 } | 499 } |
515 | 500 |
516 void RecreateChromeLauncher() { | 501 void RecreateChromeLauncher() { |
517 // Destroy controller first if it exists. | 502 // Destroy controller first if it exists. |
518 launcher_controller_.reset(); | 503 launcher_controller_.reset(); |
519 model_.reset(new ash::ShelfModel); | 504 while (model_->item_count() > 0) |
| 505 model_->RemoveItemAt(0); |
520 AddAppListLauncherItem(); | 506 AddAppListLauncherItem(); |
521 launcher_controller_ = | 507 launcher_controller_ = |
522 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get()); | 508 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_); |
523 launcher_controller_->Init(); | 509 launcher_controller_->Init(); |
524 } | 510 } |
525 | 511 |
526 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { | 512 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { |
527 app_service_->MergeDataAndStartSyncing( | 513 app_service_->MergeDataAndStartSyncing( |
528 syncer::APP_LIST, init_sync_list, | 514 syncer::APP_LIST, init_sync_list, |
529 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), | 515 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), |
530 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 516 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
531 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); | 517 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); |
532 } | 518 } |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 scoped_refptr<Extension> extension5_; | 896 scoped_refptr<Extension> extension5_; |
911 scoped_refptr<Extension> extension6_; | 897 scoped_refptr<Extension> extension6_; |
912 scoped_refptr<Extension> extension7_; | 898 scoped_refptr<Extension> extension7_; |
913 scoped_refptr<Extension> extension8_; | 899 scoped_refptr<Extension> extension8_; |
914 scoped_refptr<Extension> arc_support_host_; | 900 scoped_refptr<Extension> arc_support_host_; |
915 | 901 |
916 ArcAppTest arc_test_; | 902 ArcAppTest arc_test_; |
917 bool auto_start_arc_test_ = false; | 903 bool auto_start_arc_test_ = false; |
918 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_; | 904 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_; |
919 std::unique_ptr<TestShelfModelObserver> model_observer_; | 905 std::unique_ptr<TestShelfModelObserver> model_observer_; |
920 std::unique_ptr<ash::ShelfModel> model_; | 906 ash::ShelfModel* model_ = nullptr; |
921 std::unique_ptr<TestingProfileManager> profile_manager_; | 907 std::unique_ptr<TestingProfileManager> profile_manager_; |
922 | 908 |
923 // |item_delegate_manager_| owns |test_controller_|. | 909 // |item_delegate_manager_| owns |test_controller_|. |
924 LauncherItemController* test_controller_; | 910 LauncherItemController* test_controller_ = nullptr; |
925 | 911 |
926 ExtensionService* extension_service_; | 912 ExtensionService* extension_service_ = nullptr; |
927 | 913 |
928 app_list::AppListSyncableService* app_service_; | 914 app_list::AppListSyncableService* app_service_ = nullptr; |
929 | 915 |
930 private: | 916 private: |
931 TestBrowserWindow* CreateTestBrowserWindowAura() { | 917 TestBrowserWindow* CreateTestBrowserWindowAura() { |
932 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 918 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
933 window->set_id(0); | 919 window->set_id(0); |
934 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 920 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
935 window->Init(ui::LAYER_TEXTURED); | 921 window->Init(ui::LAYER_TEXTURED); |
936 aura::client::ParentWindowWithContext(window.get(), GetContext(), | 922 aura::client::ParentWindowWithContext(window.get(), GetContext(), |
937 gfx::Rect(200, 200)); | 923 gfx::Rect(200, 200)); |
938 | 924 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 private: | 999 private: |
1014 // The associated browser with this app. | 1000 // The associated browser with this app. |
1015 std::unique_ptr<Browser> browser_; | 1001 std::unique_ptr<Browser> browser_; |
1016 | 1002 |
1017 // The native window we use. | 1003 // The native window we use. |
1018 std::unique_ptr<aura::Window> native_window_; | 1004 std::unique_ptr<aura::Window> native_window_; |
1019 | 1005 |
1020 DISALLOW_COPY_AND_ASSIGN(V1App); | 1006 DISALLOW_COPY_AND_ASSIGN(V1App); |
1021 }; | 1007 }; |
1022 | 1008 |
1023 // A V2 application which gets created with an |extension| and for a |profile|. | 1009 // A V2 application window created with an |extension| and for a |profile|. |
1024 // Upon destruction it will properly close the application. | 1010 // Upon destruction it will properly close the application; supports panels too. |
1025 class V2App { | 1011 class V2App { |
1026 public: | 1012 public: |
1027 V2App(Profile* profile, const extensions::Extension* extension) | 1013 V2App(Profile* profile, |
| 1014 const extensions::Extension* extension, |
| 1015 extensions::AppWindow::WindowType window_type = |
| 1016 extensions::AppWindow::WINDOW_TYPE_DEFAULT) |
1028 : creator_web_contents_( | 1017 : creator_web_contents_( |
1029 content::WebContentsTester::CreateTestWebContents(profile, | 1018 content::WebContentsTester::CreateTestWebContents(profile, |
1030 nullptr)) { | 1019 nullptr)) { |
1031 window_ = new extensions::AppWindow(profile, new ChromeAppDelegate(true), | 1020 window_ = new extensions::AppWindow(profile, new ChromeAppDelegate(true), |
1032 extension); | 1021 extension); |
1033 extensions::AppWindow::CreateParams params = | 1022 extensions::AppWindow::CreateParams params; |
1034 extensions::AppWindow::CreateParams(); | 1023 params.window_type = window_type; |
1035 // Note: normally, the creator RFH is the background page of the | 1024 // Note: normally, the creator RFH is the background page of the |
1036 // app/extension | 1025 // app/extension |
1037 // calling chrome.app.window.create. For unit testing purposes, just passing | 1026 // calling chrome.app.window.create. For unit testing purposes, just passing |
1038 // in a random RenderFrameHost is Good Enoughâ„¢. | 1027 // in a random RenderFrameHost is Good Enoughâ„¢. |
1039 window_->Init(GURL(std::string()), | 1028 window_->Init(GURL(std::string()), |
1040 new extensions::AppWindowContentsImpl(window_), | 1029 new extensions::AppWindowContentsImpl(window_), |
1041 creator_web_contents_->GetMainFrame(), params); | 1030 creator_web_contents_->GetMainFrame(), params); |
1042 } | 1031 } |
1043 | 1032 |
1044 virtual ~V2App() { | 1033 virtual ~V2App() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 V1App* v1_app = new V1App(profile, app_name); | 1170 V1App* v1_app = new V1App(profile, app_name); |
1182 // Create a new launcher controller helper and assign it to the launcher so | 1171 // Create a new launcher controller helper and assign it to the launcher so |
1183 // that this app gets properly detected. | 1172 // that this app gets properly detected. |
1184 // TODO(skuhne): Create a more intelligent launcher controller helper that | 1173 // TODO(skuhne): Create a more intelligent launcher controller helper that |
1185 // is able to detect all running apps properly. | 1174 // is able to detect all running apps properly. |
1186 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; | 1175 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; |
1187 helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), | 1176 helper->SetAppID(v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), |
1188 app_name); | 1177 app_name); |
1189 SetLauncherControllerHelper(helper); | 1178 SetLauncherControllerHelper(helper); |
1190 | 1179 |
1191 NavigateAndCommitActiveTabWithTitle( | 1180 NavigateAndCommitActiveTabWithTitle(v1_app->browser(), GURL(url), |
1192 v1_app->browser(), GURL(url), ASCIIToUTF16("")); | 1181 base::string16()); |
1193 return v1_app; | 1182 return v1_app; |
1194 } | 1183 } |
1195 | 1184 |
1196 ash::test::TestShellDelegate* shell_delegate() { return shell_delegate_; } | 1185 ash::test::TestShellDelegate* shell_delegate() { return shell_delegate_; } |
1197 | 1186 |
1198 // Override BrowserWithTestWindowTest: | 1187 // Override BrowserWithTestWindowTest: |
1199 TestingProfile* CreateProfile() override { | 1188 TestingProfile* CreateProfile() override { |
1200 return CreateMultiUserProfile("user1"); | 1189 return CreateMultiUserProfile("user1"); |
1201 } | 1190 } |
1202 void DestroyProfile(TestingProfile* profile) override { | 1191 void DestroyProfile(TestingProfile* profile) override { |
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3266 { | 3255 { |
3267 ChromeLauncherAppMenuItems items = | 3256 ChromeLauncherAppMenuItems items = |
3268 launcher_controller_->GetApplicationList(item_gmail, 0); | 3257 launcher_controller_->GetApplicationList(item_gmail, 0); |
3269 items[1]->Execute(ui::EF_SHIFT_DOWN); | 3258 items[1]->Execute(ui::EF_SHIFT_DOWN); |
3270 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); | 3259 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); |
3271 } | 3260 } |
3272 } | 3261 } |
3273 | 3262 |
3274 // Tests that panels create launcher items correctly | 3263 // Tests that panels create launcher items correctly |
3275 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { | 3264 TEST_F(ChromeLauncherControllerImplTest, AppPanels) { |
3276 InitLauncherControllerWithBrowser(); | 3265 InitLauncherController(); |
3277 // App list and Browser shortcut ShelfItems are added. | 3266 model_observer_->clear_counts(); |
3278 EXPECT_EQ(2, model_observer_->added()); | 3267 const std::string app_id = extension1_->id(); |
3279 EXPECT_EQ(1, model_observer_->changed()); | |
3280 | 3268 |
3281 const std::string app_id = extension1_->id(); | |
3282 // app_icon_loader is owned by ChromeLauncherControllerImpl. | 3269 // app_icon_loader is owned by ChromeLauncherControllerImpl. |
3283 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); | 3270 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); |
3284 app_icon_loader->AddSupportedApp(app_id); | 3271 app_icon_loader->AddSupportedApp(app_id); |
3285 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 3272 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |
3286 | 3273 |
3287 // Test adding an app panel | 3274 // Make an app panel; the ShelfItem is added by ash::ShelfWindowWatcher. |
3288 AppWindowLauncherItemController* app_panel_controller = | 3275 std::unique_ptr<V2App> app_panel1 = base::MakeUnique<V2App>( |
3289 new ExtensionAppWindowLauncherItemController( | 3276 profile(), extension1_.get(), extensions::AppWindow::WINDOW_TYPE_PANEL); |
3290 LauncherItemController::TYPE_APP_PANEL, app_id, "id", | 3277 EXPECT_TRUE(app_panel1->window()->GetNativeWindow()->IsVisible()); |
3291 launcher_controller_.get()); | |
3292 ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem( | |
3293 app_panel_controller, app_id, ash::STATUS_RUNNING); | |
3294 int panel_index = model_observer_->last_index(); | 3278 int panel_index = model_observer_->last_index(); |
3295 EXPECT_EQ(3, model_observer_->added()); | 3279 EXPECT_EQ(1, model_observer_->added()); |
3296 EXPECT_EQ(1, model_observer_->changed()); | |
3297 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 3280 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
3298 model_observer_->clear_counts(); | 3281 model_observer_->clear_counts(); |
3299 | 3282 |
3300 // App panels should have a separate identifier than the app id | 3283 // App panels should have a separate identifier than the app id |
3301 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); | 3284 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); |
3302 | 3285 |
3303 // Setting the app image image should not change the panel if it set its icon | 3286 // Setting the app image should not change the panel, which has a window icon. |
3304 app_panel_controller->set_image_set_by_controller(true); | |
3305 gfx::ImageSkia image; | 3287 gfx::ImageSkia image; |
3306 launcher_controller_->OnAppImageUpdated(app_id, image); | 3288 launcher_controller_->OnAppImageUpdated(app_id, image); |
3307 EXPECT_EQ(0, model_observer_->changed()); | 3289 EXPECT_EQ(0, model_observer_->changed()); |
3308 model_observer_->clear_counts(); | 3290 model_observer_->clear_counts(); |
3309 | 3291 |
3310 // Add a second app panel and verify that it get the same index as the first | 3292 // Make a second app panel and verify that it gets the same index as the first |
3311 // one had, being added to the left of the existing panel. | 3293 // panel, being added to the left of the existing panel. |
3312 AppWindowLauncherItemController* app_panel_controller2 = | 3294 std::unique_ptr<V2App> app_panel2 = base::MakeUnique<V2App>( |
3313 new ExtensionAppWindowLauncherItemController( | 3295 profile(), extension2_.get(), extensions::AppWindow::WINDOW_TYPE_PANEL); |
3314 LauncherItemController::TYPE_APP_PANEL, app_id, "id", | |
3315 launcher_controller_.get()); | |
3316 | |
3317 ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem( | |
3318 app_panel_controller2, app_id, ash::STATUS_RUNNING); | |
3319 EXPECT_EQ(panel_index, model_observer_->last_index()); | 3296 EXPECT_EQ(panel_index, model_observer_->last_index()); |
3320 EXPECT_EQ(1, model_observer_->added()); | 3297 EXPECT_EQ(1, model_observer_->added()); |
3321 model_observer_->clear_counts(); | 3298 model_observer_->clear_counts(); |
3322 | 3299 |
3323 launcher_controller_->CloseLauncherItem(shelf_id2); | 3300 app_panel1.reset(); |
3324 launcher_controller_->CloseLauncherItem(shelf_id1); | 3301 app_panel2.reset(); |
3325 EXPECT_EQ(2, model_observer_->removed()); | 3302 EXPECT_EQ(2, model_observer_->removed()); |
3326 } | 3303 } |
3327 | 3304 |
3328 // Tests that the Gmail extension matches more than the app itself claims with | 3305 // Tests that the Gmail extension matches more than the app itself claims with |
3329 // the manifest file. | 3306 // the manifest file. |
3330 TEST_F(ChromeLauncherControllerImplTest, GmailMatching) { | 3307 TEST_F(ChromeLauncherControllerImplTest, GmailMatching) { |
3331 InitLauncherControllerWithBrowser(); | 3308 InitLauncherControllerWithBrowser(); |
3332 | 3309 |
3333 // Create a Gmail browser tab. | 3310 // Create a Gmail browser tab. |
3334 chrome::NewTab(browser()); | 3311 chrome::NewTab(browser()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3412 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); | 3389 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); |
3413 | 3390 |
3414 // Move browser shortcut item from index 1 to index 3. | 3391 // Move browser shortcut item from index 1 to index 3. |
3415 model_->Move(1, 3); | 3392 model_->Move(1, 3); |
3416 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 3393 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
3417 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 3394 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
3418 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 3395 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
3419 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); | 3396 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); |
3420 | 3397 |
3421 launcher_controller_.reset(); | 3398 launcher_controller_.reset(); |
3422 model_.reset(new ash::ShelfModel); | 3399 while (!model_->items().empty()) |
| 3400 model_->RemoveItemAt(0); |
3423 | 3401 |
3424 AddAppListLauncherItem(); | 3402 AddAppListLauncherItem(); |
3425 launcher_controller_ = | 3403 launcher_controller_ = |
3426 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get()); | 3404 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_); |
3427 helper = new TestLauncherControllerHelper(profile()); | 3405 helper = new TestLauncherControllerHelper(profile()); |
3428 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 3406 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
3429 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); | 3407 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); |
3430 SetLauncherControllerHelper(helper); | 3408 SetLauncherControllerHelper(helper); |
3431 launcher_controller_->Init(); | 3409 launcher_controller_->Init(); |
3432 | 3410 |
3433 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. | 3411 // Check ShelfItems are restored after resetting ChromeLauncherControllerImpl. |
3434 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); | 3412 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); |
3435 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); | 3413 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); |
3436 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 3414 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
(...skipping 21 matching lines...) Expand all Loading... |
3458 launcher_controller_->PinAppWithID("1"); | 3436 launcher_controller_->PinAppWithID("1"); |
3459 ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1"); | 3437 ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1"); |
3460 int app_index = model_->ItemIndexByID(id); | 3438 int app_index = model_->ItemIndexByID(id); |
3461 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 3439 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
3462 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 3440 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
3463 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 3441 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
3464 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 3442 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
3465 EXPECT_EQ(initial_size + 1, model_->items().size()); | 3443 EXPECT_EQ(initial_size + 1, model_->items().size()); |
3466 | 3444 |
3467 launcher_controller_.reset(); | 3445 launcher_controller_.reset(); |
3468 model_.reset(new ash::ShelfModel); | 3446 while (!model_->items().empty()) |
| 3447 model_->RemoveItemAt(0); |
3469 | 3448 |
3470 AddAppListLauncherItem(); | 3449 AddAppListLauncherItem(); |
3471 launcher_controller_ = | 3450 launcher_controller_ = |
3472 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_.get()); | 3451 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_); |
3473 helper = new TestLauncherControllerHelper(profile()); | 3452 helper = new TestLauncherControllerHelper(profile()); |
3474 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 3453 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
3475 SetLauncherControllerHelper(helper); | 3454 SetLauncherControllerHelper(helper); |
3476 // app_icon_loader is owned by ChromeLauncherControllerImpl. | 3455 // app_icon_loader is owned by ChromeLauncherControllerImpl. |
3477 app_icon_loader = new TestAppIconLoaderImpl; | 3456 app_icon_loader = new TestAppIconLoaderImpl; |
3478 app_icon_loader->AddSupportedApp("1"); | 3457 app_icon_loader->AddSupportedApp("1"); |
3479 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 3458 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |
3480 launcher_controller_->Init(); | 3459 launcher_controller_->Init(); |
3481 | 3460 |
3482 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 3461 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
(...skipping 14 matching lines...) Expand all Loading... |
3497 const std::string app_id3 = extension3_->id(); | 3476 const std::string app_id3 = extension3_->id(); |
3498 // app_icon_loader1 and app_icon_loader2 are owned by | 3477 // app_icon_loader1 and app_icon_loader2 are owned by |
3499 // ChromeLauncherControllerImpl. | 3478 // ChromeLauncherControllerImpl. |
3500 TestAppIconLoaderImpl* app_icon_loader1 = new TestAppIconLoaderImpl(); | 3479 TestAppIconLoaderImpl* app_icon_loader1 = new TestAppIconLoaderImpl(); |
3501 TestAppIconLoaderImpl* app_icon_loader2 = new TestAppIconLoaderImpl(); | 3480 TestAppIconLoaderImpl* app_icon_loader2 = new TestAppIconLoaderImpl(); |
3502 app_icon_loader1->AddSupportedApp(app_id1); | 3481 app_icon_loader1->AddSupportedApp(app_id1); |
3503 app_icon_loader2->AddSupportedApp(app_id2); | 3482 app_icon_loader2->AddSupportedApp(app_id2); |
3504 SetAppIconLoaders(std::unique_ptr<AppIconLoader>(app_icon_loader1), | 3483 SetAppIconLoaders(std::unique_ptr<AppIconLoader>(app_icon_loader1), |
3505 std::unique_ptr<AppIconLoader>(app_icon_loader2)); | 3484 std::unique_ptr<AppIconLoader>(app_icon_loader2)); |
3506 | 3485 |
3507 AppWindowLauncherItemController* app_panel_controller3 = | 3486 AppWindowLauncherItemController* app_controller3 = |
3508 new ExtensionAppWindowLauncherItemController( | 3487 new ExtensionAppWindowLauncherItemController( |
3509 LauncherItemController::TYPE_APP_PANEL, app_id3, "id", | 3488 LauncherItemController::TYPE_APP, app_id3, "id", |
3510 launcher_controller_.get()); | 3489 launcher_controller_.get()); |
3511 const ash::ShelfID shelfId3 = launcher_controller_->CreateAppLauncherItem( | 3490 const ash::ShelfID shelfId3 = launcher_controller_->CreateAppLauncherItem( |
3512 app_panel_controller3, app_id3, ash::STATUS_RUNNING); | 3491 app_controller3, app_id3, ash::STATUS_RUNNING); |
3513 EXPECT_EQ(0, app_icon_loader1->fetch_count()); | 3492 EXPECT_EQ(0, app_icon_loader1->fetch_count()); |
3514 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3493 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
3515 EXPECT_EQ(0, app_icon_loader2->fetch_count()); | 3494 EXPECT_EQ(0, app_icon_loader2->fetch_count()); |
3516 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3495 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
3517 | 3496 |
3518 AppWindowLauncherItemController* app_panel_controller2 = | 3497 AppWindowLauncherItemController* app_controller2 = |
3519 new ExtensionAppWindowLauncherItemController( | 3498 new ExtensionAppWindowLauncherItemController( |
3520 LauncherItemController::TYPE_APP_PANEL, app_id2, "id", | 3499 LauncherItemController::TYPE_APP, app_id2, "id", |
3521 launcher_controller_.get()); | 3500 launcher_controller_.get()); |
3522 const ash::ShelfID shelfId2 = launcher_controller_->CreateAppLauncherItem( | 3501 const ash::ShelfID shelfId2 = launcher_controller_->CreateAppLauncherItem( |
3523 app_panel_controller2, app_id2, ash::STATUS_RUNNING); | 3502 app_controller2, app_id2, ash::STATUS_RUNNING); |
3524 EXPECT_EQ(0, app_icon_loader1->fetch_count()); | 3503 EXPECT_EQ(0, app_icon_loader1->fetch_count()); |
3525 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3504 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
3526 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3505 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
3527 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3506 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
3528 | 3507 |
3529 // Test adding an app panel | 3508 AppWindowLauncherItemController* app_controller1 = |
3530 AppWindowLauncherItemController* app_panel_controller1 = | |
3531 new ExtensionAppWindowLauncherItemController( | 3509 new ExtensionAppWindowLauncherItemController( |
3532 LauncherItemController::TYPE_APP_PANEL, app_id1, "id", | 3510 LauncherItemController::TYPE_APP, app_id1, "id", |
3533 launcher_controller_.get()); | 3511 launcher_controller_.get()); |
3534 | 3512 |
3535 const ash::ShelfID shelfId1 = launcher_controller_->CreateAppLauncherItem( | 3513 const ash::ShelfID shelfId1 = launcher_controller_->CreateAppLauncherItem( |
3536 app_panel_controller1, app_id1, ash::STATUS_RUNNING); | 3514 app_controller1, app_id1, ash::STATUS_RUNNING); |
3537 EXPECT_EQ(1, app_icon_loader1->fetch_count()); | 3515 EXPECT_EQ(1, app_icon_loader1->fetch_count()); |
3538 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3516 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
3539 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3517 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
3540 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3518 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
3541 | 3519 |
3542 launcher_controller_->CloseLauncherItem(shelfId1); | 3520 launcher_controller_->CloseLauncherItem(shelfId1); |
3543 EXPECT_EQ(1, app_icon_loader1->fetch_count()); | 3521 EXPECT_EQ(1, app_icon_loader1->fetch_count()); |
3544 EXPECT_EQ(1, app_icon_loader1->clear_count()); | 3522 EXPECT_EQ(1, app_icon_loader1->clear_count()); |
3545 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3523 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
3546 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3524 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4043 | 4021 |
4044 // Pinned state should not change. | 4022 // Pinned state should not change. |
4045 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); | 4023 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); |
4046 launcher_controller_->UnpinAppWithID(extension2_->id()); | 4024 launcher_controller_->UnpinAppWithID(extension2_->id()); |
4047 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 4025 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
4048 | 4026 |
4049 // Resume syncing and sync information overrides local copy. | 4027 // Resume syncing and sync information overrides local copy. |
4050 StartAppSyncService(copy_sync_list); | 4028 StartAppSyncService(copy_sync_list); |
4051 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); | 4029 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); |
4052 } | 4030 } |
OLD | NEW |