Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: chrome/browser/ui/extensions/hosted_app_browsertest.cc

Issue 1164873003: Show origin for hosted apps that navigate away from their start origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback for the stig Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/extensions/hosted_app_browser_controller.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60%
rename from chrome/browser/ui/extensions/bookmark_app_browsertest.cc
rename to chrome/browser/ui/extensions/hosted_app_browsertest.cc
index 186029b026c89fdaefa84bdb1f604276ca44cee4..fa964556c8516716d18783f55206f982d67c381e 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,8 +28,6 @@
using content::WebContents;
using extensions::Extension;
-typedef ExtensionBrowserTest BookmarkAppTest;
-
namespace {
// Used by ShouldLocationBarForXXX. Performs a navigation and then checks that
@@ -40,141 +38,174 @@ 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
+class HostedAppTest : public ExtensionBrowserTest {
+ public:
+ HostedAppTest() : app_browser_(nullptr) {}
+ ~HostedAppTest() override {}
+
+ protected:
+ void SetupApp(const std::string& app_folder, bool is_bookmark_app) {
+ const Extension* app = InstallExtensionWithSourceAndFlags(
+ test_data_dir_.AppendASCII(app_folder), 1,
+ extensions::Manifest::INTERNAL,
+ is_bookmark_app ? extensions::Extension::FROM_BOOKMARK
+ : extensions::Extension::NO_FLAGS);
+ ASSERT_TRUE(app);
+
+ // Launch it in a window.
+ ASSERT_TRUE(OpenApplication(AppLaunchParams(
+ browser()->profile(), app, extensions::LAUNCH_CONTAINER_WINDOW,
+ NEW_WINDOW, extensions::SOURCE_TEST)));
+
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) {
+ if (*it == browser())
+ continue;
+
+ std::string browser_app_id =
+ web_app::GetExtensionIdFromApplicationName((*it)->app_name());
+ if (browser_app_id == app->id()) {
+ app_browser_ = *it;
+ break;
+ }
+ }
+
+ ASSERT_TRUE(app_browser_);
+ ASSERT_TRUE(app_browser_ != browser());
+ }
+
+ Browser* app_browser_;
+};
+
// 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);
- ASSERT_TRUE(test_server()->Start());
- // Load a http bookmark app.
- const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags(
- test_data_dir_.AppendASCII("app/"),
- 1,
- extensions::Manifest::INTERNAL,
- extensions::Extension::FROM_BOOKMARK);
- ASSERT_TRUE(http_bookmark_app);
-
- // Launch it in a window.
- WebContents* app_window = OpenApplication(AppLaunchParams(
- browser()->profile(), http_bookmark_app,
- extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
- extensions::SOURCE_TEST));
- ASSERT_TRUE(app_window);
-
- // Find the new browser.
- Browser* http_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 == http_bookmark_app->id()) {
- http_app_browser = *it;
- }
- }
- ASSERT_TRUE(http_app_browser);
- ASSERT_TRUE(http_app_browser != browser());
+ SetupApp("app", true);
// Navigate to the app's launch page; the location bar should be hidden.
NavigateAndCheckForLocationBar(
- http_app_browser, "http://www.example.com/empty.html", false);
+ app_browser_, "http://www.example.com/empty.html", false);
// Navigate to another page on the same origin; the location bar should still
// hidden.
NavigateAndCheckForLocationBar(
- http_app_browser, "http://www.example.com/blah", false);
+ 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);
+ app_browser_, "https://www.example.com/blah", false);
// Navigate to different origin; the location bar should now be visible.
NavigateAndCheckForLocationBar(
- http_app_browser, "http://www.foo.com/blah", true);
+ app_browser_, "http://www.foo.com/blah", true);
// Navigate back to the app's origin; the location bar should now be hidden.
NavigateAndCheckForLocationBar(
- http_app_browser, "http://www.example.com/blah", false);
+ app_browser_, "http://www.example.com/blah", false);
}
// 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);
- ASSERT_TRUE(test_server()->Start());
- // Load a https bookmark app.
- const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags(
- test_data_dir_.AppendASCII("https_app/"),
- 1,
- extensions::Manifest::INTERNAL,
- extensions::Extension::FROM_BOOKMARK);
- ASSERT_TRUE(https_bookmark_app);
-
- // Launch it in a window.
- WebContents* app_window = OpenApplication(AppLaunchParams(
- browser()->profile(), https_bookmark_app,
- extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW,
- extensions::SOURCE_TEST));
- ASSERT_TRUE(app_window);
-
- // Find the new browser.
- Browser* https_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 == https_bookmark_app->id()) {
- https_app_browser = *it;
- }
- }
- ASSERT_TRUE(https_app_browser);
- ASSERT_TRUE(https_app_browser != browser());
+ SetupApp("https_app", true);
// Navigate to the app's launch page; the location bar should be hidden.
NavigateAndCheckForLocationBar(
- https_app_browser, "https://www.example.com/empty.html", false);
+ app_browser_, "https://www.example.com/empty.html", false);
// Navigate to another page on the same origin; the location bar should still
// hidden.
NavigateAndCheckForLocationBar(
- https_app_browser, "https://www.example.com/blah", false);
+ app_browser_, "https://www.example.com/blah", false);
// Navigate to the http version of the site; the location bar should
// be visible for the https version as it is now on a less secure version
// of its host.
NavigateAndCheckForLocationBar(
- https_app_browser, "http://www.example.com/blah", true);
+ app_browser_, "http://www.example.com/blah", true);
+
+ // 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_, "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) {
+ SetupApp("app", false);
+
+ // 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) {
+ SetupApp("app_no_www", false);
+
+ // 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(
- https_app_browser, "http://www.foo.com/blah", true);
+ app_browser_, "http://www.foo.com/blah", true);
// Navigate back to the app's origin; the location bar should now be hidden.
NavigateAndCheckForLocationBar(
- https_app_browser, "https://www.example.com/blah", false);
+ 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) {
- ASSERT_TRUE(test_server()->Start());
+IN_PROC_BROWSER_TEST_F(HostedAppTest, ShouldUseWebAppFrame) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableWebAppFrame);
// Load a hosted app.
const Extension* bookmark_app = InstallExtensionWithSourceAndFlags(
- test_data_dir_.AppendASCII("app/"),
+ test_data_dir_.AppendASCII("app"),
1,
extensions::Manifest::INTERNAL,
extensions::Extension::FROM_BOOKMARK);
@@ -187,7 +218,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) {
ASSERT_TRUE(bookmark_app_window);
// Load a packaged app.
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app/")));
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app")));
const Extension* packaged_app = nullptr;
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(browser()->profile());
@@ -212,9 +243,9 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppTest, ShouldUseWebAppFrame) {
browser()->host_desktop_type()));
// Find the new browsers.
- Browser* bookmark_app_browser = NULL;
- Browser* packaged_app_browser = NULL;
- Browser* dev_tools_browser = NULL;
+ Browser* bookmark_app_browser = nullptr;
+ Browser* packaged_app_browser = nullptr;
+ Browser* dev_tools_browser = nullptr;
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
if (*it == browser()) {
continue;
« no previous file with comments | « chrome/browser/ui/extensions/hosted_app_browser_controller.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698