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

Side by Side Diff: chrome/browser/ui/extensions/hosted_app_browsertest.cc

Issue 2891633002: Add a test for subframes redirecting to hosted app URLs. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/test/scoped_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 if (browser_app_id == app->id()) { 92 if (browser_app_id == app->id()) {
93 app_browser_ = b; 93 app_browser_ = b;
94 break; 94 break;
95 } 95 }
96 } 96 }
97 97
98 ASSERT_TRUE(app_browser_); 98 ASSERT_TRUE(app_browser_);
99 ASSERT_TRUE(app_browser_ != browser()); 99 ASSERT_TRUE(app_browser_ != browser());
100 } 100 }
101 101
102 void SetUpOnMainThread() override {
103 ExtensionBrowserTest::SetUpOnMainThread();
104 host_resolver()->AddRule("*", "127.0.0.1");
105 }
106
102 Browser* app_browser_; 107 Browser* app_browser_;
103 108
104 private: 109 private:
105 base::test::ScopedFeatureList scoped_feature_list_; 110 base::test::ScopedFeatureList scoped_feature_list_;
106 111
107 DISALLOW_COPY_AND_ASSIGN(HostedAppTest); 112 DISALLOW_COPY_AND_ASSIGN(HostedAppTest);
108 }; 113 };
109 114
110 // Check that the location bar is shown correctly for bookmark apps. 115 // Check that the location bar is shown correctly for bookmark apps.
111 IN_PROC_BROWSER_TEST_F(HostedAppTest, 116 IN_PROC_BROWSER_TEST_F(HostedAppTest,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Navigate to the app's launch page with the 'www.' prefis; the location bar 196 // Navigate to the app's launch page with the 'www.' prefis; the location bar
192 // should be hidden. 197 // should be hidden.
193 NavigateAndCheckForLocationBar( 198 NavigateAndCheckForLocationBar(
194 app_browser_, "http://www.example.com/empty.html", false); 199 app_browser_, "http://www.example.com/empty.html", false);
195 200
196 // Navigate to different origin; the location bar should now be visible. 201 // Navigate to different origin; the location bar should now be visible.
197 NavigateAndCheckForLocationBar( 202 NavigateAndCheckForLocationBar(
198 app_browser_, "http://www.foo.com/blah", true); 203 app_browser_, "http://www.foo.com/blah", true);
199 } 204 }
200 205
206 // Check that a subframe on a regular web page can navigate to a URL that
207 // redirects to a hosted app. https://crbug.com/721949.
208 IN_PROC_BROWSER_TEST_F(HostedAppTest, SubframeRedirectsToHostedApp) {
209 ASSERT_TRUE(embedded_test_server()->Start());
210
211 // Set up an app which covers app.com URLs.
212 GURL app_url = embedded_test_server()->GetURL("app.com", "/title1.html");
213 extensions::TestExtensionDir test_app_dir;
214 test_app_dir.WriteManifest(base::StringPrintf(
215 R"( { "name": "Hosted App",
216 "version": "1",
217 "manifest_version": 2,
218 "app": {
219 "launch": {
220 "web_url": "%s"
221 },
222 "urls": ["*://app.com/"]
223 }
224 } )",
225 app_url.spec().c_str()));
226 SetupApp(test_app_dir.UnpackedPath(), false);
227
228 // Navigate a regular tab to a page with a subframe.
229 GURL url = embedded_test_server()->GetURL("foo.com", "/iframe.html");
230 content::WebContents* tab =
231 browser()->tab_strip_model()->GetActiveWebContents();
232 ui_test_utils::NavigateToURL(browser(), url);
233
234 // Navigate the subframe to a URL that redirects to a URL in the hosted app's
235 // web extent.
236 GURL redirect_url = embedded_test_server()->GetURL(
237 "bar.com", "/server-redirect?" + app_url.spec());
238 EXPECT_TRUE(NavigateIframeToURL(tab, "test", redirect_url));
239
240 // Ensure that the frame navigated successfully and that it has correct
241 // content.
242 content::RenderFrameHost* subframe =
243 content::ChildFrameAt(tab->GetMainFrame(), 0);
244 EXPECT_EQ(app_url, subframe->GetLastCommittedURL());
245 std::string result;
246 EXPECT_TRUE(ExecuteScriptAndExtractString(
247 subframe, "window.domAutomationController.send(document.body.innerText);",
248 &result));
249 EXPECT_EQ("This page has no title.", result);
250 }
251
201 class HostedAppVsTdiTest : public HostedAppTest { 252 class HostedAppVsTdiTest : public HostedAppTest {
202 public: 253 public:
203 HostedAppVsTdiTest() {} 254 HostedAppVsTdiTest() {}
204 ~HostedAppVsTdiTest() override {} 255 ~HostedAppVsTdiTest() override {}
205 256
206 void SetUpOnMainThread() override { 257 void SetUpOnMainThread() override {
207 scoped_feature_list_.InitAndEnableFeature(features::kTopDocumentIsolation); 258 scoped_feature_list_.InitAndEnableFeature(features::kTopDocumentIsolation);
208 HostedAppTest::SetUpOnMainThread(); 259 HostedAppTest::SetUpOnMainThread();
209 host_resolver()->AddRule("*", "127.0.0.1");
210 ASSERT_TRUE(embedded_test_server()->Start()); 260 ASSERT_TRUE(embedded_test_server()->Start());
211 } 261 }
212 262
213 private: 263 private:
214 base::test::ScopedFeatureList scoped_feature_list_; 264 base::test::ScopedFeatureList scoped_feature_list_;
215 265
216 DISALLOW_COPY_AND_ASSIGN(HostedAppVsTdiTest); 266 DISALLOW_COPY_AND_ASSIGN(HostedAppVsTdiTest);
217 }; 267 };
218 268
219 // Tests that even with --top-document-isolation, app.site.com (covered by app's 269 // Tests that even with --top-document-isolation, app.site.com (covered by app's
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } else { 393 } else {
344 // TODO(lukasza): https://crbug.com/718516: Process policy is not 394 // TODO(lukasza): https://crbug.com/718516: Process policy is not
345 // well-defined / settled wrt relationship between 1) hosted apps and 2) 395 // well-defined / settled wrt relationship between 1) hosted apps and 2)
346 // same-site web content outside of hosted app's extent. When this test was 396 // same-site web content outside of hosted app's extent. When this test was
347 // authored --site-per-process would put |app| in a separate renderer 397 // authored --site-per-process would put |app| in a separate renderer
348 // process from |diff_dir| and |same_site|, even though such process 398 // process from |diff_dir| and |same_site|, even though such process
349 // placement can be problematic (if |app| tries to synchronously script 399 // placement can be problematic (if |app| tries to synchronously script
350 // |diff_dir| and/or |same_site|). 400 // |diff_dir| and/or |same_site|).
351 } 401 }
352 } 402 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698