OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include <shlobj.h> // Must be before propkey. | 7 #include <shlobj.h> // Must be before propkey. |
8 #include <propkey.h> | 8 #include <propkey.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
15 #include "base/win/scoped_propvariant.h" | 15 #include "base/win/scoped_propvariant.h" |
16 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/extensions/extension_browsertest.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" | 22 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" |
22 #include "chrome/browser/profiles/profiles_state.h" | 23 #include "chrome/browser/profiles/profiles_state.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_iterator.h" |
24 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/extensions/application_launch.h" |
| 29 #include "chrome/browser/web_applications/web_app.h" |
| 30 #include "chrome/browser/web_applications/web_app_win.h" |
25 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/extensions/extension_constants.h" |
26 #include "chrome/installer/util/browser_distribution.h" | 33 #include "chrome/installer/util/browser_distribution.h" |
27 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
28 #include "chrome/test/base/test_switches.h" | 35 #include "chrome/test/base/test_switches.h" |
29 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
| 37 #include "extensions/common/extension.h" |
30 #include "ui/views/win/hwnd_util.h" | 38 #include "ui/views/win/hwnd_util.h" |
31 | 39 |
| 40 typedef ExtensionBrowserTest BrowserWindowPropertyManagerTest; |
| 41 |
32 namespace { | 42 namespace { |
33 | 43 |
34 // An observer that resumes test code after a new profile is initialized by | 44 // An observer that resumes test code after a new profile is initialized by |
35 // quitting the message loop it's blocked on. | 45 // quitting the message loop it's blocked on. |
36 void UnblockOnProfileCreation(Profile* profile, | 46 void UnblockOnProfileCreation(Profile* profile, |
37 Profile::CreateStatus status) { | 47 Profile::CreateStatus status) { |
38 if (status == Profile::CREATE_STATUS_INITIALIZED) | 48 if (status == Profile::CREATE_STATUS_INITIALIZED) |
39 base::MessageLoop::current()->Quit(); | 49 base::MessageLoop::current()->Quit(); |
40 } | 50 } |
41 | 51 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, | 88 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, |
79 prop_var.Receive())); | 89 prop_var.Receive())); |
80 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); | 90 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); |
81 EXPECT_EQ(profiles::internal::GetProfileIconPath( | 91 EXPECT_EQ(profiles::internal::GetProfileIconPath( |
82 browser->profile()->GetPath()).value(), | 92 browser->profile()->GetPath()).value(), |
83 prop_var.get().pwszVal); | 93 prop_var.get().pwszVal); |
84 prop_var.Reset(); | 94 prop_var.Reset(); |
85 base::MessageLoop::current()->Quit(); | 95 base::MessageLoop::current()->Quit(); |
86 } | 96 } |
87 | 97 |
| 98 void ValidateHostedAppWindowProperties(const Browser* browser, |
| 99 const extensions::Extension* extension) { |
| 100 HWND hwnd = views::HWNDForNativeWindow(browser->window()->GetNativeWindow()); |
| 101 |
| 102 base::win::ScopedComPtr<IPropertyStore> pps; |
| 103 HRESULT result = |
| 104 SHGetPropertyStoreForWindow(hwnd, IID_IPropertyStore, pps.ReceiveVoid()); |
| 105 EXPECT_TRUE(SUCCEEDED(result)); |
| 106 |
| 107 base::win::ScopedPropVariant prop_var; |
| 108 // The relaunch name should be the extension name. |
| 109 EXPECT_EQ(S_OK, |
| 110 pps->GetValue(PKEY_AppUserModel_RelaunchDisplayNameResource, |
| 111 prop_var.Receive())); |
| 112 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); |
| 113 EXPECT_EQ(base::UTF8ToWide(extension->name()), prop_var.get().pwszVal); |
| 114 prop_var.Reset(); |
| 115 |
| 116 // The relaunch command should specify the profile and the app id. |
| 117 EXPECT_EQ( |
| 118 S_OK, |
| 119 pps->GetValue(PKEY_AppUserModel_RelaunchCommand, prop_var.Receive())); |
| 120 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); |
| 121 CommandLine cmd_line(CommandLine::FromString(prop_var.get().pwszVal)); |
| 122 EXPECT_EQ(browser->profile()->GetPath().BaseName().value(), |
| 123 cmd_line.GetSwitchValueNative(switches::kProfileDirectory)); |
| 124 EXPECT_EQ(base::UTF8ToWide(extension->id()), |
| 125 cmd_line.GetSwitchValueNative(switches::kAppId)); |
| 126 prop_var.Reset(); |
| 127 |
| 128 // The app icon should be set to the extension app icon. |
| 129 base::FilePath web_app_dir = web_app::GetWebAppDataDirectory( |
| 130 browser->profile()->GetPath(), extension->id(), GURL()); |
| 131 EXPECT_EQ(S_OK, |
| 132 pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, |
| 133 prop_var.Receive())); |
| 134 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); |
| 135 EXPECT_EQ(web_app::internals::GetIconFilePath( |
| 136 web_app_dir, base::UTF8ToUTF16(extension->name())).value(), |
| 137 prop_var.get().pwszVal); |
| 138 prop_var.Reset(); |
| 139 base::MessageLoop::current()->Quit(); |
| 140 } |
| 141 |
88 void PostValidationTaskToUIThread(const base::Closure& validation_task) { | 142 void PostValidationTaskToUIThread(const base::Closure& validation_task) { |
89 content::BrowserThread::PostTask( | 143 content::BrowserThread::PostTask( |
90 content::BrowserThread::UI, FROM_HERE, validation_task); | 144 content::BrowserThread::UI, FROM_HERE, validation_task); |
91 } | 145 } |
92 | 146 |
93 // Posts a validation task to the FILE thread which bounces back to the UI | 147 // Posts a validation task to the FILE thread which bounces back to the UI |
94 // thread and then does validation. This is necessary because the icon profile | 148 // thread and then does validation. This is necessary because the icon profile |
95 // pref only gets set at the end of icon creation (which happens on the FILE | 149 // pref only gets set at the end of icon creation (which happens on the FILE |
96 // thread) and is set on the UI thread. | 150 // thread) and is set on the UI thread. |
97 void WaitAndValidateBrowserWindowProperties( | 151 void WaitAndValidateBrowserWindowProperties( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 218 |
165 // The second profile's name should be part of the relaunch name. | 219 // The second profile's name should be part of the relaunch name. |
166 Browser* profile2_browser = | 220 Browser* profile2_browser = |
167 CreateBrowser(profile_manager->GetProfileByPath(path_profile2)); | 221 CreateBrowser(profile_manager->GetProfileByPath(path_profile2)); |
168 size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2); | 222 size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2); |
169 WaitAndValidateBrowserWindowProperties( | 223 WaitAndValidateBrowserWindowProperties( |
170 base::Bind(&ValidateBrowserWindowProperties, | 224 base::Bind(&ValidateBrowserWindowProperties, |
171 profile2_browser, | 225 profile2_browser, |
172 cache.GetNameOfProfileAtIndex(profile2_index))); | 226 cache.GetNameOfProfileAtIndex(profile2_index))); |
173 } | 227 } |
| 228 |
| 229 IN_PROC_BROWSER_TEST_F(BrowserWindowPropertyManagerTest, HostedApp) { |
| 230 #if defined(USE_ASH) |
| 231 // Disable this test in Metro+Ash where Windows window properties aren't used. |
| 232 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 233 return; |
| 234 #endif |
| 235 |
| 236 // This test checks HWND properties that are only available on Win7+. |
| 237 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 238 return; |
| 239 |
| 240 // Load an app. |
| 241 const extensions::Extension* extension = |
| 242 LoadExtension(test_data_dir_.AppendASCII("app/")); |
| 243 EXPECT_TRUE(extension); |
| 244 |
| 245 OpenApplication(AppLaunchParams(browser()->profile(), |
| 246 extension, |
| 247 extensions::LAUNCH_CONTAINER_WINDOW, |
| 248 NEW_FOREGROUND_TAB)); |
| 249 |
| 250 // Check that the new browser has an app name. |
| 251 // The launch should have created a new browser. |
| 252 ASSERT_EQ(2u, |
| 253 chrome::GetBrowserCount(browser()->profile(), |
| 254 browser()->host_desktop_type())); |
| 255 |
| 256 // Find the new browser. |
| 257 Browser* app_browser = NULL; |
| 258 for (chrome::BrowserIterator it; !it.done() && !app_browser; it.Next()) { |
| 259 if (*it != browser()) |
| 260 app_browser = *it; |
| 261 } |
| 262 ASSERT_TRUE(app_browser); |
| 263 ASSERT_TRUE(app_browser != browser()); |
| 264 |
| 265 WaitAndValidateBrowserWindowProperties( |
| 266 base::Bind(&ValidateHostedAppWindowProperties, app_browser, extension)); |
| 267 } |
OLD | NEW |