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

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

Issue 1074273002: Move the event attach/detach logic on unload from event.js to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: being process of relanding - more test assertions Created 5 years, 8 months 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/test/data/extensions/api_test/events_are_unregistered/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/events_apitest.cc
diff --git a/chrome/browser/extensions/events_apitest.cc b/chrome/browser/extensions/events_apitest.cc
index 3420022dc8b3ba664a153583b7ed8d65c89ae699..8ebff3cdde31b65addb609e32e3b2014ce54f129 100644
--- a/chrome/browser/extensions/events_apitest.cc
+++ b/chrome/browser/extensions/events_apitest.cc
@@ -2,8 +2,51 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
+#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_registry.h"
+
+namespace extensions {
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Events) {
ASSERT_TRUE(RunExtensionTest("events")) << message_;
}
+
+// Tests that events are unregistered when an extension page shuts down.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, EventsAreUnregistered) {
+ // In this test, page1.html registers for a number of events, then navigates
+ // to page2.html, which should unregister those events. page2.html notifies
+ // pass, by which point the event should have been unregistered.
+ EventRouter* event_router = EventRouter::Get(profile());
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
+
+ std::string test_extension_name = "events_are_unregistered";
+ ASSERT_TRUE(RunExtensionSubtest(test_extension_name, "page1.html"))
+ << message_;
+
+ // Find the extension we just installed by looking for the path.
+ base::FilePath extension_path =
+ test_data_dir_.AppendASCII(test_extension_name);
+ const Extension* extension =
+ GetExtensionByPath(registry->enabled_extensions(), extension_path);
+ ASSERT_TRUE(extension) << "No extension found at \"" << extension_path.value()
+ << "\" (absolute path \""
+ << base::MakeAbsoluteFilePath(extension_path).value()
+ << "\")";
+ const std::string& id = extension->id();
+
+ // The page has closed, so no matter what all events are no longer listened
+ // to.
+ EXPECT_FALSE(
+ event_router->ExtensionHasEventListener(id, "browserAction.onClicked"));
+ EXPECT_FALSE(
+ event_router->ExtensionHasEventListener(id, "runtime.onStartup"));
+ EXPECT_FALSE(
+ event_router->ExtensionHasEventListener(id, "runtime.onSuspend"));
+ EXPECT_FALSE(
+ event_router->ExtensionHasEventListener(id, "runtime.onInstalled"));
+}
+
+} // namespace extensions
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/events_are_unregistered/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698