Chromium Code Reviews| Index: chrome/browser/ui/browser_browsertest.cc |
| diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc |
| index c4f0a0eda571f15dcf02f685574425c31652d7c6..826dc2cd64b769382edf4a52a5a741aed6aa5bc0 100644 |
| --- a/chrome/browser/ui/browser_browsertest.cc |
| +++ b/chrome/browser/ui/browser_browsertest.cc |
| @@ -88,8 +88,19 @@ |
| #endif |
| #if defined(OS_WIN) |
| +#include <shlobj.h> // Must be before propkey. |
| +#include <propkey.h> |
| +#include <shellapi.h> |
| + |
| #include "base/i18n/rtl.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_shortcut_manager_win.h" |
| +#include "chrome/browser/profiles/profiles_state.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "ui/views/win/hwnd_util.h" |
| #endif |
| using content::InterstitialPage; |
| @@ -326,6 +337,62 @@ class RenderViewSizeObserver : public content::WebContentsObserver { |
| DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); |
| }; |
| +#if defined(OS_WIN) |
|
gab
2013/10/17 15:13:31
Wait... isn't this part of the other change you're
calamity
2013/11/20 05:43:30
Removed.
|
| + |
| +// An observer that returns back to test code after a new profile is |
| +// initialized. |
| +void UnblockOnProfileCreation(Profile* profile, |
| + Profile::CreateStatus status) { |
| + if (status == Profile::CREATE_STATUS_INITIALIZED) |
| + base::MessageLoop::current()->Quit(); |
| +} |
| + |
| +// Checks that the relaunch name, relaunch command and app icon for the given |
| +// |browser| are correct. |
| +void ValidateBrowserWindowProperties( |
| + 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; |
| + // The relaunch name should be of the form "Chromium" if there is only 1 |
| + // profile and "First User - Chromium" if there are more. The expected value |
| + // is given by |expected_profile_name|. |
| + 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::GetShortcutFilenameForProfile( |
| + expected_profile_name, |
| + BrowserDistribution::GetDistribution())).RemoveExtension().value(), |
| + prop_var.get().pwszVal); |
| + prop_var.Reset(); |
| + |
| + // The relaunch command should specify the profile. |
| + 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(); |
| + |
| + // The app icon should be set to the profile icon. |
| + EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, |
| + prop_var.Receive())); |
| + EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); |
| + EXPECT_EQ(profiles::GetProfileIconPath(browser->profile()->GetPath()).value(), |
| + prop_var.get().pwszVal); |
| + prop_var.Reset(); |
| +} |
| + |
| +#endif |
| + |
| } // namespace |
| class BrowserTest : public ExtensionBrowserTest { |
| @@ -2509,3 +2576,53 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_GetSizeForNewRenderView) { |
| web_contents->GetRenderWidgetHostView()->GetViewBounds().size()); |
| EXPECT_EQ(wcv_commit_size2, web_contents->GetView()->GetContainerSize()); |
| } |
| + |
| +#if defined(OS_WIN) |
| + |
| +// Check that the window properties on Windows are properly set. |
| +IN_PROC_BROWSER_TEST_F(BrowserTest, WindowProperties) { |
| +#if defined(USE_ASH) |
| + // Disable this test in Metro+Ash where Windows window properties aren't used. |
| + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| + return; |
| +#endif |
| + |
| + // This test checks HWND properties that are only available on Win7+. |
| + if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| + return; |
| + |
| + // Single profile case. The profile name should not be shown. |
| + ValidateBrowserWindowProperties(browser(), base::string16()); |
| + |
| + // If multiprofile mode is not enabled, we can't test the behavior when there |
| + // are multiple profiles. |
| + if (!profiles::IsMultipleProfilesEnabled()) |
| + return; |
| + |
| + // Two profile case. Both profile names should be shown. |
| + 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), |
| + string16(), string16(), std::string()); |
| + |
| + // Spin to allow profile creation to take place, loop is terminated |
| + // by UnblockOnProfileCreation when the profile is created. |
| + content::RunMessageLoop(); |
| + |
| + // The default profile's name should be part of the relaunch name. |
| + ValidateBrowserWindowProperties( |
| + browser(), UTF8ToUTF16(browser()->profile()->GetProfileName())); |
| + |
| + // The second profile's name should be part of the relaunch name. |
| + Browser* profile2_browser = |
| + CreateBrowser(profile_manager->GetProfileByPath(path_profile2)); |
| + size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2); |
| + ValidateBrowserWindowProperties( |
| + profile2_browser, cache.GetNameOfProfileAtIndex(profile2_index)); |
| +} |
| + |
| +#endif |