Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / extensions / events_apitest.cc
blob8787df1e60d083be72a850e2172ccf85857c39bf
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "extensions/browser/event_router.h"
9 #include "extensions/browser/extension_registry.h"
11 namespace extensions {
13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Events) {
14 ASSERT_TRUE(RunExtensionTest("events")) << message_;
17 // Tests that events are unregistered when an extension page shuts down.
18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, EventsAreUnregistered) {
19 // In this test, page1.html registers for a number of events, then navigates
20 // to page2.html, which should unregister those events. page2.html notifies
21 // pass, by which point the event should have been unregistered.
23 // This test relies on the extension installed with RunExtensionSubtest
24 // actually being installed, which won't happen if subtests are skipped (see
25 // comment on ExtensionApiTest::ExtensionSubtestsAreSkipped)
26 if (ExtensionSubtestsAreSkipped())
27 return;
29 EventRouter* event_router = EventRouter::Get(profile());
30 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
32 std::string test_extension_name = "events_are_unregistered";
33 ASSERT_TRUE(RunExtensionSubtest(test_extension_name, "page1.html"))
34 << message_;
36 // Find the extension we just installed by looking for the path.
37 base::FilePath extension_path =
38 test_data_dir_.AppendASCII(test_extension_name);
39 const Extension* extension =
40 GetExtensionByPath(registry->enabled_extensions(), extension_path);
41 ASSERT_TRUE(extension) << "No extension found at \"" << extension_path.value()
42 << "\" (absolute path \""
43 << base::MakeAbsoluteFilePath(extension_path).value()
44 << "\")";
45 const std::string& id = extension->id();
47 // The page has closed, so no matter what all events are no longer listened
48 // to. Assertions for normal events:
49 EXPECT_FALSE(
50 event_router->ExtensionHasEventListener(id, "browserAction.onClicked"));
51 EXPECT_FALSE(
52 event_router->ExtensionHasEventListener(id, "runtime.onStartup"));
53 EXPECT_FALSE(
54 event_router->ExtensionHasEventListener(id, "runtime.onSuspend"));
55 EXPECT_FALSE(
56 event_router->ExtensionHasEventListener(id, "runtime.onInstalled"));
57 // Assertions for filtered events:
58 EXPECT_FALSE(event_router->ExtensionHasEventListener(
59 id, "webNavigation.onBeforeNavigate"));
60 EXPECT_FALSE(
61 event_router->ExtensionHasEventListener(id, "webNavigation.onCommitted"));
62 EXPECT_FALSE(event_router->ExtensionHasEventListener(
63 id, "webNavigation.onDOMContentLoaded"));
64 EXPECT_FALSE(
65 event_router->ExtensionHasEventListener(id, "webNavigation.onCompleted"));
68 } // namespace extensions