1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
// Copyright 2018 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 CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_NAVIGATION_BROWSERTEST_H_
#define CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_NAVIGATION_BROWSERTEST_H_
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ssl/chrome_mock_cert_verifier.h"
#include "extensions/common/extension.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
class Browser;
namespace content {
class RenderFrameHost;
class TestNavigationObserver;
class WebContents;
} // namespace content
namespace extensions {
namespace test {
class BookmarkAppNavigationBrowserTest : public ExtensionBrowserTest {
public:
enum class LinkTarget {
SELF,
BLANK,
};
// Various string constants for in/out-of-scope URLs.
static const char* GetLaunchingPageHost();
static const char* GetLaunchingPagePath();
static const char* GetAppUrlHost();
static const char* GetOtherAppUrlHost();
static const char* GetAppScopePath();
static const char* GetAppUrlPath();
static const char* GetInScopeUrlPath();
static const char* GetOutOfScopeUrlPath();
static const char* GetAppName();
static std::string CreateServerRedirect(const GURL& target_url);
static std::unique_ptr<content::TestNavigationObserver>
GetTestNavigationObserver(const GURL& target_url);
// Returns a subframe in |web_contents|. |web_contents| is expected to have
// exactly 2 frames: the main frame and a subframe.
static content::RenderFrameHost* GetIFrame(
content::WebContents* web_contents);
protected:
// Creates an <a> element, sets its href and target to |link_url| and |target|
// respectively, adds it to the DOM, and clicks on it with |modifiers|.
// Returns once |target_url| has loaded. |modifiers| should be based on
// blink::WebInputEvent::Modifiers.
static void ClickLinkWithModifiersAndWaitForURL(
content::WebContents* web_contents,
const GURL& link_url,
const GURL& target_url,
LinkTarget target,
const std::string& rel,
int modifiers);
// Creates an <a> element, sets its href and target to |link_url| and |target|
// respectively, adds it to the DOM, and clicks on it. Returns once
// |target_url| has loaded.
static void ClickLinkAndWaitForURL(content::WebContents* web_contents,
const GURL& link_url,
const GURL& target_url,
LinkTarget target,
const std::string& rel);
// Creates an <a> element, sets its href and target to |link_url| and |target|
// respectively, adds it to the DOM, and clicks on it. Returns once the link
// has loaded.
static void ClickLinkAndWait(content::WebContents* web_contents,
const GURL& link_url,
LinkTarget target,
const std::string& rel);
// Creates an <a> element, sets its href and target to |link_url| and |target|
// respectively, adds it to the DOM, and clicks on it with |modifiers|.
// Returns once the link has loaded. |modifiers| should be based on
// blink::WebInputEvent::Modifiers.
static void ClickLinkWithModifiersAndWait(content::WebContents* web_contents,
const GURL& link_url,
LinkTarget target,
const std::string& rel,
int modifiers);
BookmarkAppNavigationBrowserTest();
~BookmarkAppNavigationBrowserTest() override;
void SetUp() override;
void SetUpInProcessBrowserTestFixture() override;
void TearDownInProcessBrowserTestFixture() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
void InstallTestBookmarkApp();
void InstallOtherTestBookmarkApp();
const Extension* InstallTestBookmarkApp(const std::string& app_host);
// Installs a Bookmark App that immediately redirects to a URL with
// |target_host| and |target_path|.
const Extension* InstallImmediateRedirectingApp(
const std::string& target_host,
const std::string& target_path);
Browser* OpenTestBookmarkApp();
// Navigates the active tab in |browser| to the launching page.
void NavigateToLaunchingPage(Browser* browser);
// Navigates the active tab to the launching page.
void NavigateToLaunchingPage();
// Navigates the browser's current active tab to the test app's URL. It does
// not open a new app window.
void NavigateToTestAppURL();
// Checks that, after running |action|, the initial tab's window doesn't have
// any new tabs, the initial tab did not navigate, and that no new windows
// have been opened.
void TestTabActionDoesNotNavigateOrOpenAppWindow(base::OnceClosure action);
// Checks that, after running |action|, a new tab is opened with |target_url|,
// the initial tab is still focused, and that the initial tab didn't
// navigate.
void TestTabActionOpensBackgroundTab(const GURL& target_url,
base::OnceClosure action);
// Checks that a new regular browser window is opened, that the new window
// is in the foreground, and that the initial tab didn't navigate.
void TestTabActionOpensForegroundWindow(const GURL& target_url,
base::OnceClosure action);
// Checks that, after running |action|, the initial tab's window doesn't have
// any new tabs, the initial tab did not navigate, and that a new app window
// with |target_url| is opened.
void TestTabActionOpensAppWindow(const GURL& target_url,
base::OnceClosure action);
// Same as TestTabActionOpensAppWindow(), but also tests that the newly opened
// app window has an opener.
void TestTabActionOpensAppWindowWithOpener(const GURL& target_url,
base::OnceClosure action);
// Checks that no new windows are opened after running |action| and that the
// existing |browser| window is still the active one and navigated to
// |target_url|. Returns true if there were no errors.
bool TestActionDoesNotOpenAppWindow(Browser* browser,
const GURL& target_url,
base::OnceClosure action);
// Checks that a new foreground tab is opened in an existing browser, that the
// new tab's browser is in the foreground, and that |app_browser| didn't
// navigate.
void TestAppActionOpensForegroundTab(Browser* app_browser,
const GURL& target_url,
base::OnceClosure action);
// Checks that a new app window is opened, that the new window is in the
// foreground, that the |app_browser| didn't navigate and that the new window
// has an opener.
void TestAppActionOpensAppWindowWithOpener(Browser* app_browser,
const GURL& target_url,
base::OnceClosure action);
// Checks that no new windows are opened after running |action| and that the
// main browser window is still the active one and navigated to |target_url|.
// Returns true if there were no errors.
bool TestTabActionDoesNotOpenAppWindow(const GURL& target_url,
base::OnceClosure action);
// Checks that no new windows are opened after running |action| and that the
// iframe in the initial tab navigated to |target_url|. Returns true if there
// were no errors.
bool TestIFrameActionDoesNotOpenAppWindow(const GURL& target_url,
base::OnceClosure action);
GURL GetLaunchingPageURL();
const base::HistogramTester& global_histogram() { return histogram_tester_; }
const Extension* test_bookmark_app() { return test_bookmark_app_; }
const net::EmbeddedTestServer& https_server() { return https_server_; }
content::ContentMockCertVerifier::CertVerifier& mock_cert_verifier() {
return *cert_verifier_.mock_cert_verifier();
}
private:
net::EmbeddedTestServer https_server_;
net::MockCertVerifier mock_cert_verifier_;
// Similar to net::MockCertVerifier, but also updates the CertVerifier
// used by the NetworkService. This is needed for when tests run with
// the NetworkService enabled.
ChromeMockCertVerifier cert_verifier_;
const Extension* test_bookmark_app_;
base::HistogramTester histogram_tester_;
};
} // namespace test
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_NAVIGATION_BROWSERTEST_H_
|