This source file includes following definitions.
- changed_
- ShelfItemAdded
- ShelfItemRemoved
- ShelfItemChanged
- ShelfItemMoved
- ShelfStatusChanged
- clear_counts
- added
- removed
- changed
- last_index
- FetchImage
- ClearImage
- UpdateImage
- fetch_count
- SetAppID
- HasAppID
- GetAppID
- IsValidIDForCurrentUser
- SetCurrentUser
- IsOpen
- IsVisible
- Launch
- Activate
- Close
- ItemSelected
- GetTitle
- GetApplicationList
- CreateContextMenu
- CreateApplicationMenu
- IsDraggable
- ShouldShowTooltip
- extension_service_
- SetUp
- CreateRunningV2App
- SetUpMultiUserScenario
- TearDown
- AddAppListLauncherItem
- InitLauncherController
- InitLauncherControllerWithBrowser
- SetAppIconLoader
- SetAppTabHelper
- SetShelfItemDelegateManager
- InsertPrefValue
- GetAppLaunchers
- GetPinnedAppStatus
- SetShelfChromeIconIndex
- RememberUnpinnedRunningApplicationOrder
- RestoreUnpinnedRunningApplicationOrder
- SetUp
- GetNativeWindow
- browser
- CreateBrowser
- CreateTestBrowserWindow
- message_loop_runner_
- Wait
- WebContentsDestroyed
- browser
- GetNativeWindow
- window
- SetUp
- TearDown
- CreateMultiUserProfile
- SwitchActiveUser
- CreateBrowserAndTabWithProfile
- CreateRunningV1App
- session_delegate
- shell_delegate
- CreateProfile
- DestroyProfile
- CreateViewsDelegate
- profile_manager
- GetFakeUserManager
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- CheckMenuCreation
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include <algorithm>
#include <string>
#include <vector>
#include "ash/ash_switches.h"
#include "ash/shelf/shelf_item_delegate_manager.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_model_observer.h"
#include "ash/shell.h"
#include "ash/test/shelf_item_delegate_manager_test_api.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
#include "chrome/browser/ui/ash/test_views_delegate_with_parent.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/base/models/menu_model.h"
#if defined(OS_CHROMEOS)
#include "apps/app_window_contents.h"
#include "apps/app_window_registry.h"
#include "apps/ui/native_app_window.h"
#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "chrome/browser/chromeos/login/fake_user_manager.h"
#include "chrome/browser/ui/apps/chrome_app_window_delegate.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/test_utils.h"
#include "ui/aura/window.h"
#endif
using base::ASCIIToUTF16;
using extensions::Extension;
using extensions::Manifest;
using extensions::UnloadedExtensionInfo;
namespace {
const char* offline_gmail_url = "https://mail.google.com/mail/mu/u";
const char* gmail_url = "https://mail.google.com/mail/u";
const char* kGmailLaunchURL = "https://mail.google.com/mail/ca";
const char kUserIdHashSuffix[] = "-hash";
const char kCrxAppPrefix[] = "_crx_";
class TestShelfModelObserver : public ash::ShelfModelObserver {
public:
TestShelfModelObserver()
: added_(0),
removed_(0),
changed_(0) {
}
virtual ~TestShelfModelObserver() {
}
virtual void ShelfItemAdded(int index) OVERRIDE {
++added_;
last_index_ = index;
}
virtual void ShelfItemRemoved(int index, ash::ShelfID id) OVERRIDE {
++removed_;
last_index_ = index;
}
virtual void ShelfItemChanged(int index,
const ash::ShelfItem& old_item) OVERRIDE {
++changed_;
last_index_ = index;
}
virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE {
last_index_ = target_index;
}
virtual void ShelfStatusChanged() OVERRIDE {
}
void clear_counts() {
added_ = 0;
removed_ = 0;
changed_ = 0;
last_index_ = 0;
}
int added() const { return added_; }
int removed() const { return removed_; }
int changed() const { return changed_; }
int last_index() const { return last_index_; }
private:
int added_;
int removed_;
int changed_;
int last_index_;
DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver);
};
class TestAppIconLoaderImpl : public extensions::AppIconLoader {
public:
TestAppIconLoaderImpl() : fetch_count_(0) {
}
virtual ~TestAppIconLoaderImpl() {
}
virtual void FetchImage(const std::string& id) OVERRIDE {
++fetch_count_;
}
virtual void ClearImage(const std::string& id) OVERRIDE {
}
virtual void UpdateImage(const std::string& id) OVERRIDE {
}
int fetch_count() const { return fetch_count_; }
private:
int fetch_count_;
DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl);
};
class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper {
public:
TestAppTabHelperImpl() {}
virtual ~TestAppTabHelperImpl() {}
void SetAppID(content::WebContents* tab, const std::string& id) {
tab_id_map_[tab] = id;
}
bool HasAppID(content::WebContents* tab) const {
return tab_id_map_.find(tab) != tab_id_map_.end();
}
virtual std::string GetAppID(content::WebContents* tab) OVERRIDE {
return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] :
std::string();
}
virtual bool IsValidIDForCurrentUser(const std::string& id) OVERRIDE {
for (TabToStringMap::const_iterator i = tab_id_map_.begin();
i != tab_id_map_.end(); ++i) {
if (i->second == id)
return true;
}
return false;
}
virtual void SetCurrentUser(Profile* profile) OVERRIDE {
}
private:
typedef std::map<content::WebContents*, std::string> TabToStringMap;
TabToStringMap tab_id_map_;
DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl);
};
class TestV2AppLauncherItemController : public LauncherItemController {
public:
TestV2AppLauncherItemController(const std::string& app_id,
ChromeLauncherController* controller)
: LauncherItemController(LauncherItemController::TYPE_APP,
app_id,
controller) {
}
virtual ~TestV2AppLauncherItemController() {}
virtual bool IsOpen() const OVERRIDE { return true; }
virtual bool IsVisible() const OVERRIDE { return true; }
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {}
virtual bool Activate(ash::LaunchSource source) OVERRIDE { return false; }
virtual void Close() OVERRIDE {}
virtual bool ItemSelected(const ui::Event& event) OVERRIDE { return false; }
virtual base::string16 GetTitle() OVERRIDE { return base::string16(); }
virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE {
ChromeLauncherAppMenuItems items;
items.push_back(
new ChromeLauncherAppMenuItem(base::string16(), NULL, false));
items.push_back(
new ChromeLauncherAppMenuItem(base::string16(), NULL, false));
return items.Pass();
}
virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) OVERRIDE {
return NULL;
}
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE {
return NULL;
}
virtual bool IsDraggable() OVERRIDE { return false; }
virtual bool ShouldShowTooltip() OVERRIDE { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
};
}
class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
protected:
ChromeLauncherControllerTest()
: BrowserWithTestWindowTest(
Browser::TYPE_TABBED,
chrome::HOST_DESKTOP_TYPE_ASH,
false),
test_controller_(NULL),
extension_service_(NULL) {
}
virtual ~ChromeLauncherControllerTest() {
}
virtual void SetUp() OVERRIDE {
BrowserWithTestWindowTest::SetUp();
model_.reset(new ash::ShelfModel);
model_observer_.reset(new TestShelfModelObserver);
model_->AddObserver(model_observer_.get());
if (ash::Shell::HasInstance()) {
item_delegate_manager_ =
ash::Shell::GetInstance()->shelf_item_delegate_manager();
} else {
item_delegate_manager_ =
new ash::ShelfItemDelegateManager(model_.get());
}
base::DictionaryValue manifest;
manifest.SetString(extensions::manifest_keys::kName,
"launcher controller test extension");
manifest.SetString(extensions::manifest_keys::kVersion, "1");
manifest.SetString(extensions::manifest_keys::kDescription,
"for testing pinned apps");
extensions::TestExtensionSystem* extension_system(
static_cast<extensions::TestExtensionSystem*>(
extensions::ExtensionSystem::Get(profile())));
extension_service_ = extension_system->CreateExtensionService(
CommandLine::ForCurrentProcess(), base::FilePath(), false);
std::string error;
extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
&error);
extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
&error);
base::DictionaryValue manifest_gmail;
manifest_gmail.SetString(extensions::manifest_keys::kName,
"Gmail launcher controller test extension");
manifest_gmail.SetString(extensions::manifest_keys::kVersion, "1");
manifest_gmail.SetString(extensions::manifest_keys::kDescription,
"for testing pinned Gmail");
manifest_gmail.SetString(extensions::manifest_keys::kLaunchWebURL,
kGmailLaunchURL);
base::ListValue* list = new base::ListValue();
list->Append(base::Value::CreateStringValue("*://mail.google.com/mail/ca"));
manifest_gmail.Set(extensions::manifest_keys::kWebURLs, list);
extension3_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest_gmail,
Extension::NO_FLAGS,
extension_misc::kGmailAppId,
&error);
extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
extension_misc::kGoogleSearchAppId,
&error);
extension5_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"cccccccccccccccccccccccccccccccc",
&error);
extension6_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"dddddddddddddddddddddddddddddddd",
&error);
extension7_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
&error);
extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest,
Extension::NO_FLAGS,
"ffffffffffffffffffffffffffffffff",
&error);
}
virtual void CreateRunningV2App(const std::string& app_id) {
DCHECK(!test_controller_);
ash::ShelfID id =
launcher_controller_->CreateAppShortcutLauncherItemWithType(
app_id,
model_->item_count(),
ash::TYPE_PLATFORM_APP);
DCHECK(id);
test_controller_ = new TestV2AppLauncherItemController(app_id,
launcher_controller_.get());
launcher_controller_->SetItemController(id, test_controller_);
}
virtual void SetUpMultiUserScenario(base::ListValue* user_a,
base::ListValue* user_b) {
InitLauncherController();
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
base::ListValue no_user;
SetShelfChromeIconIndex(0);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
no_user.DeepCopy());
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension2_.get());
extension_service_->AddExtension(extension3_.get());
extension_service_->AddExtension(extension4_.get());
extension_service_->AddExtension(extension5_.get());
extension_service_->AddExtension(extension6_.get());
extension_service_->AddExtension(extension7_.get());
extension_service_->AddExtension(extension8_.get());
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
InsertPrefValue(user_a, 0, extension1_->id());
InsertPrefValue(user_a, 1, extension2_->id());
InsertPrefValue(user_a, 2, extension3_->id());
InsertPrefValue(user_a, 3, extension4_->id());
InsertPrefValue(user_a, 4, extension5_->id());
InsertPrefValue(user_a, 5, extension6_->id());
InsertPrefValue(user_b, 0, extension7_->id());
InsertPrefValue(user_b, 1, extension8_->id());
}
virtual void TearDown() OVERRIDE {
if (!ash::Shell::HasInstance())
delete item_delegate_manager_;
model_->RemoveObserver(model_observer_.get());
model_observer_.reset();
launcher_controller_.reset();
model_.reset();
BrowserWithTestWindowTest::TearDown();
}
void AddAppListLauncherItem() {
ash::ShelfItem app_list;
app_list.type = ash::TYPE_APP_LIST;
model_->Add(app_list);
}
void InitLauncherController() {
AddAppListLauncherItem();
launcher_controller_.reset(
new ChromeLauncherController(profile(), model_.get()));
if (!ash::Shell::HasInstance())
SetShelfItemDelegateManager(item_delegate_manager_);
launcher_controller_->Init();
}
void InitLauncherControllerWithBrowser() {
chrome::NewTab(browser());
BrowserList::SetLastActive(browser());
InitLauncherController();
}
void SetAppIconLoader(extensions::AppIconLoader* loader) {
launcher_controller_->SetAppIconLoaderForTest(loader);
}
void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) {
launcher_controller_->SetAppTabHelperForTest(helper);
}
void SetShelfItemDelegateManager(ash::ShelfItemDelegateManager* manager) {
launcher_controller_->SetShelfItemDelegateManagerForTest(manager);
}
void InsertPrefValue(base::ListValue* pref_value,
int index,
const std::string& extension_id) {
base::DictionaryValue* entry = new base::DictionaryValue();
entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id);
pref_value->Insert(index, entry);
}
void GetAppLaunchers(ChromeLauncherController* controller,
std::vector<std::string>* launchers) {
launchers->clear();
for (ash::ShelfItems::const_iterator iter(model_->items().begin());
iter != model_->items().end(); ++iter) {
ChromeLauncherController::IDToItemControllerMap::const_iterator
entry(controller->id_to_item_controller_map_.find(iter->id));
if (iter->type == ash::TYPE_APP_SHORTCUT &&
entry != controller->id_to_item_controller_map_.end()) {
launchers->push_back(entry->second->app_id());
}
}
}
std::string GetPinnedAppStatus() {
std::string result;
for (int i = 0; i < model_->item_count(); i++) {
if (!result.empty())
result.append(", ");
switch (model_->items()[i].type) {
case ash::TYPE_PLATFORM_APP:
result+= "*";
case ash::TYPE_WINDOWED_APP: {
const std::string& app =
launcher_controller_->GetAppIDForShelfID(model_->items()[i].id);
if (app == extension1_->id()) {
result += "app1";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension1_->id()));
} else if (app == extension2_->id()) {
result += "app2";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension2_->id()));
} else if (app == extension3_->id()) {
result += "app3";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension3_->id()));
} else if (app == extension4_->id()) {
result += "app4";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension4_->id()));
} else if (app == extension5_->id()) {
result += "app5";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension5_->id()));
} else if (app == extension6_->id()) {
result += "app6";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension6_->id()));
} else if (app == extension7_->id()) {
result += "app7";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension7_->id()));
} else if (app == extension8_->id()) {
result += "app8";
EXPECT_FALSE(
launcher_controller_->IsAppPinned(extension8_->id()));
} else {
result += "unknown";
}
break;
}
case ash::TYPE_APP_SHORTCUT: {
const std::string& app =
launcher_controller_->GetAppIDForShelfID(model_->items()[i].id);
if (app == extension1_->id()) {
result += "App1";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
} else if (app == extension2_->id()) {
result += "App2";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
} else if (app == extension3_->id()) {
result += "App3";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
} else if (app == extension4_->id()) {
result += "App4";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
} else if (app == extension5_->id()) {
result += "App5";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id()));
} else if (app == extension6_->id()) {
result += "App6";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id()));
} else if (app == extension7_->id()) {
result += "App7";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id()));
} else if (app == extension8_->id()) {
result += "App8";
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id()));
} else {
result += "unknown";
}
break;
}
case ash::TYPE_BROWSER_SHORTCUT:
result += "Chrome";
break;
case ash::TYPE_APP_LIST:
result += "AppList";
break;
default:
result += "Unknown";
break;
}
}
return result;
}
void SetShelfChromeIconIndex(int index) {
profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
index);
}
void RememberUnpinnedRunningApplicationOrder() {
launcher_controller_->RememberUnpinnedRunningApplicationOrder();
}
void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id) {
launcher_controller_->RestoreUnpinnedRunningApplicationOrder(user_id);
}
scoped_refptr<Extension> extension1_;
scoped_refptr<Extension> extension2_;
scoped_refptr<Extension> extension3_;
scoped_refptr<Extension> extension4_;
scoped_refptr<Extension> extension5_;
scoped_refptr<Extension> extension6_;
scoped_refptr<Extension> extension7_;
scoped_refptr<Extension> extension8_;
scoped_ptr<ChromeLauncherController> launcher_controller_;
scoped_ptr<TestShelfModelObserver> model_observer_;
scoped_ptr<ash::ShelfModel> model_;
LauncherItemController* test_controller_;
ExtensionService* extension_service_;
ash::ShelfItemDelegateManager* item_delegate_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
};
class LegacyShelfLayoutChromeLauncherControllerTest
: public ChromeLauncherControllerTest {
protected:
LegacyShelfLayoutChromeLauncherControllerTest() {
}
virtual ~LegacyShelfLayoutChromeLauncherControllerTest() {
}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshDisableAlternateShelfLayout);
ChromeLauncherControllerTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(LegacyShelfLayoutChromeLauncherControllerTest);
};
#if defined(OS_CHROMEOS)
class TestBrowserWindowAura : public TestBrowserWindow {
public:
explicit TestBrowserWindowAura(aura::Window* native_window)
: native_window_(native_window) {
}
virtual ~TestBrowserWindowAura() {}
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE {
return native_window_.get();
}
Browser* browser() { return browser_.get(); }
void CreateBrowser(const Browser::CreateParams& params) {
Browser::CreateParams create_params = params;
create_params.window = this;
browser_.reset(new Browser(create_params));
}
private:
scoped_ptr<Browser> browser_;
scoped_ptr<aura::Window> native_window_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
};
scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow(
const Browser::CreateParams& params) {
aura::Window* window = new aura::Window(NULL);
window->set_id(0);
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
window->Show();
scoped_ptr<TestBrowserWindowAura> browser_window(
new TestBrowserWindowAura(window));
browser_window->CreateBrowser(params);
return browser_window.Pass();
}
class WebContentsDestroyedWatcher : public content::WebContentsObserver {
public:
explicit WebContentsDestroyedWatcher(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
message_loop_runner_(new content::MessageLoopRunner) {
EXPECT_TRUE(web_contents != NULL);
}
virtual ~WebContentsDestroyedWatcher() {}
void Wait() {
message_loop_runner_->Run();
}
private:
virtual void WebContentsDestroyed(
content::WebContents* web_contents) OVERRIDE {
message_loop_runner_->Quit();
}
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher);
};
class V1App : public TestBrowserWindow {
public:
V1App(Profile* profile, const std::string& app_name) {
native_window_.reset(new aura::Window(NULL));
native_window_->set_id(0);
native_window_->SetType(ui::wm::WINDOW_TYPE_POPUP);
native_window_->Init(aura::WINDOW_LAYER_TEXTURED);
native_window_->Show();
aura::client::ParentWindowWithContext(native_window_.get(),
ash::Shell::GetPrimaryRootWindow(),
gfx::Rect(10, 10, 20, 30));
Browser::CreateParams params = Browser::CreateParams::CreateForApp(
Browser::TYPE_POPUP,
kCrxAppPrefix + app_name,
gfx::Rect(),
profile,
chrome::HOST_DESKTOP_TYPE_ASH);
params.window = this;
browser_.reset(new Browser(params));
chrome::AddTabAt(browser_.get(), GURL(), 0, true);
}
virtual ~V1App() {
browser_->tab_strip_model()->CloseAllTabs();
}
Browser* browser() { return browser_.get(); }
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE {
return native_window_.get();
}
private:
scoped_ptr<Browser> browser_;
scoped_ptr<aura::Window> native_window_;
DISALLOW_COPY_AND_ASSIGN(V1App);
};
class V2App {
public:
V2App(Profile* profile, const extensions::Extension* extension) {
window_ =
new apps::AppWindow(profile, new ChromeAppWindowDelegate(), extension);
apps::AppWindow::CreateParams params = apps::AppWindow::CreateParams();
window_->Init(
GURL(std::string()), new apps::AppWindowContentsImpl(window_), params);
}
virtual ~V2App() {
WebContentsDestroyedWatcher destroyed_watcher(window_->web_contents());
window_->GetBaseWindow()->Close();
destroyed_watcher.Wait();
}
apps::AppWindow* window() { return window_; }
private:
apps::AppWindow* window_;
DISALLOW_COPY_AND_ASSIGN(V2App);
};
class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest
: public ChromeLauncherControllerTest {
protected:
MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest() {
}
virtual ~MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest() {
}
virtual void SetUp() OVERRIDE {
profile_manager_.reset(
new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
ASSERT_TRUE(profile_manager_->SetUp());
profile_manager_->SetLoggedIn(true);
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
user_manager_enabler_.reset(
new chromeos::ScopedUserManagerEnabler(new chromeos::FakeUserManager));
ChromeLauncherControllerTest::SetUp();
session_delegate_ = static_cast<ash::test::TestSessionStateDelegate*>(
ash::Shell::GetInstance()->session_state_delegate());
session_delegate_->set_logged_in_users(2);
shell_delegate_ = static_cast<ash::test::TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
shell_delegate_->set_multi_profiles_enabled(true);
}
virtual void TearDown() {
ChromeLauncherControllerTest::TearDown();
user_manager_enabler_.reset();
for (ProfileToNameMap::iterator it = created_profiles_.begin();
it != created_profiles_.end(); ++it)
profile_manager_->DeleteTestingProfile(it->second);
base::MessageLoop::current()->PostTask(FROM_HERE,
base::MessageLoop::QuitClosure());
base::MessageLoop::current()->Run();
}
TestingProfile* CreateMultiUserProfile(const std::string& user_name) {
std::string email_string = user_name + "@example.com";
GetFakeUserManager()->AddUser(email_string);
GetFakeUserManager()->UserLoggedIn(
email_string,
email_string + kUserIdHashSuffix,
false);
std::string profile_name =
chrome::kProfileDirPrefix + email_string + kUserIdHashSuffix;
TestingProfile* profile = profile_manager()->CreateTestingProfile(
profile_name,
scoped_ptr<PrefServiceSyncable>(),
ASCIIToUTF16(email_string), 0, std::string(),
TestingProfile::TestingFactories());
profile->set_profile_name(email_string);
EXPECT_TRUE(profile);
created_profiles_[profile] = profile_name;
if (chrome::MultiUserWindowManager::GetInstance())
chrome::MultiUserWindowManager::GetInstance()->AddUser(profile);
if (launcher_controller_)
launcher_controller_->AdditionalUserAddedToSession(profile);
return profile;
}
void SwitchActiveUser(const std::string& name) {
session_delegate()->SwitchActiveUser(name);
GetFakeUserManager()->SwitchActiveUser(name);
chrome::MultiUserWindowManagerChromeOS* manager =
static_cast<chrome::MultiUserWindowManagerChromeOS*>(
chrome::MultiUserWindowManager::GetInstance());
manager->SetAnimationsForTest(true);
manager->ActiveUserChanged(name);
launcher_controller_->browser_status_monitor_for_test()->
ActiveUserChanged(name);
launcher_controller_->app_window_controller_for_test()->
ActiveUserChanged(name);
}
Browser* CreateBrowserAndTabWithProfile(Profile* profile,
const std::string& title,
const std::string& url) {
Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH);
Browser* browser = chrome::CreateBrowserWithTestWindowForParams(¶ms);
chrome::NewTab(browser);
BrowserList::SetLastActive(browser);
NavigateAndCommitActiveTabWithTitle(
browser, GURL(url), ASCIIToUTF16(title));
return browser;
}
V1App* CreateRunningV1App(Profile* profile,
const std::string& app_name,
const std::string& url) {
V1App* v1_app = new V1App(profile, app_name);
TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
app_tab_helper->SetAppID(
v1_app->browser()->tab_strip_model()->GetWebContentsAt(0),
app_name);
SetAppTabHelper(app_tab_helper);
NavigateAndCommitActiveTabWithTitle(
v1_app->browser(), GURL(url), ASCIIToUTF16(""));
return v1_app;
}
ash::test::TestSessionStateDelegate*
session_delegate() { return session_delegate_; }
ash::test::TestShellDelegate* shell_delegate() { return shell_delegate_; }
virtual TestingProfile* CreateProfile() OVERRIDE {
return CreateMultiUserProfile("user1");
}
virtual void DestroyProfile(TestingProfile* profile) OVERRIDE {
ProfileToNameMap::iterator it = created_profiles_.find(profile);
DCHECK(it != created_profiles_.end());
profile_manager_->DeleteTestingProfile(it->second);
created_profiles_.erase(it);
}
virtual views::ViewsDelegate* CreateViewsDelegate() OVERRIDE {
return new TestViewsDelegateWithParent;
}
private:
typedef std::map<Profile*, std::string> ProfileToNameMap;
TestingProfileManager* profile_manager() { return profile_manager_.get(); }
chromeos::FakeUserManager* GetFakeUserManager() {
return static_cast<chromeos::FakeUserManager*>(
chromeos::UserManager::Get());
}
scoped_ptr<TestingProfileManager> profile_manager_;
scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
ash::test::TestSessionStateDelegate* session_delegate_;
ash::test::TestShellDelegate* shell_delegate_;
ProfileToNameMap created_profiles_;
DISALLOW_COPY_AND_ASSIGN(
MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest);
};
#endif
TEST_F(LegacyShelfLayoutChromeLauncherControllerTest, DefaultApps) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
}
TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
RestoreDefaultAppsReverseOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
ash::ShelfItem item;
extension_service_->AddExtension(extension3_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_EQ("Chrome, App2, App3, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
}
TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
RestoreDefaultAppsRandomOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, App1, App2, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
}
TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
RestoreDefaultAppsRandomOrderChromeMoved) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
ash::ShelfItem item;
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("App1, Chrome, App2, AppList", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("App1, Chrome, App2, App3, AppList", GetPinnedAppStatus());
}
TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
RestoreDefaultAppsResyncOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
extension_service_->AddExtension(extension2_.get());
extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
base::ListValue policy_value1;
InsertPrefValue(&policy_value1, 0, extension3_->id());
InsertPrefValue(&policy_value1, 1, extension1_->id());
InsertPrefValue(&policy_value1, 2, extension2_->id());
profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
2);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value1.DeepCopy());
EXPECT_EQ("App3, App1, Chrome, App2, AppList", GetPinnedAppStatus());
base::ListValue policy_value2;
InsertPrefValue(&policy_value2, 0, extension2_->id());
InsertPrefValue(&policy_value2, 1, extension3_->id());
InsertPrefValue(&policy_value2, 2, extension1_->id());
profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value2.DeepCopy());
EXPECT_EQ("App2, Chrome, App3, App1, AppList", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, DefaultApps) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
}
TEST_F(ChromeLauncherControllerTest,
SwitchingFromAlternateShelfLayoutToLegacyAndBack) {
InitLauncherController();
const char kAppShelfIdPlaceholder[] = "AppShelfIDPlaceholder--------";
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, kAppShelfIdPlaceholder);
InsertPrefValue(&policy_value, 2, extension2_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension2_.get());
EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
SetShelfChromeIconIndex(0);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
ash::ShelfItem item;
extension_service_->AddExtension(extension3_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_EQ("AppList, Chrome, App2, App3", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
SetShelfChromeIconIndex(0);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
SetShelfChromeIconIndex(1);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
ash::ShelfItem item;
extension_service_->AddExtension(extension2_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) {
InitLauncherController();
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
InsertPrefValue(&policy_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
SetShelfChromeIconIndex(0);
extension_service_->AddExtension(extension2_.get());
EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension1_.get());
EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, Chrome, App1, App2, App3", GetPinnedAppStatus());
base::ListValue policy_value1;
InsertPrefValue(&policy_value1, 0, extension3_->id());
InsertPrefValue(&policy_value1, 1, extension1_->id());
InsertPrefValue(&policy_value1, 2, extension2_->id());
SetShelfChromeIconIndex(3);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value1.DeepCopy());
EXPECT_EQ("AppList, App3, App1, App2, Chrome", GetPinnedAppStatus());
base::ListValue policy_value2;
InsertPrefValue(&policy_value2, 0, extension2_->id());
InsertPrefValue(&policy_value2, 1, extension3_->id());
InsertPrefValue(&policy_value2, 2, extension1_->id());
SetShelfChromeIconIndex(2);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value2.DeepCopy());
EXPECT_EQ("AppList, App2, App3, Chrome, App1", GetPinnedAppStatus());
SetShelfChromeIconIndex(0);
base::ListValue policy_value3;
InsertPrefValue(&policy_value3, 0, extension3_->id());
InsertPrefValue(&policy_value3, 1, extension2_->id());
InsertPrefValue(&policy_value3, 2, extension1_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value3.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
extension_service_->UnloadExtension(extension1_->id(),
UnloadedExtensionInfo::REASON_UNINSTALL);
EXPECT_EQ("AppList, Chrome, App3, App2", GetPinnedAppStatus());
extension_service_->UnloadExtension(extension2_->id(),
UnloadedExtensionInfo::REASON_UNINSTALL);
EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
extension_service_->UnloadExtension(extension3_->id(),
UnloadedExtensionInfo::REASON_UPDATE);
EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, CheckLockApps) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension2_->id()));
launcher_controller_->LockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension2_->id()));
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension2_->id()));
}
TEST_F(ChromeLauncherControllerTest, CheckMultiLockApps) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
for (int i = 0; i < 2; i++) {
launcher_controller_->LockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(
extension1_->id()));
}
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
}
TEST_F(ChromeLauncherControllerTest, CheckAlreadyPinnedLockApps) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
launcher_controller_->PinAppWithID(extension1_->id());
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->LockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnpinAppWithID(extension1_->id());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(ChromeLauncherControllerTest, CheckPinnedAppsStayAfterUnlock) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->PinAppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->LockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnpinAppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(2, model_->item_count());
}
#if defined(OS_CHROMEOS)
TEST_F(ChromeLauncherControllerTest, CheckRunningAppOrder) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
launcher_controller_->LockV1AppWithID(extension1_->id());
launcher_controller_->LockV1AppWithID(extension2_->id());
launcher_controller_->LockV1AppWithID(extension3_->id());
EXPECT_EQ(5, model_->item_count());
EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
const std::string& current_user_id =
multi_user_util::GetUserIDFromProfile(profile());
RememberUnpinnedRunningApplicationOrder();
model_->Move(2, 3);
EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
RestoreUnpinnedRunningApplicationOrder("second-fake-user@fake.com");
EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
RestoreUnpinnedRunningApplicationOrder(current_user_id);
EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
model_->Move(3, 4);
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus());
RestoreUnpinnedRunningApplicationOrder(current_user_id);
EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus());
launcher_controller_->UnlockV1AppWithID(extension2_->id());
RestoreUnpinnedRunningApplicationOrder(current_user_id);
EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
launcher_controller_->UnlockV1AppWithID(extension3_->id());
RestoreUnpinnedRunningApplicationOrder(current_user_id);
EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V1AppUpdateOnUserSwitch) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
{
scoped_ptr<V1App> v1_app(CreateRunningV1App(
profile(), extension_misc::kGmailAppId, gmail_url));
EXPECT_EQ(3, model_->item_count());
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(3, model_->item_count());
}
EXPECT_EQ(2, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V1AppUpdateOnUserSwitchEdgecases) {
InitLauncherController();
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
{
scoped_ptr<V1App> v1_app(CreateRunningV1App(
profile2, extension_misc::kGmailAppId, gmail_url));
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(3, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V1CloseOnVisitingDesktop) {
InitLauncherController();
chrome::MultiUserWindowManager* manager =
chrome::MultiUserWindowManager::GetInstance();
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
{
scoped_ptr<V1App> v1_app(CreateRunningV1App(
profile(),
extension_misc::kGmailAppId,
kGmailLaunchURL));
EXPECT_EQ(3, model_->item_count());
manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(),
user2);
EXPECT_EQ(3, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(2, model_->item_count());
{
scoped_ptr<V1App> v1_app(CreateRunningV1App(
profile(),
extension_misc::kGmailAppId,
kGmailLaunchURL));
EXPECT_EQ(3, model_->item_count());
}
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V1AppUpdateOnUserSwitchEdgecases2) {
InitLauncherController();
TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
SetAppTabHelper(app_tab_helper);
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
SwitchActiveUser(profile2->GetProfileName());
{
scoped_ptr<V1App> v1_app(CreateRunningV1App(
profile(), extension_misc::kGmailAppId, gmail_url));
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(3, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
v1_app.reset();
}
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
TestLauncherActivationPullsBackWindow) {
InitLauncherController();
chrome::MultiUserWindowManager* manager =
chrome::MultiUserWindowManager::GetInstance();
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
manager->AddUser(profile());
manager->AddUser(profile2);
const std::string& current_user =
multi_user_util::GetUserIDFromProfile(profile());
scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow(
Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH)));
aura::Window* window = browser_window->GetNativeWindow();
manager->SetWindowOwner(window, current_user);
launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(),
false);
EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
manager->ShowWindowForUser(window, user2);
EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user));
launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(),
false);
EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
}
#endif
TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) {
InitLauncherController();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->LockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->PinAppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnlockV1AppWithID(extension1_->id());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(
launcher_controller_->IsWindowedAppInLauncher(extension1_->id()));
launcher_controller_->UnpinAppWithID(extension1_->id());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) {
InitLauncherController();
base::ListValue policy_value0;
InsertPrefValue(&policy_value0, 0, extension1_->id());
InsertPrefValue(&policy_value0, 1, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value0.DeepCopy());
SetShelfChromeIconIndex(0);
extension_service_->AddExtension(extension1_.get());
EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
launcher_controller_->LockV1AppWithID(extension2_->id());
EXPECT_EQ("AppList, Chrome, App1, app2", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, Chrome, App1, App3, app2", GetPinnedAppStatus());
base::ListValue policy_value1;
InsertPrefValue(&policy_value1, 0, extension3_->id());
InsertPrefValue(&policy_value1, 1, extension2_->id());
InsertPrefValue(&policy_value1, 2, extension1_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value1.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
base::ListValue policy_value2;
InsertPrefValue(&policy_value2, 0, extension3_->id());
InsertPrefValue(&policy_value2, 1, extension1_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value2.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, App1, app2", GetPinnedAppStatus());
base::ListValue policy_value3;
InsertPrefValue(&policy_value3, 0, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value3.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, app2", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest,
RestoreDefaultAndRunningV2AppsResyncOrder) {
InitLauncherController();
base::ListValue policy_value0;
InsertPrefValue(&policy_value0, 0, extension1_->id());
InsertPrefValue(&policy_value0, 1, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value0.DeepCopy());
SetShelfChromeIconIndex(0);
extension_service_->AddExtension(extension1_.get());
EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
extension_service_->AddExtension(extension2_.get());
EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
CreateRunningV2App(extension2_->id());
EXPECT_EQ("AppList, Chrome, App1, *app2", GetPinnedAppStatus());
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ("AppList, Chrome, App1, App3, *app2", GetPinnedAppStatus());
base::ListValue policy_value1;
InsertPrefValue(&policy_value1, 0, extension3_->id());
InsertPrefValue(&policy_value1, 1, extension2_->id());
InsertPrefValue(&policy_value1, 2, extension1_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value1.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, App2, App1", GetPinnedAppStatus());
base::ListValue policy_value2;
InsertPrefValue(&policy_value2, 0, extension3_->id());
InsertPrefValue(&policy_value2, 1, extension1_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value2.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, App1, *app2", GetPinnedAppStatus());
base::ListValue policy_value3;
InsertPrefValue(&policy_value3, 0, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
policy_value3.DeepCopy());
EXPECT_EQ("AppList, Chrome, App3, *app2", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) {
base::ListValue user_a;
base::ListValue user_b;
SetUpMultiUserScenario(&user_a, &user_b);
SetShelfChromeIconIndex(6);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
GetPinnedAppStatus());
SetShelfChromeIconIndex(4);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_b.DeepCopy());
EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
SetShelfChromeIconIndex(8);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
GetPinnedAppStatus());
SetShelfChromeIconIndex(4);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_b.DeepCopy());
EXPECT_EQ("AppList, App7, App8, Chrome", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) {
base::ListValue user_a;
base::ListValue user_b;
SetUpMultiUserScenario(&user_a, &user_b);
CreateRunningV2App(extension1_->id());
SetShelfChromeIconIndex(6);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
GetPinnedAppStatus());
SetShelfChromeIconIndex(4);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_b.DeepCopy());
EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
SetShelfChromeIconIndex(8);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome",
GetPinnedAppStatus());
SetShelfChromeIconIndex(4);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_b.DeepCopy());
EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest,
UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) {
base::ListValue user_a;
base::ListValue user_b;
SetUpMultiUserScenario(&user_a, &user_b);
CreateRunningV2App(extension1_->id());
SetShelfChromeIconIndex(5);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
GetPinnedAppStatus());
SetShelfChromeIconIndex(4);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_b.DeepCopy());
EXPECT_EQ("AppList, App7, App8, Chrome, *app1", GetPinnedAppStatus());
SetShelfChromeIconIndex(5);
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
user_a.DeepCopy());
EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6",
GetPinnedAppStatus());
}
TEST_F(ChromeLauncherControllerTest, Policy) {
extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension3_.get());
base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id());
profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
InitLauncherController();
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
extension_service_->AddExtension(extension2_.get());
EXPECT_EQ(4, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
policy_value.Remove(0, NULL);
profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps,
policy_value.DeepCopy());
EXPECT_EQ(3, model_->item_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
}
TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
extension_service_->AddExtension(extension3_.get());
extension_service_->AddExtension(extension4_.get());
InitLauncherController();
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
extension_service_->UnloadExtension(extension3_->id(),
UnloadedExtensionInfo::REASON_UNINSTALL);
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id()));
}
TEST_F(ChromeLauncherControllerTest, PrefUpdates) {
extension_service_->AddExtension(extension2_.get());
extension_service_->AddExtension(extension3_.get());
extension_service_->AddExtension(extension4_.get());
InitLauncherController();
std::vector<std::string> expected_launchers;
std::vector<std::string> actual_launchers;
base::ListValue pref_value;
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
InsertPrefValue(&pref_value, 0, extension1_->id());
InsertPrefValue(&pref_value, 1, extension2_->id());
InsertPrefValue(&pref_value, 2, extension4_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
expected_launchers.push_back(extension2_->id());
expected_launchers.push_back(extension4_->id());
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
InsertPrefValue(&pref_value, 2, extension3_->id());
InsertPrefValue(&pref_value, 2, extension3_->id());
InsertPrefValue(&pref_value, 5, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id());
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
pref_value.Clear();
InsertPrefValue(&pref_value, 0, extension4_->id());
InsertPrefValue(&pref_value, 1, extension3_->id());
InsertPrefValue(&pref_value, 2, extension2_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
std::reverse(expected_launchers.begin(), expected_launchers.end());
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
pref_value.Clear();
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
expected_launchers.clear();
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
}
TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) {
extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension3_.get());
InitLauncherController();
base::ListValue pref_value;
InsertPrefValue(&pref_value, 0, extension1_->id());
InsertPrefValue(&pref_value, 1, extension2_->id());
InsertPrefValue(&pref_value, 2, extension3_->id());
profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
pref_value.DeepCopy());
std::vector<std::string> expected_launchers;
expected_launchers.push_back(extension1_->id());
expected_launchers.push_back(extension3_->id());
std::vector<std::string> actual_launchers;
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
extension_service_->AddExtension(extension2_.get());
expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id());
GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
EXPECT_EQ(expected_launchers, actual_launchers);
}
bool CheckMenuCreation(ChromeLauncherController* controller,
const ash::ShelfItem& item,
size_t expected_items,
base::string16 title[],
bool is_browser) {
ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0);
if (expected_items < 1 && is_browser) {
EXPECT_EQ(0u, items.size());
return items.size() == 0;
}
EXPECT_EQ(expected_items + 1, items.size());
EXPECT_FALSE(items[0]->IsEnabled());
for (size_t i = 0; i < expected_items; i++) {
EXPECT_EQ(title[i], items[1 + i]->title());
if (i == 1)
EXPECT_TRUE(items[i]->HasLeadingSeparator());
else
EXPECT_FALSE(items[i]->HasLeadingSeparator());
}
scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel(
controller->GetApplicationList(item, 0)));
int first_item = menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR ? 1 : 0;
int expected_menu_items = first_item +
(expected_items ? (expected_items + 3) : 2);
EXPECT_EQ(expected_menu_items, menu->GetItemCount());
EXPECT_FALSE(menu->IsEnabledAt(first_item));
if (expected_items) {
EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR,
menu->GetTypeAt(first_item + 1));
}
return items.size() == expected_items + 1;
}
TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) {
EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
chrome::NewTab(browser());
InitLauncherController();
ash::ShelfItem item_browser;
item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
item_browser.id =
launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 0, NULL, true));
BrowserList::SetLastActive(browser());
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
base::string16 one_menu_item[] = { title1 };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, one_menu_item, true));
Browser::CreateParams ash_params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser2(
chrome::CreateBrowserWithTestWindowForParams(&ash_params));
chrome::NewTab(browser2.get());
BrowserList::SetLastActive(browser2.get());
base::string16 title2 = ASCIIToUTF16("Test2");
NavigateAndCommitActiveTabWithTitle(browser2.get(), GURL("http://test2"),
title2);
base::string16 two_menu_items[] = {title1, title2};
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 2, two_menu_items, true));
chrome::CloseTab(browser2.get());
}
#if defined(OS_CHROMEOS)
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
BrowserMenuGenerationTwoUsers) {
InitLauncherController();
ash::ShelfItem item_browser;
item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
item_browser.id =
launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
chrome::NewTab(browser());
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 0, NULL, true));
BrowserList::SetLastActive(browser());
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
base::string16 one_menu_item1[] = { title1 };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
scoped_ptr<Browser> browser2(
CreateBrowserAndTabWithProfile(profile2, user2, "http://test2"));
base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
SwitchActiveUser(profile2->GetProfileName());
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, one_menu_item2, true));
chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
browser()->window()->GetNativeWindow(),
user2);
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, one_menu_item2, true));
chrome::CloseTab(browser2.get());
}
#endif
TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) {
EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
EXPECT_EQ(0, browser()->tab_strip_model()->count());
InitLauncherControllerWithBrowser();
EXPECT_EQ(2, model_->item_count());
EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ(3, model_->item_count());
int gmail_index = model_->ItemIndexByID(gmail_id);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
ash::ShelfItem item_browser;
item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
item_browser.id =
launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
ash::ShelfItem item_gmail;
item_gmail.type = ash::TYPE_APP_SHORTCUT;
item_gmail.id = gmail_id;
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 0, NULL, false));
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
base::string16 one_menu_item[] = { title1 };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 1, one_menu_item, false));
chrome::NewTab(browser());
base::string16 title2 = ASCIIToUTF16("Test2");
NavigateAndCommitActiveTabWithTitle(
browser(),
GURL("https://bla"),
title2);
chrome::NewTab(browser());
base::string16 title3 = ASCIIToUTF16("Test3");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title3);
base::string16 two_menu_items[] = {title1, title3};
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 2, two_menu_items, false));
base::string16 browser_menu_item[] = {title3};
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, browser_menu_item, false));
launcher_controller_->Close(item_gmail.id);
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 0, NULL, false));
base::string16 browser_menu_item2[] = { title2 };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 1, browser_menu_item2, false));
}
#if defined(OS_CHROMEOS)
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V1AppMenuGenerationTwoUsers) {
InitLauncherController();
chrome::NewTab(browser());
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ(3, model_->item_count());
int gmail_index = model_->ItemIndexByID(gmail_id);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
ash::ShelfItem item_browser;
item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
item_browser.id =
launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
ash::ShelfItem item_gmail;
item_gmail.type = ash::TYPE_APP_SHORTCUT;
item_gmail.id = gmail_id;
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 0, NULL, false));
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
base::string16 one_menu_item[] = { title1 };
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 1, one_menu_item, false));
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
SwitchActiveUser(profile2->GetProfileName());
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 0, NULL, true));
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 0, NULL, false));
chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
browser()->window()->GetNativeWindow(),
user2);
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_browser, 0, NULL, true));
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 0, NULL, false));
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V2AppHandlingTwoUsers) {
InitLauncherController();
TestingProfile* profile2 = CreateMultiUserProfile("user2");
EXPECT_EQ(2, model_->item_count());
V2App v2_app(profile(), extension1_);
EXPECT_EQ(3, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(3, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V2AppHandlingTwoUsersEdgeCases) {
InitLauncherController();
TestingProfile* profile2 = CreateMultiUserProfile("user2");
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
{
V2App v2_app(profile(), extension1_);
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(3, model_->item_count());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
EXPECT_EQ(2, model_->item_count());
SwitchActiveUser(profile()->GetProfileName());
EXPECT_EQ(2, model_->item_count());
}
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
V2AppFollowsTeleportedWindow) {
InitLauncherController();
chrome::MultiUserWindowManager* manager =
chrome::MultiUserWindowManager::GetInstance();
TestingProfile* profile1 = CreateMultiUserProfile("user-1");
TestingProfile* profile2 = CreateMultiUserProfile("user-2");
TestingProfile* profile3 = CreateMultiUserProfile("user-3");
SwitchActiveUser(profile1->GetProfileName());
V2App v2_app_1(profile1, extension1_);
EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
SwitchActiveUser(profile2->GetProfileName());
EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
V2App v2_app_2(profile1, extension1_);
EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
manager->ShowWindowForUser(v2_app_1.window()->GetNativeWindow(),
profile2->GetProfileName());
EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
V2App v2_app_3(profile1, extension1_);
EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
EXPECT_TRUE(v2_app_3.window()->GetNativeWindow()->IsVisible());
SwitchActiveUser(profile1->GetProfileName());
V2App v2_app_4(profile1, extension1_);
EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
EXPECT_TRUE(v2_app_2.window()->GetNativeWindow()->IsVisible());
EXPECT_FALSE(v2_app_3.window()->GetNativeWindow()->IsVisible());
EXPECT_TRUE(v2_app_4.window()->GetNativeWindow()->IsVisible());
SwitchActiveUser(profile3->GetProfileName());
V2App v2_app_5(profile1, extension1_);
EXPECT_FALSE(v2_app_5.window()->GetNativeWindow()->IsVisible());
SwitchActiveUser(profile1->GetProfileName());
EXPECT_TRUE(v2_app_5.window()->GetNativeWindow()->IsVisible());
}
#endif
TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) {
InitLauncherControllerWithBrowser();
GURL gmail = GURL("https://mail.google.com/mail/u");
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
chrome::NewTab(browser());
base::string16 title2 = ASCIIToUTF16("Test2");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2);
ash::ShelfItem item_gmail;
item_gmail.type = ash::TYPE_APP_SHORTCUT;
item_gmail.id = gmail_id;
base::string16 two_menu_items[] = {title1, title2};
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 2, two_menu_items, false));
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
{
scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel(
launcher_controller_->GetApplicationList(item_gmail, 0)));
int first_item =
(menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0;
menu->ActivatedAt(first_item + 3);
}
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
{
scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel(
launcher_controller_->GetApplicationList(item_gmail, 0)));
int first_item =
(menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0;
menu->ActivatedAt(first_item + 2);
}
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
}
TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) {
InitLauncherControllerWithBrowser();
GURL gmail = GURL("https://mail.google.com/mail/u");
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
base::string16 title1 = ASCIIToUTF16("Test1");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
chrome::NewTab(browser());
base::string16 title2 = ASCIIToUTF16("Test2");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2);
ash::ShelfItem item_gmail;
item_gmail.type = ash::TYPE_APP_SHORTCUT;
item_gmail.id = gmail_id;
base::string16 two_menu_items[] = {title1, title2};
EXPECT_TRUE(CheckMenuCreation(
launcher_controller_.get(), item_gmail, 2, two_menu_items, false));
int tabs = browser()->tab_strip_model()->count();
{
ChromeLauncherAppMenuItems items =
launcher_controller_->GetApplicationList(item_gmail, 0);
items[1]->Execute(0);
EXPECT_EQ(tabs, browser()->tab_strip_model()->count());
}
{
ChromeLauncherAppMenuItems items =
launcher_controller_->GetApplicationList(item_gmail, 0);
items[1]->Execute(ui::EF_SHIFT_DOWN);
EXPECT_EQ(--tabs, browser()->tab_strip_model()->count());
}
}
TEST_F(ChromeLauncherControllerTest, AppPanels) {
InitLauncherControllerWithBrowser();
EXPECT_EQ(2, model_observer_->added());
TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl();
SetAppIconLoader(app_icon_loader);
std::string app_id = extension1_->id();
AppWindowLauncherItemController* app_panel_controller =
new AppWindowLauncherItemController(
LauncherItemController::TYPE_APP_PANEL,
"id",
app_id,
launcher_controller_.get());
ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem(
app_panel_controller, app_id, ash::STATUS_RUNNING);
int panel_index = model_observer_->last_index();
EXPECT_EQ(3, model_observer_->added());
EXPECT_EQ(0, model_observer_->changed());
EXPECT_EQ(1, app_icon_loader->fetch_count());
model_observer_->clear_counts();
EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id));
app_panel_controller->set_image_set_by_controller(true);
gfx::ImageSkia image;
launcher_controller_->SetAppImage(app_id, image);
EXPECT_EQ(0, model_observer_->changed());
model_observer_->clear_counts();
AppWindowLauncherItemController* app_panel_controller2 =
new AppWindowLauncherItemController(
LauncherItemController::TYPE_APP_PANEL,
"id",
app_id,
launcher_controller_.get());
ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem(
app_panel_controller2, app_id, ash::STATUS_RUNNING);
EXPECT_EQ(panel_index, model_observer_->last_index());
EXPECT_EQ(1, model_observer_->added());
model_observer_->clear_counts();
launcher_controller_->CloseLauncherItem(shelf_id2);
launcher_controller_->CloseLauncherItem(shelf_id1);
EXPECT_EQ(2, model_observer_->removed());
}
TEST_F(ChromeLauncherControllerTest, GmailMatching) {
InitLauncherControllerWithBrowser();
chrome::NewTab(browser());
base::string16 title = ASCIIToUTF16("Test");
NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title);
content::WebContents* content =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ(3, model_->item_count());
int gmail_index = model_->ItemIndexByID(gmail_id);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
ash::ShelfItem item_gmail;
item_gmail.type = ash::TYPE_APP_SHORTCUT;
item_gmail.id = gmail_id;
EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size());
}
TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) {
InitLauncherControllerWithBrowser();
chrome::NewTab(browser());
base::string16 title = ASCIIToUTF16("Test");
NavigateAndCommitActiveTabWithTitle(browser(),
GURL(offline_gmail_url),
title);
content::WebContents* content =
browser()->tab_strip_model()->GetActiveWebContents();
ash::ShelfID gmail_id = model_->next_id();
extension_service_->AddExtension(extension3_.get());
EXPECT_EQ(3, model_->item_count());
int gmail_index = model_->ItemIndexByID(gmail_id);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
}
TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) {
InitLauncherController();
TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
SetAppTabHelper(app_tab_helper);
EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type);
TabStripModel* tab_strip_model = browser()->tab_strip_model();
EXPECT_EQ(0, tab_strip_model->count());
chrome::NewTab(browser());
chrome::NewTab(browser());
EXPECT_EQ(2, tab_strip_model->count());
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
EXPECT_FALSE(launcher_controller_->IsAppPinned("1"));
launcher_controller_->PinAppWithID("1");
EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
launcher_controller_->PinAppWithID("2");
EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[3].type);
model_->Move(1, 3);
EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type);
launcher_controller_.reset();
if (!ash::Shell::HasInstance()) {
delete item_delegate_manager_;
} else {
ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
test.RemoveAllShelfItemDelegateForTest();
}
model_.reset(new ash::ShelfModel);
AddAppListLauncherItem();
launcher_controller_.reset(
ChromeLauncherController::CreateInstance(profile(), model_.get()));
app_tab_helper = new TestAppTabHelperImpl;
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
SetAppTabHelper(app_tab_helper);
if (!ash::Shell::HasInstance()) {
item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
SetShelfItemDelegateManager(item_delegate_manager_);
}
launcher_controller_->Init();
EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type);
}
TEST_F(ChromeLauncherControllerTest, PersistPinned) {
InitLauncherControllerWithBrowser();
size_t initial_size = model_->items().size();
TabStripModel* tab_strip_model = browser()->tab_strip_model();
EXPECT_EQ(1, tab_strip_model->count());
TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
SetAppTabHelper(app_tab_helper);
TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl;
SetAppIconLoader(app_icon_loader);
EXPECT_EQ(0, app_icon_loader->fetch_count());
launcher_controller_->PinAppWithID("1");
ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1");
int app_index = model_->ItemIndexByID(id);
EXPECT_EQ(1, app_icon_loader->fetch_count());
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
EXPECT_EQ(initial_size + 1, model_->items().size());
launcher_controller_.reset();
if (!ash::Shell::HasInstance()) {
delete item_delegate_manager_;
} else {
ash::test::ShelfItemDelegateManagerTestAPI test(item_delegate_manager_);
test.RemoveAllShelfItemDelegateForTest();
}
model_.reset(new ash::ShelfModel);
AddAppListLauncherItem();
launcher_controller_.reset(
ChromeLauncherController::CreateInstance(profile(), model_.get()));
app_tab_helper = new TestAppTabHelperImpl;
app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
SetAppTabHelper(app_tab_helper);
app_icon_loader = new TestAppIconLoaderImpl;
SetAppIconLoader(app_icon_loader);
if (!ash::Shell::HasInstance()) {
item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
SetShelfItemDelegateManager(item_delegate_manager_);
}
launcher_controller_->Init();
EXPECT_EQ(1, app_icon_loader->fetch_count());
ASSERT_EQ(initial_size + 1, model_->items().size());
EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
launcher_controller_->UnpinAppWithID("1");
ASSERT_EQ(initial_size, model_->items().size());
}