0
Files
src/content/browser/site_per_process_browsertest.h
Lukasz Anforowicz e9db2659d4 Make Blink compatible with url::Origin::Resolve(...'about:blank'...).
Main change: blink::SecurityOrigin::CreateWithReferenceOrigin
=============================================================

The main change in this CL is changing how blink::SecurityOrigin's
CreateWithReferenceOrigin handles "about:blank" URLs.  Before this CL,
an opaque origin would be returned;  after this CL, the reference origin
is returned.

This change is desirable, because:

1. It makes blink::SecurityOrigin::CreateWithReferenceOrigin
   compatible with url::Origin::Resolve.  This lets us copy additional
   test assertions from OriginTest.ConstructFromGURL testcase in
   //url/origin_unittest.cc (url::Origin-specific tests) to
   AbstractOriginTest::VerifyOriginInvariants in
   //url/origin_abstract_tests.h (tests shared across
   blink::SecurityOrigin and url::Origin)

2. It causes "about:blank" to commit with the correct origin (based on
   the origin of the initiator of the navigation) when the
   `owner_document` is missing (e.g. when the parent is a remote frame,
   see also a follow-up CL: https://crrev.com/c/2639656).  This lets us
   have mostly correct test expectations in the new
   NavigationBrowserTest*ToAboutBlank* tests added in this CL, as well
   as fix test expectations in some already existing tests:
   - ChromeNavigationBrowserTest.
     NavigationInitiatedByCrossSiteSubframeRedirectedToAboutBlank
   - ExtensionApiTest.TabsUpdate_WebToAboutBlank

   - MultiOriginSessionRestoreTest.BackToAboutBlank1
   - MultiOriginSessionRestoreTest.BackToAboutBlank2
   - TabRestoreTest.BackToAboutBlank

   - SitePerProcessBrowserTest.SandboxFlagsNotInheritedBeforeNavigation
   - SitePerProcessBrowserTest.SubframeBlankUrlsAfterRestore


Supplementary changes
=====================

To make sure that the new origin of "about:blank" remains compatible
with the process lock, some additional changes need to be made:

- ExtensionApiTabTest.Tabs2 navigates to about:blank in noopener mode.
  We are preserving the initiator_origin (if url were http then the
  initiator would control SameSite cookies, etc).  But if we preserve
  the initiator origin then "about:blank" needs to commit with the same
  origin as the initiator.  And if the initiator origin requires process
  locks, then we can’t commit in an unlocked process.  Therefore we need
  to call NavigationRequest::SetSourceSiteInstanceToInitiatorIfNeeded
  for non-history navigations in no-opener mode.

- ExtensionApiTabTest.HostPermission hits a browsing-instance-swap case
  in DetermineSiteInstanceForURL (swap forced because of going from
  WebUI to non-WebUI: current_effective_url = chrome://new-tab-page/;
  destination_effective_url = about:blank).  This forces the CL to
  modify `force_browsing_instance_swap` case in
  DetermineSiteInstanceForURL to use `source_instance` if the
  `source_instance` already comes from a different browsing instance.
  Without this tweak, about:blank would commit in an unlocked site
  instance and fail with CANNOT_COMMIT_ORIGIN url 'about:blank' origin
  'chrome-extension://...'.


Summary of new tests added in this CL
=====================================

- NavigationBrowserTest.GrandchildToAboutBlank_ABA_SameSite
  (no process swaps, parent of the navigated frame is a local frame)

- NavigationBrowserTest.GrandchildToAboutBlank_ABA_CrossSite
  (no process swaps, parent of the navigated frame is a remote frame)

- NavigationBrowserTest.GrandchildToAboutBlank_ABB_CrossSite
  (process swap required, initially parent of the navigated frame is a
  local frame, when committing parent of the navigated frame is a remote
  frame)

- NavigationBrowserTest.TopToAboutBlank_CrossSite
  (the initiator of the navigation is destroyed as the result of the
  navigation)

- SameSiteSiblingToAboutBlank_CrossSiteTop
  (initiator of the navigation is not an ancestor nor a child of the
  navigated frame; the initiator has to be same-origin as the target
  frame - a cross-origin initiator would be blocked from navigating the
  target frame)

Bug: 585649
Change-Id: Ibc4a25a3af96e65b4d7759a09c3cc47d6fb51356
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637187
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#847405}
2021-01-27 00:24:12 +00:00

64 lines
1.8 KiB
C++

// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_
#define CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_
#include <string>
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/content_browser_test.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "url/gurl.h"
namespace content {
class FrameTreeNode;
class SitePerProcessBrowserTestBase : public ContentBrowserTest {
public:
SitePerProcessBrowserTestBase();
protected:
std::string DepictFrameTree(FrameTreeNode* node);
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
WebContentsImpl* web_contents() const {
return static_cast<WebContentsImpl*>(shell()->web_contents());
}
static void ForceUpdateViewportIntersection(
FrameTreeNode* frame_tree_node,
const blink::mojom::ViewportIntersectionState& intersection_state);
private:
FrameTreeVisualizer visualizer_;
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(SitePerProcessBrowserTestBase);
};
class SitePerProcessBrowserTest
: public SitePerProcessBrowserTestBase,
public ::testing::WithParamInterface<std::string> {
public:
SitePerProcessBrowserTest();
std::string GetExpectedOrigin(const std::string& host);
private:
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(SitePerProcessBrowserTest);
};
} // namespace content
#endif // CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_