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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/extensions/api/messaging/incognito_connectability.h" 25 #include "chrome/browser/extensions/api/messaging/incognito_connectability.h"
26 #include "chrome/browser/extensions/extension_apitest.h" 26 #include "chrome/browser/extensions/extension_apitest.h"
27 #include "chrome/browser/extensions/test_extension_dir.h" 27 #include "chrome/browser/extensions/test_extension_dir.h"
28 #include "chrome/browser/infobars/infobar_service.h" 28 #include "chrome/browser/infobars/infobar_service.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_commands.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
34 #include "chrome/test/base/ui_test_utils.h" 35 #include "chrome/test/base/ui_test_utils.h"
35 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "content/public/test/browser_test_utils.h" 38 #include "content/public/test/browser_test_utils.h"
39 #include "content/public/test/test_utils.h"
38 #include "extensions/browser/event_router.h" 40 #include "extensions/browser/event_router.h"
39 #include "extensions/browser/extension_prefs.h" 41 #include "extensions/browser/extension_prefs.h"
40 #include "extensions/browser/extension_system.h" 42 #include "extensions/browser/extension_system.h"
43 #include "extensions/browser/process_manager.h"
41 #include "extensions/common/api/runtime.h" 44 #include "extensions/common/api/runtime.h"
42 #include "extensions/common/extension_builder.h" 45 #include "extensions/common/extension_builder.h"
43 #include "extensions/common/value_builder.h" 46 #include "extensions/common/value_builder.h"
44 #include "extensions/test/extension_test_message_listener.h" 47 #include "extensions/test/extension_test_message_listener.h"
45 #include "extensions/test/result_catcher.h" 48 #include "extensions/test/result_catcher.h"
46 #include "net/cert/asn1_util.h" 49 #include "net/cert/asn1_util.h"
47 #include "net/cert/jwk_serializer.h" 50 #include "net/cert/jwk_serializer.h"
48 #include "net/dns/mock_host_resolver.h" 51 #include "net/dns/mock_host_resolver.h"
49 #include "net/ssl/channel_id_service.h" 52 #include "net/ssl/channel_id_service.h"
50 #include "net/test/embedded_test_server/embedded_test_server.h" 53 #include "net/test/embedded_test_server/embedded_test_server.h"
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 .Build()) 1282 .Build())
1280 .Build(); 1283 .Build();
1281 1284
1282 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); 1285 ui_test_utils::NavigateToURL(browser(), chromium_org_url());
1283 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, 1286 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR,
1284 CanConnectAndSendMessagesToMainFrame(invalid.get())); 1287 CanConnectAndSendMessagesToMainFrame(invalid.get()));
1285 } 1288 }
1286 1289
1287 #endif // !defined(OS_WIN) - http://crbug.com/350517. 1290 #endif // !defined(OS_WIN) - http://crbug.com/350517.
1288 1291
1292 // Tests that messages sent in the unload handler of a window arrive.
1293 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingOnUnload) {
1294 host_resolver()->AddRule("*", "127.0.0.1");
1295 ASSERT_TRUE(StartEmbeddedTestServer());
1296 const Extension* extension =
1297 LoadExtension(test_data_dir_.AppendASCII("messaging/on_unload"));
1298 ExtensionTestMessageListener listener("listening", false);
1299 ASSERT_TRUE(extension);
1300 ui_test_utils::NavigateToURL(
1301 browser(), embedded_test_server()->GetURL("example.com", "/empty.html"));
1302 EXPECT_TRUE(listener.WaitUntilSatisfied());
1303 ExtensionHost* background_host =
1304 ProcessManager::Get(profile())->GetBackgroundHostForExtension(
1305 extension->id());
1306 ASSERT_TRUE(background_host);
1307 content::WebContents* background_contents = background_host->host_contents();
1308 ASSERT_TRUE(background_contents);
1309 int message_count = -1;
1310 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
1311 background_contents,
1312 "window.domAutomationController.send(window.messageCount);",
1313 &message_count));
1314 // There shouldn't be any messages yet.
1315 EXPECT_EQ(0, message_count);
1316
1317 content::WebContentsDestroyedWatcher destroyed_watcher(
1318 browser()->tab_strip_model()->GetActiveWebContents());
1319 chrome::CloseTab(browser());
1320 destroyed_watcher.Wait();
1321 base::RunLoop().RunUntilIdle();
1322 // The extension should have sent a message from its unload handler.
1323 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
1324 background_contents,
1325 "window.domAutomationController.send(window.messageCount);",
1326 &message_count));
1327 EXPECT_EQ(1, message_count);
1328 }
1329
1289 } // namespace 1330 } // namespace
1290 1331
1291 }; // namespace extensions 1332 }; // namespace extensions
OLDNEW
« 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