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

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

Issue 23068021: Remove PerBrowser launcher, reland step 1 of 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/host_desktop.h" 30 #include "chrome/browser/ui/host_desktop.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/extensions/extension_constants.h" 33 #include "chrome/common/extensions/extension_constants.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "chrome/test/base/browser_with_test_window_test.h" 35 #include "chrome/test/base/browser_with_test_window_test.h"
36 #include "chrome/test/base/testing_pref_service_syncable.h" 36 #include "chrome/test/base/testing_pref_service_syncable.h"
37 #include "chrome/test/base/testing_profile.h" 37 #include "chrome/test/base/testing_profile.h"
38 #include "content/public/browser/web_contents.h"
38 #include "content/public/test/test_browser_thread.h" 39 #include "content/public/test/test_browser_thread.h"
39 #include "extensions/common/manifest_constants.h" 40 #include "extensions/common/manifest_constants.h"
40 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
41 #include "ui/base/models/menu_model.h" 42 #include "ui/base/models/menu_model.h"
42 43
43 using extensions::Extension; 44 using extensions::Extension;
44 using extensions::Manifest; 45 using extensions::Manifest;
45 46
46 namespace { 47 namespace {
47 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; 48 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u";
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 int fetch_count() const { return fetch_count_; } 131 int fetch_count() const { return fetch_count_; }
131 132
132 private: 133 private:
133 int fetch_count_; 134 int fetch_count_;
134 135
135 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); 136 DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl);
136 }; 137 };
137 138
139 // Test implementation of AppTabHelper.
140 class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper {
141 public:
142 TestAppTabHelperImpl() {}
143 virtual ~TestAppTabHelperImpl() {}
144
145 // Sets the id for the specified tab. The id is removed if Remove() is
146 // invoked.
147 void SetAppID(content::WebContents* tab, const std::string& id) {
148 tab_id_map_[tab] = id;
149 }
150
151 // Returns true if there is an id registered for |tab|.
152 bool HasAppID(content::WebContents* tab) const {
153 return tab_id_map_.find(tab) != tab_id_map_.end();
154 }
155
156 // AppTabHelper implementation:
157 virtual std::string GetAppID(content::WebContents* tab) OVERRIDE {
158 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] :
159 std::string();
160 }
161
162 virtual bool IsValidID(const std::string& id) OVERRIDE {
163 for (TabToStringMap::const_iterator i = tab_id_map_.begin();
164 i != tab_id_map_.end(); ++i) {
165 if (i->second == id)
166 return true;
167 }
168 return false;
169 }
170
171 private:
172 typedef std::map<content::WebContents*, std::string> TabToStringMap;
173
174 TabToStringMap tab_id_map_;
175
176 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl);
177 };
178
138 } // namespace 179 } // namespace
139 180
140 class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { 181 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
141 protected: 182 protected:
142 ChromeLauncherControllerPerAppTest() 183 ChromeLauncherControllerTest() : extension_service_(NULL) {
143 : extension_service_(NULL) {
144 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); 184 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
145 } 185 }
146 186
147 virtual ~ChromeLauncherControllerPerAppTest() { 187 virtual ~ChromeLauncherControllerTest() {
148 } 188 }
149 189
150 virtual void SetUp() OVERRIDE { 190 virtual void SetUp() OVERRIDE {
151 BrowserWithTestWindowTest::SetUp(); 191 BrowserWithTestWindowTest::SetUp();
152 192
153 model_.reset(new ash::LauncherModel); 193 model_.reset(new ash::LauncherModel);
154 model_observer_.reset(new TestLauncherModelObserver); 194 model_observer_.reset(new TestLauncherModelObserver);
155 model_->AddObserver(model_observer_.get()); 195 model_->AddObserver(model_observer_.get());
156 196
157 DictionaryValue manifest; 197 DictionaryValue manifest;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 model_->RemoveObserver(model_observer_.get()); 249 model_->RemoveObserver(model_observer_.get());
210 model_observer_.reset(); 250 model_observer_.reset();
211 launcher_controller_.reset(); 251 launcher_controller_.reset();
212 model_.reset(); 252 model_.reset();
213 253
214 BrowserWithTestWindowTest::TearDown(); 254 BrowserWithTestWindowTest::TearDown();
215 } 255 }
216 256
217 void InitLauncherController() { 257 void InitLauncherController() {
218 launcher_controller_.reset( 258 launcher_controller_.reset(
219 new ChromeLauncherControllerPerApp(profile(), model_.get())); 259 new ChromeLauncherController(profile(), model_.get()));
220 launcher_controller_->Init(); 260 launcher_controller_->Init();
221 } 261 }
222 262
223 void InitLauncherControllerWithBrowser() { 263 void InitLauncherControllerWithBrowser() {
224 chrome::NewTab(browser()); 264 chrome::NewTab(browser());
225 BrowserList::SetLastActive(browser()); 265 BrowserList::SetLastActive(browser());
226 InitLauncherController(); 266 InitLauncherController();
227 } 267 }
228 268
229 void SetAppIconLoader(extensions::AppIconLoader* loader) { 269 void SetAppIconLoader(extensions::AppIconLoader* loader) {
230 launcher_controller_->SetAppIconLoaderForTest(loader); 270 launcher_controller_->SetAppIconLoaderForTest(loader);
231 } 271 }
232 272
273 void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) {
274 launcher_controller_->SetAppTabHelperForTest(helper);
275 }
276
233 void InsertPrefValue(base::ListValue* pref_value, 277 void InsertPrefValue(base::ListValue* pref_value,
234 int index, 278 int index,
235 const std::string& extension_id) { 279 const std::string& extension_id) {
236 base::DictionaryValue* entry = new DictionaryValue(); 280 base::DictionaryValue* entry = new DictionaryValue();
237 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 281 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id);
238 pref_value->Insert(index, entry); 282 pref_value->Insert(index, entry);
239 } 283 }
240 284
241 // Gets the currently configured app launchers from the controller. 285 // Gets the currently configured app launchers from the controller.
242 void GetAppLaunchers(ChromeLauncherControllerPerApp* controller, 286 void GetAppLaunchers(ChromeLauncherController* controller,
243 std::vector<std::string>* launchers) { 287 std::vector<std::string>* launchers) {
244 launchers->clear(); 288 launchers->clear();
245 for (ash::LauncherItems::const_iterator iter(model_->items().begin()); 289 for (ash::LauncherItems::const_iterator iter(model_->items().begin());
246 iter != model_->items().end(); ++iter) { 290 iter != model_->items().end(); ++iter) {
247 ChromeLauncherControllerPerApp::IDToItemControllerMap::const_iterator 291 ChromeLauncherController::IDToItemControllerMap::const_iterator
248 entry(controller->id_to_item_controller_map_.find(iter->id)); 292 entry(controller->id_to_item_controller_map_.find(iter->id));
249 if (iter->type == ash::TYPE_APP_SHORTCUT && 293 if (iter->type == ash::TYPE_APP_SHORTCUT &&
250 entry != controller->id_to_item_controller_map_.end()) { 294 entry != controller->id_to_item_controller_map_.end()) {
251 launchers->push_back(entry->second->app_id()); 295 launchers->push_back(entry->second->app_id());
252 } 296 }
253 } 297 }
254 } 298 }
255 299
256 std::string GetPinnedAppStatus() { 300 std::string GetPinnedAppStatus() {
257 std::string result; 301 std::string result;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 334 }
291 } 335 }
292 return result; 336 return result;
293 } 337 }
294 338
295 // Needed for extension service & friends to work. 339 // Needed for extension service & friends to work.
296 scoped_refptr<Extension> extension1_; 340 scoped_refptr<Extension> extension1_;
297 scoped_refptr<Extension> extension2_; 341 scoped_refptr<Extension> extension2_;
298 scoped_refptr<Extension> extension3_; 342 scoped_refptr<Extension> extension3_;
299 scoped_refptr<Extension> extension4_; 343 scoped_refptr<Extension> extension4_;
300 scoped_ptr<ChromeLauncherControllerPerApp> launcher_controller_; 344 scoped_ptr<ChromeLauncherController> launcher_controller_;
301 scoped_ptr<TestLauncherModelObserver> model_observer_; 345 scoped_ptr<TestLauncherModelObserver> model_observer_;
302 scoped_ptr<ash::LauncherModel> model_; 346 scoped_ptr<ash::LauncherModel> model_;
303 347
304 ExtensionService* extension_service_; 348 ExtensionService* extension_service_;
305 349
306 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerAppTest); 350 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
307 }; 351 };
308 352
309 // The testing framework to test the alternate shelf layout. 353 // The testing framework to test the alternate shelf layout.
310 class AlternateLayoutChromeLauncherControllerPerAppTest 354 class AlternateLayoutChromeLauncherControllerTest
311 : public ChromeLauncherControllerPerAppTest { 355 : public ChromeLauncherControllerTest {
312 protected: 356 protected:
313 AlternateLayoutChromeLauncherControllerPerAppTest() { 357 AlternateLayoutChromeLauncherControllerTest() {
314 } 358 }
315 359
316 virtual ~AlternateLayoutChromeLauncherControllerPerAppTest() { 360 virtual ~AlternateLayoutChromeLauncherControllerTest() {
317 } 361 }
318 362
319 // Overwrite the Setup function to add the Alternate Shelf layout option. 363 // Overwrite the Setup function to add the Alternate Shelf layout option.
320 virtual void SetUp() OVERRIDE { 364 virtual void SetUp() OVERRIDE {
321 CommandLine::ForCurrentProcess()->AppendSwitch( 365 CommandLine::ForCurrentProcess()->AppendSwitch(
322 ash::switches::kAshUseAlternateShelfLayout); 366 ash::switches::kAshUseAlternateShelfLayout);
323 ChromeLauncherControllerPerAppTest::SetUp(); 367 ChromeLauncherControllerTest::SetUp();
324 } 368 }
325 369
326 // Set the index at which the chrome icon should be. 370 // Set the index at which the chrome icon should be.
327 void SetShelfChromeIconIndex(int index) { 371 void SetShelfChromeIconIndex(int index) {
328 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, 372 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
329 index + 1); 373 index + 1);
330 } 374 }
331 375
332 private: 376 private:
333 377
334 DISALLOW_COPY_AND_ASSIGN(AlternateLayoutChromeLauncherControllerPerAppTest); 378 DISALLOW_COPY_AND_ASSIGN(AlternateLayoutChromeLauncherControllerTest);
335 }; 379 };
336 380
337 381
338 TEST_F(ChromeLauncherControllerPerAppTest, DefaultApps) { 382 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
339 InitLauncherController(); 383 InitLauncherController();
340 // Model should only contain the browser shortcut and app list items. 384 // Model should only contain the browser shortcut and app list items.
341 EXPECT_EQ(2, model_->item_count()); 385 EXPECT_EQ(2, model_->item_count());
342 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 386 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
343 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 387 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
344 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 388 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
345 389
346 // Installing |extension3_| should add it to the launcher - behind the 390 // Installing |extension3_| should add it to the launcher - behind the
347 // chrome icon. 391 // chrome icon.
348 extension_service_->AddExtension(extension3_.get()); 392 extension_service_->AddExtension(extension3_.get());
349 EXPECT_EQ("Chrome, App3, AppList, ", GetPinnedAppStatus()); 393 EXPECT_EQ("Chrome, App3, AppList, ", GetPinnedAppStatus());
350 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 394 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
351 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 395 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
352 } 396 }
353 397
354 // Check that the restauration of launcher items is happening in the same order 398 // Check that the restauration of launcher items is happening in the same order
355 // as the user has pinned them (on another system) when they are synced reverse 399 // as the user has pinned them (on another system) when they are synced reverse
356 // order. 400 // order.
357 TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsReverseOrder) { 401 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
358 InitLauncherController(); 402 InitLauncherController();
359 403
360 base::ListValue policy_value; 404 base::ListValue policy_value;
361 InsertPrefValue(&policy_value, 0, extension1_->id()); 405 InsertPrefValue(&policy_value, 0, extension1_->id());
362 InsertPrefValue(&policy_value, 1, extension2_->id()); 406 InsertPrefValue(&policy_value, 1, extension2_->id());
363 InsertPrefValue(&policy_value, 2, extension3_->id()); 407 InsertPrefValue(&policy_value, 2, extension3_->id());
364 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 408 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
365 policy_value.DeepCopy()); 409 policy_value.DeepCopy());
366 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); 410 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
367 // Model should only contain the browser shortcut and app list items. 411 // Model should only contain the browser shortcut and app list items.
(...skipping 18 matching lines...) Expand all
386 430
387 // Installing |extension1_| should add it to the launcher - behind the 431 // Installing |extension1_| should add it to the launcher - behind the
388 // chrome icon, but in first location. 432 // chrome icon, but in first location.
389 extension_service_->AddExtension(extension1_.get()); 433 extension_service_->AddExtension(extension1_.get());
390 EXPECT_EQ("Chrome, App1, App2, App3, AppList, ", GetPinnedAppStatus()); 434 EXPECT_EQ("Chrome, App1, App2, App3, AppList, ", GetPinnedAppStatus());
391 } 435 }
392 436
393 // Check that the restauration of launcher items is happening in the same order 437 // Check that the restauration of launcher items is happening in the same order
394 // as the user has pinned them (on another system) when they are synced random 438 // as the user has pinned them (on another system) when they are synced random
395 // order. 439 // order.
396 TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsRandomOrder) { 440 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) {
397 InitLauncherController(); 441 InitLauncherController();
398 442
399 base::ListValue policy_value; 443 base::ListValue policy_value;
400 InsertPrefValue(&policy_value, 0, extension1_->id()); 444 InsertPrefValue(&policy_value, 0, extension1_->id());
401 InsertPrefValue(&policy_value, 1, extension2_->id()); 445 InsertPrefValue(&policy_value, 1, extension2_->id());
402 InsertPrefValue(&policy_value, 2, extension3_->id()); 446 InsertPrefValue(&policy_value, 2, extension3_->id());
403 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 447 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
404 policy_value.DeepCopy()); 448 policy_value.DeepCopy());
405 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); 449 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
406 // Model should only contain the browser shortcut and app list items. 450 // Model should only contain the browser shortcut and app list items.
(...skipping 17 matching lines...) Expand all
424 468
425 // Installing |extension3_| should add it to the launcher - behind the 469 // Installing |extension3_| should add it to the launcher - behind the
426 // chrome icon, but in first location. 470 // chrome icon, but in first location.
427 extension_service_->AddExtension(extension3_.get()); 471 extension_service_->AddExtension(extension3_.get());
428 EXPECT_EQ("Chrome, App1, App2, App3, AppList, ", GetPinnedAppStatus()); 472 EXPECT_EQ("Chrome, App1, App2, App3, AppList, ", GetPinnedAppStatus());
429 } 473 }
430 474
431 // Check that the restauration of launcher items is happening in the same order 475 // Check that the restauration of launcher items is happening in the same order
432 // as the user has pinned / moved them (on another system) when they are synced 476 // as the user has pinned / moved them (on another system) when they are synced
433 // random order - including the chrome icon. 477 // random order - including the chrome icon.
434 TEST_F(ChromeLauncherControllerPerAppTest, 478 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) {
435 RestoreDefaultAppsRandomOrderChromeMoved) {
436 InitLauncherController(); 479 InitLauncherController();
437 480
438 base::ListValue policy_value; 481 base::ListValue policy_value;
439 InsertPrefValue(&policy_value, 0, extension1_->id()); 482 InsertPrefValue(&policy_value, 0, extension1_->id());
440 InsertPrefValue(&policy_value, 1, extension2_->id()); 483 InsertPrefValue(&policy_value, 1, extension2_->id());
441 InsertPrefValue(&policy_value, 2, extension3_->id()); 484 InsertPrefValue(&policy_value, 2, extension3_->id());
442 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 485 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
443 policy_value.DeepCopy()); 486 policy_value.DeepCopy());
444 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, 487 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
445 1); 488 1);
(...skipping 17 matching lines...) Expand all
463 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 506 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
464 EXPECT_EQ("App1, Chrome, App2, AppList, ", GetPinnedAppStatus()); 507 EXPECT_EQ("App1, Chrome, App2, AppList, ", GetPinnedAppStatus());
465 508
466 // Installing |extension3_| should add it to the launcher - behind the 509 // Installing |extension3_| should add it to the launcher - behind the
467 // chrome icon, but in first location. 510 // chrome icon, but in first location.
468 extension_service_->AddExtension(extension3_.get()); 511 extension_service_->AddExtension(extension3_.get());
469 EXPECT_EQ("App1, Chrome, App2, App3, AppList, ", GetPinnedAppStatus()); 512 EXPECT_EQ("App1, Chrome, App2, App3, AppList, ", GetPinnedAppStatus());
470 } 513 }
471 514
472 // Check that syncing to a different state does the correct thing. 515 // Check that syncing to a different state does the correct thing.
473 TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsResyncOrder) { 516 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) {
474 InitLauncherController(); 517 InitLauncherController();
475 base::ListValue policy_value; 518 base::ListValue policy_value;
476 InsertPrefValue(&policy_value, 0, extension1_->id()); 519 InsertPrefValue(&policy_value, 0, extension1_->id());
477 InsertPrefValue(&policy_value, 1, extension2_->id()); 520 InsertPrefValue(&policy_value, 1, extension2_->id());
478 InsertPrefValue(&policy_value, 2, extension3_->id()); 521 InsertPrefValue(&policy_value, 2, extension3_->id());
479 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 522 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
480 policy_value.DeepCopy()); 523 policy_value.DeepCopy());
481 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); 524 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
482 extension_service_->AddExtension(extension2_.get()); 525 extension_service_->AddExtension(extension2_.get());
483 extension_service_->AddExtension(extension1_.get()); 526 extension_service_->AddExtension(extension1_.get());
(...skipping 14 matching lines...) Expand all
498 InsertPrefValue(&policy_value2, 0, extension2_->id()); 541 InsertPrefValue(&policy_value2, 0, extension2_->id());
499 InsertPrefValue(&policy_value2, 1, extension3_->id()); 542 InsertPrefValue(&policy_value2, 1, extension3_->id());
500 InsertPrefValue(&policy_value2, 2, extension1_->id()); 543 InsertPrefValue(&policy_value2, 2, extension1_->id());
501 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, 544 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
502 1); 545 1);
503 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 546 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
504 policy_value2.DeepCopy()); 547 policy_value2.DeepCopy());
505 EXPECT_EQ("App2, Chrome, App3, App1, AppList, ", GetPinnedAppStatus()); 548 EXPECT_EQ("App2, Chrome, App3, App1, AppList, ", GetPinnedAppStatus());
506 } 549 }
507 550
508 TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, DefaultApps) { 551 TEST_F(AlternateLayoutChromeLauncherControllerTest, DefaultApps) {
509 InitLauncherController(); 552 InitLauncherController();
510 // Model should only contain the browser shortcut and app list items. 553 // Model should only contain the browser shortcut and app list items.
511 EXPECT_EQ(2, model_->item_count()); 554 EXPECT_EQ(2, model_->item_count());
512 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 555 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
513 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 556 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
514 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 557 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
515 558
516 // Installing |extension3_| should add it to the launcher - behind the 559 // Installing |extension3_| should add it to the launcher - behind the
517 // chrome icon. 560 // chrome icon.
518 extension_service_->AddExtension(extension3_.get()); 561 extension_service_->AddExtension(extension3_.get());
519 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus()); 562 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus());
520 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 563 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
521 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 564 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
522 } 565 }
523 566
524 // Check that the restauration of launcher items is happening in the same order 567 // Check that the restauration of launcher items is happening in the same order
525 // as the user has pinned them (on another system) when they are synced reverse 568 // as the user has pinned them (on another system) when they are synced reverse
526 // order. 569 // order.
527 TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, 570 TEST_F(AlternateLayoutChromeLauncherControllerTest,
528 RestoreDefaultAppsReverseOrder) { 571 RestoreDefaultAppsReverseOrder) {
529 InitLauncherController(); 572 InitLauncherController();
530 573
531 base::ListValue policy_value; 574 base::ListValue policy_value;
532 InsertPrefValue(&policy_value, 0, extension1_->id()); 575 InsertPrefValue(&policy_value, 0, extension1_->id());
533 InsertPrefValue(&policy_value, 1, extension2_->id()); 576 InsertPrefValue(&policy_value, 1, extension2_->id());
534 InsertPrefValue(&policy_value, 2, extension3_->id()); 577 InsertPrefValue(&policy_value, 2, extension3_->id());
535 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 578 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
536 policy_value.DeepCopy()); 579 policy_value.DeepCopy());
537 SetShelfChromeIconIndex(0); 580 SetShelfChromeIconIndex(0);
(...skipping 19 matching lines...) Expand all
557 600
558 // Installing |extension1_| should add it to the launcher - behind the 601 // Installing |extension1_| should add it to the launcher - behind the
559 // chrome icon, but in first location. 602 // chrome icon, but in first location.
560 extension_service_->AddExtension(extension1_.get()); 603 extension_service_->AddExtension(extension1_.get());
561 EXPECT_EQ("AppList, Chrome, App1, App2, App3, ", GetPinnedAppStatus()); 604 EXPECT_EQ("AppList, Chrome, App1, App2, App3, ", GetPinnedAppStatus());
562 } 605 }
563 606
564 // Check that the restauration of launcher items is happening in the same order 607 // Check that the restauration of launcher items is happening in the same order
565 // as the user has pinned them (on another system) when they are synced random 608 // as the user has pinned them (on another system) when they are synced random
566 // order. 609 // order.
567 TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, 610 TEST_F(AlternateLayoutChromeLauncherControllerTest,
568 RestoreDefaultAppsRandomOrder) { 611 RestoreDefaultAppsRandomOrder) {
569 InitLauncherController(); 612 InitLauncherController();
570 613
571 base::ListValue policy_value; 614 base::ListValue policy_value;
572 InsertPrefValue(&policy_value, 0, extension1_->id()); 615 InsertPrefValue(&policy_value, 0, extension1_->id());
573 InsertPrefValue(&policy_value, 1, extension2_->id()); 616 InsertPrefValue(&policy_value, 1, extension2_->id());
574 InsertPrefValue(&policy_value, 2, extension3_->id()); 617 InsertPrefValue(&policy_value, 2, extension3_->id());
575 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 618 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
576 policy_value.DeepCopy()); 619 policy_value.DeepCopy());
577 SetShelfChromeIconIndex(0); 620 SetShelfChromeIconIndex(0);
(...skipping 18 matching lines...) Expand all
596 639
597 // Installing |extension3_| should add it to the launcher - behind the 640 // Installing |extension3_| should add it to the launcher - behind the
598 // chrome icon, but in first location. 641 // chrome icon, but in first location.
599 extension_service_->AddExtension(extension3_.get()); 642 extension_service_->AddExtension(extension3_.get());
600 EXPECT_EQ("AppList, Chrome, App1, App2, App3, ", GetPinnedAppStatus()); 643 EXPECT_EQ("AppList, Chrome, App1, App2, App3, ", GetPinnedAppStatus());
601 } 644 }
602 645
603 // Check that the restauration of launcher items is happening in the same order 646 // Check that the restauration of launcher items is happening in the same order
604 // as the user has pinned / moved them (on another system) when they are synced 647 // as the user has pinned / moved them (on another system) when they are synced
605 // random order - including the chrome icon - using the alternate shelf layout. 648 // random order - including the chrome icon - using the alternate shelf layout.
606 TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, 649 TEST_F(AlternateLayoutChromeLauncherControllerTest,
607 RestoreDefaultAppsRandomOrderChromeMoved) { 650 RestoreDefaultAppsRandomOrderChromeMoved) {
608 InitLauncherController(); 651 InitLauncherController();
609 652
610 base::ListValue policy_value; 653 base::ListValue policy_value;
611 InsertPrefValue(&policy_value, 0, extension1_->id()); 654 InsertPrefValue(&policy_value, 0, extension1_->id());
612 InsertPrefValue(&policy_value, 1, extension2_->id()); 655 InsertPrefValue(&policy_value, 1, extension2_->id());
613 InsertPrefValue(&policy_value, 2, extension3_->id()); 656 InsertPrefValue(&policy_value, 2, extension3_->id());
614 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 657 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
615 policy_value.DeepCopy()); 658 policy_value.DeepCopy());
616 SetShelfChromeIconIndex(1); 659 SetShelfChromeIconIndex(1);
(...skipping 18 matching lines...) Expand all
635 EXPECT_EQ("AppList, App1, Chrome, App2, ", GetPinnedAppStatus()); 678 EXPECT_EQ("AppList, App1, Chrome, App2, ", GetPinnedAppStatus());
636 679
637 // Installing |extension3_| should add it to the launcher - behind the 680 // Installing |extension3_| should add it to the launcher - behind the
638 // chrome icon, but in first location. 681 // chrome icon, but in first location.
639 extension_service_->AddExtension(extension3_.get()); 682 extension_service_->AddExtension(extension3_.get());
640 EXPECT_EQ("AppList, App1, Chrome, App2, App3, ", GetPinnedAppStatus()); 683 EXPECT_EQ("AppList, App1, Chrome, App2, App3, ", GetPinnedAppStatus());
641 } 684 }
642 685
643 // Check that syncing to a different state does the correct thing with the 686 // Check that syncing to a different state does the correct thing with the
644 // alternate shelf layout. 687 // alternate shelf layout.
645 TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, 688 TEST_F(AlternateLayoutChromeLauncherControllerTest,
646 RestoreDefaultAppsResyncOrder) { 689 RestoreDefaultAppsResyncOrder) {
647 InitLauncherController(); 690 InitLauncherController();
648 base::ListValue policy_value; 691 base::ListValue policy_value;
649 InsertPrefValue(&policy_value, 0, extension1_->id()); 692 InsertPrefValue(&policy_value, 0, extension1_->id());
650 InsertPrefValue(&policy_value, 1, extension2_->id()); 693 InsertPrefValue(&policy_value, 1, extension2_->id());
651 InsertPrefValue(&policy_value, 2, extension3_->id()); 694 InsertPrefValue(&policy_value, 2, extension3_->id());
652 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 695 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
653 policy_value.DeepCopy()); 696 policy_value.DeepCopy());
654 // The alternate shelf layout has always one static item at the beginning. 697 // The alternate shelf layout has always one static item at the beginning.
655 SetShelfChromeIconIndex(0); 698 SetShelfChromeIconIndex(0);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 extension_misc::UNLOAD_REASON_UNINSTALL); 740 extension_misc::UNLOAD_REASON_UNINSTALL);
698 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus()); 741 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus());
699 742
700 // Check that an update of an extension does not crash the system. 743 // Check that an update of an extension does not crash the system.
701 extension_service_->UnloadExtension(extension3_->id(), 744 extension_service_->UnloadExtension(extension3_->id(),
702 extension_misc::UNLOAD_REASON_UPDATE); 745 extension_misc::UNLOAD_REASON_UPDATE);
703 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus()); 746 EXPECT_EQ("AppList, Chrome, App3, ", GetPinnedAppStatus());
704 } 747 }
705 748
706 // Check that simple locking of an application will 'create' a launcher item. 749 // Check that simple locking of an application will 'create' a launcher item.
707 TEST_F(ChromeLauncherControllerPerAppTest, CheckLockApps) { 750 TEST_F(ChromeLauncherControllerTest, CheckLockApps) {
708 InitLauncherController(); 751 InitLauncherController();
709 // Model should only contain the browser shortcut and app list items. 752 // Model should only contain the browser shortcut and app list items.
710 EXPECT_EQ(2, model_->item_count()); 753 EXPECT_EQ(2, model_->item_count());
711 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 754 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
712 EXPECT_FALSE( 755 EXPECT_FALSE(
713 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 756 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
714 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 757 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
715 EXPECT_FALSE( 758 EXPECT_FALSE(
716 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); 759 launcher_controller_->IsWindowedAppInLauncher(extension2_->id()));
717 760
(...skipping 12 matching lines...) Expand all
730 EXPECT_EQ(2, model_->item_count()); 773 EXPECT_EQ(2, model_->item_count());
731 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 774 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
732 EXPECT_FALSE( 775 EXPECT_FALSE(
733 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 776 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
734 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 777 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
735 EXPECT_FALSE( 778 EXPECT_FALSE(
736 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); 779 launcher_controller_->IsWindowedAppInLauncher(extension2_->id()));
737 } 780 }
738 781
739 // Check that multiple locks of an application will be properly handled. 782 // Check that multiple locks of an application will be properly handled.
740 TEST_F(ChromeLauncherControllerPerAppTest, CheckMukltiLockApps) { 783 TEST_F(ChromeLauncherControllerTest, CheckMukltiLockApps) {
741 InitLauncherController(); 784 InitLauncherController();
742 // Model should only contain the browser shortcut and app list items. 785 // Model should only contain the browser shortcut and app list items.
743 EXPECT_EQ(2, model_->item_count()); 786 EXPECT_EQ(2, model_->item_count());
744 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 787 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
745 EXPECT_FALSE( 788 EXPECT_FALSE(
746 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 789 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
747 790
748 for (int i = 0; i < 2; i++) { 791 for (int i = 0; i < 2; i++) {
749 launcher_controller_->LockV1AppWithID(extension1_->id()); 792 launcher_controller_->LockV1AppWithID(extension1_->id());
750 793
(...skipping 16 matching lines...) Expand all
767 EXPECT_EQ(2, model_->item_count()); 810 EXPECT_EQ(2, model_->item_count());
768 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 811 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
769 EXPECT_FALSE( 812 EXPECT_FALSE(
770 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 813 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
771 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 814 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
772 EXPECT_FALSE( 815 EXPECT_FALSE(
773 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 816 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
774 } 817 }
775 818
776 // Check that already pinned items are not effected by locks. 819 // Check that already pinned items are not effected by locks.
777 TEST_F(ChromeLauncherControllerPerAppTest, CheckAlreadyPinnedLockApps) { 820 TEST_F(ChromeLauncherControllerTest, CheckAlreadyPinnedLockApps) {
778 InitLauncherController(); 821 InitLauncherController();
779 // Model should only contain the browser shortcut and app list items. 822 // Model should only contain the browser shortcut and app list items.
780 EXPECT_EQ(2, model_->item_count()); 823 EXPECT_EQ(2, model_->item_count());
781 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 824 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
782 EXPECT_FALSE( 825 EXPECT_FALSE(
783 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 826 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
784 827
785 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 828 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
786 launcher_controller_->PinAppWithID(extension1_->id()); 829 launcher_controller_->PinAppWithID(extension1_->id());
787 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 830 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 19 matching lines...) Expand all
807 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 850 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
808 EXPECT_FALSE( 851 EXPECT_FALSE(
809 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 852 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
810 853
811 launcher_controller_->UnpinAppsWithID(extension1_->id()); 854 launcher_controller_->UnpinAppsWithID(extension1_->id());
812 855
813 EXPECT_EQ(2, model_->item_count()); 856 EXPECT_EQ(2, model_->item_count());
814 } 857 }
815 858
816 // Check that already pinned items which get locked stay after unpinning. 859 // Check that already pinned items which get locked stay after unpinning.
817 TEST_F(ChromeLauncherControllerPerAppTest, CheckPinnedAppsStayAfterUnlock) { 860 TEST_F(ChromeLauncherControllerTest, CheckPinnedAppsStayAfterUnlock) {
818 InitLauncherController(); 861 InitLauncherController();
819 // Model should only contain the browser shortcut and app list items. 862 // Model should only contain the browser shortcut and app list items.
820 EXPECT_EQ(2, model_->item_count()); 863 EXPECT_EQ(2, model_->item_count());
821 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 864 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
822 EXPECT_FALSE( 865 EXPECT_FALSE(
823 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 866 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
824 867
825 launcher_controller_->PinAppWithID(extension1_->id()); 868 launcher_controller_->PinAppWithID(extension1_->id());
826 869
827 EXPECT_EQ(3, model_->item_count()); 870 EXPECT_EQ(3, model_->item_count());
(...skipping 16 matching lines...) Expand all
844 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[1].type); 887 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[1].type);
845 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 888 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
846 EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 889 EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
847 890
848 launcher_controller_->UnlockV1AppWithID(extension1_->id()); 891 launcher_controller_->UnlockV1AppWithID(extension1_->id());
849 892
850 EXPECT_EQ(2, model_->item_count()); 893 EXPECT_EQ(2, model_->item_count());
851 } 894 }
852 895
853 // Check that lock -> pin -> unlock -> unpin does properly transition. 896 // Check that lock -> pin -> unlock -> unpin does properly transition.
854 TEST_F(ChromeLauncherControllerPerAppTest, CheckLockPinUnlockUnpin) { 897 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) {
855 InitLauncherController(); 898 InitLauncherController();
856 // Model should only contain the browser shortcut and app list items. 899 // Model should only contain the browser shortcut and app list items.
857 EXPECT_EQ(2, model_->item_count()); 900 EXPECT_EQ(2, model_->item_count());
858 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 901 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
859 EXPECT_FALSE( 902 EXPECT_FALSE(
860 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 903 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
861 904
862 launcher_controller_->LockV1AppWithID(extension1_->id()); 905 launcher_controller_->LockV1AppWithID(extension1_->id());
863 906
864 EXPECT_EQ(3, model_->item_count()); 907 EXPECT_EQ(3, model_->item_count());
(...skipping 15 matching lines...) Expand all
880 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 923 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
881 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 924 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
882 EXPECT_FALSE( 925 EXPECT_FALSE(
883 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 926 launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
884 927
885 launcher_controller_->UnpinAppsWithID(extension1_->id()); 928 launcher_controller_->UnpinAppsWithID(extension1_->id());
886 929
887 EXPECT_EQ(2, model_->item_count()); 930 EXPECT_EQ(2, model_->item_count());
888 } 931 }
889 932
890 TEST_F(ChromeLauncherControllerPerAppTest, Policy) { 933 TEST_F(ChromeLauncherControllerTest, Policy) {
891 extension_service_->AddExtension(extension1_.get()); 934 extension_service_->AddExtension(extension1_.get());
892 extension_service_->AddExtension(extension3_.get()); 935 extension_service_->AddExtension(extension3_.get());
893 936
894 base::ListValue policy_value; 937 base::ListValue policy_value;
895 InsertPrefValue(&policy_value, 0, extension1_->id()); 938 InsertPrefValue(&policy_value, 0, extension1_->id());
896 InsertPrefValue(&policy_value, 1, extension2_->id()); 939 InsertPrefValue(&policy_value, 1, extension2_->id());
897 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 940 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
898 policy_value.DeepCopy()); 941 policy_value.DeepCopy());
899 942
900 // Only |extension1_| should get pinned. |extension2_| is specified but not 943 // Only |extension1_| should get pinned. |extension2_| is specified but not
(...skipping 19 matching lines...) Expand all
920 policy_value.Remove(0, NULL); 963 policy_value.Remove(0, NULL);
921 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 964 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
922 policy_value.DeepCopy()); 965 policy_value.DeepCopy());
923 EXPECT_EQ(3, model_->item_count()); 966 EXPECT_EQ(3, model_->item_count());
924 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 967 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
925 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 968 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
926 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 969 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
927 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 970 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
928 } 971 }
929 972
930 TEST_F(ChromeLauncherControllerPerAppTest, UnpinWithUninstall) { 973 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
931 extension_service_->AddExtension(extension3_.get()); 974 extension_service_->AddExtension(extension3_.get());
932 extension_service_->AddExtension(extension4_.get()); 975 extension_service_->AddExtension(extension4_.get());
933 976
934 InitLauncherController(); 977 InitLauncherController();
935 978
936 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 979 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
937 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 980 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
938 981
939 extension_service_->UnloadExtension(extension3_->id(), 982 extension_service_->UnloadExtension(extension3_->id(),
940 extension_misc::UNLOAD_REASON_UNINSTALL); 983 extension_misc::UNLOAD_REASON_UNINSTALL);
941 984
942 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 985 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
943 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 986 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
944 } 987 }
945 988
946 TEST_F(ChromeLauncherControllerPerAppTest, PrefUpdates) { 989 TEST_F(ChromeLauncherControllerTest, PrefUpdates) {
947 extension_service_->AddExtension(extension2_.get()); 990 extension_service_->AddExtension(extension2_.get());
948 extension_service_->AddExtension(extension3_.get()); 991 extension_service_->AddExtension(extension3_.get());
949 extension_service_->AddExtension(extension4_.get()); 992 extension_service_->AddExtension(extension4_.get());
950 993
951 InitLauncherController(); 994 InitLauncherController();
952 995
953 std::vector<std::string> expected_launchers; 996 std::vector<std::string> expected_launchers;
954 std::vector<std::string> actual_launchers; 997 std::vector<std::string> actual_launchers;
955 base::ListValue pref_value; 998 base::ListValue pref_value;
956 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 999 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 1035
993 // Clearing works. 1036 // Clearing works.
994 pref_value.Clear(); 1037 pref_value.Clear();
995 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1038 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
996 pref_value.DeepCopy()); 1039 pref_value.DeepCopy());
997 expected_launchers.clear(); 1040 expected_launchers.clear();
998 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 1041 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
999 EXPECT_EQ(expected_launchers, actual_launchers); 1042 EXPECT_EQ(expected_launchers, actual_launchers);
1000 } 1043 }
1001 1044
1002 TEST_F(ChromeLauncherControllerPerAppTest, PendingInsertionOrder) { 1045 TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) {
1003 extension_service_->AddExtension(extension1_.get()); 1046 extension_service_->AddExtension(extension1_.get());
1004 extension_service_->AddExtension(extension3_.get()); 1047 extension_service_->AddExtension(extension3_.get());
1005 1048
1006 InitLauncherController(); 1049 InitLauncherController();
1007 1050
1008 base::ListValue pref_value; 1051 base::ListValue pref_value;
1009 InsertPrefValue(&pref_value, 0, extension1_->id()); 1052 InsertPrefValue(&pref_value, 0, extension1_->id());
1010 InsertPrefValue(&pref_value, 1, extension2_->id()); 1053 InsertPrefValue(&pref_value, 1, extension2_->id());
1011 InsertPrefValue(&pref_value, 2, extension3_->id()); 1054 InsertPrefValue(&pref_value, 2, extension3_->id());
1012 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1055 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
(...skipping 12 matching lines...) Expand all
1025 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); 1068 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id());
1026 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 1069 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
1027 EXPECT_EQ(expected_launchers, actual_launchers); 1070 EXPECT_EQ(expected_launchers, actual_launchers);
1028 } 1071 }
1029 1072
1030 // Checks the created menus and menu lists for correctness. It uses the given 1073 // Checks the created menus and menu lists for correctness. It uses the given
1031 // |controller| to create the objects for the given |item| and checks the 1074 // |controller| to create the objects for the given |item| and checks the
1032 // found item count against the |expected_items|. The |title| list contains the 1075 // found item count against the |expected_items|. The |title| list contains the
1033 // menu titles in the order of their appearance in the menu (not including the 1076 // menu titles in the order of their appearance in the menu (not including the
1034 // application name). 1077 // application name).
1035 bool CheckMenuCreation(ChromeLauncherControllerPerApp* controller, 1078 bool CheckMenuCreation(ChromeLauncherController* controller,
1036 const ash::LauncherItem& item, 1079 const ash::LauncherItem& item,
1037 size_t expected_items, 1080 size_t expected_items,
1038 string16 title[], 1081 string16 title[],
1039 bool is_browser) { 1082 bool is_browser) {
1040 ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0); 1083 ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0);
1041 // A new behavior has been added: Only show menus if there is at least one 1084 // A new behavior has been added: Only show menus if there is at least one
1042 // item available. 1085 // item available.
1043 if (expected_items < 1 && is_browser) { 1086 if (expected_items < 1 && is_browser) {
1044 EXPECT_EQ(0u, items.size()); 1087 EXPECT_EQ(0u, items.size());
1045 return items.size() == 0; 1088 return items.size() == 0;
(...skipping 21 matching lines...) Expand all
1067 EXPECT_EQ(expected_menu_items, menu->GetItemCount()); 1110 EXPECT_EQ(expected_menu_items, menu->GetItemCount());
1068 EXPECT_FALSE(menu->IsEnabledAt(first_item)); 1111 EXPECT_FALSE(menu->IsEnabledAt(first_item));
1069 if (expected_items) { 1112 if (expected_items) {
1070 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, 1113 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR,
1071 menu->GetTypeAt(first_item + 1)); 1114 menu->GetTypeAt(first_item + 1));
1072 } 1115 }
1073 return items.size() == expected_items + 1; 1116 return items.size() == expected_items + 1;
1074 } 1117 }
1075 1118
1076 // Check that browsers get reflected correctly in the launcher menu. 1119 // Check that browsers get reflected correctly in the launcher menu.
1077 TEST_F(ChromeLauncherControllerPerAppTest, BrowserMenuGeneration) { 1120 TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) {
1078 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 1121 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
1079 chrome::NewTab(browser()); 1122 chrome::NewTab(browser());
1080 1123
1081 InitLauncherController(); 1124 InitLauncherController();
1082 1125
1083 // Check that the browser list is empty at this time. 1126 // Check that the browser list is empty at this time.
1084 ash::LauncherItem item_browser; 1127 ash::LauncherItem item_browser;
1085 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 1128 item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
1086 item_browser.id = 1129 item_browser.id =
1087 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId); 1130 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId);
(...skipping 27 matching lines...) Expand all
1115 launcher_controller_.get(), item_browser, 2, two_menu_items, true)); 1158 launcher_controller_.get(), item_browser, 2, two_menu_items, true));
1116 1159
1117 // Apparently we have to close all tabs we have. 1160 // Apparently we have to close all tabs we have.
1118 chrome::CloseTab(browser2.get()); 1161 chrome::CloseTab(browser2.get());
1119 } 1162 }
1120 1163
1121 // Check that V1 apps are correctly reflected in the launcher menu using the 1164 // Check that V1 apps are correctly reflected in the launcher menu using the
1122 // refocus logic. 1165 // refocus logic.
1123 // Note that the extension matching logic is tested by the extension system 1166 // Note that the extension matching logic is tested by the extension system
1124 // and does not need a separate test here. 1167 // and does not need a separate test here.
1125 TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuGeneration) { 1168 TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) {
1126 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 1169 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
1127 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 1170 EXPECT_EQ(0, browser()->tab_strip_model()->count());
1128 1171
1129 InitLauncherControllerWithBrowser(); 1172 InitLauncherControllerWithBrowser();
1130 1173
1131 // Model should only contain the browser shortcut and app list items. 1174 // Model should only contain the browser shortcut and app list items.
1132 EXPECT_EQ(2, model_->item_count()); 1175 EXPECT_EQ(2, model_->item_count());
1133 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1176 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1134 1177
1135 // Installing |extension3_| adds it to the launcher. 1178 // Installing |extension3_| adds it to the launcher.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 launcher_controller_->Close(item_gmail.id); 1231 launcher_controller_->Close(item_gmail.id);
1189 1232
1190 EXPECT_TRUE(CheckMenuCreation( 1233 EXPECT_TRUE(CheckMenuCreation(
1191 launcher_controller_.get(), item_gmail, 0, NULL, false)); 1234 launcher_controller_.get(), item_gmail, 0, NULL, false));
1192 string16 browser_menu_item2[] = {title2}; 1235 string16 browser_menu_item2[] = {title2};
1193 EXPECT_TRUE(CheckMenuCreation( 1236 EXPECT_TRUE(CheckMenuCreation(
1194 launcher_controller_.get(), item_browser, 1, browser_menu_item2, false)); 1237 launcher_controller_.get(), item_browser, 1, browser_menu_item2, false));
1195 } 1238 }
1196 1239
1197 // Checks that the generated menu list properly activates items. 1240 // Checks that the generated menu list properly activates items.
1198 TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuExecution) { 1241 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) {
1199 InitLauncherControllerWithBrowser(); 1242 InitLauncherControllerWithBrowser();
1200 1243
1201 // Add |extension3_| to the launcher and add two items. 1244 // Add |extension3_| to the launcher and add two items.
1202 GURL gmail = GURL("https://mail.google.com/mail/u"); 1245 GURL gmail = GURL("https://mail.google.com/mail/u");
1203 ash::LauncherID gmail_id = model_->next_id(); 1246 ash::LauncherID gmail_id = model_->next_id();
1204 extension_service_->AddExtension(extension3_.get()); 1247 extension_service_->AddExtension(extension3_.get());
1205 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 1248 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
1206 string16 title1 = ASCIIToUTF16("Test1"); 1249 string16 title1 = ASCIIToUTF16("Test1");
1207 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 1250 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
1208 chrome::NewTab(browser()); 1251 chrome::NewTab(browser());
(...skipping 28 matching lines...) Expand all
1237 launcher_controller_->CreateApplicationMenu(item_gmail, 0)); 1280 launcher_controller_->CreateApplicationMenu(item_gmail, 0));
1238 int first_item = 1281 int first_item =
1239 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; 1282 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0;
1240 menu->ActivatedAt(first_item + 2); 1283 menu->ActivatedAt(first_item + 2);
1241 } 1284 }
1242 // Now the active tab should be the second item. 1285 // Now the active tab should be the second item.
1243 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 1286 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1244 } 1287 }
1245 1288
1246 // Checks that the generated menu list properly deletes items. 1289 // Checks that the generated menu list properly deletes items.
1247 TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuDeletionExecution) { 1290 TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) {
1248 InitLauncherControllerWithBrowser(); 1291 InitLauncherControllerWithBrowser();
1249 1292
1250 // Add |extension3_| to the launcher and add two items. 1293 // Add |extension3_| to the launcher and add two items.
1251 GURL gmail = GURL("https://mail.google.com/mail/u"); 1294 GURL gmail = GURL("https://mail.google.com/mail/u");
1252 ash::LauncherID gmail_id = model_->next_id(); 1295 ash::LauncherID gmail_id = model_->next_id();
1253 extension_service_->AddExtension(extension3_.get()); 1296 extension_service_->AddExtension(extension3_.get());
1254 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 1297 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
1255 string16 title1 = ASCIIToUTF16("Test1"); 1298 string16 title1 = ASCIIToUTF16("Test1");
1256 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 1299 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
1257 chrome::NewTab(browser()); 1300 chrome::NewTab(browser());
(...skipping 20 matching lines...) Expand all
1278 // Delete one tab through the menu item. 1321 // Delete one tab through the menu item.
1279 { 1322 {
1280 ChromeLauncherAppMenuItems items = 1323 ChromeLauncherAppMenuItems items =
1281 launcher_controller_->GetApplicationList(item_gmail, 0); 1324 launcher_controller_->GetApplicationList(item_gmail, 0);
1282 items[1]->Execute(ui::EF_SHIFT_DOWN); 1325 items[1]->Execute(ui::EF_SHIFT_DOWN);
1283 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); 1326 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count());
1284 } 1327 }
1285 } 1328 }
1286 1329
1287 // Tests that panels create launcher items correctly 1330 // Tests that panels create launcher items correctly
1288 TEST_F(ChromeLauncherControllerPerAppTest, AppPanels) { 1331 TEST_F(ChromeLauncherControllerTest, AppPanels) {
1289 InitLauncherControllerWithBrowser(); 1332 InitLauncherControllerWithBrowser();
1333 // Browser shortcut LauncherItem is added.
1290 EXPECT_EQ(1, model_observer_->added()); 1334 EXPECT_EQ(1, model_observer_->added());
1291 1335
1292 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); 1336 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl();
1293 SetAppIconLoader(app_icon_loader); 1337 SetAppIconLoader(app_icon_loader);
1294 1338
1295 // Test adding an app panel 1339 // Test adding an app panel
1296 std::string app_id = extension1_->id(); 1340 std::string app_id = extension1_->id();
1297 ShellWindowLauncherItemController app_panel_controller( 1341 ShellWindowLauncherItemController app_panel_controller(
1298 LauncherItemController::TYPE_APP_PANEL, "id", app_id, 1342 LauncherItemController::TYPE_APP_PANEL, "id", app_id,
1299 launcher_controller_.get()); 1343 launcher_controller_.get());
(...skipping 23 matching lines...) Expand all
1323 EXPECT_EQ(1, model_observer_->added()); 1367 EXPECT_EQ(1, model_observer_->added());
1324 model_observer_->clear_counts(); 1368 model_observer_->clear_counts();
1325 1369
1326 launcher_controller_->CloseLauncherItem(launcher_id2); 1370 launcher_controller_->CloseLauncherItem(launcher_id2);
1327 launcher_controller_->CloseLauncherItem(launcher_id1); 1371 launcher_controller_->CloseLauncherItem(launcher_id1);
1328 EXPECT_EQ(2, model_observer_->removed()); 1372 EXPECT_EQ(2, model_observer_->removed());
1329 } 1373 }
1330 1374
1331 // Tests that the Gmail extension matches more then the app itself claims with 1375 // Tests that the Gmail extension matches more then the app itself claims with
1332 // the manifest file. 1376 // the manifest file.
1333 TEST_F(ChromeLauncherControllerPerAppTest, GmailMatching) { 1377 TEST_F(ChromeLauncherControllerTest, GmailMatching) {
1334 InitLauncherControllerWithBrowser(); 1378 InitLauncherControllerWithBrowser();
1335 1379
1336 // Create a Gmail browser tab. 1380 // Create a Gmail browser tab.
1337 chrome::NewTab(browser()); 1381 chrome::NewTab(browser());
1338 string16 title = ASCIIToUTF16("Test"); 1382 string16 title = ASCIIToUTF16("Test");
1339 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title); 1383 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title);
1340 content::WebContents* content = 1384 content::WebContents* content =
1341 browser()->tab_strip_model()->GetActiveWebContents(); 1385 browser()->tab_strip_model()->GetActiveWebContents();
1342 1386
1343 // Check that the launcher controller does not recognize the running app. 1387 // Check that the launcher controller does not recognize the running app.
(...skipping 11 matching lines...) Expand all
1355 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 1399 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
1356 1400
1357 // Check also that the app has detected that properly. 1401 // Check also that the app has detected that properly.
1358 ash::LauncherItem item_gmail; 1402 ash::LauncherItem item_gmail;
1359 item_gmail.type = ash::TYPE_APP_SHORTCUT; 1403 item_gmail.type = ash::TYPE_APP_SHORTCUT;
1360 item_gmail.id = gmail_id; 1404 item_gmail.id = gmail_id;
1361 EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size()); 1405 EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size());
1362 } 1406 }
1363 1407
1364 // Tests that the Gmail extension does not match the offline verison. 1408 // Tests that the Gmail extension does not match the offline verison.
1365 TEST_F(ChromeLauncherControllerPerAppTest, GmailOfflineMatching) { 1409 TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) {
1366 InitLauncherControllerWithBrowser(); 1410 InitLauncherControllerWithBrowser();
1367 1411
1368 // Create a Gmail browser tab. 1412 // Create a Gmail browser tab.
1369 chrome::NewTab(browser()); 1413 chrome::NewTab(browser());
1370 string16 title = ASCIIToUTF16("Test"); 1414 string16 title = ASCIIToUTF16("Test");
1371 NavigateAndCommitActiveTabWithTitle(browser(), 1415 NavigateAndCommitActiveTabWithTitle(browser(),
1372 GURL(offline_gmail_url), 1416 GURL(offline_gmail_url),
1373 title); 1417 title);
1374 content::WebContents* content = 1418 content::WebContents* content =
1375 browser()->tab_strip_model()->GetActiveWebContents(); 1419 browser()->tab_strip_model()->GetActiveWebContents();
1376 1420
1377 // Installing |extension3_| adds it to the launcher. 1421 // Installing |extension3_| adds it to the launcher.
1378 ash::LauncherID gmail_id = model_->next_id(); 1422 ash::LauncherID gmail_id = model_->next_id();
1379 extension_service_->AddExtension(extension3_.get()); 1423 extension_service_->AddExtension(extension3_.get());
1380 EXPECT_EQ(3, model_->item_count()); 1424 EXPECT_EQ(3, model_->item_count());
1381 int gmail_index = model_->ItemIndexByID(gmail_id); 1425 int gmail_index = model_->ItemIndexByID(gmail_id);
1382 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 1426 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
1383 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1427 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1384 1428
1385 // The content should not be able to be handled by the app. 1429 // The content should not be able to be handled by the app.
1386 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 1430 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
1387 } 1431 }
1432
1433 // Verify that the launcher item positions are persisted and restored.
1434 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) {
1435 InitLauncherController();
1436
1437 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
1438 SetAppTabHelper(app_tab_helper);
1439
1440 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[0].type);
1441 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[1].type);
1442
1443 TabStripModel* tab_strip_model = browser()->tab_strip_model();
1444 EXPECT_EQ(0, tab_strip_model->count());
1445 chrome::NewTab(browser());
1446 chrome::NewTab(browser());
1447 EXPECT_EQ(2, tab_strip_model->count());
1448 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
1449 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
1450
1451 EXPECT_FALSE(launcher_controller_->IsAppPinned("1"));
1452 launcher_controller_->PinAppWithID("1");
1453 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
1454 launcher_controller_->PinAppWithID("2");
1455
1456 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[0].type);
1457 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
1458 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
1459 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type);
1460
1461 // Move browser shortcut item from index 0 to index 2.
1462 model_->Move(0, 2);
1463 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[0].type);
1464 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
1465 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
1466 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type);
1467
1468 launcher_controller_.reset();
1469 model_.reset(new ash::LauncherModel);
1470 launcher_controller_.reset(
1471 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1472 app_tab_helper = new TestAppTabHelperImpl;
1473 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
1474 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
1475 SetAppTabHelper(app_tab_helper);
1476
1477 launcher_controller_->Init();
1478
1479 // Check LauncherItems are restored after resetting ChromeLauncherController.
1480 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[0].type);
1481 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
1482 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
1483 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type);
1484 }
1485
1486 // Verifies pinned apps are persisted and restored.
1487 TEST_F(ChromeLauncherControllerTest, PersistPinned) {
1488 InitLauncherControllerWithBrowser();
1489 size_t initial_size = model_->items().size();
1490
1491 TabStripModel* tab_strip_model = browser()->tab_strip_model();
1492 EXPECT_EQ(1, tab_strip_model->count());
1493
1494 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
1495 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
1496 SetAppTabHelper(app_tab_helper);
1497
1498 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl;
1499 SetAppIconLoader(app_icon_loader);
1500 EXPECT_EQ(0, app_icon_loader->fetch_count());
1501
1502 launcher_controller_->PinAppWithID("1");
1503 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1");
1504 int app_index = model_->ItemIndexByID(id);
1505 EXPECT_EQ(1, app_icon_loader->fetch_count());
1506 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
1507 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
1508 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
1509 EXPECT_EQ(initial_size + 1, model_->items().size());
1510
1511 launcher_controller_.reset();
1512 model_.reset(new ash::LauncherModel);
1513 launcher_controller_.reset(
1514 ChromeLauncherController::CreateInstance(profile(), model_.get()));
1515 app_tab_helper = new TestAppTabHelperImpl;
1516 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
1517 SetAppTabHelper(app_tab_helper);
1518 app_icon_loader = new TestAppIconLoaderImpl;
1519 SetAppIconLoader(app_icon_loader);
1520 launcher_controller_->Init();
1521
1522 EXPECT_EQ(1, app_icon_loader->fetch_count());
1523 ASSERT_EQ(initial_size + 1, model_->items().size());
1524 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
1525 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
1526 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
1527
1528 launcher_controller_->UnpinAppsWithID("1");
1529 ASSERT_EQ(initial_size, model_->items().size());
1530 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698