Index: chrome/browser/extensions/platform_app_browsertest.cc |
diff --git a/chrome/browser/extensions/platform_app_browsertest.cc b/chrome/browser/extensions/platform_app_browsertest.cc |
index 2615e82d5b1c4c53f0f31ed6ea40de2bfc33bb9b..9d3de2a83ef94adf275708daae7b3a97e12d96c4 100644 |
--- a/chrome/browser/extensions/platform_app_browsertest.cc |
+++ b/chrome/browser/extensions/platform_app_browsertest.cc |
@@ -9,6 +9,7 @@ |
#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/automation/automation_util.h" |
#include "chrome/browser/debugger/devtools_window.h" |
+#include "chrome/browser/lifetime/application_lifetime.h" |
#include "chrome/browser/extensions/app_restore_service_factory.h" |
#include "chrome/browser/extensions/app_restore_service.h" |
#include "chrome/browser/extensions/extension_browsertest.h" |
@@ -21,6 +22,7 @@ |
#include "chrome/browser/extensions/shell_window_registry.h" |
#include "chrome/browser/tab_contents/render_view_context_menu.h" |
#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/extensions/application_launch.h" |
#include "chrome/browser/ui/extensions/shell_window.h" |
@@ -143,6 +145,8 @@ const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
} // namespace |
+// TODO(benwells): Break up this file into some sensible smaller files. |
+ |
// Tests that CreateShellWindow doesn't crash if you close it straight away. |
// LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
// ash, so we test that it works here. |
@@ -150,6 +154,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
ShellWindow* window = CreateShellWindow(extension); |
CloseShellWindow(window); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that platform apps can be launched in incognito mode without crashing. |
@@ -168,6 +173,16 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchAppIncognito) { |
NEW_WINDOW)); |
ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ CloseShellWindowsAndWaitForAppToExit(); |
+} |
+ |
+// Tests that the browser process is kept alive by the platform app's background |
+// page. |
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppEventPageKeepsBrowserAlive) { |
+ LoadAndLaunchPlatformApp("minimal"); |
+ browser()->window()->Close(); |
+ ASSERT_TRUE(browser::WillKeepAlive()); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that platform apps received the "launch" event when launched. |
@@ -202,6 +217,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) { |
web_contents); |
ASSERT_TRUE(handler.WaitUntilReply()); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that platform apps cannot use certain disabled window properties, but |
@@ -212,11 +228,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("minimal"); |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// The empty app doesn't add any context menu items, so its menu should |
// only include the developer tools. |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
@@ -232,16 +245,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("context_menu"); |
- // Wait for the extension to tell us it's initialized its context menus and |
- // launched a window. |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// The context_menu app has two context menu items. These, along with a |
// separator and the developer tools, is all that should be in the menu. |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
@@ -260,16 +269,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
InstallAndLaunchPlatformApp("context_menu"); |
- // Wait for the extension to tell us it's initialized its context menus and |
- // launched a window. |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// The context_menu app has two context menu items. For an installed app |
// these are all that should be in the menu. |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
@@ -288,16 +293,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("context_menu"); |
- // Wait for the extension to tell us it's initialized its context menus and |
- // launched a window. |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// The context_menu app has one context menu item. This, along with a |
// separator and the developer tools, is all that should be in the menu. |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
@@ -317,16 +318,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("context_menu"); |
- // Wait for the extension to tell us it's initialized its context menus and |
- // launched a window. |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// The context_menu app has one context menu item. This, along with a |
// separator and the developer tools, is all that should be in the menu. |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
@@ -346,16 +343,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("context_menu_click"); |
- // Wait for the extension to tell us it's initialized its context menus and |
- // launched a window. |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
- |
// Test that the menu item shows up |
WebContents* web_contents = GetFirstShellWindowWebContents(); |
ASSERT_TRUE(web_contents); |
@@ -373,13 +366,15 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
TabsAddedNotificationObserver observer(2); |
ASSERT_TRUE(StartTestServer()); |
- ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
+ ASSERT_TRUE(RunPlatformAppTestReturnImmediately("platform_apps/navigation")) |
+ << message_; |
observer.Wait(); |
ASSERT_EQ(2U, observer.tabs().size()); |
@@ -387,6 +382,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
observer.tabs()[0]->GetURL().spec()); |
EXPECT_EQ("http://chromium.org/", |
observer.tabs()[1]->GetURL().spec()); |
+ browser()->window()->Close(); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
@@ -456,9 +453,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
ASSERT_EQ(0U, GetShellWindowCount()); |
// Launch a platform app that shows a window. |
- ExtensionTestMessageListener launched_listener("Launched", false); |
LoadAndLaunchPlatformApp("minimal"); |
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
ASSERT_EQ(1U, GetShellWindowCount()); |
ShellWindowRegistry::ShellWindowSet shell_windows = |
ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
@@ -475,13 +470,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
// to get a list of all the shell windows, so we can test this. |
// Launch another platform app that also shows a window. |
- ExtensionTestMessageListener launched_listener2("Launched", false); |
LoadAndLaunchPlatformApp("context_menu"); |
- ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
// There are two total shell windows, but each app can only see its own. |
ASSERT_EQ(2U, GetShellWindowCount()); |
// TODO(jeremya): as above, this requires more extension functions. |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// ChromeOS does not support passing arguments on the command line, so the tests |
@@ -525,6 +519,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) { |
message_ = catcher.message(); |
ASSERT_TRUE(0); |
} |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that no launch data is sent through if the platform app provides |
@@ -599,6 +594,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
LoadAndLaunchPlatformApp("open_link"); |
observer.Wait(); |
ASSERT_EQ(2, browser()->tab_count()); |
+ browser()->window()->Close(); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
@@ -673,6 +670,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
// Wait for javascript to verify that the third window got the restored size |
// and explicitly specified coordinates. |
ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that a running app is recorded in the preferences as such. |
@@ -704,6 +702,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { |
AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
HandleStartup(true); |
restart_listener.WaitUntilSatisfied(); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
// Tests that relaunching an app with devtools open reopens devtools. |
@@ -758,6 +757,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_DevToolsOpenedWithReload) { |
rvh = window->web_contents()->GetRenderViewHost(); |
ASSERT_TRUE(rvh); |
ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
+ CloseShellWindowsAndWaitForAppToExit(); |
} |
} // namespace extensions |