| 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 "base/test/scoped_feature_list.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/extensions/app_launch_params.h" | 14 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 14 #include "chrome/browser/ui/extensions/application_launch.h" | 15 #include "chrome/browser/ui/extensions/application_launch.h" |
| 15 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" | 16 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/web_applications/web_app.h" | 18 #include "chrome/browser/web_applications/web_app.h" |
| 18 #include "chrome/common/chrome_switches.h" | |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
| 23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 24 #include "extensions/common/extension_set.h" | 24 #include "extensions/common/extension_set.h" |
| 25 | 25 |
| 26 #if defined(OS_MACOSX) |
| 27 #include "chrome/common/chrome_features.h" |
| 28 #endif |
| 29 |
| 26 using content::WebContents; | 30 using content::WebContents; |
| 27 using extensions::Extension; | 31 using extensions::Extension; |
| 28 | 32 |
| 29 namespace { | 33 namespace { |
| 30 | 34 |
| 31 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that | 35 // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that |
| 32 // the location bar visibility is as expcted. | 36 // the location bar visibility is as expcted. |
| 33 void NavigateAndCheckForLocationBar(Browser* browser, | 37 void NavigateAndCheckForLocationBar(Browser* browser, |
| 34 const std::string& url_string, | 38 const std::string& url_string, |
| 35 bool expected_visibility) { | 39 bool expected_visibility) { |
| 36 GURL url(url_string); | 40 GURL url(url_string); |
| 37 ui_test_utils::NavigateToURL(browser, url); | 41 ui_test_utils::NavigateToURL(browser, url); |
| 38 EXPECT_EQ(expected_visibility, | 42 EXPECT_EQ(expected_visibility, |
| 39 browser->hosted_app_controller()->ShouldShowLocationBar()); | 43 browser->hosted_app_controller()->ShouldShowLocationBar()); |
| 40 } | 44 } |
| 41 | 45 |
| 42 } // namespace | 46 } // namespace |
| 43 | 47 |
| 44 class HostedAppTest : public ExtensionBrowserTest { | 48 class HostedAppTest : public ExtensionBrowserTest { |
| 45 public: | 49 public: |
| 46 HostedAppTest() : app_browser_(nullptr) {} | 50 HostedAppTest() : app_browser_(nullptr) {} |
| 47 ~HostedAppTest() override {} | 51 ~HostedAppTest() override {} |
| 48 | 52 |
| 53 // testing::Test: |
| 54 void SetUp() override { |
| 55 ExtensionBrowserTest::SetUp(); |
| 56 #if defined(OS_MACOSX) |
| 57 scoped_feature_list_.InitAndEnableFeature(features::kBookmarkApps); |
| 58 #endif |
| 59 } |
| 60 |
| 49 protected: | 61 protected: |
| 50 void SetupApp(const std::string& app_folder, bool is_bookmark_app) { | 62 void SetupApp(const std::string& app_folder, bool is_bookmark_app) { |
| 51 const Extension* app = InstallExtensionWithSourceAndFlags( | 63 const Extension* app = InstallExtensionWithSourceAndFlags( |
| 52 test_data_dir_.AppendASCII(app_folder), 1, | 64 test_data_dir_.AppendASCII(app_folder), 1, |
| 53 extensions::Manifest::INTERNAL, | 65 extensions::Manifest::INTERNAL, |
| 54 is_bookmark_app ? extensions::Extension::FROM_BOOKMARK | 66 is_bookmark_app ? extensions::Extension::FROM_BOOKMARK |
| 55 : extensions::Extension::NO_FLAGS); | 67 : extensions::Extension::NO_FLAGS); |
| 56 ASSERT_TRUE(app); | 68 ASSERT_TRUE(app); |
| 57 | 69 |
| 58 // Launch it in a window. | 70 // Launch it in a window. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 app_browser_ = b; | 82 app_browser_ = b; |
| 71 break; | 83 break; |
| 72 } | 84 } |
| 73 } | 85 } |
| 74 | 86 |
| 75 ASSERT_TRUE(app_browser_); | 87 ASSERT_TRUE(app_browser_); |
| 76 ASSERT_TRUE(app_browser_ != browser()); | 88 ASSERT_TRUE(app_browser_ != browser()); |
| 77 } | 89 } |
| 78 | 90 |
| 79 Browser* app_browser_; | 91 Browser* app_browser_; |
| 92 |
| 93 private: |
| 94 base::test::ScopedFeatureList scoped_feature_list_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(HostedAppTest); |
| 80 }; | 97 }; |
| 81 | 98 |
| 82 // Check that the location bar is shown correctly for bookmark apps. | 99 // Check that the location bar is shown correctly for bookmark apps. |
| 83 IN_PROC_BROWSER_TEST_F(HostedAppTest, | 100 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
| 84 ShouldShowLocationBarForBookmarkApp) { | 101 ShouldShowLocationBarForBookmarkApp) { |
| 85 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 86 switches::kEnableNewBookmarkApps); | |
| 87 | |
| 88 SetupApp("app", true); | 102 SetupApp("app", true); |
| 89 | 103 |
| 90 // Navigate to the app's launch page; the location bar should be hidden. | 104 // Navigate to the app's launch page; the location bar should be hidden. |
| 91 NavigateAndCheckForLocationBar( | 105 NavigateAndCheckForLocationBar( |
| 92 app_browser_, "http://www.example.com/empty.html", false); | 106 app_browser_, "http://www.example.com/empty.html", false); |
| 93 | 107 |
| 94 // Navigate to another page on the same origin; the location bar should still | 108 // Navigate to another page on the same origin; the location bar should still |
| 95 // hidden. | 109 // hidden. |
| 96 NavigateAndCheckForLocationBar( | 110 NavigateAndCheckForLocationBar( |
| 97 app_browser_, "http://www.example.com/blah", false); | 111 app_browser_, "http://www.example.com/blah", false); |
| 98 | 112 |
| 99 // Navigate to different origin; the location bar should now be visible. | 113 // Navigate to different origin; the location bar should now be visible. |
| 100 NavigateAndCheckForLocationBar( | 114 NavigateAndCheckForLocationBar( |
| 101 app_browser_, "http://www.foo.com/blah", true); | 115 app_browser_, "http://www.foo.com/blah", true); |
| 102 } | 116 } |
| 103 | 117 |
| 104 // Check that the location bar is shown correctly for HTTP bookmark apps when | 118 // Check that the location bar is shown correctly for HTTP bookmark apps when |
| 105 // they navigate to a HTTPS page on the same origin. | 119 // they navigate to a HTTPS page on the same origin. |
| 106 IN_PROC_BROWSER_TEST_F(HostedAppTest, | 120 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
| 107 ShouldShowLocationBarForHTTPBookmarkApp) { | 121 ShouldShowLocationBarForHTTPBookmarkApp) { |
| 108 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 109 switches::kEnableNewBookmarkApps); | |
| 110 | |
| 111 SetupApp("app", true); | 122 SetupApp("app", true); |
| 112 | 123 |
| 113 // Navigate to the app's launch page; the location bar should be hidden. | 124 // Navigate to the app's launch page; the location bar should be hidden. |
| 114 NavigateAndCheckForLocationBar( | 125 NavigateAndCheckForLocationBar( |
| 115 app_browser_, "http://www.example.com/empty.html", false); | 126 app_browser_, "http://www.example.com/empty.html", false); |
| 116 | 127 |
| 117 // Navigate to the https version of the site; the location bar should | 128 // Navigate to the https version of the site; the location bar should |
| 118 // be hidden. | 129 // be hidden. |
| 119 NavigateAndCheckForLocationBar( | 130 NavigateAndCheckForLocationBar( |
| 120 app_browser_, "https://www.example.com/blah", false); | 131 app_browser_, "https://www.example.com/blah", false); |
| 121 } | 132 } |
| 122 | 133 |
| 123 // Check that the location bar is shown correctly for HTTPS bookmark apps when | 134 // Check that the location bar is shown correctly for HTTPS bookmark apps when |
| 124 // they navigate to a HTTP page on the same origin. | 135 // they navigate to a HTTP page on the same origin. |
| 125 IN_PROC_BROWSER_TEST_F(HostedAppTest, | 136 IN_PROC_BROWSER_TEST_F(HostedAppTest, |
| 126 ShouldShowLocationBarForHTTPSBookmarkApp) { | 137 ShouldShowLocationBarForHTTPSBookmarkApp) { |
| 127 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 128 switches::kEnableNewBookmarkApps); | |
| 129 | |
| 130 SetupApp("https_app", true); | 138 SetupApp("https_app", true); |
| 131 | 139 |
| 132 // Navigate to the app's launch page; the location bar should be hidden. | 140 // Navigate to the app's launch page; the location bar should be hidden. |
| 133 NavigateAndCheckForLocationBar( | 141 NavigateAndCheckForLocationBar( |
| 134 app_browser_, "https://www.example.com/empty.html", false); | 142 app_browser_, "https://www.example.com/empty.html", false); |
| 135 | 143 |
| 136 // Navigate to the http version of the site; the location bar should | 144 // Navigate to the http version of the site; the location bar should |
| 137 // be visible for the https version as it is now on a less secure version | 145 // be visible for the https version as it is now on a less secure version |
| 138 // of its host. | 146 // of its host. |
| 139 NavigateAndCheckForLocationBar( | 147 NavigateAndCheckForLocationBar( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 179 |
| 172 // Navigate to the app's launch page with the 'www.' prefis; the location bar | 180 // Navigate to the app's launch page with the 'www.' prefis; the location bar |
| 173 // should be hidden. | 181 // should be hidden. |
| 174 NavigateAndCheckForLocationBar( | 182 NavigateAndCheckForLocationBar( |
| 175 app_browser_, "http://www.example.com/empty.html", false); | 183 app_browser_, "http://www.example.com/empty.html", false); |
| 176 | 184 |
| 177 // Navigate to different origin; the location bar should now be visible. | 185 // Navigate to different origin; the location bar should now be visible. |
| 178 NavigateAndCheckForLocationBar( | 186 NavigateAndCheckForLocationBar( |
| 179 app_browser_, "http://www.foo.com/blah", true); | 187 app_browser_, "http://www.foo.com/blah", true); |
| 180 } | 188 } |
| OLD | NEW |