NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_window_property_manager_browsertest_win.cc
blob41cbd3c3b1d3e4318e63908bd8dea5c5464424df
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
7 #include <shlobj.h> // Must be before propkey.
8 #include <propkey.h>
9 #include <shellapi.h>
11 #include "base/command_line.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_propvariant.h"
16 #include "base/win/windows_version.h"
17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_info_cache.h"
20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
22 #include "chrome/browser/profiles/profiles_state.h"
23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/installer/util/browser_distribution.h"
27 #include "chrome/test/base/in_process_browser_test.h"
28 #include "chrome/test/base/test_switches.h"
29 #include "content/public/test/test_utils.h"
30 #include "ui/views/win/hwnd_util.h"
32 namespace {
34 // An observer that resumes test code after a new profile is initialized by
35 // quitting the message loop it's blocked on.
36 void UnblockOnProfileCreation(Profile* profile,
37 Profile::CreateStatus status) {
38 if (status == Profile::CREATE_STATUS_INITIALIZED)
39 base::MessageLoop::current()->Quit();
42 // Checks that the relaunch name, relaunch command and app icon for the given
43 // |browser| are correct.
44 void ValidateBrowserWindowProperties(
45 const Browser* browser,
46 const base::string16& expected_profile_name) {
47 HWND hwnd = views::HWNDForNativeWindow(browser->window()->GetNativeWindow());
49 base::win::ScopedComPtr<IPropertyStore> pps;
50 HRESULT result = SHGetPropertyStoreForWindow(hwnd, IID_IPropertyStore,
51 pps.ReceiveVoid());
52 EXPECT_TRUE(SUCCEEDED(result));
54 base::win::ScopedPropVariant prop_var;
55 // The relaunch name should be of the form "Chromium" if there is only 1
56 // profile and "First User - Chromium" if there are more. The expected value
57 // is given by |expected_profile_name|.
58 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchDisplayNameResource,
59 prop_var.Receive()));
60 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
61 EXPECT_EQ(
62 base::FilePath(profiles::internal::GetShortcutFilenameForProfile(
63 expected_profile_name,
64 BrowserDistribution::GetDistribution())).RemoveExtension().value(),
65 prop_var.get().pwszVal);
66 prop_var.Reset();
68 // The relaunch command should specify the profile.
69 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchCommand,
70 prop_var.Receive()));
71 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
72 CommandLine cmd_line(CommandLine::FromString(prop_var.get().pwszVal));
73 EXPECT_EQ(browser->profile()->GetPath().BaseName().value(),
74 cmd_line.GetSwitchValueNative(switches::kProfileDirectory));
75 prop_var.Reset();
77 // The app icon should be set to the profile icon.
78 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource,
79 prop_var.Receive()));
80 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
81 EXPECT_EQ(profiles::internal::GetProfileIconPath(
82 browser->profile()->GetPath()).value(),
83 prop_var.get().pwszVal);
84 prop_var.Reset();
87 } // namespace
89 // Tests that require the profile shortcut manager to be instantiated despite
90 // having --user-data-dir specified.
91 class BrowserTestWithProfileShortcutManager : public InProcessBrowserTest {
92 public:
93 BrowserTestWithProfileShortcutManager() {}
95 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
96 command_line->AppendSwitch(switches::kEnableProfileShortcutManager);
99 private:
100 DISALLOW_COPY_AND_ASSIGN(BrowserTestWithProfileShortcutManager);
103 // Test is flaky on Win7 bots. See crbug.com/332628.
104 // Check that the window properties on Windows are properly set.
105 IN_PROC_BROWSER_TEST_F(BrowserTestWithProfileShortcutManager,
106 DISABLED_WindowProperties) {
107 #if defined(USE_ASH)
108 // Disable this test in Metro+Ash where Windows window properties aren't used.
109 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
110 return;
111 #endif
113 // This test checks HWND properties that are only available on Win7+.
114 if (base::win::GetVersion() < base::win::VERSION_WIN7)
115 return;
117 // Single profile case. The profile name should not be shown.
118 ValidateBrowserWindowProperties(browser(), base::string16());
120 // If multiprofile mode is not enabled, we can't test the behavior when there
121 // are multiple profiles.
122 if (!profiles::IsMultipleProfilesEnabled())
123 return;
125 // Two profile case. Both profile names should be shown.
126 ProfileManager* profile_manager = g_browser_process->profile_manager();
127 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
129 base::FilePath path_profile2 =
130 profile_manager->GenerateNextProfileDirectoryPath();
131 profile_manager->CreateProfileAsync(path_profile2,
132 base::Bind(&UnblockOnProfileCreation),
133 base::string16(), base::string16(),
134 std::string());
136 // Spin to allow profile creation to take place, loop is terminated
137 // by UnblockOnProfileCreation when the profile is created.
138 content::RunMessageLoop();
140 // The default profile's name should be part of the relaunch name.
141 ValidateBrowserWindowProperties(
142 browser(), base::UTF8ToUTF16(browser()->profile()->GetProfileName()));
144 // The second profile's name should be part of the relaunch name.
145 Browser* profile2_browser =
146 CreateBrowser(profile_manager->GetProfileByPath(path_profile2));
147 size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2);
148 ValidateBrowserWindowProperties(
149 profile2_browser, cache.GetNameOfProfileAtIndex(profile2_index));