Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/ui/views/frame/browser_window_property_manager_browsertest_win.cc

Issue 298003005: Revert of Support "Pin to taskbar" for hosted app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
19 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_info_cache.h" 19 #include "chrome/browser/profiles/profile_info_cache.h"
21 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" 21 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
23 #include "chrome/browser/profiles/profiles_state.h" 22 #include "chrome/browser/profiles/profiles_state.h"
24 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_iterator.h"
27 #include "chrome/browser/ui/browser_window.h" 24 #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"
31 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/extension_constants.h"
33 #include "chrome/installer/util/browser_distribution.h" 26 #include "chrome/installer/util/browser_distribution.h"
34 #include "chrome/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
35 #include "chrome/test/base/test_switches.h" 28 #include "chrome/test/base/test_switches.h"
36 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
37 #include "extensions/common/extension.h"
38 #include "ui/views/win/hwnd_util.h" 30 #include "ui/views/win/hwnd_util.h"
39 31
40 typedef ExtensionBrowserTest BrowserWindowPropertyManagerTest;
41
42 namespace { 32 namespace {
43 33
44 // An observer that resumes test code after a new profile is initialized by 34 // An observer that resumes test code after a new profile is initialized by
45 // quitting the message loop it's blocked on. 35 // quitting the message loop it's blocked on.
46 void UnblockOnProfileCreation(Profile* profile, 36 void UnblockOnProfileCreation(Profile* profile,
47 Profile::CreateStatus status) { 37 Profile::CreateStatus status) {
48 if (status == Profile::CREATE_STATUS_INITIALIZED) 38 if (status == Profile::CREATE_STATUS_INITIALIZED)
49 base::MessageLoop::current()->Quit(); 39 base::MessageLoop::current()->Quit();
50 } 40 }
51 41
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 76
87 // The app icon should be set to the profile icon. 77 // The app icon should be set to the profile icon.
88 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource, 78 EXPECT_EQ(S_OK, pps->GetValue(PKEY_AppUserModel_RelaunchIconResource,
89 prop_var.Receive())); 79 prop_var.Receive()));
90 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt); 80 EXPECT_EQ(VT_LPWSTR, prop_var.get().vt);
91 EXPECT_EQ(profiles::internal::GetProfileIconPath( 81 EXPECT_EQ(profiles::internal::GetProfileIconPath(
92 browser->profile()->GetPath()).value(), 82 browser->profile()->GetPath()).value(),
93 prop_var.get().pwszVal); 83 prop_var.get().pwszVal);
94 prop_var.Reset(); 84 prop_var.Reset();
95 base::MessageLoop::current()->Quit(); 85 base::MessageLoop::current()->Quit();
96 }
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 } 86 }
141 87
142 void PostValidationTaskToUIThread(const base::Closure& validation_task) { 88 void PostValidationTaskToUIThread(const base::Closure& validation_task) {
143 content::BrowserThread::PostTask( 89 content::BrowserThread::PostTask(
144 content::BrowserThread::UI, FROM_HERE, validation_task); 90 content::BrowserThread::UI, FROM_HERE, validation_task);
145 } 91 }
146 92
147 // Posts a validation task to the FILE thread which bounces back to the UI 93 // Posts a validation task to the FILE thread which bounces back to the UI
148 // thread and then does validation. This is necessary because the icon profile 94 // thread and then does validation. This is necessary because the icon profile
149 // pref only gets set at the end of icon creation (which happens on the FILE 95 // pref only gets set at the end of icon creation (which happens on the FILE
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 164
219 // The second profile's name should be part of the relaunch name. 165 // The second profile's name should be part of the relaunch name.
220 Browser* profile2_browser = 166 Browser* profile2_browser =
221 CreateBrowser(profile_manager->GetProfileByPath(path_profile2)); 167 CreateBrowser(profile_manager->GetProfileByPath(path_profile2));
222 size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2); 168 size_t profile2_index = cache.GetIndexOfProfileWithPath(path_profile2);
223 WaitAndValidateBrowserWindowProperties( 169 WaitAndValidateBrowserWindowProperties(
224 base::Bind(&ValidateBrowserWindowProperties, 170 base::Bind(&ValidateBrowserWindowProperties,
225 profile2_browser, 171 profile2_browser,
226 cache.GetNameOfProfileAtIndex(profile2_index))); 172 cache.GetNameOfProfileAtIndex(profile2_index)));
227 } 173 }
228
229 IN_PROC_BROWSER_TEST_F(BrowserWindowPropertyManagerTest, HostedApp) {
230 // Load an app.
231 const extensions::Extension* extension =
232 LoadExtension(test_data_dir_.AppendASCII("app/"));
233 EXPECT_TRUE(extension);
234
235 OpenApplication(AppLaunchParams(browser()->profile(),
236 extension,
237 extensions::LAUNCH_CONTAINER_WINDOW,
238 NEW_FOREGROUND_TAB));
239
240 // Check that the new browser has an app name.
241 // The launch should have created a new browser.
242 ASSERT_EQ(2u,
243 chrome::GetBrowserCount(browser()->profile(),
244 browser()->host_desktop_type()));
245
246 // Find the new browser.
247 Browser* app_browser = NULL;
248 for (chrome::BrowserIterator it; !it.done() && !app_browser; it.Next()) {
249 if (*it != browser())
250 app_browser = *it;
251 }
252 ASSERT_TRUE(app_browser);
253 ASSERT_TRUE(app_browser != browser());
254
255 WaitAndValidateBrowserWindowProperties(
256 base::Bind(&ValidateHostedAppWindowProperties, app_browser, extension));
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698