OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/compiler_specific.h" | |
9 #include "chrome/browser/devtools/devtools_window_testing.h" | |
10 #include "chrome/browser/extensions/extension_browsertest.h" | |
11 #include "chrome/browser/extensions/extension_service.h" | |
12 #include "chrome/browser/extensions/extension_util.h" | |
13 #include "chrome/browser/ui/browser_finder.h" | |
14 #include "chrome/browser/ui/browser_iterator.h" | |
15 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
16 #include "chrome/browser/ui/extensions/application_launch.h" | |
17 #include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h" | |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
19 #include "chrome/browser/web_applications/web_app.h" | |
20 #include "chrome/common/chrome_switches.h" | |
21 #include "chrome/test/base/ui_test_utils.h" | |
22 #include "content/public/browser/web_contents.h" | |
23 #include "extensions/browser/extension_registry.h" | |
24 #include "extensions/common/constants.h" | |
25 #include "extensions/common/extension.h" | |
26 #include "extensions/common/extension_set.h" | |
27 | |
28 using content::WebContents; | |
29 using extensions::Extension; | |
30 | |
31 typedef ExtensionBrowserTest BookmarkAppTest; | |
32 | |
33 namespace { | |
34 | |
35 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that | |
36 // the location bar visibility is as expcted. | |
37 void NavigateAndCheckForLocationBar(Browser* browser, | |
38 const std::string& url_string, | |
39 bool expected_visibility) { | |
40 GURL url(url_string); | |
41 ui_test_utils::NavigateToURL(browser, url); | |
42 EXPECT_EQ(expected_visibility, | |
43 browser->bookmark_app_controller()->ShouldShowLocationBar()); | |
44 } | |
45 | |
46 } // namespace | |
47 | |
48 // Check that the location bar is shown correctly for HTTP bookmark apps. | |
49 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | |
50 ShouldShowLocationBarForHTTPBookmarkApp) { | |
51 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
52 switches::kEnableNewBookmarkApps); | |
53 ASSERT_TRUE(test_server()->Start()); | |
54 | |
55 // Load a http bookmark app. | |
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 | |
84 // Navigate to the app's launch page; the location bar should be hidden. | |
85 NavigateAndCheckForLocationBar( | |
86 http_app_browser, "http://www.example.com/empty.html", false); | |
87 | |
88 // Navigate to another page on the same origin; the location bar should still | |
89 // hidden. | |
90 NavigateAndCheckForLocationBar( | |
91 http_app_browser, "http://www.example.com/blah", false); | |
92 | |
93 // Navigate to the https version of the site; the location bar should | |
94 // be hidden for both browsers. | |
95 NavigateAndCheckForLocationBar( | |
96 http_app_browser, "https://www.example.com/blah", false); | |
97 | |
98 // Navigate to different origin; the location bar should now be visible. | |
99 NavigateAndCheckForLocationBar( | |
100 http_app_browser, "http://www.foo.com/blah", true); | |
101 | |
102 // Navigate back to the app's origin; the location bar should now be hidden. | |
103 NavigateAndCheckForLocationBar( | |
104 http_app_browser, "http://www.example.com/blah", false); | |
105 } | |
106 | |
107 // Check that the location bar is shown correctly for HTTPS bookmark apps. | |
108 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, | |
109 ShouldShowLocationBarForHTTPSBookmarkApp) { | |
110 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
111 switches::kEnableNewBookmarkApps); | |
112 ASSERT_TRUE(test_server()->Start()); | |
113 | |
114 // Load a https bookmark app. | |
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 | |
143 // Navigate to the app's launch page; the location bar should be hidden. | |
144 NavigateAndCheckForLocationBar( | |
145 https_app_browser, "https://www.example.com/empty.html", false); | |
146 | |
147 // Navigate to another page on the same origin; the location bar should still | |
148 // hidden. | |
149 NavigateAndCheckForLocationBar( | |
150 https_app_browser, "https://www.example.com/blah", false); | |
151 | |
152 // 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 | |
154 // of its host. | |
155 NavigateAndCheckForLocationBar( | |
156 https_app_browser, "http://www.example.com/blah", true); | |
157 | |
158 // Navigate to different origin; the location bar should now be visible. | |
159 NavigateAndCheckForLocationBar( | |
160 https_app_browser, "http://www.foo.com/blah", true); | |
161 | |
162 // Navigate back to the app's origin; the location bar should now be hidden. | |
163 NavigateAndCheckForLocationBar( | |
164 https_app_browser, "https://www.example.com/blah", false); | |
165 } | |
166 | |
167 // 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 | |
169 // supported correctly. | |
170 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) { | |
171 ASSERT_TRUE(test_server()->Start()); | |
172 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
173 switches::kEnableWebAppFrame); | |
174 | |
175 // Load a hosted app. | |
176 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags( | |
177 test_data_dir_.AppendASCII("app/"), | |
178 1, | |
179 extensions::Manifest::INTERNAL, | |
180 extensions::Extension::FROM_BOOKMARK); | |
181 ASSERT_TRUE(bookmark_app); | |
182 | |
183 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | |
184 WebContents* bookmark_app_window = OpenApplication(AppLaunchParams( | |
185 browser()->profile(), bookmark_app, extensions::LAUNCH_CONTAINER_WINDOW, | |
186 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); | |
187 ASSERT_TRUE(bookmark_app_window); | |
188 | |
189 // Load a packaged app. | |
190 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app/"))); | |
191 const Extension* packaged_app = nullptr; | |
192 extensions::ExtensionRegistry* registry = | |
193 extensions::ExtensionRegistry::Get(browser()->profile()); | |
194 for (const scoped_refptr<const extensions::Extension>& extension : | |
195 registry->enabled_extensions()) { | |
196 if (extension->name() == "Packaged App Test") | |
197 packaged_app = extension.get(); | |
198 } | |
199 ASSERT_TRUE(packaged_app); | |
200 | |
201 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | |
202 WebContents* packaged_app_window = OpenApplication(AppLaunchParams( | |
203 browser()->profile(), packaged_app, extensions::LAUNCH_CONTAINER_WINDOW, | |
204 NEW_WINDOW, extensions::SOURCE_UNTRACKED)); | |
205 ASSERT_TRUE(packaged_app_window); | |
206 | |
207 DevToolsWindow* devtools_window = | |
208 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | |
209 | |
210 // The launch should have created a new app browser and a dev tools browser. | |
211 ASSERT_EQ(4u, chrome::GetBrowserCount(browser()->profile(), | |
212 browser()->host_desktop_type())); | |
213 | |
214 // Find the new browsers. | |
215 Browser* bookmark_app_browser = NULL; | |
216 Browser* packaged_app_browser = NULL; | |
217 Browser* dev_tools_browser = NULL; | |
218 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
219 if (*it == browser()) { | |
220 continue; | |
221 } else if ((*it)->app_name() == DevToolsWindow::kDevToolsApp) { | |
222 dev_tools_browser = *it; | |
223 } else if ((*it)->tab_strip_model()->GetActiveWebContents() == | |
224 bookmark_app_window) { | |
225 bookmark_app_browser = *it; | |
226 } else { | |
227 packaged_app_browser = *it; | |
228 } | |
229 } | |
230 ASSERT_TRUE(dev_tools_browser); | |
231 ASSERT_TRUE(bookmark_app_browser); | |
232 ASSERT_TRUE(bookmark_app_browser != browser()); | |
233 ASSERT_TRUE(packaged_app_browser); | |
234 ASSERT_TRUE(packaged_app_browser != browser()); | |
235 ASSERT_TRUE(packaged_app_browser != bookmark_app_browser); | |
236 | |
237 EXPECT_FALSE(browser()->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); | |
238 EXPECT_FALSE( | |
239 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME)); | |
240 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH, | |
241 bookmark_app_browser->SupportsWindowFeature( | |
242 Browser::FEATURE_WEBAPPFRAME)); | |
243 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature( | |
244 Browser::FEATURE_WEBAPPFRAME)); | |
245 | |
246 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); | |
247 } | |
OLD | NEW |