This source file includes following definitions.
- SetUpCommandLine
- TestNavigationInTab
- TestMismatchingNavigationInTab
- TestNegativeXhrInTab
- TestNavigationInApp
- TestNegativeNavigationInApp
- TestMismatchingNavigationInApp
- TestNavigationInBrowser
- TestNegativeNavigationInBrowser
- TestMismatchingNavigationInBrowser
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace extensions {
class PlatformAppUrlRedirectorBrowserTest : public PlatformAppBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
protected:
void TestNavigationInTab(const char* launcher_page,
const char* handler,
const char* handler_start_message);
void TestMismatchingNavigationInTab(const char* launcher_page,
const char* success_tab_title,
const char* handler);
void TestNegativeXhrInTab(const char* xhr_opening_page,
const char* success_tab_title,
const char* failure_tab_title,
const char* handler);
void TestNavigationInApp(const char* launcher,
const char* launcher_done_message,
const char* handler,
const char* handler_start_message);
void TestMismatchingNavigationInApp(const char* launcher,
const char* launcher_done_message,
const char* handler);
void TestNegativeNavigationInApp(const char* launcher,
const char* launcher_done_message,
const char* handler);
void TestNavigationInBrowser(const char* matching_target_page,
content::PageTransition transition,
const char* handler,
const char* handler_start_message);
void TestNegativeNavigationInBrowser(const char* matching_target_page,
content::PageTransition transition,
const char* success_tab_title,
const char* handler);
void TestMismatchingNavigationInBrowser(const char* mismatching_target_page,
content::PageTransition transition,
const char* success_tab_title,
const char* handler);
};
void PlatformAppUrlRedirectorBrowserTest::SetUpCommandLine(
CommandLine* command_line) {
PlatformAppBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(::switches::kDisablePopupBlocking);
}
void PlatformAppUrlRedirectorBrowserTest::TestNavigationInTab(
const char* launcher_page,
const char* handler,
const char* handler_start_message) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
ExtensionTestMessageListener handler_listener(handler_start_message, false);
ui_test_utils::NavigateToURLWithDisposition(
browser(),
embedded_test_server()->GetURL(base::StringPrintf(
"/extensions/platform_apps/%s", launcher_page)),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ASSERT_TRUE(handler_listener.WaitUntilSatisfied());
ASSERT_EQ(1U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestMismatchingNavigationInTab(
const char* launcher_page,
const char* success_tab_title,
const char* handler) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
const base::string16 success_title = base::ASCIIToUTF16(success_tab_title);
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher title_watcher(tab, success_title);
ui_test_utils::NavigateToURLWithDisposition(
browser(),
embedded_test_server()->GetURL(base::StringPrintf(
"/extensions/platform_apps/%s", launcher_page)),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ASSERT_EQ(success_title, title_watcher.WaitAndGetTitle());
ASSERT_EQ(1, browser()->tab_strip_model()->count());
ASSERT_EQ(0U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestNegativeXhrInTab(
const char* launcher_page,
const char* success_tab_title,
const char* failure_tab_title,
const char* handler) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
const base::string16 success_title = base::ASCIIToUTF16(success_tab_title);
const base::string16 failure_title = base::ASCIIToUTF16(failure_tab_title);
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher title_watcher(tab, success_title);
title_watcher.AlsoWaitForTitle(failure_title);
ui_test_utils::NavigateToURLWithDisposition(
browser(),
embedded_test_server()->GetURL(base::StringPrintf(
"/extensions/platform_apps/%s", launcher_page)),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
ASSERT_EQ(success_title, title_watcher.WaitAndGetTitle());
ASSERT_EQ(1, browser()->tab_strip_model()->count());
ASSERT_EQ(0U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestNavigationInApp(
const char* launcher,
const char* launcher_done_message,
const char* handler,
const char* handler_start_message) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
ExtensionTestMessageListener launcher_listener(launcher_done_message, false);
ExtensionTestMessageListener handler_listener(handler_start_message, false);
LoadAndLaunchPlatformApp(launcher);
ASSERT_TRUE(launcher_listener.WaitUntilSatisfied());
ASSERT_TRUE(handler_listener.WaitUntilSatisfied());
ASSERT_EQ(2U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestNegativeNavigationInApp(
const char* launcher,
const char* launcher_done_message,
const char* handler) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::Source<content::WebContentsDelegate>(browser()));
ExtensionTestMessageListener launcher_done_listener(launcher_done_message,
false);
LoadAndLaunchPlatformApp(launcher);
ASSERT_TRUE(launcher_done_listener.WaitUntilSatisfied());
observer.Wait();
ASSERT_EQ(1U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestMismatchingNavigationInApp(
const char* launcher,
const char* launcher_done_message,
const char* handler) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TAB_ADDED,
content::Source<content::WebContentsDelegate>(browser()));
ExtensionTestMessageListener launcher_listener(launcher_done_message, false);
LoadAndLaunchPlatformApp(launcher);
ASSERT_TRUE(launcher_listener.WaitUntilSatisfied());
observer.Wait();
ASSERT_EQ(1U, GetAppWindowCount());
ASSERT_EQ(2, browser()->tab_strip_model()->count());
}
void PlatformAppUrlRedirectorBrowserTest::TestNavigationInBrowser(
const char* matching_target_page,
content::PageTransition transition,
const char* handler,
const char* handler_start_message) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
ExtensionTestMessageListener handler_listener(handler_start_message, false);
chrome::NavigateParams params(
browser(),
embedded_test_server()->GetURL(base::StringPrintf(
"/extensions/platform_apps/%s", matching_target_page)),
transition);
ui_test_utils::NavigateToURL(¶ms);
ASSERT_TRUE(handler_listener.WaitUntilSatisfied());
ASSERT_EQ(1U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestNegativeNavigationInBrowser(
const char* matching_target_page,
content::PageTransition transition,
const char* success_tab_title,
const char* handler) {
ASSERT_TRUE(StartEmbeddedTestServer());
InstallPlatformApp(handler);
const base::string16 success_title = base::ASCIIToUTF16(success_tab_title);
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher title_watcher(tab, success_title);
chrome::NavigateParams params(
browser(),
embedded_test_server()->GetURL(base::StringPrintf(
"/extensions/platform_apps/%s", matching_target_page)),
transition);
ui_test_utils::NavigateToURL(¶ms);
ASSERT_EQ(success_title, title_watcher.WaitAndGetTitle());
ASSERT_EQ(0U, GetAppWindowCount());
}
void PlatformAppUrlRedirectorBrowserTest::TestMismatchingNavigationInBrowser(
const char* mismatching_target_page,
content::PageTransition transition,
const char* success_tab_title,
const char* handler) {
TestNegativeNavigationInBrowser(
mismatching_target_page, transition, success_tab_title, handler);
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
ClickInTabIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInTab(
"url_handlers/launching_pages/click_link.html",
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
BlankClickInTabIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInTab(
"url_handlers/launching_pages/click_blank_link.html",
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
WindowOpenInTabIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInTab(
"url_handlers/launching_pages/call_window_open.html",
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
MismatchingClickInTabNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestMismatchingNavigationInTab(
"url_handlers/launching_pages/click_mismatching_link.html",
"Mismatching link target loaded",
"url_handlers/handlers/simple");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
BlankClickInAppIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInApp(
"url_handlers/launchers/click_blank_link",
"Launcher done",
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
WindowOpenInAppIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInApp(
"url_handlers/launchers/call_window_open",
"Launcher done",
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
MismatchingWindowOpenInAppNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestMismatchingNavigationInApp(
"url_handlers/launchers/call_mismatching_window_open",
"Launcher done",
"url_handlers/handlers/simple");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
WebviewNavigationNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInApp(
"url_handlers/launchers/click_blank_link",
"Launcher done",
"url_handlers/handlers/navigate_webview_to_url",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
MismatchingBlankClickInAppNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestMismatchingNavigationInApp(
"url_handlers/launchers/click_mismatching_blank_link",
"Launcher done",
"url_handlers/handlers/simple");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
EntryInOmnibarIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNavigationInBrowser(
"url_handlers/common/target.html",
content::PAGE_TRANSITION_TYPED,
"url_handlers/handlers/simple",
"Handler launched");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
MismatchingEntryInOmnibarNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestMismatchingNavigationInBrowser(
"url_handlers/common/mismatching_target.html",
content::PAGE_TRANSITION_TYPED,
"Mismatching link target loaded",
"url_handlers/handlers/simple");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
FormSubmissionInTabNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestMismatchingNavigationInTab(
"url_handlers/launching_pages/submit_form.html",
"Link target loaded",
"url_handlers/handlers/simple");
}
IN_PROC_BROWSER_TEST_F(PlatformAppUrlRedirectorBrowserTest,
XhrInTabNotIntercepted) {
#if defined (OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) return;
#endif
TestNegativeXhrInTab(
"url_handlers/xhr_downloader/main.html",
"XHR succeeded",
"XHR failed",
"url_handlers/handlers/steal_xhr_target");
}
}