This source file includes following definitions.
- GetTestBaseURL
- SetUpCommandLine
- TestAppInstancesHelper
- SetUpCommandLine
- 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
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_map.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "sync/api/string_ordinal.h"
using content::NavigationController;
using content::RenderViewHost;
using content::SiteInstance;
using content::WebContents;
using extensions::Extension;
class AppApiTest : public ExtensionApiTest {
protected:
GURL GetTestBaseURL(std::string test_directory) {
GURL::Replacements replace_host;
std::string host_str("localhost");
replace_host.SetHostStr(host_str);
GURL base_url = embedded_test_server()->GetURL(
"/extensions/api_test/" + test_directory + "/");
return base_url.ReplaceComponents(replace_host);
}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kDisablePopupBlocking);
CommandLine::ForCurrentProcess()->AppendSwitch(
extensions::switches::kAllowHTTPBackgroundPage);
}
void TestAppInstancesHelper(std::string app_name) {
LOG(INFO) << "Start of test.";
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII(app_name)));
const Extension* extension = GetSingleLoadedExtension();
GURL base_url = GetTestBaseURL(app_name);
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
LOG(INFO) << "Nav 1.";
EXPECT_TRUE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(1)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
content::WindowedNotificationObserver tab_added_observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
chrome::NewTab(browser());
tab_added_observer.Wait();
LOG(INFO) << "New tab.";
ui_test_utils::NavigateToURL(browser(),
base_url.Resolve("path2/empty.html"));
LOG(INFO) << "Nav 2.";
EXPECT_TRUE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
ASSERT_EQ(3, browser()->tab_strip_model()->count());
WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(1);
WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(2);
EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
browser()->host_desktop_type()));
OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL);
LOG(INFO) << "WindowOpenHelper 1.";
OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL);
LOG(INFO) << "End of test.";
UnloadExtension(extension->id());
}
};
class BlockedAppApiTest : public AppApiTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
CommandLine::ForCurrentProcess()->AppendSwitch(
extensions::switches::kAllowHTTPBackgroundPage);
}
};
IN_PROC_BROWSER_TEST_F(AppApiTest, DISABLED_AppProcess) {
LOG(INFO) << "Start of test.";
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
LOG(INFO) << "Loaded extension.";
GURL base_url = GetTestBaseURL("app_process");
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_TRUE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(1)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
LOG(INFO) << "Nav 1.";
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_TRUE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
LOG(INFO) << "Nav 2.";
content::WindowedNotificationObserver tab_added_observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
chrome::NewTab(browser());
tab_added_observer.Wait();
LOG(INFO) << "New tab.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
LOG(INFO) << "Nav 3.";
EXPECT_FALSE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(3)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(3)->GetWebUI());
ASSERT_EQ(4, browser()->tab_strip_model()->count());
WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_EQ(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
EXPECT_NE(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(3)->
GetRenderProcessHost());
ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
browser()->host_desktop_type()));
OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
LOG(INFO) << "WindowOpenHelper 1.";
OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
LOG(INFO) << "WindowOpenHelper 2.";
OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL);
LOG(INFO) << "WindowOpenHelper 3.";
const GURL& app_url(base_url.Resolve("path1/empty.html"));
const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
non_app_url);
LOG(INFO) << "NavigateTabHelper 1.";
NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(3),
app_url);
LOG(INFO) << "NavigateTabHelper 2.";
EXPECT_NE(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
EXPECT_EQ(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(3)->
GetRenderProcessHost());
NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(6),
app_url);
LOG(INFO) << "NavigateTabHelper 3.";
EXPECT_EQ(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(6)->
GetRenderProcessHost());
bool windowOpenerValid = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetWebContentsAt(6),
"window.domAutomationController.send(window.opener != null)",
&windowOpenerValid));
ASSERT_TRUE(windowOpenerValid);
LOG(INFO) << "End of test.";
}
#if defined(OS_WIN)
#define MAYBE_AppProcessInstances DISABLED_AppProcessInstances
#else
#define MAYBE_AppProcessInstances AppProcessInstances
#endif
IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) {
TestAppInstancesHelper("app_process_instances");
}
#if defined(OS_WIN)
#define MAYBE_AppProcessBackgroundInstances \
DISABLED_AppProcessBackgroundInstances
#else
#define MAYBE_AppProcessBackgroundInstances AppProcessBackgroundInstances
#endif
IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessBackgroundInstances) {
TestAppInstancesHelper("app_process_background_instances");
}
#if defined(OS_WIN)
#define MAYBE_BookmarkAppGetsNormalProcess DISABLED_BookmarkAppGetsNormalProcess
#else
#define MAYBE_BookmarkAppGetsNormalProcess BookmarkAppGetsNormalProcess
#endif
IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_BookmarkAppGetsNormalProcess) {
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
std::string error;
scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
test_data_dir_.AppendASCII("app_process"),
extensions::Manifest::UNPACKED,
Extension::FROM_BOOKMARK,
&error));
service->OnExtensionInstalled(extension.get(),
syncer::StringOrdinal::CreateInitialOrdinal(),
false ,
extensions::NOT_BLACKLISTED,
false );
ASSERT_TRUE(extension.get());
ASSERT_TRUE(extension->from_bookmark());
ui_test_utils::NavigateToURLWithDisposition(
browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_FALSE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(1)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
content::WindowedNotificationObserver tab_added_observer(
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
chrome::NewTab(browser());
tab_added_observer.Wait();
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
EXPECT_FALSE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost()->GetID()));
EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
ASSERT_EQ(3, browser()->tab_strip_model()->count());
WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_NE(tab->GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
browser()->host_desktop_type()));
OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
const GURL& app_url(base_url.Resolve("path1/empty.html"));
const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
RenderViewHost* host2 =
browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderViewHost();
NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
non_app_url);
EXPECT_EQ(host2->GetProcess(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
app_url);
EXPECT_EQ(host2->GetProcess(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
}
#if defined(OS_LINUX)
#define MAYBE_AppProcessRedirectBack DISABLED_AppProcessRedirectBack
#else
#define MAYBE_AppProcessRedirectBack AppProcessRedirectBack
#endif
IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessRedirectBack) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
GURL base_url = GetTestBaseURL("app_process");
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
chrome::NewTab(browser());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(), base_url.Resolve("path1/redirect.html"), 2);
ASSERT_EQ(3, browser()->tab_strip_model()->count());
EXPECT_EQ("/extensions/api_test/app_process/path1/empty.html",
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetController().GetLastCommittedEntry()->GetURL().path());
EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)->
GetRenderProcessHost(),
browser()->tab_strip_model()->GetWebContentsAt(2)->
GetRenderProcessHost());
}
IN_PROC_BROWSER_TEST_F(AppApiTest, NavigateIntoAppProcess) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
LOG(INFO) << "Loading path1/empty.html.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
LOG(INFO) << "Loading path1/empty.html - done.";
WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Loading extension.";
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
LOG(INFO) << "Loading extension - done.";
ASSERT_TRUE(app);
LOG(INFO) << "Loading path1/empty.html.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
LOG(INFO) << "Loading path1/empty.html - done.";
EXPECT_TRUE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Disabling extension.";
DisableExtension(app->id());
LOG(INFO) << "Disabling extension - done.";
LOG(INFO) << "Loading path1/empty.html.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
LOG(INFO) << "Loading path1/empty.html - done.";
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
}
IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
LOG(INFO) << "Loading extension.";
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
LOG(INFO) << "Loading extension - done.";
ASSERT_TRUE(app);
LOG(INFO) << "Disabling extension.";
DisableExtension(app->id());
LOG(INFO) << "Disabling extension - done.";
LOG(INFO) << "Navigate to path1/empty.html.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
LOG(INFO) << "Navigate to path1/empty.html - done.";
WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Enabling extension.";
EnableExtension(app->id());
LOG(INFO) << "Enabling extension - done.";
content::WindowedNotificationObserver reload_observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
LOG(INFO) << "Reloading.";
chrome::Reload(browser(), CURRENT_TAB);
reload_observer.Wait();
LOG(INFO) << "Reloading - done.";
EXPECT_TRUE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Disabling extension.";
DisableExtension(app->id());
LOG(INFO) << "Disabling extension - done.";
content::WindowedNotificationObserver reload_observer2(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
LOG(INFO) << "Reloading.";
chrome::Reload(browser(), CURRENT_TAB);
reload_observer2.Wait();
LOG(INFO) << "Reloading - done.";
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
}
IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcessWithJavaScript) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
LOG(INFO) << "Loading extension.";
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
LOG(INFO) << "Loading extension - done.";
ASSERT_TRUE(app);
LOG(INFO) << "Disabling extension.";
DisableExtension(app->id());
LOG(INFO) << "Disabling extension - done.";
LOG(INFO) << "Navigate to path1/empty.html.";
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
LOG(INFO) << "Navigate to path1/empty.html - done.";
WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Enabling extension.";
EnableExtension(app->id());
LOG(INFO) << "Enabling extension - done.";
content::WindowedNotificationObserver js_reload_observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
LOG(INFO) << "Executing location.reload().";
ASSERT_TRUE(content::ExecuteScript(contents, "location.reload();"));
js_reload_observer.Wait();
LOG(INFO) << "Executing location.reload() - done.";
EXPECT_TRUE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
LOG(INFO) << "Disabling extension.";
DisableExtension(app->id());
LOG(INFO) << "Disabling extension - done.";
content::WindowedNotificationObserver js_reload_observer2(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
LOG(INFO) << "Executing location = location.";
ASSERT_TRUE(content::ExecuteScript(contents, "location = location;"));
js_reload_observer2.Wait();
LOG(INFO) << "Executing location = location - done.";
EXPECT_FALSE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
}
IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
ASSERT_TRUE(app);
ui_test_utils::NavigateToURL(browser(),
base_url.Resolve("path3/container.html"));
EXPECT_FALSE(process_map->Contains(
browser()->tab_strip_model()->GetWebContentsAt(0)->
GetRenderProcessHost()->GetID()));
const BrowserList* active_browser_list =
BrowserList::GetInstance(chrome::GetActiveDesktop());
EXPECT_EQ(2U, active_browser_list->size());
content::WebContents* popup_contents =
active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(popup_contents);
RenderViewHost* popup_host = popup_contents->GetRenderViewHost();
EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID()));
}
#if defined(OS_CHROMEOS)
#define MAYBE_OpenAppFromIframe DISABLED_OpenAppFromIframe
#else
#define MAYBE_OpenAppFromIframe OpenAppFromIframe
#endif
IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
ASSERT_TRUE(app);
ui_test_utils::NavigateToURL(
browser(), GetTestBaseURL("app_process").Resolve("path3/container.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
PopupBlockerTabHelper* popup_blocker_tab_helper =
PopupBlockerTabHelper::FromWebContents(tab);
if (!popup_blocker_tab_helper->GetBlockedPopupsCount()) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::NotificationService::AllSources());
observer.Wait();
}
EXPECT_EQ(1u, popup_blocker_tab_helper->GetBlockedPopupsCount());
}
IN_PROC_BROWSER_TEST_F(AppApiTest, ServerRedirectToAppFromExtension) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(StartEmbeddedTestServer());
LoadExtension(test_data_dir_.AppendASCII("app_process"));
const Extension* launcher =
LoadExtension(test_data_dir_.AppendASCII("app_launcher"));
content::TestNavigationObserver test_navigation_observer(
browser()->tab_strip_model()->GetActiveWebContents(),
2);
test_navigation_observer.StartWatchingNewWebContents();
ui_test_utils::NavigateToURLWithDisposition(
browser(),
launcher->GetResourceURL("server_redirect.html"),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
test_navigation_observer.Wait();
bool is_installed = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(chrome.app.isInstalled)",
&is_installed));
ASSERT_TRUE(is_installed);
}
IN_PROC_BROWSER_TEST_F(AppApiTest, ClientRedirectToAppFromExtension) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(StartEmbeddedTestServer());
LoadExtension(test_data_dir_.AppendASCII("app_process"));
const Extension* launcher =
LoadExtension(test_data_dir_.AppendASCII("app_launcher"));
content::TestNavigationObserver test_navigation_observer(
browser()->tab_strip_model()->GetActiveWebContents(),
3);
test_navigation_observer.StartWatchingNewWebContents();
ui_test_utils::NavigateToURLWithDisposition(
browser(),
launcher->GetResourceURL("client_redirect.html"),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
test_navigation_observer.Wait();
bool is_installed = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(chrome.app.isInstalled)",
&is_installed));
ASSERT_TRUE(is_installed);
}
IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
ASSERT_TRUE(app);
ui_test_utils::NavigateToURL(browser(),
base_url.Resolve("path1/container.html"));
content::RenderProcessHost* process =
browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost();
EXPECT_TRUE(process_map->Contains(process->GetID()));
const BrowserList* active_browser_list =
BrowserList::GetInstance(chrome::GetActiveDesktop());
EXPECT_EQ(2U, active_browser_list->size());
content::WebContents* popup_contents =
active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(popup_contents);
RenderViewHost* popup_host = popup_contents->GetRenderViewHost();
EXPECT_EQ(process, popup_host->GetProcess());
}
#if defined(OS_MACOSX) || defined(OS_LINUX)
#define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash
#else
#define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash
#endif
IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
GURL base_url = GetTestBaseURL("app_process");
ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
EXPECT_TRUE(process_map->Contains(
contents->GetRenderProcessHost()->GetID()));
bool is_installed = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
contents,
"window.domAutomationController.send(chrome.app.isInstalled)",
&is_installed));
ASSERT_TRUE(is_installed);
content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
chrome::Reload(browser(), CURRENT_TAB);
observer.Wait();
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
contents,
"window.domAutomationController.send(chrome.app.isInstalled)",
&is_installed));
ASSERT_TRUE(is_installed);
}
IN_PROC_BROWSER_TEST_F(AppApiTest, SameBrowsingInstanceAfterSwap) {
extensions::ProcessMap* process_map =
extensions::ProcessMap::Get(browser()->profile());
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL base_url = GetTestBaseURL("app_process");
const Extension* app =
LoadExtension(test_data_dir_.AppendASCII("app_process"));
ASSERT_TRUE(app);
ui_test_utils::NavigateToURL(browser(),
base_url.Resolve("path1/iframe.html"));
content::SiteInstance* app_instance =
browser()->tab_strip_model()->GetWebContentsAt(0)->GetSiteInstance();
EXPECT_TRUE(process_map->Contains(app_instance->GetProcess()->GetID()));
const BrowserList* active_browser_list =
BrowserList::GetInstance(chrome::GetActiveDesktop());
EXPECT_EQ(2U, active_browser_list->size());
content::WebContents* popup_contents =
active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(popup_contents);
SiteInstance* popup_instance = popup_contents->GetSiteInstance();
EXPECT_EQ(app_instance, popup_instance);
GURL non_app_url(base_url.Resolve("path3/empty.html"));
ui_test_utils::NavigateToURL(active_browser_list->get(1), non_app_url);
SiteInstance* new_instance = popup_contents->GetSiteInstance();
EXPECT_NE(app_instance, new_instance);
EXPECT_TRUE(app_instance->IsRelatedSiteInstance(new_instance));
}