This source file includes following definitions.
- UnblockOnProfileCreation
- ValidateBrowserWindowProperties
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
#include <string>
#include <shlobj.h>
#include <propkey.h>
#include <shellapi.h>
#include "base/command_line.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_propvariant.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_shortcut_manager_win.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "content/public/test/test_utils.h"
#include "ui/views/win/hwnd_util.h"
namespace {
void UnblockOnProfileCreation(Profile* profile,
Profile::CreateStatus status) {
if (status == Profile::CREATE_STATUS_INITIALIZED)
base::MessageLoop::current()->Quit();
}
void ValidateBrowserWindowProperties(
const Browser* browser,
const base::string16& expected_profile_name) {
HWND hwnd = views::HWNDForNativeWindow(browser->window()->GetNativeWindow());
base::win::ScopedComPtr<IPropertyStore> pps;
HRESULT result = SHGetPropertyStoreForWindow(hwnd, IID_IPropertyStore,
pps.ReceiveVoid());
EXPECT_TRUE(SUCCEEDED(result));
base::win::ScopedPropVariant prop_var;
EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchDisplayNameResource,
prop_var.Receive()));
EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
EXPECT_EQ(
base::FilePath(profiles::internal::GetShortcutFilenameForProfile(
expected_profile_name,
BrowserDistribution::GetDistribution())).RemoveExtension().value(),
prop_var.get().pwszVal);
prop_var.Reset();
EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchCommand,
prop_var.Receive()));
EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
CommandLine cmd_line(CommandLine::FromString(prop_var.get().pwszVal));
EXPECT_EQ(browser->profile()->GetPath().BaseName().value(),
cmd_line.GetSwitchValueNative(switches::kProfileDirectory));
prop_var.Reset();
EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource,
prop_var.Receive()));
EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
EXPECT_EQ(profiles::internal::GetProfileIconPath(
browser->profile()->GetPath()).value(),
prop_var.get().pwszVal);
prop_var.Reset();
}
}
class BrowserTestWithProfileShortcutManager : public InProcessBrowserTest {
public:
BrowserTestWithProfileShortcutManager() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kEnableProfileShortcutManager);
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserTestWithProfileShortcutManager);
};
IN_PROC_BROWSER_TEST_F(BrowserTestWithProfileShortcutManager,
DISABLED_WindowProperties) {
#if defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
ValidateBrowserWindowProperties(browser(), base::string16());
if (!profiles::IsMultipleProfilesEnabled())
return;
ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
base::FilePath path_profile2 =
profile_manager->GenerateNextProfileDirectoryPath();
profile_manager->CreateProfileAsync(path_profile2,
base::Bind(&UnblockOnProfileCreation),
base::string16(), base::string16(),
std::string());
content::RunMessageLoop();
ValidateBrowserWindowProperties(
browser(), base::UTF8ToUTF16(browser()->profile()->GetProfileName()));
Browser* profile2_browser =
CreateBrowser(profile_manager->GetProfileByPath(path_profile2));
size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2);
ValidateBrowserWindowProperties(
profile2_browser, cache.GetNameOfProfileAtIndex(profile2_index));
}