chromium/chrome/browser/apps/platform_apps/platform_app_navigation_redirector_browsertest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/embedder_support/switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/base/page_transition_types.h"

namespace extensions {

class PlatformAppNavigationRedirectorBrowserTest
    : public PlatformAppBrowserTest {};

void PlatformAppNavigationRedirectorBrowserTest::SetUpCommandLine(
    base::CommandLine* command_line) {}

// TODO(sergeygs): Factor out common functionality from TestXyz,
// TestNegativeXyz, and TestMismatchingXyz versions.

// TODO(sergeys): Return testing::AssertionErrors from these methods to
// preserve line numbers and (if applicable) failure messages.

void PlatformAppNavigationRedirectorBrowserTest::TestNavigationInTab(
    const char* launcher_page,
    const char* handler,
    const char* handler_start_message) {}

void PlatformAppNavigationRedirectorBrowserTest::TestMismatchingNavigationInTab(
    const char* launcher_page,
    const char* success_tab_title,
    const char* handler) {}

void PlatformAppNavigationRedirectorBrowserTest::TestNegativeXhrInTab(
    const char* launcher_page,
    const char* success_tab_title,
    const char* failure_tab_title,
    const char* handler) {}

void PlatformAppNavigationRedirectorBrowserTest::TestNavigationInApp(
    const char* launcher,
    const char* launcher_done_message,
    const char* handler,
    const char* handler_start_message) {}

void PlatformAppNavigationRedirectorBrowserTest::TestNegativeNavigationInApp(
    const char* launcher,
    const char* launcher_done_message,
    const char* handler) {}

void PlatformAppNavigationRedirectorBrowserTest::TestMismatchingNavigationInApp(
    const char* launcher,
    const char* launcher_done_message,
    const char* handler) {}

void PlatformAppNavigationRedirectorBrowserTest::TestNavigationInBrowser(
    const char* matching_target_page,
    ui::PageTransition transition,
    const char* handler,
    const char* handler_start_message) {}

void PlatformAppNavigationRedirectorBrowserTest::
    TestNegativeNavigationInBrowser(const char* matching_target_page,
                                    ui::PageTransition transition,
                                    const char* success_tab_title,
                                    const char* handler) {}

void PlatformAppNavigationRedirectorBrowserTest::
    TestMismatchingNavigationInBrowser(const char* mismatching_target_page,
                                       ui::PageTransition transition,
                                       const char* success_tab_title,
                                       const char* handler) {}

// Test that a click on a regular link in a tab launches an app that has
// matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       ClickInTabIntercepted) {}

// Test that a click on a target='_blank' link in a tab launches an app that has
// matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       BlankClickInTabIntercepted) {}

// Test that a call to window.open() in a tab launches an app that has
// matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       WindowOpenInTabIntercepted) {}

// Test that a click on a regular link in a tab launches an app that has
// matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       MismatchingClickInTabNotIntercepted) {}

// Test that a click on target='_blank' link in an app's window launches
// another app that has matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       BlankClickInAppIntercepted) {}

// Test that a call to window.open() in the app's foreground page launches
// another app that has matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       WindowOpenInAppIntercepted) {}

// Test that an app with url_handlers does not intercept a mismatching
// click on a target='_blank' link in another app's window.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       MismatchingWindowOpenInAppNotIntercepted) {}

// Test that a webview in an app can be navigated to a URL without interception
// even when there are other (or the same) apps that have matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       WebviewNavigationNotIntercepted) {}

// Test that a webview in an app can be navigated to a URL without interception
// even when there are other (or the same) apps that have matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       MismatchingBlankClickInAppNotIntercepted) {}

// Test that a URL entry in the omnibar launches an app that has matching
// url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       EntryInOmnibarIntercepted) {}

// Test that an app with url_handlers does not intercept a mismatching
// URL entry in the omnibar.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       MismatchingEntryInOmnibarNotIntercepted) {}

// Test that a form submission in a page is never subject to interception
// by apps even with matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       FormSubmissionInTabNotIntercepted) {}

// Test that a form submission in a page is never subject to interception
// by apps even with matching url_handlers.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorBrowserTest,
                       XhrInTabNotIntercepted) {}

class PlatformAppNavigationRedirectorPrerenderingBrowserTest
    : public PlatformAppNavigationRedirectorBrowserTest {};

// Test that prerendering doesn't launch an app but aborts the navigation.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorPrerenderingBrowserTest,
                       DoNotLaunchAppInPrerendering) {}

class PlatformAppNavigationRedirectorFencedFrameBrowserTest
    : public PlatformAppNavigationRedirectorBrowserTest {};

// Test that PlatformAppNavigationRedirector doesn't apply to fenced frames.
IN_PROC_BROWSER_TEST_F(PlatformAppNavigationRedirectorFencedFrameBrowserTest,
                       DoNotLaunchAppInFencedFrames) {}

}  // namespace extensions