10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file. 40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <string> 60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <shlobj.h> // Must be before propkey. 80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <propkey.h> 90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <shellapi.h> 100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/command_line.h" 120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/strings/string16.h" 130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/win/scoped_comptr.h" 150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/win/scoped_propvariant.h" 160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "base/win/windows_version.h" 170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/browser_process.h" 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/extensions/extension_browsertest.h" 190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/profiles/profile_info_cache.h" 210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/profiles/profile_shortcut_manager_win.h" 230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/profiles/profiles_state.h" 240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h" 270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h" 28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/extensions/application_launch.h" 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/web_applications/web_app.h" 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/web_applications/web_app_win.h" 310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/common/extensions/extension_constants.h" 330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h" 340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/test/base/test_switches.h" 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/test/test_utils.h" 37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "extensions/common/extension.h" 380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ui/views/win/hwnd_util.h" 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)typedef ExtensionBrowserTest BrowserWindowPropertyManagerTest; 41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace { 430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// An observer that resumes test code after a new profile is initialized by 450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// quitting the message loop it's blocked on. 460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void UnblockOnProfileCreation(Profile* profile, 470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Profile::CreateStatus status) { 480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (status == Profile::CREATE_STATUS_INITIALIZED) 490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::MessageLoop::current()->Quit(); 500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Checks that the relaunch name, relaunch command and app icon for the given 530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// |browser| are correct. 540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void ValidateBrowserWindowProperties( 550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const Browser* browser, 560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const base::string16& expected_profile_name) { 570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) HWND hwnd = views::HWNDForNativeWindow(browser->window()->GetNativeWindow()); 580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::win::ScopedComPtr<IPropertyStore> pps; 600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) HRESULT result = SHGetPropertyStoreForWindow(hwnd, IID_IPropertyStore, 610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) pps.ReceiveVoid()); 620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_TRUE(SUCCEEDED(result)); 630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::win::ScopedPropVariant prop_var; 650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The relaunch name should be of the form "Chromium" if there is only 1 660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // profile and "First User - Chromium" if there are more. The expected value 670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // is given by |expected_profile_name|. 680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchDisplayNameResource, 690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Receive())); 700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ( 720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::FilePath(profiles::internal::GetShortcutFilenameForProfile( 730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) expected_profile_name, 740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) BrowserDistribution::GetDistribution())).RemoveExtension().value(), 750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.get().pwszVal); 760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Reset(); 770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The relaunch command should specify the profile. 790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchCommand, 800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Receive())); 810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) CommandLine cmd_line(CommandLine::FromString(prop_var.get().pwszVal)); 830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(browser->profile()->GetPath().BaseName().value(), 840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) cmd_line.GetSwitchValueNative(switches::kProfileDirectory)); 850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Reset(); 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The app icon should be set to the profile icon. 880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, 890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Receive())); 900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_EQ(profiles::internal::GetProfileIconPath( 920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) browser->profile()->GetPath()).value(), 930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.get().pwszVal); 940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) prop_var.Reset(); 95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::MessageLoop::current()->Quit(); 96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void ValidateHostedAppWindowProperties(const Browser* browser, 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const extensions::Extension* extension) { 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) HWND hwnd = views::HWNDForNativeWindow(browser->window()->GetNativeWindow()); 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::win::ScopedComPtr<IPropertyStore> pps; 103cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) HRESULT result = 104cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) SHGetPropertyStoreForWindow(hwnd, IID_IPropertyStore, pps.ReceiveVoid()); 105cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_TRUE(SUCCEEDED(result)); 106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::win::ScopedPropVariant prop_var; 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // The relaunch name should be the extension name. 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(S_OK, 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) pps->GetValue(PKEY_AppUserModel_RelaunchDisplayNameResource, 111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.Receive())); 112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(base::UTF8ToWide(extension->name()), prop_var.get().pwszVal); 114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.Reset(); 115cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 116cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // The relaunch command should specify the profile and the app id. 117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ( 118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) S_OK, 119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) pps->GetValue(PKEY_AppUserModel_RelaunchCommand, prop_var.Receive())); 120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CommandLine cmd_line(CommandLine::FromString(prop_var.get().pwszVal)); 122cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(browser->profile()->GetPath().BaseName().value(), 123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) cmd_line.GetSwitchValueNative(switches::kProfileDirectory)); 124cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(base::UTF8ToWide(extension->id()), 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) cmd_line.GetSwitchValueNative(switches::kAppId)); 126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.Reset(); 127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // The app icon should be set to the extension app icon. 129cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FilePath web_app_dir = web_app::GetWebAppDataDirectory( 130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) browser->profile()->GetPath(), extension->id(), GURL()); 131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(S_OK, 132cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, 133cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.Receive())); 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 135cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(web_app::internals::GetIconFilePath( 136cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) web_app_dir, base::UTF8ToUTF16(extension->name())).value(), 137cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.get().pwszVal); 138cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prop_var.Reset(); 139cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::MessageLoop::current()->Quit(); 140cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 141cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 142010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void PostValidationTaskToUIThread(const base::Closure& validation_task) { 143010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::BrowserThread::PostTask( 144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::BrowserThread::UI, FROM_HERE, validation_task); 145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 147010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Posts a validation task to the FILE thread which bounces back to the UI 148010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// thread and then does validation. This is necessary because the icon profile 149010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// pref only gets set at the end of icon creation (which happens on the FILE 150010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// thread) and is set on the UI thread. 151010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void WaitAndValidateBrowserWindowProperties( 152010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const base::Closure& validation_task) { 153010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::BrowserThread::PostTask( 154010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::BrowserThread::FILE, 155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) FROM_HERE, 156010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::Bind(&PostValidationTaskToUIThread, validation_task)); 157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::RunMessageLoop(); 1580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace 1610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Tests that require the profile shortcut manager to be instantiated despite 1630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// having --user-data-dir specified. 1640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class BrowserTestWithProfileShortcutManager : public InProcessBrowserTest { 1650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public: 1660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) BrowserTestWithProfileShortcutManager() {} 1670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 1690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) command_line->AppendSwitch(switches::kEnableProfileShortcutManager); 1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) } 1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) private: 1730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BrowserTestWithProfileShortcutManager); 1740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}; 1750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Check that the window properties on Windows are properly set. 1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// http://crbug.com/396344 1780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(BrowserTestWithProfileShortcutManager, 1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DISABLED_WindowProperties) { 1800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Disable this test in Metro+Ash where Windows window properties aren't used. 1810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 1820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 1830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // This test checks HWND properties that are only available on Win7+. 1850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_WIN7) 1860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 1870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Single profile case. The profile name should not be shown. 189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) WaitAndValidateBrowserWindowProperties(base::Bind( 190010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) &ValidateBrowserWindowProperties, browser(), base::string16())); 1910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // If multiprofile mode is not enabled, we can't test the behavior when there 1930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // are multiple profiles. 1940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (!profiles::IsMultipleProfilesEnabled()) 1950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return; 1960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Two profile case. Both profile names should be shown. 1980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ProfileManager* profile_manager = g_browser_process->profile_manager(); 1990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::FilePath path_profile2 = 2020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profile_manager->GenerateNextProfileDirectoryPath(); 2030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profile_manager->CreateProfileAsync(path_profile2, 2040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::Bind(&UnblockOnProfileCreation), 2050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) base::string16(), base::string16(), 2060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) std::string()); 2070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Spin to allow profile creation to take place, loop is terminated 2090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // by UnblockOnProfileCreation when the profile is created. 2100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) content::RunMessageLoop(); 2110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The default profile's name should be part of the relaunch name. 213010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) WaitAndValidateBrowserWindowProperties( 214010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::Bind(&ValidateBrowserWindowProperties, 215010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) browser(), 216010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::UTF8ToUTF16(browser()->profile()->GetProfileName()))); 2170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The second profile's name should be part of the relaunch name. 2190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Browser* profile2_browser = 2200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) CreateBrowser(profile_manager->GetProfileByPath(path_profile2)); 2210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2); 222010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) WaitAndValidateBrowserWindowProperties( 223010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::Bind(&ValidateBrowserWindowProperties, 224010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) profile2_browser, 225010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cache.GetNameOfProfileAtIndex(profile2_index))); 2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 227cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 2285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// http://crbug.com/396344 2295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(BrowserWindowPropertyManagerTest, DISABLED_HostedApp) { 230cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(USE_ASH) 231cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Disable this test in Metro+Ash where Windows window properties aren't used. 232cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 233cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 234cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 235cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 236cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // This test checks HWND properties that are only available on Win7+. 237cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_WIN7) 238cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 239cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 240cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Load an app. 241cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const extensions::Extension* extension = 242cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) LoadExtension(test_data_dir_.AppendASCII("app/")); 243cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_TRUE(extension); 244cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 245cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OpenApplication(AppLaunchParams(browser()->profile(), 246cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) extension, 247cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) extensions::LAUNCH_CONTAINER_WINDOW, 248cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) NEW_FOREGROUND_TAB)); 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 250cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Check that the new browser has an app name. 251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // The launch should have created a new browser. 252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_EQ(2u, 253cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) chrome::GetBrowserCount(browser()->profile(), 254cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) browser()->host_desktop_type())); 255cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 256cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Find the new browser. 257cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Browser* app_browser = NULL; 258cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) for (chrome::BrowserIterator it; !it.done() && !app_browser; it.Next()) { 259cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (*it != browser()) 260cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) app_browser = *it; 261cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 262cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(app_browser); 263cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(app_browser != browser()); 264cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 265cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) WaitAndValidateBrowserWindowProperties( 266cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::Bind(&ValidateHostedAppWindowProperties, app_browser, extension)); 267cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 268