Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / extensions / bookmark_app_browsertest.cc
blobbe61abf9e1b766692a24836f202ec8d389457f3b
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.
5 #include <string>
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/tabs/tab_strip_model.h"
18 #include "chrome/browser/web_applications/web_app.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/web_contents.h"
22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/common/constants.h"
24 #include "extensions/common/extension.h"
25 #include "extensions/common/extension_set.h"
27 using content::WebContents;
28 using extensions::Extension;
30 typedef ExtensionBrowserTest BookmarkAppTest;
32 namespace {
34 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that
35 // the location bar visibility is as expcted.
36 void NavigateAndCheckForLocationBar(Browser* browser,
37 const std::string& url_string,
38 bool expected_visibility) {
39 GURL url(url_string);
40 ui_test_utils::NavigateToURL(browser, url);
41 EXPECT_EQ(expected_visibility,
42 browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
45 } // namespace
47 // Check that the location bar is shown correctly for HTTP bookmark apps.
48 IN_PROC_BROWSER_TEST_F(BookmarkAppTest,
49 ShouldShowLocationBarForHTTPBookmarkApp) {
50 base::CommandLine::ForCurrentProcess()->AppendSwitch(
51 switches::kEnableNewBookmarkApps);
52 ASSERT_TRUE(test_server()->Start());
54 // Load a http bookmark app.
55 const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags(
56 test_data_dir_.AppendASCII("app/"),
58 extensions::Manifest::INTERNAL,
59 extensions::Extension::FROM_BOOKMARK);
60 ASSERT_TRUE(http_bookmark_app);
62 // Launch it in a window.
63 WebContents* app_window = OpenApplication(AppLaunchParams(
64 browser()->profile(), http_bookmark_app,
65 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
66 extensions::SOURCE_TEST));
67 ASSERT_TRUE(app_window);
69 // Find the new browser.
70 Browser* http_app_browser = NULL;
71 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
72 std::string app_id =
73 web_app::GetExtensionIdFromApplicationName((*it)->app_name());
74 if (*it == browser()) {
75 continue;
76 } else if (app_id == http_bookmark_app->id()) {
77 http_app_browser = *it;
80 ASSERT_TRUE(http_app_browser);
81 ASSERT_TRUE(http_app_browser != browser());
83 // Navigate to the app's launch page; the location bar should be hidden.
84 NavigateAndCheckForLocationBar(
85 http_app_browser, "http://www.example.com/empty.html", false);
87 // Navigate to another page on the same origin; the location bar should still
88 // hidden.
89 NavigateAndCheckForLocationBar(
90 http_app_browser, "http://www.example.com/blah", false);
92 // Navigate to the https version of the site; the location bar should
93 // be hidden for both browsers.
94 NavigateAndCheckForLocationBar(
95 http_app_browser, "https://www.example.com/blah", false);
97 // Navigate to different origin; the location bar should now be visible.
98 NavigateAndCheckForLocationBar(
99 http_app_browser, "http://www.foo.com/blah", true);
101 // Navigate back to the app's origin; the location bar should now be hidden.
102 NavigateAndCheckForLocationBar(
103 http_app_browser, "http://www.example.com/blah", false);
106 // Check that the location bar is shown correctly for HTTPS bookmark apps.
107 IN_PROC_BROWSER_TEST_F(BookmarkAppTest,
108 ShouldShowLocationBarForHTTPSBookmarkApp) {
109 base::CommandLine::ForCurrentProcess()->AppendSwitch(
110 switches::kEnableNewBookmarkApps);
111 ASSERT_TRUE(test_server()->Start());
113 // Load a https bookmark app.
114 const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags(
115 test_data_dir_.AppendASCII("https_app/"),
117 extensions::Manifest::INTERNAL,
118 extensions::Extension::FROM_BOOKMARK);
119 ASSERT_TRUE(https_bookmark_app);
121 // Launch it in a window.
122 WebContents* app_window = OpenApplication(AppLaunchParams(
123 browser()->profile(), https_bookmark_app,
124 extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
125 extensions::SOURCE_TEST));
126 ASSERT_TRUE(app_window);
128 // Find the new browser.
129 Browser* https_app_browser = NULL;
130 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
131 std::string app_id =
132 web_app::GetExtensionIdFromApplicationName((*it)->app_name());
133 if (*it == browser()) {
134 continue;
135 } else if (app_id == https_bookmark_app->id()) {
136 https_app_browser = *it;
139 ASSERT_TRUE(https_app_browser);
140 ASSERT_TRUE(https_app_browser != browser());
142 // Navigate to the app's launch page; the location bar should be hidden.
143 NavigateAndCheckForLocationBar(
144 https_app_browser, "https://www.example.com/empty.html", false);
146 // Navigate to another page on the same origin; the location bar should still
147 // hidden.
148 NavigateAndCheckForLocationBar(
149 https_app_browser, "https://www.example.com/blah", false);
151 // Navigate to the http version of the site; the location bar should
152 // be visible for the https version as it is now on a less secure version
153 // of its host.
154 NavigateAndCheckForLocationBar(
155 https_app_browser, "http://www.example.com/blah", true);
157 // Navigate to different origin; the location bar should now be visible.
158 NavigateAndCheckForLocationBar(
159 https_app_browser, "http://www.foo.com/blah", true);
161 // Navigate back to the app's origin; the location bar should now be hidden.
162 NavigateAndCheckForLocationBar(
163 https_app_browser, "https://www.example.com/blah", false);
166 // Open a normal browser window, a hosted app window, a legacy packaged app
167 // window and a dev tools window, and check that the web app frame feature is
168 // supported correctly.
169 IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) {
170 ASSERT_TRUE(test_server()->Start());
171 base::CommandLine::ForCurrentProcess()->AppendSwitch(
172 switches::kEnableWebAppFrame);
174 // Load a hosted app.
175 const Extension* bookmark_app = InstallExtensionWithSourceAndFlags(
176 test_data_dir_.AppendASCII("app/"),
178 extensions::Manifest::INTERNAL,
179 extensions::Extension::FROM_BOOKMARK);
180 ASSERT_TRUE(bookmark_app);
182 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would.
183 WebContents* bookmark_app_window = OpenApplication(AppLaunchParams(
184 browser()->profile(), bookmark_app, extensions::LAUNCH_CONTAINER_WINDOW,
185 NEW_WINDOW, extensions::SOURCE_UNTRACKED));
186 ASSERT_TRUE(bookmark_app_window);
188 // Load a packaged app.
189 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app/")));
190 const Extension* packaged_app = nullptr;
191 extensions::ExtensionRegistry* registry =
192 extensions::ExtensionRegistry::Get(browser()->profile());
193 for (const scoped_refptr<const extensions::Extension>& extension :
194 registry->enabled_extensions()) {
195 if (extension->name() == "Packaged App Test")
196 packaged_app = extension.get();
198 ASSERT_TRUE(packaged_app);
200 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would.
201 WebContents* packaged_app_window = OpenApplication(AppLaunchParams(
202 browser()->profile(), packaged_app, extensions::LAUNCH_CONTAINER_WINDOW,
203 NEW_WINDOW, extensions::SOURCE_UNTRACKED));
204 ASSERT_TRUE(packaged_app_window);
206 DevToolsWindow* devtools_window =
207 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
209 // The launch should have created a new app browser and a dev tools browser.
210 ASSERT_EQ(4u, chrome::GetBrowserCount(browser()->profile(),
211 browser()->host_desktop_type()));
213 // Find the new browsers.
214 Browser* bookmark_app_browser = NULL;
215 Browser* packaged_app_browser = NULL;
216 Browser* dev_tools_browser = NULL;
217 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
218 if (*it == browser()) {
219 continue;
220 } else if ((*it)->app_name() == DevToolsWindow::kDevToolsApp) {
221 dev_tools_browser = *it;
222 } else if ((*it)->tab_strip_model()->GetActiveWebContents() ==
223 bookmark_app_window) {
224 bookmark_app_browser = *it;
225 } else {
226 packaged_app_browser = *it;
229 ASSERT_TRUE(dev_tools_browser);
230 ASSERT_TRUE(bookmark_app_browser);
231 ASSERT_TRUE(bookmark_app_browser != browser());
232 ASSERT_TRUE(packaged_app_browser);
233 ASSERT_TRUE(packaged_app_browser != browser());
234 ASSERT_TRUE(packaged_app_browser != bookmark_app_browser);
236 EXPECT_FALSE(browser()->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME));
237 EXPECT_FALSE(
238 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME));
239 EXPECT_EQ(browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH,
240 bookmark_app_browser->SupportsWindowFeature(
241 Browser::FEATURE_WEBAPPFRAME));
242 EXPECT_FALSE(packaged_app_browser->SupportsWindowFeature(
243 Browser::FEATURE_WEBAPPFRAME));
245 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);