Index: chrome/browser/ui/extensions/hosted_app_browsertest.cc |
diff --git a/chrome/browser/ui/extensions/bookmark_app_browsertest.cc b/chrome/browser/ui/extensions/hosted_app_browsertest.cc |
similarity index 69% |
rename from chrome/browser/ui/extensions/bookmark_app_browsertest.cc |
rename to chrome/browser/ui/extensions/hosted_app_browsertest.cc |
index 186029b026c89fdaefa84bdb1f604276ca44cee4..cb9d2945e01ac524a9b6cecfe0959224a1bd8a35 100644 |
--- a/chrome/browser/ui/extensions/bookmark_app_browsertest.cc |
+++ b/chrome/browser/ui/extensions/hosted_app_browsertest.cc |
@@ -14,7 +14,7 @@ |
#include "chrome/browser/ui/browser_iterator.h" |
#include "chrome/browser/ui/extensions/app_launch_params.h" |
#include "chrome/browser/ui/extensions/application_launch.h" |
-#include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h" |
+#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/browser/web_applications/web_app.h" |
#include "chrome/common/chrome_switches.h" |
@@ -28,7 +28,7 @@ |
using content::WebContents; |
using extensions::Extension; |
-typedef ExtensionBrowserTest BookmarkAppTest; |
+typedef ExtensionBrowserTest HostedAppTest; |
namespace { |
@@ -40,13 +40,13 @@ void NavigateAndCheckForLocationBar(Browser* browser, |
GURL url(url_string); |
ui_test_utils::NavigateToURL(browser, url); |
EXPECT_EQ(expected_visibility, |
- browser->bookmark_app_controller()->ShouldShowLocationBar()); |
+ browser->hosted_app_controller()->ShouldShowLocationBar()); |
} |
} // namespace |
// Check that the location bar is shown correctly for HTTP bookmark apps. |
-IN_PROC_BROWSER_TEST_F(BookmarkAppTest, |
+IN_PROC_BROWSER_TEST_F(HostedAppTest, |
ShouldShowLocationBarForHTTPBookmarkApp) { |
base::CommandLine::ForCurrentProcess()->AppendSwitch( |
switches::kEnableNewBookmarkApps); |
@@ -91,7 +91,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, |
http_app_browser, "http://www.example.com/blah", false); |
// Navigate to the https version of the site; the location bar should |
- // be hidden for both browsers. |
+ // be hidden. |
NavigateAndCheckForLocationBar( |
http_app_browser, "https://www.example.com/blah", false); |
@@ -105,7 +105,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, |
} |
// Check that the location bar is shown correctly for HTTPS bookmark apps. |
-IN_PROC_BROWSER_TEST_F(BookmarkAppTest, |
+IN_PROC_BROWSER_TEST_F(HostedAppTest, |
ShouldShowLocationBarForHTTPSBookmarkApp) { |
base::CommandLine::ForCurrentProcess()->AppendSwitch( |
switches::kEnableNewBookmarkApps); |
@@ -164,10 +164,115 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, |
https_app_browser, "https://www.example.com/blah", false); |
} |
+// Check that the location bar is shown correctly for normal hosted apps. |
+IN_PROC_BROWSER_TEST_F(HostedAppTest, |
+ ShouldShowLocationBarForHostedApp) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ // Load a hosted app. |
+ const Extension* hosted_app = InstallExtension( |
+ test_data_dir_.AppendASCII("app/"), 1, extensions::Manifest::INTERNAL); |
Lei Zhang
2015/06/05 01:51:50
Do you need the trailing path separate in "app/" ?
benwells
2015/06/05 03:19:47
Done.
|
+ ASSERT_TRUE(hosted_app); |
+ |
+ // Launch it in a window. |
+ WebContents* app_window = OpenApplication(AppLaunchParams( |
+ browser()->profile(), hosted_app, |
+ extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, |
+ extensions::SOURCE_TEST)); |
+ ASSERT_TRUE(app_window); |
+ |
+ // Find the new browser. |
+ Browser* app_browser = NULL; |
Lei Zhang
2015/06/05 01:51:50
nit: nullptr in new code.
benwells
2015/06/05 03:19:47
Done.
|
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
+ std::string app_id = |
+ web_app::GetExtensionIdFromApplicationName((*it)->app_name()); |
+ if (*it == browser()) { |
Lei Zhang
2015/06/05 01:51:50
You can check this first before setting app_id.
i
benwells
2015/06/05 03:19:47
Done.
|
+ continue; |
+ } else if (app_id == hosted_app->id()) { |
+ app_browser = *it; |
+ } |
+ } |
+ ASSERT_TRUE(app_browser); |
+ ASSERT_TRUE(app_browser != browser()); |
+ |
+ // Navigate to the app's launch page; the location bar should be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.example.com/empty.html", false); |
+ |
+ // Navigate to another page on the same origin; the location bar should still |
+ // hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.example.com/blah", false); |
+ |
+ // Navigate to the https version of the site; the location bar should |
+ // be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "https://www.example.com/blah", false); |
+ |
+ // Navigate to different origin; the location bar should now be visible. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.foo.com/blah", true); |
+ |
+ // Navigate back to the app's origin; the location bar should now be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.example.com/blah", false); |
+} |
+ |
+// Check that the location bar is shown correctly for hosted apps that specify |
+// start URLs without the 'www.' prefix. |
+IN_PROC_BROWSER_TEST_F(HostedAppTest, |
+ LocationBarForHostedAppWithoutWWW) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ // Load a hosted app. |
+ const Extension* hosted_app = |
+ InstallExtension(test_data_dir_.AppendASCII("app_no_www/"), 1, |
+ extensions::Manifest::INTERNAL); |
+ ASSERT_TRUE(hosted_app); |
+ |
+ // Launch it in a window. |
+ WebContents* app_window = OpenApplication(AppLaunchParams( |
+ browser()->profile(), hosted_app, |
+ extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, |
+ extensions::SOURCE_TEST)); |
+ ASSERT_TRUE(app_window); |
+ |
+ // Find the new browser. |
+ Browser* app_browser = NULL; |
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
+ std::string app_id = |
+ web_app::GetExtensionIdFromApplicationName((*it)->app_name()); |
+ if (*it == browser()) { |
+ continue; |
+ } else if (app_id == hosted_app->id()) { |
+ app_browser = *it; |
+ } |
+ } |
+ ASSERT_TRUE(app_browser); |
+ ASSERT_TRUE(app_browser != browser()); |
+ |
+ // Navigate to the app's launch page; the location bar should be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://example.com/empty.html", false); |
+ |
+ // Navigate to the app's launch page with the 'www.' prefis; the location bar |
+ // should be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.example.com/empty.html", false); |
+ |
+ // Navigate to different origin; the location bar should now be visible. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://www.foo.com/blah", true); |
+ |
+ // Navigate back to the app's origin; the location bar should now be hidden. |
+ NavigateAndCheckForLocationBar( |
+ app_browser, "http://example.com/blah", false); |
+} |
+ |
// Open a normal browser window, a hosted app window, a legacy packaged app |
// window and a dev tools window, and check that the web app frame feature is |
// supported correctly. |
-IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) { |
+IN_PROC_BROWSER_TEST_F(HostedAppTest, ShouldUseWebAppFrame) { |
ASSERT_TRUE(test_server()->Start()); |
base::CommandLine::ForCurrentProcess()->AppendSwitch( |
switches::kEnableWebAppFrame); |