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; | 31 typedef ExtensionBrowserTest HostedAppTest; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that | 35 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that |
36 // the location bar visibility is as expcted. | 36 // the location bar visibility is as expcted. |
37 void NavigateAndCheckForLocationBar(Browser* browser, | 37 void NavigateAndCheckForLocationBar(Browser* browser, |
38 const std::string& url_string, | 38 const std::string& url_string, |
39 bool expected_visibility) { | 39 bool expected_visibility) { |
40 GURL url(url_string); | 40 GURL url(url_string); |
41 ui_test_utils::NavigateToURL(browser, url); | 41 ui_test_utils::NavigateToURL(browser, url); |
42 EXPECT_EQ(expected_visibility, | 42 EXPECT_EQ(expected_visibility, |
43 browser->bookmark_app_controller()->ShouldShowLocationBar()); | 43 browser->hosted_app_controller()->ShouldShowLocationBar()); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 // Check that the location bar is shown correctly for HTTP bookmark apps. | 48 // Check that the location bar is shown correctly for HTTP bookmark apps. |
49 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | 49 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
50 ShouldShowLocationBarForHTTPBookmarkApp) { | 50 ShouldShowLocationBarForHTTPBookmarkApp) { |
51 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 51 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
52 switches::kEnableNewBookmarkApps); | 52 switches::kEnableNewBookmarkApps); |
53 ASSERT_TRUE(test_server()->Start()); | 53 ASSERT_TRUE(test_server()->Start()); |
54 | 54 |
55 // Load a http bookmark app. | 55 // Load a http bookmark app. |
56 const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags( | 56 const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags( |
57 test_data_dir_.AppendASCII("app/"), | 57 test_data_dir_.AppendASCII("app/"), |
58 1, | 58 1, |
59 extensions::Manifest::INTERNAL, | 59 extensions::Manifest::INTERNAL, |
(...skipping 24 matching lines...) Expand all Loading... | |
84 // Navigate to the app's launch page; the location bar should be hidden. | 84 // Navigate to the app's launch page; the location bar should be hidden. |
85 NavigateAndCheckForLocationBar( | 85 NavigateAndCheckForLocationBar( |
86 http_app_browser, "http://www.example.com/empty.html", false); | 86 http_app_browser, "http://www.example.com/empty.html", false); |
87 | 87 |
88 // Navigate to another page on the same origin; the location bar should still | 88 // Navigate to another page on the same origin; the location bar should still |
89 // hidden. | 89 // hidden. |
90 NavigateAndCheckForLocationBar( | 90 NavigateAndCheckForLocationBar( |
91 http_app_browser, "http://www.example.com/blah", false); | 91 http_app_browser, "http://www.example.com/blah", false); |
92 | 92 |
93 // Navigate to the https version of the site; the location bar should | 93 // Navigate to the https version of the site; the location bar should |
94 // be hidden for both browsers. | 94 // be hidden. |
95 NavigateAndCheckForLocationBar( | 95 NavigateAndCheckForLocationBar( |
96 http_app_browser, "https://www.example.com/blah", false); | 96 http_app_browser, "https://www.example.com/blah", false); |
97 | 97 |
98 // Navigate to different origin; the location bar should now be visible. | 98 // Navigate to different origin; the location bar should now be visible. |
99 NavigateAndCheckForLocationBar( | 99 NavigateAndCheckForLocationBar( |
100 http_app_browser, "http://www.foo.com/blah", true); | 100 http_app_browser, "http://www.foo.com/blah", true); |
101 | 101 |
102 // Navigate back to the app's origin; the location bar should now be hidden. | 102 // Navigate back to the app's origin; the location bar should now be hidden. |
103 NavigateAndCheckForLocationBar( | 103 NavigateAndCheckForLocationBar( |
104 http_app_browser, "http://www.example.com/blah", false); | 104 http_app_browser, "http://www.example.com/blah", false); |
105 } | 105 } |
106 | 106 |
107 // Check that the location bar is shown correctly for HTTPS bookmark apps. | 107 // Check that the location bar is shown correctly for HTTPS bookmark apps. |
108 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | 108 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
109 ShouldShowLocationBarForHTTPSBookmarkApp) { | 109 ShouldShowLocationBarForHTTPSBookmarkApp) { |
110 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 110 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
111 switches::kEnableNewBookmarkApps); | 111 switches::kEnableNewBookmarkApps); |
112 ASSERT_TRUE(test_server()->Start()); | 112 ASSERT_TRUE(test_server()->Start()); |
113 | 113 |
114 // Load a https bookmark app. | 114 // Load a https bookmark app. |
115 const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags( | 115 const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags( |
116 test_data_dir_.AppendASCII("https_app/"), | 116 test_data_dir_.AppendASCII("https_app/"), |
117 1, | 117 1, |
118 extensions::Manifest::INTERNAL, | 118 extensions::Manifest::INTERNAL, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 | 157 |
158 // Navigate to different origin; the location bar should now be visible. | 158 // Navigate to different origin; the location bar should now be visible. |
159 NavigateAndCheckForLocationBar( | 159 NavigateAndCheckForLocationBar( |
160 https_app_browser, "http://www.foo.com/blah", true); | 160 https_app_browser, "http://www.foo.com/blah", true); |
161 | 161 |
162 // Navigate back to the app's origin; the location bar should now be hidden. | 162 // Navigate back to the app's origin; the location bar should now be hidden. |
163 NavigateAndCheckForLocationBar( | 163 NavigateAndCheckForLocationBar( |
164 https_app_browser, "https://www.example.com/blah", false); | 164 https_app_browser, "https://www.example.com/blah", false); |
165 } | 165 } |
166 | 166 |
167 // Check that the location bar is shown correctly for normal hosted apps. | |
168 IN_PROC_BROWSER_TEST_F(HostedAppTest, | |
169 ShouldShowLocationBarForHostedApp) { | |
170 ASSERT_TRUE(test_server()->Start()); | |
171 | |
172 // Load a hosted app. | |
173 const Extension* hosted_app = InstallExtension( | |
174 test_data_dir_.AppendASCII("app/"), 1, extensions::Manifest::INTERNAL); | |
175 ASSERT_TRUE(hosted_app); | |
176 | |
177 // Launch it in a window. | |
178 WebContents* app_window = OpenApplication(AppLaunchParams( | |
179 browser()->profile(), hosted_app, | |
180 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, | |
181 extensions::SOURCE_TEST)); | |
182 ASSERT_TRUE(app_window); | |
183 | |
184 // Find the new browser. | |
185 Browser* app_browser = NULL; | |
186 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
187 std::string app_id = | |
188 web_app::GetExtensionIdFromApplicationName((*it)->app_name()); | |
189 if (*it == browser()) { | |
190 continue; | |
191 } else if (app_id == hosted_app->id()) { | |
192 app_browser = *it; | |
193 } | |
194 } | |
195 ASSERT_TRUE(app_browser); | |
196 ASSERT_TRUE(app_browser != browser()); | |
197 | |
198 // Navigate to the app's launch page; the location bar should be hidden. | |
199 NavigateAndCheckForLocationBar( | |
200 app_browser, "http://www.example.com/empty.html", false); | |
201 | |
202 // Navigate to another page on the same origin; the location bar should still | |
203 // hidden. | |
204 NavigateAndCheckForLocationBar( | |
205 app_browser, "http://www.example.com/blah", false); | |
206 | |
felt
2015/06/04 19:21:34
maybe check the subdomain properties you care abou
benwells
2015/06/05 01:20:44
Done.
| |
207 // Navigate to the https version of the site; the location bar should | |
208 // be hidden. | |
209 NavigateAndCheckForLocationBar( | |
210 app_browser, "https://www.example.com/blah", false); | |
211 | |
212 // Navigate to different origin; the location bar should now be visible. | |
213 NavigateAndCheckForLocationBar( | |
214 app_browser, "http://www.foo.com/blah", true); | |
215 | |
216 // Navigate back to the app's origin; the location bar should now be hidden. | |
217 NavigateAndCheckForLocationBar( | |
218 app_browser, "http://www.example.com/blah", false); | |
219 } | |
220 | |
167 // Open a normal browser window, a hosted app window, a legacy packaged app | 221 // 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 | 222 // window and a dev tools window, and check that the web app frame feature is |
169 // supported correctly. | 223 // supported correctly. |
170 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) { | 224 IN_PROC_BROWSER_TEST_F(HostedAppTest, ShouldUseWebAppFrame) { |
171 ASSERT_TRUE(test_server()->Start()); | 225 ASSERT_TRUE(test_server()->Start()); |
172 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 226 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
173 switches::kEnableWebAppFrame); | 227 switches::kEnableWebAppFrame); |
174 | 228 |
175 // Load a hosted app. | 229 // Load a hosted app. |
176 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags( | 230 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags( |
177 test_data_dir_.AppendASCII("app/"), | 231 test_data_dir_.AppendASCII("app/"), |
178 1, | 232 1, |
179 extensions::Manifest::INTERNAL, | 233 extensions::Manifest::INTERNAL, |
180 extensions::Extension::FROM_BOOKMARK); | 234 extensions::Extension::FROM_BOOKMARK); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 EXPECT_FALSE( | 292 EXPECT_FALSE( |
239 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); | 293 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); |
240 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH, | 294 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH, |
241 bookmark_app_browser->SupportsWindowFeature( | 295 bookmark_app_browser->SupportsWindowFeature( |
242 Browser::FEATURE_WEBAPPFRAME)); | 296 Browser::FEATURE_WEBAPPFRAME)); |
243 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature( | 297 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature( |
244 Browser::FEATURE_WEBAPPFRAME)); | 298 Browser::FEATURE_WEBAPPFRAME)); |
245 | 299 |
246 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); | 300 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); |
247 } | 301 } |
OLD | NEW |