OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "chrome/browser/devtools/devtools_window_testing.h" | 9 #include "chrome/browser/devtools/devtools_window_testing.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_iterator.h" | 14 #include "chrome/browser/ui/browser_iterator.h" |
15 #include "chrome/browser/ui/extensions/app_launch_params.h" | 15 #include "chrome/browser/ui/extensions/app_launch_params.h" |
16 #include "chrome/browser/ui/extensions/application_launch.h" | 16 #include "chrome/browser/ui/extensions/application_launch.h" |
17 #include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h" | 17 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
27 | 27 |
28 using content::WebContents; | 28 using content::WebContents; |
29 using extensions::Extension; | 29 using extensions::Extension; |
30 | 30 |
31 typedef ExtensionBrowserTest BookmarkAppTest; | |
32 | |
33 namespace { | 31 namespace { |
34 | 32 |
35 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that | 33 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that |
36 // the location bar visibility is as expcted. | 34 // the location bar visibility is as expcted. |
37 void NavigateAndCheckForLocationBar(Browser* browser, | 35 void NavigateAndCheckForLocationBar(Browser* browser, |
38 const std::string& url_string, | 36 const std::string& url_string, |
39 bool expected_visibility) { | 37 bool expected_visibility) { |
40 GURL url(url_string); | 38 GURL url(url_string); |
41 ui_test_utils::NavigateToURL(browser, url); | 39 ui_test_utils::NavigateToURL(browser, url); |
42 EXPECT_EQ(expected_visibility, | 40 EXPECT_EQ(expected_visibility, |
43 browser->bookmark_app_controller()->ShouldShowLocationBar()); | 41 browser->hosted_app_controller()->ShouldShowLocationBar()); |
44 } | 42 } |
45 | 43 |
46 } // namespace | 44 } // namespace |
47 | 45 |
| 46 class HostedAppTest : public ExtensionBrowserTest { |
| 47 public: |
| 48 HostedAppTest() : app_browser_(nullptr) {} |
| 49 ~HostedAppTest() override {} |
| 50 |
| 51 protected: |
| 52 void SetupApp(const std::string& app_folder, bool is_bookmark_app) { |
| 53 const Extension* app = InstallExtensionWithSourceAndFlags( |
| 54 test_data_dir_.AppendASCII(app_folder), 1, |
| 55 extensions::Manifest::INTERNAL, |
| 56 is_bookmark_app ? extensions::Extension::FROM_BOOKMARK |
| 57 : extensions::Extension::NO_FLAGS); |
| 58 ASSERT_TRUE(app); |
| 59 |
| 60 // Launch it in a window. |
| 61 ASSERT_TRUE(OpenApplication(AppLaunchParams( |
| 62 browser()->profile(), app, extensions::LAUNCH_CONTAINER_WINDOW, |
| 63 NEW_WINDOW, extensions::SOURCE_TEST))); |
| 64 |
| 65 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 66 if (*it == browser()) |
| 67 continue; |
| 68 |
| 69 std::string browser_app_id = |
| 70 web_app::GetExtensionIdFromApplicationName((*it)->app_name()); |
| 71 if (browser_app_id == app->id()) { |
| 72 app_browser_ = *it; |
| 73 break; |
| 74 } |
| 75 } |
| 76 |
| 77 ASSERT_TRUE(app_browser_); |
| 78 ASSERT_TRUE(app_browser_ != browser()); |
| 79 } |
| 80 |
| 81 Browser* app_browser_; |
| 82 }; |
| 83 |
48 // Check that the location bar is shown correctly for HTTP bookmark apps. | 84 // Check that the location bar is shown correctly for HTTP bookmark apps. |
49 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | 85 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
50 ShouldShowLocationBarForHTTPBookmarkApp) { | 86 ShouldShowLocationBarForHTTPBookmarkApp) { |
51 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 87 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
52 switches::kEnableNewBookmarkApps); | 88 switches::kEnableNewBookmarkApps); |
53 ASSERT_TRUE(test_server()->Start()); | |
54 | 89 |
55 // Load a http bookmark app. | 90 SetupApp("app", true); |
56 const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags( | |
57 test_data_dir_.AppendASCII("app/"), | |
58 1, | |
59 extensions::Manifest::INTERNAL, | |
60 extensions::Extension::FROM_BOOKMARK); | |
61 ASSERT_TRUE(http_bookmark_app); | |
62 | |
63 // Launch it in a window. | |
64 WebContents* app_window = OpenApplication(AppLaunchParams( | |
65 browser()->profile(), http_bookmark_app, | |
66 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, | |
67 extensions::SOURCE_TEST)); | |
68 ASSERT_TRUE(app_window); | |
69 | |
70 // Find the new browser. | |
71 Browser* http_app_browser = NULL; | |
72 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
73 std::string app_id = | |
74 web_app::GetExtensionIdFromApplicationName((*it)->app_name()); | |
75 if (*it == browser()) { | |
76 continue; | |
77 } else if (app_id == http_bookmark_app->id()) { | |
78 http_app_browser = *it; | |
79 } | |
80 } | |
81 ASSERT_TRUE(http_app_browser); | |
82 ASSERT_TRUE(http_app_browser != browser()); | |
83 | 91 |
84 // Navigate to the app's launch page; the location bar should be hidden. | 92 // Navigate to the app's launch page; the location bar should be hidden. |
85 NavigateAndCheckForLocationBar( | 93 NavigateAndCheckForLocationBar( |
86 http_app_browser, "http://www.example.com/empty.html", false); | 94 app_browser_, "http://www.example.com/empty.html", false); |
87 | 95 |
88 // Navigate to another page on the same origin; the location bar should still | 96 // Navigate to another page on the same origin; the location bar should still |
89 // hidden. | 97 // hidden. |
90 NavigateAndCheckForLocationBar( | 98 NavigateAndCheckForLocationBar( |
91 http_app_browser, "http://www.example.com/blah", false); | 99 app_browser_, "http://www.example.com/blah", false); |
92 | 100 |
93 // Navigate to the https version of the site; the location bar should | 101 // Navigate to the https version of the site; the location bar should |
94 // be hidden for both browsers. | 102 // be hidden. |
95 NavigateAndCheckForLocationBar( | 103 NavigateAndCheckForLocationBar( |
96 http_app_browser, "https://www.example.com/blah", false); | 104 app_browser_, "https://www.example.com/blah", false); |
97 | 105 |
98 // Navigate to different origin; the location bar should now be visible. | 106 // Navigate to different origin; the location bar should now be visible. |
99 NavigateAndCheckForLocationBar( | 107 NavigateAndCheckForLocationBar( |
100 http_app_browser, "http://www.foo.com/blah", true); | 108 app_browser_, "http://www.foo.com/blah", true); |
101 | 109 |
102 // Navigate back to the app's origin; the location bar should now be hidden. | 110 // Navigate back to the app's origin; the location bar should now be hidden. |
103 NavigateAndCheckForLocationBar( | 111 NavigateAndCheckForLocationBar( |
104 http_app_browser, "http://www.example.com/blah", false); | 112 app_browser_, "http://www.example.com/blah", false); |
105 } | 113 } |
106 | 114 |
107 // Check that the location bar is shown correctly for HTTPS bookmark apps. | 115 // Check that the location bar is shown correctly for HTTPS bookmark apps. |
108 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | 116 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
109 ShouldShowLocationBarForHTTPSBookmarkApp) { | 117 ShouldShowLocationBarForHTTPSBookmarkApp) { |
110 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 118 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
111 switches::kEnableNewBookmarkApps); | 119 switches::kEnableNewBookmarkApps); |
112 ASSERT_TRUE(test_server()->Start()); | |
113 | 120 |
114 // Load a https bookmark app. | 121 SetupApp("https_app", true); |
115 const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags( | |
116 test_data_dir_.AppendASCII("https_app/"), | |
117 1, | |
118 extensions::Manifest::INTERNAL, | |
119 extensions::Extension::FROM_BOOKMARK); | |
120 ASSERT_TRUE(https_bookmark_app); | |
121 | |
122 // Launch it in a window. | |
123 WebContents* app_window = OpenApplication(AppLaunchParams( | |
124 browser()->profile(), https_bookmark_app, | |
125 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, | |
126 extensions::SOURCE_TEST)); | |
127 ASSERT_TRUE(app_window); | |
128 | |
129 // Find the new browser. | |
130 Browser* https_app_browser = NULL; | |
131 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
132 std::string app_id = | |
133 web_app::GetExtensionIdFromApplicationName((*it)->app_name()); | |
134 if (*it == browser()) { | |
135 continue; | |
136 } else if (app_id == https_bookmark_app->id()) { | |
137 https_app_browser = *it; | |
138 } | |
139 } | |
140 ASSERT_TRUE(https_app_browser); | |
141 ASSERT_TRUE(https_app_browser != browser()); | |
142 | 122 |
143 // Navigate to the app's launch page; the location bar should be hidden. | 123 // Navigate to the app's launch page; the location bar should be hidden. |
144 NavigateAndCheckForLocationBar( | 124 NavigateAndCheckForLocationBar( |
145 https_app_browser, "https://www.example.com/empty.html", false); | 125 app_browser_, "https://www.example.com/empty.html", false); |
146 | 126 |
147 // Navigate to another page on the same origin; the location bar should still | 127 // Navigate to another page on the same origin; the location bar should still |
148 // hidden. | 128 // hidden. |
149 NavigateAndCheckForLocationBar( | 129 NavigateAndCheckForLocationBar( |
150 https_app_browser, "https://www.example.com/blah", false); | 130 app_browser_, "https://www.example.com/blah", false); |
151 | 131 |
152 // Navigate to the http version of the site; the location bar should | 132 // Navigate to the http version of the site; the location bar should |
153 // be visible for the https version as it is now on a less secure version | 133 // be visible for the https version as it is now on a less secure version |
154 // of its host. | 134 // of its host. |
155 NavigateAndCheckForLocationBar( | 135 NavigateAndCheckForLocationBar( |
156 https_app_browser, "http://www.example.com/blah", true); | 136 app_browser_, "http://www.example.com/blah", true); |
157 | 137 |
158 // Navigate to different origin; the location bar should now be visible. | 138 // Navigate to different origin; the location bar should now be visible. |
159 NavigateAndCheckForLocationBar( | 139 NavigateAndCheckForLocationBar( |
160 https_app_browser, "http://www.foo.com/blah", true); | 140 app_browser_, "http://www.foo.com/blah", true); |
161 | 141 |
162 // Navigate back to the app's origin; the location bar should now be hidden. | 142 // Navigate back to the app's origin; the location bar should now be hidden. |
163 NavigateAndCheckForLocationBar( | 143 NavigateAndCheckForLocationBar( |
164 https_app_browser, "https://www.example.com/blah", false); | 144 app_browser_, "https://www.example.com/blah", false); |
| 145 } |
| 146 |
| 147 // Check that the location bar is shown correctly for normal hosted apps. |
| 148 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
| 149 ShouldShowLocationBarForHostedApp) { |
| 150 SetupApp("app", false); |
| 151 |
| 152 // Navigate to the app's launch page; the location bar should be hidden. |
| 153 NavigateAndCheckForLocationBar( |
| 154 app_browser_, "http://www.example.com/empty.html", false); |
| 155 |
| 156 // Navigate to another page on the same origin; the location bar should still |
| 157 // hidden. |
| 158 NavigateAndCheckForLocationBar( |
| 159 app_browser_, "http://www.example.com/blah", false); |
| 160 |
| 161 // Navigate to the https version of the site; the location bar should |
| 162 // be hidden. |
| 163 NavigateAndCheckForLocationBar( |
| 164 app_browser_, "https://www.example.com/blah", false); |
| 165 |
| 166 // Navigate to different origin; the location bar should now be visible. |
| 167 NavigateAndCheckForLocationBar( |
| 168 app_browser_, "http://www.foo.com/blah", true); |
| 169 |
| 170 // Navigate back to the app's origin; the location bar should now be hidden. |
| 171 NavigateAndCheckForLocationBar( |
| 172 app_browser_, "http://www.example.com/blah", false); |
| 173 } |
| 174 |
| 175 // Check that the location bar is shown correctly for hosted apps that specify |
| 176 // start URLs without the 'www.' prefix. |
| 177 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
| 178 LocationBarForHostedAppWithoutWWW) { |
| 179 SetupApp("app_no_www", false); |
| 180 |
| 181 // Navigate to the app's launch page; the location bar should be hidden. |
| 182 NavigateAndCheckForLocationBar( |
| 183 app_browser_, "http://example.com/empty.html", false); |
| 184 |
| 185 // Navigate to the app's launch page with the 'www.' prefis; the location bar |
| 186 // should be hidden. |
| 187 NavigateAndCheckForLocationBar( |
| 188 app_browser_, "http://www.example.com/empty.html", false); |
| 189 |
| 190 // Navigate to different origin; the location bar should now be visible. |
| 191 NavigateAndCheckForLocationBar( |
| 192 app_browser_, "http://www.foo.com/blah", true); |
| 193 |
| 194 // Navigate back to the app's origin; the location bar should now be hidden. |
| 195 NavigateAndCheckForLocationBar( |
| 196 app_browser_, "http://example.com/blah", false); |
165 } | 197 } |
166 | 198 |
167 // Open a normal browser window, a hosted app window, a legacy packaged app | 199 // Open a normal browser window, a hosted app window, a legacy packaged app |
168 // window and a dev tools window, and check that the web app frame feature is | 200 // window and a dev tools window, and check that the web app frame feature is |
169 // supported correctly. | 201 // supported correctly. |
170 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) { | 202 IN_PROC_BROWSER_TEST_F(HostedAppTest, ShouldUseWebAppFrame) { |
171 ASSERT_TRUE(test_server()->Start()); | |
172 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 203 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
173 switches::kEnableWebAppFrame); | 204 switches::kEnableWebAppFrame); |
174 | 205 |
175 // Load a hosted app. | 206 // Load a hosted app. |
176 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags( | 207 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags( |
177 test_data_dir_.AppendASCII("app/"), | 208 test_data_dir_.AppendASCII("app"), |
178 1, | 209 1, |
179 extensions::Manifest::INTERNAL, | 210 extensions::Manifest::INTERNAL, |
180 extensions::Extension::FROM_BOOKMARK); | 211 extensions::Extension::FROM_BOOKMARK); |
181 ASSERT_TRUE(bookmark_app); | 212 ASSERT_TRUE(bookmark_app); |
182 | 213 |
183 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | 214 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. |
184 WebContents* bookmark_app_window = OpenApplication(AppLaunchParams( | 215 WebContents* bookmark_app_window = OpenApplication(AppLaunchParams( |
185 browser()->profile(), bookmark_app, extensions::LAUNCH_CONTAINER_WINDOW, | 216 browser()->profile(), bookmark_app, extensions::LAUNCH_CONTAINER_WINDOW, |
186 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); | 217 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); |
187 ASSERT_TRUE(bookmark_app_window); | 218 ASSERT_TRUE(bookmark_app_window); |
188 | 219 |
189 // Load a packaged app. | 220 // Load a packaged app. |
190 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app/"))); | 221 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app"))); |
191 const Extension* packaged_app = nullptr; | 222 const Extension* packaged_app = nullptr; |
192 extensions::ExtensionRegistry* registry = | 223 extensions::ExtensionRegistry* registry = |
193 extensions::ExtensionRegistry::Get(browser()->profile()); | 224 extensions::ExtensionRegistry::Get(browser()->profile()); |
194 for (const scoped_refptr<const extensions::Extension>& extension : | 225 for (const scoped_refptr<const extensions::Extension>& extension : |
195 registry->enabled_extensions()) { | 226 registry->enabled_extensions()) { |
196 if (extension->name() == "Packaged App Test") | 227 if (extension->name() == "Packaged App Test") |
197 packaged_app = extension.get(); | 228 packaged_app = extension.get(); |
198 } | 229 } |
199 ASSERT_TRUE(packaged_app); | 230 ASSERT_TRUE(packaged_app); |
200 | 231 |
201 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | 232 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. |
202 WebContents* packaged_app_window = OpenApplication(AppLaunchParams( | 233 WebContents* packaged_app_window = OpenApplication(AppLaunchParams( |
203 browser()->profile(), packaged_app, extensions::LAUNCH_CONTAINER_WINDOW, | 234 browser()->profile(), packaged_app, extensions::LAUNCH_CONTAINER_WINDOW, |
204 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); | 235 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); |
205 ASSERT_TRUE(packaged_app_window); | 236 ASSERT_TRUE(packaged_app_window); |
206 | 237 |
207 DevToolsWindow* devtools_window = | 238 DevToolsWindow* devtools_window = |
208 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | 239 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); |
209 | 240 |
210 // The launch should have created a new app browser and a dev tools browser. | 241 // The launch should have created a new app browser and a dev tools browser. |
211 ASSERT_EQ(4u, chrome::GetBrowserCount(browser()->profile(), | 242 ASSERT_EQ(4u, chrome::GetBrowserCount(browser()->profile(), |
212 browser()->host_desktop_type())); | 243 browser()->host_desktop_type())); |
213 | 244 |
214 // Find the new browsers. | 245 // Find the new browsers. |
215 Browser* bookmark_app_browser = NULL; | 246 Browser* bookmark_app_browser = nullptr; |
216 Browser* packaged_app_browser = NULL; | 247 Browser* packaged_app_browser = nullptr; |
217 Browser* dev_tools_browser = NULL; | 248 Browser* dev_tools_browser = nullptr; |
218 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 249 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
219 if (*it == browser()) { | 250 if (*it == browser()) { |
220 continue; | 251 continue; |
221 } else if ((*it)->app_name() == DevToolsWindow::kDevToolsApp) { | 252 } else if ((*it)->app_name() == DevToolsWindow::kDevToolsApp) { |
222 dev_tools_browser = *it; | 253 dev_tools_browser = *it; |
223 } else if ((*it)->tab_strip_model()->GetActiveWebContents() == | 254 } else if ((*it)->tab_strip_model()->GetActiveWebContents() == |
224 bookmark_app_window) { | 255 bookmark_app_window) { |
225 bookmark_app_browser = *it; | 256 bookmark_app_browser = *it; |
226 } else { | 257 } else { |
227 packaged_app_browser = *it; | 258 packaged_app_browser = *it; |
(...skipping 10 matching lines...) Expand all Loading... |
238 EXPECT_FALSE( | 269 EXPECT_FALSE( |
239 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); | 270 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); |
240 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH, | 271 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH, |
241 bookmark_app_browser->SupportsWindowFeature( | 272 bookmark_app_browser->SupportsWindowFeature( |
242 Browser::FEATURE_WEBAPPFRAME)); | 273 Browser::FEATURE_WEBAPPFRAME)); |
243 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature( | 274 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature( |
244 Browser::FEATURE_WEBAPPFRAME)); | 275 Browser::FEATURE_WEBAPPFRAME)); |
245 | 276 |
246 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); | 277 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); |
247 } | 278 } |
OLD | NEW |