13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <algorithm> 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/ash_switches.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_item_delegate_manager.h" 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h" 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model_observer.h" 1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/shell.h" 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/test/shelf_item_delegate_manager_test_api.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 219ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/extension_service.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/test_extension_system.h" 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" 284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_list.h" 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/browser_tabstrip.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/common/extensions/extension_constants.h" 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/browser_with_test_window_test.h" 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/testing_pref_service_syncable.h" 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/testing_profile.h" 423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/browser/web_contents.h" 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h" 443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "extensions/common/manifest_constants.h" 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/aura/client/window_tree_client.h" 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/models/menu_model.h" 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS) 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/test/test_session_state_delegate.h" 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/test/test_shell_delegate.h" 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/apps/scoped_keep_alive.h" 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/chromeos/login/users/fake_user_manager.h" 546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/apps/chrome_app_delegate.h" 56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/test/base/testing_browser_process.h" 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/test/base/testing_profile_manager.h" 65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h" 66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/test/test_utils.h" 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window_contents.h" 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/app_window/app_window_registry.h" 6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "extensions/browser/app_window/native_app_window.h" 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/window.h" 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using extensions::Extension; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using extensions::Manifest; 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)using extensions::UnloadedExtensionInfo; 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char* gmail_url = "https://mail.google.com/mail/u"; 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char* kGmailLaunchURL = "https://mail.google.com/mail/ca"; 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// An extension prefix. 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char kCrxAppPrefix[] = "_crx_"; 86cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// ShelfModelObserver implementation that tracks what messages are invoked. 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class TestShelfModelObserver : public ash::ShelfModelObserver { 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 91f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestShelfModelObserver() 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : added_(0), 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) removed_(0), 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) changed_(0) { 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 97f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual ~TestShelfModelObserver() { 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Overridden from ash::ShelfModelObserver: 101f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void ShelfItemAdded(int index) OVERRIDE { 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++added_; 103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch last_index_ = index; 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void ShelfItemRemoved(int index, ash::ShelfID id) OVERRIDE { 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++removed_; 108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch last_index_ = index; 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void ShelfItemChanged(int index, 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ash::ShelfItem& old_item) OVERRIDE { 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++changed_; 114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch last_index_ = index; 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 117f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE { 118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch last_index_ = target_index; 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void ShelfStatusChanged() OVERRIDE { 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void clear_counts() { 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) added_ = 0; 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) removed_ = 0; 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) changed_ = 0; 128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch last_index_ = 0; 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int added() const { return added_; } 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int removed() const { return removed_; } 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int changed() const { return changed_; } 134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int last_index() const { return last_index_; } 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int added_; 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int removed_; 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int changed_; 140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int last_index_; 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Test implementation of AppIconLoader. 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestAppIconLoaderImpl : public extensions::AppIconLoader { 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestAppIconLoaderImpl() : fetch_count_(0) { 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TestAppIconLoaderImpl() { 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // AppIconLoader implementation: 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void FetchImage(const std::string& id) OVERRIDE { 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++fetch_count_; 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ClearImage(const std::string& id) OVERRIDE { 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void UpdateImage(const std::string& id) OVERRIDE { 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int fetch_count() const { return fetch_count_; } 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int fetch_count_; 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Test implementation of AppTabHelper. 1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { 1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TestAppTabHelperImpl() {} 1773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual ~TestAppTabHelperImpl() {} 1783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Sets the id for the specified tab. The id is removed if Remove() is 1803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // invoked. 1813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetAppID(content::WebContents* tab, const std::string& id) { 1823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) tab_id_map_[tab] = id; 1833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Returns true if there is an id registered for |tab|. 1863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool HasAppID(content::WebContents* tab) const { 1873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return tab_id_map_.find(tab) != tab_id_map_.end(); 1883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // AppTabHelper implementation: 1913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual std::string GetAppID(content::WebContents* tab) OVERRIDE { 1923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : 1933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::string(); 1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 1953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual bool IsValidIDForCurrentUser(const std::string& id) OVERRIDE { 1973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) for (TabToStringMap::const_iterator i = tab_id_map_.begin(); 1983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) i != tab_id_map_.end(); ++i) { 1993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (i->second == id) 2003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return true; 2013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return false; 2033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void SetCurrentUser(Profile* profile) OVERRIDE { 2064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // We can ignore this for now. 2074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 2084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private: 2103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) typedef std::map<content::WebContents*, std::string> TabToStringMap; 2113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TabToStringMap tab_id_map_; 2133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); 2153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 21768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Test implementation of a V2 app launcher item controller. 21868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class TestV2AppLauncherItemController : public LauncherItemController { 21968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public: 22068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) TestV2AppLauncherItemController(const std::string& app_id, 22168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ChromeLauncherController* controller) 22268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) : LauncherItemController(LauncherItemController::TYPE_APP, 22368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) app_id, 22468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) controller) { 22568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 22668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 22768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual ~TestV2AppLauncherItemController() {} 22868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 22968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Override for LauncherItemController: 23068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual bool IsOpen() const OVERRIDE { return true; } 23168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual bool IsVisible() const OVERRIDE { return true; } 23268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {} 233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual bool Activate(ash::LaunchSource source) OVERRIDE { return false; } 23468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual void Close() OVERRIDE {} 235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual bool ItemSelected(const ui::Event& event) OVERRIDE { return false; } 236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual base::string16 GetTitle() OVERRIDE { return base::string16(); } 23768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual ChromeLauncherAppMenuItems GetApplicationList( 23868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int event_flags) OVERRIDE { 23968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ChromeLauncherAppMenuItems items; 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) items.push_back( 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) items.push_back( 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new ChromeLauncherAppMenuItem(base::string16(), NULL, false)); 24468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return items.Pass(); 24568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) OVERRIDE { 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return NULL; 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 249a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE { 250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return NULL; 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 2524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual bool IsDraggable() OVERRIDE { return false; } 2534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual bool ShouldShowTooltip() OVERRIDE { return false; } 25468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 25568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) private: 25668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 25768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}; 25868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ChromeLauncherControllerTest() 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : BrowserWithTestWindowTest( 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::TYPE_TABBED, 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_ASH, 2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false), 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) test_controller_(NULL), 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extension_service_(NULL) { 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual ~ChromeLauncherControllerTest() { 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUp() OVERRIDE { 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWithTestWindowTest::SetUp(); 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 278f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) model_.reset(new ash::ShelfModel); 279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) model_observer_.reset(new TestShelfModelObserver); 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) model_->AddObserver(model_observer_.get()); 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (ash::Shell::HasInstance()) { 2834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) item_delegate_manager_ = 284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::Shell::GetInstance()->shelf_item_delegate_manager(); 2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } else { 2864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) item_delegate_manager_ = 287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) new ash::ShelfItemDelegateManager(model_.get()); 2884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 2894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::DictionaryValue manifest; 2913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest.SetString(extensions::manifest_keys::kName, 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "launcher controller test extension"); 2933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest.SetString(extensions::manifest_keys::kVersion, "1"); 2943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest.SetString(extensions::manifest_keys::kDescription, 295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "for testing pinned apps"); 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions::TestExtensionSystem* extension_system( 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<extensions::TestExtensionSystem*>( 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extensions::ExtensionSystem::Get(profile()))); 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_ = extension_system->CreateExtensionService( 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandLine::ForCurrentProcess(), base::FilePath(), false); 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string error; 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) manifest, 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Extension::NO_FLAGS, 3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) manifest, 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Extension::NO_FLAGS, 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Fake gmail extension. 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::DictionaryValue manifest_gmail; 3163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest_gmail.SetString(extensions::manifest_keys::kName, 317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Gmail launcher controller test extension"); 3183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest_gmail.SetString(extensions::manifest_keys::kVersion, "1"); 3193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest_gmail.SetString(extensions::manifest_keys::kDescription, 320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "for testing pinned Gmail"); 3213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest_gmail.SetString(extensions::manifest_keys::kLaunchWebURL, 322f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) kGmailLaunchURL); 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::ListValue* list = new base::ListValue(); 3245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) list->Append(new base::StringValue("*://mail.google.com/mail/ca")); 3253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) manifest_gmail.Set(extensions::manifest_keys::kWebURLs, list); 326c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension3_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) manifest_gmail, 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Extension::NO_FLAGS, 330c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension_misc::kGmailAppId, 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Fake search extension. 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) manifest, 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Extension::NO_FLAGS, 337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension_misc::kGoogleSearchAppId, 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &error); 33968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension5_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 34068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) manifest, 34168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Extension::NO_FLAGS, 34268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "cccccccccccccccccccccccccccccccc", 34368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) &error); 34468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension6_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 34568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) manifest, 34668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Extension::NO_FLAGS, 34768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "dddddddddddddddddddddddddddddddd", 34868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) &error); 34968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension7_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 35068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) manifest, 35168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Extension::NO_FLAGS, 35268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 35368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) &error); 35468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 35568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) manifest, 35668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Extension::NO_FLAGS, 35768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "ffffffffffffffffffffffffffffffff", 35868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) &error); 35968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 36068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 36168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Creates a running V2 app (not pinned) of type |app_id|. 36268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual void CreateRunningV2App(const std::string& app_id) { 3634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DCHECK(!test_controller_); 3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID id = 36568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->CreateAppShortcutLauncherItemWithType( 36668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) app_id, 36768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) model_->item_count(), 36868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ash::TYPE_PLATFORM_APP); 36968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DCHECK(id); 37068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Change the created launcher controller into a V2 app controller. 3714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) test_controller_ = new TestV2AppLauncherItemController(app_id, 3724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) launcher_controller_.get()); 3734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) launcher_controller_->SetItemController(id, test_controller_); 37468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 37568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 37668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Sets the stage for a multi user test. 37768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual void SetUpMultiUserScenario(base::ListValue* user_a, 37868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue* user_b) { 37968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InitLauncherController(); 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 38168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 38268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Set an empty pinned pref to begin with. 38368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue no_user; 38468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(0); 38568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 38668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) no_user.DeepCopy()); 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 38868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 38968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Assume all applications have been added already. 39068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 39168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 39268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 39368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension4_.get()); 39468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension5_.get()); 39568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension6_.get()); 39668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension7_.get()); 39768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension8_.get()); 39868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // There should be nothing in the list by now. 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 40068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 40168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Set user a preferences. 40268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 0, extension1_->id()); 40368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 1, extension2_->id()); 40468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 2, extension3_->id()); 40568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 3, extension4_->id()); 40668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 4, extension5_->id()); 40768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_a, 5, extension6_->id()); 40868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 40968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Set user b preferences. 41068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_b, 0, extension7_->id()); 41168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(user_b, 1, extension8_->id()); 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void TearDown() OVERRIDE { 4154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) 4164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) delete item_delegate_manager_; 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) model_->RemoveObserver(model_observer_.get()); 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) model_observer_.reset(); 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.reset(); 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) model_.reset(); 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWithTestWindowTest::TearDown(); 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 42558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void AddAppListLauncherItem() { 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem app_list; 42758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) app_list.type = ash::TYPE_APP_LIST; 42858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) model_->Add(app_list); 42958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 43058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void InitLauncherController() { 43258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) AddAppListLauncherItem(); 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.reset( 4343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) new ChromeLauncherController(profile(), model_.get())); 4354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) 436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetShelfItemDelegateManager(item_delegate_manager_); 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->Init(); 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void InitLauncherControllerWithBrowser() { 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserList::SetLastActive(browser()); 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetAppIconLoader(extensions::AppIconLoader* loader) { 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->SetAppIconLoaderForTest(loader); 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { 4513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->SetAppTabHelperForTest(helper); 4523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 4533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 454a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) { 455a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) launcher_controller_->SetShelfItemDelegateManagerForTest(manager); 4564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 4574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void InsertPrefValue(base::ListValue* pref_value, 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int index, 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id) { 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::DictionaryValue* entry = new base::DictionaryValue(); 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value->Insert(index, entry); 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets the currently configured app launchers from the controller. 4673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void GetAppLaunchers(ChromeLauncherController* controller, 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string>* launchers) { 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launchers->clear(); 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (ash::ShelfItems::const_iterator iter(model_->items().begin()); 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) iter != model_->items().end(); ++iter) { 4723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ChromeLauncherController::IDToItemControllerMap::const_iterator 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry(controller->id_to_item_controller_map_.find(iter->id)); 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (iter->type == ash::TYPE_APP_SHORTCUT && 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry != controller->id_to_item_controller_map_.end()) { 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launchers->push_back(entry->second->app_id()); 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 48168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Get the setup of the currently shown launcher items in one string. 48268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Each pinned element will start with a big letter, each running but not 48368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // pinned V1 app will start with a small letter and each running but not 48468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // pinned V2 app will start with a '*' + small letter. 4857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string GetPinnedAppStatus() { 4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string result; 4877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) for (int i = 0; i < model_->item_count(); i++) { 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!result.empty()) 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result.append(", "); 4907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) switch (model_->items()[i].type) { 49168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) case ash::TYPE_PLATFORM_APP: 49268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) result+= "*"; 49368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // FALLTHROUGH 49468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) case ash::TYPE_WINDOWED_APP: { 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& app = 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetAppIDForShelfID(model_->items()[i].id); 49768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (app == extension1_->id()) { 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app1"; 49968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 50068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension1_->id())); 50168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension2_->id()) { 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app2"; 50368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 50468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension2_->id())); 50568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension3_->id()) { 5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app3"; 50768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 50868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension3_->id())); 50968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension4_->id()) { 5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app4"; 51168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 51268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension4_->id())); 51368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension5_->id()) { 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app5"; 51568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 51668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension5_->id())); 51768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension6_->id()) { 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app6"; 51968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 52068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension6_->id())); 52168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension7_->id()) { 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app7"; 52368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 52468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension7_->id())); 52568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension8_->id()) { 5265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "app8"; 52768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_FALSE( 52868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->IsAppPinned(extension8_->id())); 52968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else { 5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "unknown"; 53168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 53268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) break; 53368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 5347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ash::TYPE_APP_SHORTCUT: { 5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& app = 5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetAppIDForShelfID(model_->items()[i].id); 5373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (app == extension1_->id()) { 5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App1"; 5393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 5403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } else if (app == extension2_->id()) { 5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App2"; 5423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 5433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } else if (app == extension3_->id()) { 5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App3"; 5453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 5463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } else if (app == extension4_->id()) { 5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App4"; 5483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 54968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension5_->id()) { 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App5"; 55168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id())); 55268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension6_->id()) { 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App6"; 55468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); 55568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension7_->id()) { 5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App7"; 55768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); 55868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } else if (app == extension8_->id()) { 5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "App8"; 56068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); 5613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } else { 5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "unknown"; 5633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 5643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) break; 5657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 5667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ash::TYPE_BROWSER_SHORTCUT: 5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "Chrome"; 5687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 5697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ash::TYPE_APP_LIST: 5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) result += "AppList"; 5717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 5727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) default: 5737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) result += "Unknown"; 5747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 5757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 5767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 5777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return result; 5787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 5797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 58058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Set the index at which the chrome icon should be. 58158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void SetShelfChromeIconIndex(int index) { 58258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, 58368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) index); 58458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 58558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remember the order of unpinned but running applications for the current 5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // user. 5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void RememberUnpinnedRunningApplicationOrder() { 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->RememberUnpinnedRunningApplicationOrder(); 5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Restore the order of running but unpinned applications for a given user. 5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id) { 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->RestoreUnpinnedRunningApplicationOrder(user_id); 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Needed for extension service & friends to work. 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension1_; 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension2_; 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension3_; 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<Extension> extension4_; 60268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scoped_refptr<Extension> extension5_; 60368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scoped_refptr<Extension> extension6_; 60468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scoped_refptr<Extension> extension7_; 60568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scoped_refptr<Extension> extension8_; 6063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<ChromeLauncherController> launcher_controller_; 607f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<TestShelfModelObserver> model_observer_; 608f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<ash::ShelfModel> model_; 6094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // |item_delegate_manager_| owns |test_controller_|. 6114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) LauncherItemController* test_controller_; 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExtensionService* extension_service_; 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 615a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::ShelfItemDelegateManager* item_delegate_manager_; 6164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 6183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS) 6221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// A browser window proxy which is able to associate an aura native window with 6231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// it. 6241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TestBrowserWindowAura : public TestBrowserWindow { 6251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 6261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // |native_window| will still be owned by the caller after the constructor 6271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // was called. 6281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) explicit TestBrowserWindowAura(aura::Window* native_window) 6291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : native_window_(native_window) { 6301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 6311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~TestBrowserWindowAura() {} 6321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { 6341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return native_window_.get(); 6351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 6361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* browser() { return browser_.get(); } 6381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void CreateBrowser(const Browser::CreateParams& params) { 6401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser::CreateParams create_params = params; 6411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) create_params.window = this; 6421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser_.reset(new Browser(create_params)); 6431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 6441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 6461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<Browser> browser_; 6471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<aura::Window> native_window_; 6481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); 6501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 6511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 652f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Creates a test browser window which has a native window. 6531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow( 6541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const Browser::CreateParams& params) { 6551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a window. 6561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* window = new aura::Window(NULL); 6571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window->set_id(0); 6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Init(aura::WINDOW_LAYER_TEXTURED); 6601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window->Show(); 6611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<TestBrowserWindowAura> browser_window( 6631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new TestBrowserWindowAura(window)); 6641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser_window->CreateBrowser(params); 6651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return browser_window.Pass(); 6661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 6671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 668f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Watches WebContents and blocks until it is destroyed. This is needed for 669f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the destruction of a V2 application. 670f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class WebContentsDestroyedWatcher : public content::WebContentsObserver { 671f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 672f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) explicit WebContentsDestroyedWatcher(content::WebContents* web_contents) 673f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) : content::WebContentsObserver(web_contents), 674f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) message_loop_runner_(new content::MessageLoopRunner) { 675f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_TRUE(web_contents != NULL); 676f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 677f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual ~WebContentsDestroyedWatcher() {} 678f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 679f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Waits until the WebContents is destroyed. 680f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void Wait() { 681f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) message_loop_runner_->Run(); 682f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 683f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 684f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 685f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Overridden WebContentsObserver methods. 686010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void WebContentsDestroyed() OVERRIDE { 687f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) message_loop_runner_->Quit(); 688f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 689f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 690f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 691f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 692f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); 693f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 694f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 695f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A V1 windowed application. 696f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class V1App : public TestBrowserWindow { 697f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 698f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V1App(Profile* profile, const std::string& app_name) { 699f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a window. 700f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) native_window_.reset(new aura::Window(NULL)); 701f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) native_window_->set_id(0); 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) native_window_->SetType(ui::wm::WINDOW_TYPE_POPUP); 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) native_window_->Init(aura::WINDOW_LAYER_TEXTURED); 704f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) native_window_->Show(); 705effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch aura::client::ParentWindowWithContext(native_window_.get(), 706effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ash::Shell::GetPrimaryRootWindow(), 707effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Rect(10, 10, 20, 30)); 708a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Browser::CreateParams params = 709a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Browser::CreateParams::CreateForApp(kCrxAppPrefix + app_name, 710a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch true /* trusted_source */, 711a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Rect(), 712a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile, 713a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch chrome::HOST_DESKTOP_TYPE_ASH); 714f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) params.window = this; 715f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) browser_.reset(new Browser(params)); 716f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::AddTabAt(browser_.get(), GURL(), 0, true); 717f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 718f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 719f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual ~V1App() { 720f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // close all tabs. Note that we do not need to destroy the browser itself. 721f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) browser_->tab_strip_model()->CloseAllTabs(); 722f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 723f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 724f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Browser* browser() { return browser_.get(); } 725f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 726f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // TestBrowserWindow override: 727f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { 728f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return native_window_.get(); 729f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 730f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 731f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 732f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The associated browser with this app. 733f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<Browser> browser_; 734f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 735f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The native window we use. 736f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<aura::Window> native_window_; 737f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 738f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(V1App); 739f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 740f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 741f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A V2 application which gets created with an |extension| and for a |profile|. 742f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Upon destruction it will properly close the application. 743f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class V2App { 744f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 745f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V2App(Profile* profile, const extensions::Extension* extension) { 7461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci window_ = new extensions::AppWindow( 7471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci profile, 7481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci new ChromeAppDelegate(make_scoped_ptr(new ScopedKeepAlive)), 7491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extension); 7501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extensions::AppWindow::CreateParams params = 7511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extensions::AppWindow::CreateParams(); 7521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci window_->Init(GURL(std::string()), 7531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci new extensions::AppWindowContentsImpl(window_), params); 754f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 755f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 756f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual ~V2App() { 757f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) WebContentsDestroyedWatcher destroyed_watcher(window_->web_contents()); 758f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window_->GetBaseWindow()->Close(); 759f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) destroyed_watcher.Wait(); 760f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 761f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 7621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extensions::AppWindow* window() { return window_; } 763effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 764f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The app window which represents the application. Note that the window 766f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // deletes itself asynchronously after window_->GetBaseWindow()->Close() gets 767f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // called. 7681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci extensions::AppWindow* window_; 769f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 770f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(V2App); 771f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 772f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 7731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The testing framework to test multi profile scenarios. 7741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest 7751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : public ChromeLauncherControllerTest { 7761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected: 7771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest() { 7781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 7791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest() { 7811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 7821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Overwrite the Setup function to enable multi profile and needed objects. 7841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void SetUp() OVERRIDE { 7851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) profile_manager_.reset( 7861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 7871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(profile_manager_->SetUp()); 7891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // AvatarMenu and multiple profiles works after user logged in. 7911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) profile_manager_->SetLoggedIn(true); 7921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Initialize the UserManager singleton to a fresh FakeUserManager instance. 7941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) user_manager_enabler_.reset( 7951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new chromeos::ScopedUserManagerEnabler(new chromeos::FakeUserManager)); 7961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Initialize the rest. 7981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ChromeLauncherControllerTest::SetUp(); 7991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Get some base objects. 8015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu session_delegate()->set_logged_in_users(2); 8021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shell_delegate_ = static_cast<ash::test::TestShellDelegate*>( 8031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::Shell::GetInstance()->delegate()); 8041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shell_delegate_->set_multi_profiles_enabled(true); 8051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void TearDown() { 8081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ChromeLauncherControllerTest::TearDown(); 8091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) user_manager_enabler_.reset(); 8101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) for (ProfileToNameMap::iterator it = created_profiles_.begin(); 8111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) it != created_profiles_.end(); ++it) 8121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) profile_manager_->DeleteTestingProfile(it->second); 8131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // A Task is leaked if we don't destroy everything, then run the message 8151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // loop. 8161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::MessageLoop::current()->PostTask(FROM_HERE, 8171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::MessageLoop::QuitClosure()); 8181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::MessageLoop::current()->Run(); 8191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Creates a profile for a given |user_name|. Note that this class will keep 8221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the ownership of the created object. 8231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfile* CreateMultiUserProfile(const std::string& user_name) { 8241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string email_string = user_name + "@example.com"; 8255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu static_cast<ash::test::TestSessionStateDelegate*>( 8265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ash::Shell::GetInstance()->session_state_delegate()) 8275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ->AddUser(email_string); 8281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Add a user to the fake user manager. 8295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu session_delegate()->AddUser(email_string); 8301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GetFakeUserManager()->AddUser(email_string); 8311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetFakeUserManager()->LoginUser(email_string); 8331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 8341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TestingProfile* profile = 8351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci profile_manager()->CreateTestingProfile(email_string); 8361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(profile); 8371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 8381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Remember the profile name so that we can destroy it upon destruction. 8391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci created_profiles_[profile] = email_string; 840effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (chrome::MultiUserWindowManager::GetInstance()) 841effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); 842effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (launcher_controller_) 843effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch launcher_controller_->AdditionalUserAddedToSession(profile); 8441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return profile; 8451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Switch to another user. 8481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SwitchActiveUser(const std::string& name) { 8491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) session_delegate()->SwitchActiveUser(name); 8501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GetFakeUserManager()->SwitchActiveUser(name); 851effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch chrome::MultiUserWindowManagerChromeOS* manager = 852effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch static_cast<chrome::MultiUserWindowManagerChromeOS*>( 853effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch chrome::MultiUserWindowManager::GetInstance()); 854a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch manager->SetAnimationSpeedForTest( 855a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 856effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch manager->ActiveUserChanged(name); 8571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_->browser_status_monitor_for_test()-> 8581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ActiveUserChanged(name); 859a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) launcher_controller_->app_window_controller_for_test()-> 860f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ActiveUserChanged(name); 8611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Creates a browser with a |profile| and load a tab with a |title| and |url|. 8641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* CreateBrowserAndTabWithProfile(Profile* profile, 8651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& title, 8661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& url) { 8671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH); 8681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* browser = chrome::CreateBrowserWithTestWindowForParams(¶ms); 8691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::NewTab(browser); 8701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) BrowserList::SetLastActive(browser); 8721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NavigateAndCommitActiveTabWithTitle( 8731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser, GURL(url), ASCIIToUTF16(title)); 8741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return browser; 8751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 877f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Creates a running V1 application. 878f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Note that with the use of the app_tab_helper as done below, this is only 879f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // usable with a single v1 application. 880f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V1App* CreateRunningV1App(Profile* profile, 881f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& app_name, 882f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& url) { 883f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V1App* v1_app = new V1App(profile, app_name); 884f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a new app tab helper and assign it to the launcher so that this 885f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // app gets properly detected. 886f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // TODO(skuhne): Create a more intelligent app tab helper which is able to 887f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // detect all running apps properly. 888f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 889f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) app_tab_helper->SetAppID( 890f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) v1_app->browser()->tab_strip_model()->GetWebContentsAt(0), 891f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) app_name); 892f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SetAppTabHelper(app_tab_helper); 893f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 894f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle( 895f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) v1_app->browser(), GURL(url), ASCIIToUTF16("")); 896f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return v1_app; 8971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 8981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ash::test::TestSessionStateDelegate* session_delegate() { 9005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return static_cast<ash::test::TestSessionStateDelegate*>( 9015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ash::Shell::GetInstance()->session_state_delegate()); 9025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 9031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::test::TestShellDelegate* shell_delegate() { return shell_delegate_; } 9041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Override BrowserWithTestWindowTest: 9061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual TestingProfile* CreateProfile() OVERRIDE { 9071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return CreateMultiUserProfile("user1"); 9081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 9091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void DestroyProfile(TestingProfile* profile) OVERRIDE { 9101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Delete the profile through our profile manager. 9111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ProfileToNameMap::iterator it = created_profiles_.find(profile); 9121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(it != created_profiles_.end()); 9131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) profile_manager_->DeleteTestingProfile(it->second); 9141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) created_profiles_.erase(it); 9151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 9161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 9181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) typedef std::map<Profile*, std::string> ProfileToNameMap; 9191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfileManager* profile_manager() { return profile_manager_.get(); } 9201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chromeos::FakeUserManager* GetFakeUserManager() { 9221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return static_cast<chromeos::FakeUserManager*>( 9236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) user_manager::UserManager::Get()); 9241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 9251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<TestingProfileManager> profile_manager_; 9271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 9281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash::test::TestShellDelegate* shell_delegate_; 9301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ProfileToNameMap created_profiles_; 9321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 9331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN( 9341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest); 9351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 9361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // defined(OS_CHROMEOS) 9373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 93958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ChromeLauncherControllerTest, DefaultApps) { 9403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 9413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Model should only contain the browser shortcut and app list items. 9423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 9433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 9443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 9453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 9463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension3_| should add it to the launcher - behind the 9483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon. 9493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 9505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 9513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 9523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 9533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 9543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Check that the restauration of launcher items is happening in the same order 9563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// as the user has pinned them (on another system) when they are synced reverse 9573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// order. 95858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { 9593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 9603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value; 9623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 0, extension1_->id()); 9633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 1, extension2_->id()); 9643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 2, extension3_->id()); 9653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 9663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value.DeepCopy()); 9673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(0); 9683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Model should only contain the browser shortcut and app list items. 9693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 9703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 9713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 9733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Installing |extension3_| should add it to the shelf - behind the 9753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon. 9765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item; 9773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 9783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 9793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 9805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 9813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension2_| should add it to the launcher - behind the 9833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 9843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 9853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App2, App3", GetPinnedAppStatus()); 9873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension1_| should add it to the launcher - behind the 9893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 9903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 9923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 9933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 9943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Check that the restauration of launcher items is happening in the same order 9953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// as the user has pinned them (on another system) when they are synced random 9963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// order. 99758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) { 9983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 9993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value; 10013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 0, extension1_->id()); 10023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 1, extension2_->id()); 10033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 2, extension3_->id()); 10043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 10053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value.DeepCopy()); 10063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(0); 10073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Model should only contain the browser shortcut and app list items. 10083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 10093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 10103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 10123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension2_| should add it to the launcher - behind the 10143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon. 10153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 10163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 10173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 10193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension1_| should add it to the launcher - behind the 10213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 10223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 10233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 10253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension3_| should add it to the launcher - behind the 10273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 10283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 10295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 10303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 10313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Check that the restauration of launcher items is happening in the same order 10333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// as the user has pinned / moved them (on another system) when they are synced 103458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// random order - including the chrome icon. 103558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) { 10363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 10373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value; 10393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 0, extension1_->id()); 10403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 1, extension2_->id()); 10413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 2, extension3_->id()); 10423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 10433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value.DeepCopy()); 10443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(1); 10453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Model should only contain the browser shortcut and app list items. 10463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 10473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 10483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 10503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Installing |extension2_| should add it to the shelf - behind the 10523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon. 10535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item; 10543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 10553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 10563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 10583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension1_| should add it to the launcher - behind the 10603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 10613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 10623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 10635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); 10643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Installing |extension3_| should add it to the launcher - behind the 10663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // chrome icon, but in first location. 10673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 10685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 10693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 10703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 107158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Check that syncing to a different state does the correct thing. 107258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) { 10733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 10743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value; 10753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 0, extension1_->id()); 10763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 1, extension2_->id()); 10773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value, 2, extension3_->id()); 10783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 10793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value.DeepCopy()); 108058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // The shelf layout has always one static item at the beginning (App List). 10813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(0); 10823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 10835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 10843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 10855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 10863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 10875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus()); 10883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 10893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Change the order with increasing chrome position and decreasing position. 10903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value1; 10913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value1, 0, extension3_->id()); 10923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value1, 1, extension1_->id()); 10933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value1, 2, extension2_->id()); 10943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(3); 10953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 10963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value1.DeepCopy()); 10975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus()); 10983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value2; 10993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value2, 0, extension2_->id()); 11003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value2, 1, extension3_->id()); 11013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value2, 2, extension1_->id()); 11023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(2); 11033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 11043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value2.DeepCopy()); 11055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus()); 11063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Check that the chrome icon can also be at the first possible location. 11083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetShelfChromeIconIndex(0); 11093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ListValue policy_value3; 11103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value3, 0, extension3_->id()); 11113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value3, 1, extension2_->id()); 11123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InsertPrefValue(&policy_value3, 2, extension1_->id()); 11133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 11143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) policy_value3.DeepCopy()); 11155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 11163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Check that unloading of extensions works as expected. 11183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->UnloadExtension(extension1_->id(), 11191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UnloadedExtensionInfo::REASON_UNINSTALL); 11205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus()); 11213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->UnloadExtension(extension2_->id(), 11231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UnloadedExtensionInfo::REASON_UNINSTALL); 11245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 11253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Check that an update of an extension does not crash the system. 11273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) extension_service_->UnloadExtension(extension3_->id(), 11281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UnloadedExtensionInfo::REASON_UPDATE); 11295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 11302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that simple locking of an application will 'create' a launcher item. 11333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckLockApps) { 113490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InitLauncherController(); 11352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 11362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 11372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 11412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); 11432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 11452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 114758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type); 11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); 11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 11612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); 11632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that multiple locks of an application will be properly handled. 116668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckMultiLockApps) { 116790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InitLauncherController(); 11682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 11692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 11702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int i = 0; i < 2; i++) { 11752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 11762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 117858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type); 11792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher( 11812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension1_->id())); 11822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 11852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 118758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type); 11882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 11922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 11942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 11952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 11972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 11982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 11992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that already pinned items are not effected by locks. 12033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckAlreadyPinnedLockApps) { 120490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InitLauncherController(); 12052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 12062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 12072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 12082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 12122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->PinAppWithID(extension1_->id()); 12137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 121658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 12172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 12222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 122458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 12252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 12302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 123258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 12332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1237424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) launcher_controller_->UnpinAppWithID(extension1_->id()); 12382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 12402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that already pinned items which get locked stay after unpinning. 12433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckPinnedAppsStayAfterUnlock) { 124490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InitLauncherController(); 12452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 12462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 12472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 12482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->PinAppWithID(extension1_->id()); 12522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 125458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 12552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 12602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 126258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 12632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 12642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 12652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1267424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) launcher_controller_->UnpinAppWithID(extension1_->id()); 12682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 127058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type); 12712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 12722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 12732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS) 12805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Check that running applications wich are not pinned get properly restored 12815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// upon user change. 12825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckRunningAppOrder) { 12835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) InitLauncherController(); 12845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Model should only contain the browser shortcut and app list items. 12855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 12865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add a few running applications. 12885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 12895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->LockV1AppWithID(extension2_->id()); 12905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->LockV1AppWithID(extension3_->id()); 12915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(5, model_->item_count()); 12925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this not only checks the order of applications but also the 12935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // running type. 12945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 12955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remember the current order of applications for the current user. 12975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& current_user_id = 12985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) multi_user_util::GetUserIDFromProfile(profile()); 12995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RememberUnpinnedRunningApplicationOrder(); 13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Switch some items and check that restoring a user which was not yet 13025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // remembered changes nothing. 13035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) model_->Move(2, 3); 13045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 13055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RestoreUnpinnedRunningApplicationOrder("second-fake-user@fake.com"); 13065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 13075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Restoring the stored user should however do the right thing. 13095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RestoreUnpinnedRunningApplicationOrder(current_user_id); 13105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 13115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Switch again some items and even delete one - making sure that the missing 13135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // item gets properly handled. 13145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) model_->Move(3, 4); 13155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 13165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus()); 13175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RestoreUnpinnedRunningApplicationOrder(current_user_id); 13185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus()); 13195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check that removing more items does not crash and changes nothing. 13215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension2_->id()); 13225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RestoreUnpinnedRunningApplicationOrder(current_user_id); 13235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 13245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension3_->id()); 13255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RestoreUnpinnedRunningApplicationOrder(current_user_id); 13265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 13275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 13285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that with multi profile V1 apps are properly added / removed from the 13301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// shelf. 13311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 13321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) V1AppUpdateOnUserSwitch) { 13331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser item in the LauncherController. 13341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) InitLauncherController(); 13351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) { 13371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a "windowed gmail app". 1338f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<V1App> v1_app(CreateRunningV1App( 1339f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile(), extension_misc::kGmailAppId, gmail_url)); 13401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 13411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // After switching to a second user the item should be gone. 13431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string user2 = "user2"; 13441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 13451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 13461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // After switching back the item should be back. 13491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 13501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 13511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Note we destroy now the gmail app with the closure end. 13521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 13531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 13551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check edge cases with multi profile V1 apps in the shelf. 13571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 13581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) V1AppUpdateOnUserSwitchEdgecases) { 13591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser item in the LauncherController. 13601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) InitLauncherController(); 13611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // First test: Create an app when the user is not active. 13631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string user2 = "user2"; 13641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 13651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) { 13661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a "windowed gmail app". 1367f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<V1App> v1_app(CreateRunningV1App( 1368f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile2, extension_misc::kGmailAppId, gmail_url)); 13691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // However - switching to the user should show it. 13721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 13731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 13741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 13751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Second test: Remove the app when the user is not active and see that it 13761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // works. 13771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 13781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Note: the closure ends and the browser will go away. 13801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 13811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 13831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 13851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 13861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 13871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1388f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check edge case where a visiting V1 app gets closed (crbug.com/321374). 1389f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1390f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V1CloseOnVisitingDesktop) { 1391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a browser item in the LauncherController. 1392f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) InitLauncherController(); 1393f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1394f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::MultiUserWindowManager* manager = 1395f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) chrome::MultiUserWindowManager::GetInstance(); 1396f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1397f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // First create an app when the user is active. 1398f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) std::string user2 = "user2"; 1399f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 1400f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 1401f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a "windowed gmail app". 1402f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<V1App> v1_app(CreateRunningV1App( 1403f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile(), 1404f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) extension_misc::kGmailAppId, 1405f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) kGmailLaunchURL)); 1406f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 1407f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1408f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Transfer the app to the other screen and switch users. 1409f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(), 1410f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) user2); 1411f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 1412f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 1413f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1414f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 1415f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // After the app was destroyed, switch back. (which caused already a crash). 1416f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 1417f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1418f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create the same app again - which was also causing the crash. 1419f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1420f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 1421f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a "windowed gmail app". 1422f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<V1App> v1_app(CreateRunningV1App( 1423f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile(), 1424f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) extension_misc::kGmailAppId, 1425f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) kGmailLaunchURL)); 1426f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 1427f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 1428f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 1429f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1430f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 1431f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1432f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check edge cases with multi profile V1 apps in the shelf. 1433f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 1434f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V1AppUpdateOnUserSwitchEdgecases2) { 1435f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a browser item in the LauncherController. 1436f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) InitLauncherController(); 1437f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 1438f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SetAppTabHelper(app_tab_helper); 1439f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1440f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // First test: Create an app when the user is not active. 1441f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) std::string user2 = "user2"; 1442f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 1443f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 1444f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 1445f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a "windowed gmail app". 1446f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<V1App> v1_app(CreateRunningV1App( 1447f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile(), extension_misc::kGmailAppId, gmail_url)); 1448f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1449f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1450f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // However - switching to the user should show it. 1451f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 1452f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 1453f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1454f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Second test: Remove the app when the user is not active and see that it 1455f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // works. 1456f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 1457f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) v1_app.reset(); 1459f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 1460f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1461f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 1462f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1463f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 1464f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 1465f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 1466f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 14671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that activating an item which is on another user's desktop, will bring 14681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// it back. 14691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 14701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestLauncherActivationPullsBackWindow) { 14711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser item in the LauncherController. 14721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) InitLauncherController(); 14731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::MultiUserWindowManager* manager = 14741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::MultiUserWindowManager::GetInstance(); 14751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 14761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Add two users to the window manager. 14771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string user2 = "user2"; 1478f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 1479f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) manager->AddUser(profile()); 1480f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) manager->AddUser(profile2); 1481f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& current_user = 1482f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) multi_user_util::GetUserIDFromProfile(profile()); 14831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 14841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser window with a native window for the current user. 14851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 14861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH))); 14871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* window = browser_window->GetNativeWindow(); 14881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) manager->SetWindowOwner(window, current_user); 14891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 14901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Check that an activation of the window on its owner's desktop does not 14911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // change the visibility to another user. 14921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 14931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) false); 14941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 14951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 14961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Transfer the window to another user's desktop and check that activating it 14971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // does pull it back to that user. 14981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) manager->ShowWindowForUser(window, user2); 14991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); 15001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 15011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) false); 15021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 15031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 15041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif 15051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 15062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that lock -> pin -> unlock -> unpin does properly transition. 15073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { 150890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InitLauncherController(); 15092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 15102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 15112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 15122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 15132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 15142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->LockV1AppWithID(extension1_->id()); 15162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 151858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type); 15192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 15202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 15212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->PinAppWithID(extension1_->id()); 15232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 152558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 15262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 15272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 15282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 15292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->UnlockV1AppWithID(extension1_->id()); 15312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 153358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 15342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 15352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE( 15362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); 15372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1538424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) launcher_controller_->UnpinAppWithID(extension1_->id()); 15392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 15412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 15422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 154368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Check that a locked (windowed V1 application) will be properly converted 154468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// between locked and pinned when the order gets changed through a profile / 154568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// policy change. 154668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) { 154768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InitLauncherController(); 154868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value0; 154968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value0, 0, extension1_->id()); 155068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value0, 1, extension3_->id()); 155168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 155268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value0.DeepCopy()); 155368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // The shelf layout has always one static item at the beginning (App List). 155468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(0); 155568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 15565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 155768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 155868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // No new app icon will be generated. 15595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 156068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Add the app as locked app which will add it (un-pinned). 156168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) launcher_controller_->LockV1AppWithID(extension2_->id()); 15625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus()); 156368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 15645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus()); 156568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 156668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Now request to pin all items which should convert the locked item into a 156768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // pinned item. 156868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value1; 156968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 0, extension3_->id()); 157068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 1, extension2_->id()); 157168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 2, extension1_->id()); 157268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 157368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value1.DeepCopy()); 15745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 157568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 157668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Going back to a status where there is no requirement for app 2 to be pinned 157768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // should convert it back to locked but not pinned and state. The position 15785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // is determined by the |ShelfModel|'s weight system and since running 15795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // applications are not allowed to be mixed with shortcuts, it should show up 15805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // at the end of the list. 158168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value2; 158268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value2, 0, extension3_->id()); 158368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value2, 1, extension1_->id()); 158468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 158568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value2.DeepCopy()); 15865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus()); 158768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 158868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Removing an item should simply close it and everything should shift. 158968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value3; 159068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value3, 0, extension3_->id()); 159168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 159268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value3.DeepCopy()); 15935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus()); 159468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 159568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 159668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Check that a running and not pinned V2 application will be properly converted 159768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// between locked and pinned when the order gets changed through a profile / 159868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// policy change. 159968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, 160068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RestoreDefaultAndRunningV2AppsResyncOrder) { 160168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InitLauncherController(); 160268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value0; 160368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value0, 0, extension1_->id()); 160468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value0, 1, extension3_->id()); 160568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 160668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value0.DeepCopy()); 160768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // The shelf layout has always one static item at the beginning (app List). 160868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(0); 160968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 16105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 161168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 161268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // No new app icon will be generated. 16135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 161468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Add the app as an unpinned but running V2 app. 161568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) CreateRunningV2App(extension2_->id()); 16165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus()); 161768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 16185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus()); 161968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 162068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Now request to pin all items which should convert the locked item into a 162168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // pinned item. 162268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value1; 162368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 0, extension3_->id()); 162468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 1, extension2_->id()); 162568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value1, 2, extension1_->id()); 162668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 162768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value1.DeepCopy()); 16285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus()); 162968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 163068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Going back to a status where there is no requirement for app 2 to be pinned 163168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // should convert it back to running V2 app. Since the position is determined 1632f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // by the |ShelfModel|'s weight system, it will be after last pinned item. 163368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value2; 163468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value2, 0, extension3_->id()); 163568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value2, 1, extension1_->id()); 163668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 163768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value2.DeepCopy()); 16385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus()); 163968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 164068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Removing an item should simply close it and everything should shift. 164168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue policy_value3; 164268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) InsertPrefValue(&policy_value3, 0, extension3_->id()); 164368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 164468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy_value3.DeepCopy()); 16455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus()); 164668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 164768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 164868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Each user has a different set of applications pinned. Check that when 164968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// switching between the two users, the state gets properly set. 165068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) { 165168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_a; 165268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_b; 165368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetUpMultiUserScenario(&user_a, &user_b); 165468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 1. 165568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(6); 165668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 165768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 16585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 165968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 166068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 166168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 2. 166268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(4); 166368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 166468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_b.DeepCopy()); 166568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 16665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 166768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 166868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Switch back to 1. 166968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(8); 167068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 167168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 16725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 167368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 167468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 167568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Switch back to 2. 167668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(4); 167768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 167868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_b.DeepCopy()); 16795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus()); 168068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 168168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 168268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Each user has a different set of applications pinned, and one user has an 168368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// application running. Check that when switching between the two users, the 168468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// state gets properly set. 168568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) { 168668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_a; 168768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_b; 168868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetUpMultiUserScenario(&user_a, &user_b); 168968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 169068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Run App1 and assume that it is a V2 app. 169168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) CreateRunningV2App(extension1_->id()); 169268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 169368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 1. 169468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(6); 169568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 169668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 16975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 169868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 169968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 170068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 2. 170168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(4); 170268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 170368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_b.DeepCopy()); 170468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 170668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 170768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Switch back to 1. 170868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(8); 170968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 171068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 17115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome", 171268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 171368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 171468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Switch back to 2. 171568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(4); 171668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 171768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_b.DeepCopy()); 17185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 171968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 172068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 172168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Each user has a different set of applications pinned, and one user has an 172268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// application running. The chrome icon is not the last item in the list. 172368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Check that when switching between the two users, the state gets properly set. 172468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// There was once a bug associated with this. 172568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, 172668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { 172768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_a; 172868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::ListValue user_b; 172968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetUpMultiUserScenario(&user_a, &user_b); 173068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 173168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Run App1 and assume that it is a V2 app. 173268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) CreateRunningV2App(extension1_->id()); 173368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 173468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 1. 173568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(5); 173668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 173768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 17385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 173968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 174068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 174168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Show user 2. 174268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(4); 174368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 174468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_b.DeepCopy()); 174568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus()); 174768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 174868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Switch back to 1. 174968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) SetShelfChromeIconIndex(5); 175068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 175168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) user_a.DeepCopy()); 17525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6", 175368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) GetPinnedAppStatus()); 175468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 175568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 17563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, Policy) { 17572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 17582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 17592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ListValue policy_value; 17612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&policy_value, 0, extension1_->id()); 17622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&policy_value, 1, extension2_->id()); 17632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 17642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) policy_value.DeepCopy()); 17652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Only |extension1_| should get pinned. |extension2_| is specified but not 17672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // installed, and |extension3_| is part of the default set, but that shouldn't 17682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // take effect when the policy override is in place. 17692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 17702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 177158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 17722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 17732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 17742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 17752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Installing |extension2_| should add it to the launcher. 17772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 17782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(4, model_->item_count()); 17792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 178058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); 17812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 17822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 17832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 17842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Removing |extension1_| from the policy should be reflected in the launcher. 17862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) policy_value.Remove(0, NULL); 17872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, 17882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) policy_value.DeepCopy()); 17892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 179058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 17912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 17922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 17932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 17942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 17952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { 17972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 17982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension4_.get()); 17992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 18012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 18032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 18042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->UnloadExtension(extension3_->id(), 18061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) UnloadedExtensionInfo::REASON_UNINSTALL); 18072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 18092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); 18102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 18112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, PrefUpdates) { 18132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 18142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 18152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension4_.get()); 18162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 18182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> expected_launchers; 18202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> actual_launchers; 18212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ListValue pref_value; 18222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unavailable extensions don't create launcher items. 18282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 0, extension1_->id()); 18292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 1, extension2_->id()); 18302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 2, extension4_->id()); 18312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.push_back(extension2_->id()); 18342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.push_back(extension4_->id()); 18352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Redundant pref entries show up only once. 18392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 2, extension3_->id()); 18402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 2, extension3_->id()); 18412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 5, extension3_->id()); 18422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id()); 18452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Order changes are reflected correctly. 18492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.Clear(); 18502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 0, extension4_->id()); 18512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 1, extension3_->id()); 18522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 2, extension2_->id()); 18532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::reverse(expected_launchers.begin(), expected_launchers.end()); 18562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Clearing works. 18602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.Clear(); 18612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.clear(); 18642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 18672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) { 18692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension1_.get()); 18702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 18712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 18732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ListValue pref_value; 18752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 0, extension1_->id()); 18762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 1, extension2_->id()); 18772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InsertPrefValue(&pref_value, 2, extension3_->id()); 18782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 18792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_value.DeepCopy()); 18802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> expected_launchers; 18822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.push_back(extension1_->id()); 18832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.push_back(extension3_->id()); 18842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<std::string> actual_launchers; 18852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Install |extension2| and verify it shows up between the other two. 18902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension2_.get()); 18912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); 18922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 18932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_launchers, actual_launchers); 18942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 18952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Checks the created menus and menu lists for correctness. It uses the given 18972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// |controller| to create the objects for the given |item| and checks the 18982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found item count against the |expected_items|. The |title| list contains the 18992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// menu titles in the order of their appearance in the menu (not including the 19002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// application name). 19013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)bool CheckMenuCreation(ChromeLauncherController* controller, 19025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ash::ShelfItem& item, 19032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) size_t expected_items, 1904a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title[], 19052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_browser) { 19062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0); 19072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A new behavior has been added: Only show menus if there is at least one 19082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // item available. 19092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (expected_items < 1 && is_browser) { 19102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0u, items.size()); 19112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return items.size() == 0; 19122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 19132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // There should be one item in there: The title. 19142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_items + 1, items.size()); 19152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(items[0]->IsEnabled()); 19162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (size_t i = 0; i < expected_items; i++) { 19172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(title[i], items[1 + i]->title()); 19182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that the first real item has a leading separator. 19192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (i == 1) 19202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(items[i]->HasLeadingSeparator()); 19212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 19222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(items[i]->HasLeadingSeparator()); 19232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 19242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1925a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel( 1926a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) controller->GetApplicationList(item, 0))); 19272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The first element in the menu is a spacing separator. On some systems 19282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // (e.g. Windows) such things do not exist. As such we check the existence 19292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and adjust dynamically. 19302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int first_item = menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR ? 1 : 0; 19312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int expected_menu_items = first_item + 19322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (expected_items ? (expected_items + 3) : 2); 19332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(expected_menu_items, menu->GetItemCount()); 19342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(menu->IsEnabledAt(first_item)); 19352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (expected_items) { 19362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, 19372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) menu->GetTypeAt(first_item + 1)); 19382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 19392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return items.size() == expected_items + 1; 19402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 19412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that browsers get reflected correctly in the launcher menu. 19433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) { 19442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 19452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 19462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherController(); 19482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that the browser list is empty at this time. 19505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_browser; 19512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 195290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) item_browser.id = 19535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); 19542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 19552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_browser, 0, NULL, true)); 19562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Now make the created browser() visible by adding it to the active browser 19582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // list. 19592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserList::SetLastActive(browser()); 1960a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 19612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 1962a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 one_menu_item[] = { title1 }; 196390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 19652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_browser, 1, one_menu_item, true)); 19662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create one more browser/window and check that one more was added. 19682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH); 19692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<Browser> browser2( 19702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::CreateBrowserWithTestWindowForParams(&ash_params)); 19712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser2.get()); 19722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserList::SetLastActive(browser2.get()); 1973a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title2 = ASCIIToUTF16("Test2"); 19742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser2.get(), GURL("http://test2"), 19752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title2); 19762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that the list contains now two entries - make furthermore sure that 19782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the active item is the first entry. 1979a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 two_menu_items[] = {title1, title2}; 19802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 19812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_browser, 2, two_menu_items, true)); 19822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Apparently we have to close all tabs we have. 19842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::CloseTab(browser2.get()); 19852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 19862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 19871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS) 19881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check the multi profile case where only user related browsers should show 19891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// up. 19901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 19911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) BrowserMenuGenerationTwoUsers) { 19921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser item in the LauncherController. 19931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) InitLauncherController(); 19941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 19955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_browser; 19961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 19971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_browser.id = 19985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); 19991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Check that the menu is empty. 20011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::NewTab(browser()); 20021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 0, NULL, true)); 20041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Show the created |browser()| by adding it to the active browser list. 20061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) BrowserList::SetLastActive(browser()); 2007a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 20081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 2009a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 one_menu_item1[] = { title1 }; 20101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 20121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser for another user and check that it is not included in the 20141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // users running browser list. 20151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string user2 = "user2"; 20161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 20171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<Browser> browser2( 20181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CreateBrowserAndTabWithProfile(profile2, user2, "http://test2")); 2019a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) }; 20201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 20221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Switch to the other user and make sure that only that browser window gets 20241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // shown. 20251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 20261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 1, one_menu_item2, true)); 20281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Transferred browsers of other users should not show up in the list. 20301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 20311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser()->window()->GetNativeWindow(), 20321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) user2); 20331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 1, one_menu_item2, true)); 20351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::CloseTab(browser2.get()); 20371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 20381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // defined(OS_CHROMEOS) 20391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 20402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Check that V1 apps are correctly reflected in the launcher menu using the 20412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// refocus logic. 20422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Note that the extension matching logic is tested by the extension system 20432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// and does not need a separate test here. 20443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) { 20452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 20462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, browser()->tab_strip_model()->count()); 20472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherControllerWithBrowser(); 20492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Model should only contain the browser shortcut and app list items. 20512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 20522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 20532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Installing |extension3_| adds it to the launcher. 20555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 20562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 20572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 20582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int gmail_index = model_->ItemIndexByID(gmail_id); 20592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 20602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 20612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 20622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check the menu content. 20645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_browser; 20652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 206690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) item_browser.id = 20675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); 20682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_gmail; 20702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.type = ash::TYPE_APP_SHORTCUT; 20712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.id = gmail_id; 20722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 0, NULL, false)); 20742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the gmail URL to a new tab. 2076a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 20772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 20782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2079a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 one_menu_item[] = { title1 }; 20802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 1, one_menu_item, false)); 20822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create one empty tab. 20842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 2085a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title2 = ASCIIToUTF16("Test2"); 20862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle( 20872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), 20882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL("https://bla"), 20892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title2); 20902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and another one with another gmail instance. 20922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 2093a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title3 = ASCIIToUTF16("Test3"); 20942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title3); 2095a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 two_menu_items[] = {title1, title3}; 20962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 20972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); 20982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Even though the item is in the V1 app list, it should also be in the 21002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // browser list. 2101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 browser_menu_item[] = {title3}; 21022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_browser, 1, browser_menu_item, false)); 21042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 21052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test that closing of (all) the item(s) does work (and all menus get 21062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // updated properly). 21072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->Close(item_gmail.id); 21082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 21092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 0, NULL, false)); 2111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 browser_menu_item2[] = { title2 }; 21122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_browser, 1, browser_menu_item2, false)); 21142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 21152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 21161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS) 21171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check the multi profile case where only user related apps should show up. 21181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 21191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) V1AppMenuGenerationTwoUsers) { 21201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a browser item in the LauncherController. 21211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) InitLauncherController(); 21221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::NewTab(browser()); 21231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Installing |extension3_| adds it to the launcher. 21255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 21261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 21271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 21281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int gmail_index = model_->ItemIndexByID(gmail_id); 21291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 21301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 21311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 21321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Check the menu content. 21345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_browser; 21351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 21361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_browser.id = 21375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId); 21381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_gmail; 21401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_gmail.type = ash::TYPE_APP_SHORTCUT; 21411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) item_gmail.id = gmail_id; 21421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_gmail, 0, NULL, false)); 21441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set the gmail URL to a new tab. 2146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 21471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 21481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 one_menu_item[] = { title1 }; 21501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_gmail, 1, one_menu_item, false)); 21521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Create a second profile and switch to that user. 21541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string user2 = "user2"; 21551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile(user2); 21561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 21571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // No item should have content yet. 21591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 0, NULL, true)); 21611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_gmail, 0, NULL, false)); 21631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Transfer the browser of the first user - it should still not show up. 21651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 21661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser()->window()->GetNativeWindow(), 21671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) user2); 21681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_browser, 0, NULL, true)); 21711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 21721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) launcher_controller_.get(), item_gmail, 0, NULL, false)); 21731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2174f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check that V2 applications are creating items properly in the launcher when 2176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// instantiated by the current user. 2177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2178f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V2AppHandlingTwoUsers) { 2179f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) InitLauncherController(); 2180f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a profile for our second user (will be destroyed by the framework). 2181f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile("user2"); 2182f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Check that there is a browser and a app launcher. 2183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Add a v2 app. 21861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app(profile(), extension1_.get()); 2187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // After switching users the item should go away. 2190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2191f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2192f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // And it should come back when switching back. 2194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 2197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check that V2 applications are creating items properly in edge cases: 2199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// a background user creates a V2 app, gets active and inactive again and then 2200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// deletes the app. 2201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) V2AppHandlingTwoUsersEdgeCases) { 2203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) InitLauncherController(); 2204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Create a profile for our second user (will be destroyed by the framework). 2205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile("user2"); 2206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Check that there is a browser and a app launcher. 2207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2208f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Switch to an inactive user. 2210f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2211f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2212f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Add the v2 app to the inactive user and check that no item was added to 2214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the launcher. 2215f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 22161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app(profile(), extension1_.get()); 2217f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2219f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Switch to the primary user and check that the item is shown. 2220f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2221f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2222f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2223f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Switch to the second user and check that the item goes away - even if the 2224f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // item gets closed. 2225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2226f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 2228f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // After the application was killed there should be still 2 items. 2230f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2231f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2232f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Switching then back to the default user should not show the additional item 2233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // anymore. 2234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2236f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 2237effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2238effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Check that V2 applications will be made visible on the target desktop if 2239effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// another window of the same type got previously teleported there. 2240effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2241effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch V2AppFollowsTeleportedWindow) { 2242effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch InitLauncherController(); 2243effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch chrome::MultiUserWindowManager* manager = 2244effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch chrome::MultiUserWindowManager::GetInstance(); 2245effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2246effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Create and add three users / profiles, and go to #1's desktop. 2247effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch TestingProfile* profile1 = CreateMultiUserProfile("user-1"); 2248effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 2249effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch TestingProfile* profile3 = CreateMultiUserProfile("user-3"); 2250effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SwitchActiveUser(profile1->GetProfileName()); 2251effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2252effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // A v2 app for user #1 should be shown first and get hidden when switching to 2253effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // desktop #2. 22541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_1(profile1, extension1_.get()); 2255effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SwitchActiveUser(profile2->GetProfileName()); 2257effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2258effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Add a v2 app for user #1 while on desktop #2 should not be shown. 22601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_2(profile1, extension1_.get()); 2261effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2262effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2263effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2264effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Teleport the app from user #1 to the desktop #2 should show it. 2265effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch manager->ShowWindowForUser(v2_app_1.window()->GetNativeWindow(), 2266effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch profile2->GetProfileName()); 2267effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2268effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2269effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2270effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Creating a new application for user #1 on desktop #2 should teleport it 2271effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // there automatically. 22721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_3(profile1, extension1_.get()); 2273effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2274effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2275effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_3.window()->GetNativeWindow()->IsVisible()); 2276effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2277effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Switching back to desktop#1 and creating an app for user #1 should move 2278effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // the app on desktop #1. 2279effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SwitchActiveUser(profile1->GetProfileName()); 22801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_4(profile1, extension1_.get()); 2281effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2282effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2283effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_3.window()->GetNativeWindow()->IsVisible()); 2284effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_4.window()->GetNativeWindow()->IsVisible()); 2285effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2286effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Switching to desktop #3 and create an app for user #1 there should land on 2287effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // his own desktop (#1). 2288effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SwitchActiveUser(profile3->GetProfileName()); 22891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_5(profile1, extension1_.get()); 2290effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_FALSE(v2_app_5.window()->GetNativeWindow()->IsVisible()); 2291effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SwitchActiveUser(profile1->GetProfileName()); 2292effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(v2_app_5.window()->GetNativeWindow()->IsVisible()); 2293010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2294010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Switching to desktop #2, hiding the app window and creating an app should 2295010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // teleport there automatically. 2296010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2297010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_1.window()->Hide(); 22981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_6(profile1, extension1_.get()); 2299010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible()); 2300010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible()); 2301010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_TRUE(v2_app_6.window()->GetNativeWindow()->IsVisible()); 2302010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 2303010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2304010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Check that V2 applications hide correctly on the shelf when the app window 2305010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// is hidden. 2306010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2307010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) V2AppHiddenWindows) { 2308010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) InitLauncherController(); 2309010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2310010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 2311010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2312010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2313010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 23141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_1(profile(), extension1_.get()); 2315010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2316010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) { 2317010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Hide and show the app. 2318010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_1.window()->Hide(); 2319010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2320010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 23211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2322010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2323010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 2324010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) { 2325010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Switch user, hide and show the app and switch back. 2326010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2327010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2328010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2329010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_1.window()->Hide(); 2330010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2331010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 23321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2333010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2334010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2335010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2336010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2337010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 2338010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) { 2339010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Switch user, hide the app, switch back and then show it again. 2340010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile2->GetProfileName()); 2341010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2342010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2343010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_1.window()->Hide(); 2344010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2345010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2346010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SwitchActiveUser(profile()->GetProfileName()); 2347010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2348010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 23491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2350010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2351010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 2352010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) { 2353010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Create a second app, hide and show it and then hide both apps. 23541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci V2App v2_app_2(profile(), extension1_.get()); 2355010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2356010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2357010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_2.window()->Hide(); 2358010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2359010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 23601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 2361010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2362010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2363010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_1.window()->Hide(); 2364010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) v2_app_2.window()->Hide(); 2365010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_EQ(2, model_->item_count()); 2366010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 2367effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 23681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // defined(OS_CHROMEOS) 23691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 23702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Checks that the generated menu list properly activates items. 23713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) { 23722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherControllerWithBrowser(); 23732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 23742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add |extension3_| to the launcher and add two items. 23752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL gmail = GURL("https://mail.google.com/mail/u"); 23765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 23772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 23782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2379a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 23802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 23812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 2382a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title2 = ASCIIToUTF16("Test2"); 23832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); 23842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 23852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that the menu is properly set. 23865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_gmail; 23872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.type = ash::TYPE_APP_SHORTCUT; 23882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.id = gmail_id; 2389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 two_menu_items[] = {title1, title2}; 23902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 23912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); 23922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 23932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Execute the second item in the list (which shouldn't do anything since that 23942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // item is per definition already the active tab). 23952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 2396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel( 2397a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) launcher_controller_->GetApplicationList(item_gmail, 0))); 23982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The first element in the menu is a spacing separator. On some systems 23992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // (e.g. Windows) such things do not exist. As such we check the existence 24002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and adjust dynamically. 24012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int first_item = 24022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; 24032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) menu->ActivatedAt(first_item + 3); 24042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 24052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 24062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Execute the first item. 24082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 2409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel( 2410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) launcher_controller_->GetApplicationList(item_gmail, 0))); 24112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int first_item = 24122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; 24132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) menu->ActivatedAt(first_item + 2); 24142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 24152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Now the active tab should be the second item. 24162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 24172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 24182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Checks that the generated menu list properly deletes items. 24203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) { 24212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherControllerWithBrowser(); 24222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add |extension3_| to the launcher and add two items. 24242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL gmail = GURL("https://mail.google.com/mail/u"); 24255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 24262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 24272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2428a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title1 = ASCIIToUTF16("Test1"); 24292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 24302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NewTab(browser()); 2431a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title2 = ASCIIToUTF16("Test2"); 24322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); 24332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that the menu is properly set. 24355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_gmail; 24362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.type = ash::TYPE_APP_SHORTCUT; 24372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) item_gmail.id = gmail_id; 2438a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 two_menu_items[] = {title1, title2}; 24392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(CheckMenuCreation( 24402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); 24412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int tabs = browser()->tab_strip_model()->count(); 24432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Activate the proper tab through the menu item. 24442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 24452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChromeLauncherAppMenuItems items = 24462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->GetApplicationList(item_gmail, 0); 24472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) items[1]->Execute(0); 24482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); 24492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 24502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Delete one tab through the menu item. 24522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 24532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ChromeLauncherAppMenuItems items = 24542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->GetApplicationList(item_gmail, 0); 24552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) items[1]->Execute(ui::EF_SHIFT_DOWN); 24562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); 24572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 24582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 24592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tests that panels create launcher items correctly 24613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, AppPanels) { 24622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitLauncherControllerWithBrowser(); 24635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // App list and Browser shortcut ShelfItems are added. 246458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(2, model_observer_->added()); 24652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); 24672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetAppIconLoader(app_icon_loader); 24682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Test adding an app panel 24702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string app_id = extension1_->id(); 2471a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AppWindowLauncherItemController* app_panel_controller = 2472a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new AppWindowLauncherItemController( 24734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) LauncherItemController::TYPE_APP_PANEL, 24744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "id", 24754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) app_id, 24764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) launcher_controller_.get()); 24775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem( 24784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) app_panel_controller, app_id, ash::STATUS_RUNNING); 2479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int panel_index = model_observer_->last_index(); 248058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(3, model_observer_->added()); 24812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, model_observer_->changed()); 24822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, app_icon_loader->fetch_count()); 24832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) model_observer_->clear_counts(); 24842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // App panels should have a separate identifier than the app id 24865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); 24872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Setting the app image image should not change the panel if it set its icon 24894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) app_panel_controller->set_image_set_by_controller(true); 24902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::ImageSkia image; 24912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) launcher_controller_->SetAppImage(app_id, image); 24922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(0, model_observer_->changed()); 2493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch model_observer_->clear_counts(); 2494eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2495eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Add a second app panel and verify that it get the same index as the first 2496eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // one had, being added to the left of the existing panel. 2497a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AppWindowLauncherItemController* app_panel_controller2 = 2498a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) new AppWindowLauncherItemController( 24994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) LauncherItemController::TYPE_APP_PANEL, 25004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "id", 25014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) app_id, 25024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) launcher_controller_.get()); 25034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 25045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem( 25054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) app_panel_controller2, app_id, ash::STATUS_RUNNING); 2506eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(panel_index, model_observer_->last_index()); 2507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(1, model_observer_->added()); 2508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch model_observer_->clear_counts(); 25092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 25105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->CloseLauncherItem(shelf_id2); 25115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launcher_controller_->CloseLauncherItem(shelf_id1); 2512eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(2, model_observer_->removed()); 25132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2514c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that the Gmail extension matches more then the app itself claims with 2516c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// the manifest file. 25173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, GmailMatching) { 2518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) InitLauncherControllerWithBrowser(); 2519c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Create a Gmail browser tab. 2521c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::NewTab(browser()); 2522a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title = ASCIIToUTF16("Test"); 2523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title); 2524c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::WebContents* content = 2525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2526c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Check that the launcher controller does not recognize the running app. 2528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2529c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Installing |extension3_| adds it to the launcher. 25315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 2532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 2533c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int gmail_index = model_->ItemIndexByID(gmail_id); 2535c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2536c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2537c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2538c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Check that it is now handled. 2539c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Check also that the app has detected that properly. 25425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfItem item_gmail; 2543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) item_gmail.type = ash::TYPE_APP_SHORTCUT; 2544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) item_gmail.id = gmail_id; 2545c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size()); 2546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 2547c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2548c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests that the Gmail extension does not match the offline verison. 25493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) { 2550c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) InitLauncherControllerWithBrowser(); 2551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2552c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Create a Gmail browser tab. 2553c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::NewTab(browser()); 2554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title = ASCIIToUTF16("Test"); 2555c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigateAndCommitActiveTabWithTitle(browser(), 2556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GURL(offline_gmail_url), 2557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) title); 2558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::WebContents* content = 2559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2560c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Installing |extension3_| adds it to the launcher. 25625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID gmail_id = model_->next_id(); 2563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension_service_->AddExtension(extension3_.get()); 2564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(3, model_->item_count()); 2565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int gmail_index = model_->ItemIndexByID(gmail_id); 2566c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2568c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2569c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // The content should not be able to be handled by the app. 2570c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 25723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 25733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Verify that the launcher item positions are persisted and restored. 25743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { 25753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherController(); 25763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 25773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 25783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppTabHelper(app_tab_helper); 25793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 258058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 258158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 25823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 25833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TabStripModel* tab_strip_model = browser()->tab_strip_model(); 25843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(0, tab_strip_model->count()); 25853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) chrome::NewTab(browser()); 25863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) chrome::NewTab(browser()); 25873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(2, tab_strip_model->count()); 25883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 25893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 25903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 25913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); 25923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->PinAppWithID("1"); 25933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 25943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->PinAppWithID("2"); 25953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 259658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 259758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 25983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 259958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type); 26003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 260158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Move browser shortcut item from index 1 to index 3. 260258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) model_->Move(1, 3); 260358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 26043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 260558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 260658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 26073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_.reset(); 26094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) { 26104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) delete item_delegate_manager_; 26114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } else { 2612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Clear already registered ShelfItemDelegate. 2613a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 2614a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test.RemoveAllShelfItemDelegateForTest(); 26154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 2616f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) model_.reset(new ash::ShelfModel); 26174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 26184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AddAppListLauncherItem(); 26193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_.reset( 26203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ChromeLauncherController::CreateInstance(profile(), model_.get())); 26213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper = new TestAppTabHelperImpl; 26223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 26233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 26243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppTabHelper(app_tab_helper); 26254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) { 2626a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 2627a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetShelfItemDelegateManager(item_delegate_manager_); 26284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 26293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->Init(); 26303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Check ShelfItems are restored after resetting ChromeLauncherController. 263258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 26333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 263458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 263558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 26363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 26373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Verifies pinned apps are persisted and restored. 26393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(ChromeLauncherControllerTest, PersistPinned) { 26403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) InitLauncherControllerWithBrowser(); 26413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) size_t initial_size = model_->items().size(); 26423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TabStripModel* tab_strip_model = browser()->tab_strip_model(); 26443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(1, tab_strip_model->count()); 26453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 26473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 26483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppTabHelper(app_tab_helper); 26493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; 26513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppIconLoader(app_icon_loader); 26523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(0, app_icon_loader->fetch_count()); 26533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->PinAppWithID("1"); 26555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1"); 26563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int app_index = model_->ItemIndexByID(id); 26573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(1, app_icon_loader->fetch_count()); 26583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 26593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 26603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 26613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(initial_size + 1, model_->items().size()); 26623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_.reset(); 26644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) { 26654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) delete item_delegate_manager_; 26664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } else { 2667a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Clear already registered ShelfItemDelegate. 2668a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_); 2669a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) test.RemoveAllShelfItemDelegateForTest(); 26704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 2671f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) model_.reset(new ash::ShelfModel); 26724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 267368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) AddAppListLauncherItem(); 26743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_.reset( 26753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ChromeLauncherController::CreateInstance(profile(), model_.get())); 26763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper = new TestAppTabHelperImpl; 26773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 26783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppTabHelper(app_tab_helper); 26793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) app_icon_loader = new TestAppIconLoaderImpl; 26803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SetAppIconLoader(app_icon_loader); 26814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!ash::Shell::HasInstance()) { 2682a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 2683a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SetShelfItemDelegateManager(item_delegate_manager_); 26844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 26853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) launcher_controller_->Init(); 26863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(1, app_icon_loader->fetch_count()); 26883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ASSERT_EQ(initial_size + 1, model_->items().size()); 26893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 26903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 26913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 26923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2693424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) launcher_controller_->UnpinAppWithID("1"); 26943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ASSERT_EQ(initial_size, model_->items().size()); 26953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 2696