Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Unified Diff: chrome/browser/extensions/extension_messages_apitest.cc

Issue 2514523002: [Extensions] Make port creation synchronous in unload handlers (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_extension_message_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_messages_apitest.cc
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc
index 9747d06632e548cdf18178f83814c25c4938a792..a46af8931d25ba75877d99eee0d58725c5c4eebd 100644
--- a/chrome/browser/extensions/extension_messages_apitest.cc
+++ b/chrome/browser/extensions/extension_messages_apitest.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -35,9 +36,11 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/process_manager.h"
#include "extensions/common/api/runtime.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
@@ -1286,6 +1289,44 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest,
#endif // !defined(OS_WIN) - http://crbug.com/350517.
+// Tests that messages sent in the unload handler of a window arrive.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingOnUnload) {
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(StartEmbeddedTestServer());
+ const Extension* extension =
+ LoadExtension(test_data_dir_.AppendASCII("messaging/on_unload"));
+ ExtensionTestMessageListener listener("listening", false);
+ ASSERT_TRUE(extension);
+ ui_test_utils::NavigateToURL(
+ browser(), embedded_test_server()->GetURL("example.com", "/empty.html"));
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ExtensionHost* background_host =
+ ProcessManager::Get(profile())->GetBackgroundHostForExtension(
+ extension->id());
+ ASSERT_TRUE(background_host);
+ content::WebContents* background_contents = background_host->host_contents();
+ ASSERT_TRUE(background_contents);
+ int message_count = -1;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
+ background_contents,
+ "window.domAutomationController.send(window.messageCount);",
+ &message_count));
+ // There shouldn't be any messages yet.
+ EXPECT_EQ(0, message_count);
+
+ content::WebContentsDestroyedWatcher destroyed_watcher(
+ browser()->tab_strip_model()->GetActiveWebContents());
+ chrome::CloseTab(browser());
+ destroyed_watcher.Wait();
+ base::RunLoop().RunUntilIdle();
+ // The extension should have sent a message from its unload handler.
+ ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
+ background_contents,
+ "window.domAutomationController.send(window.messageCount);",
+ &message_count));
+ EXPECT_EQ(1, message_count);
+}
+
} // namespace
}; // namespace extensions
« no previous file with comments | « no previous file | chrome/browser/renderer_host/chrome_extension_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698