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

Side by Side Diff: chrome/browser/extensions/extension_process_manager_browsertest.cc

Issue 62713003: Move ExtensionProcessManager to src/extensions, part 4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "chrome/browser/extensions/extension_process_manager.h"
6
7 #include "chrome/browser/extensions/browser_action_test_util.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h"
14
15 using extensions::Extension;
16 using extensions::ExtensionSystem;
17
18 // Exists as a browser test because ExtensionHosts are hard to create without
19 // a real browser.
20 typedef ExtensionBrowserTest ExtensionProcessManagerBrowserTest;
21
22 // Test that basic extension loading creates the appropriate ExtensionHosts
23 // and background pages.
24 IN_PROC_BROWSER_TEST_F(ExtensionProcessManagerBrowserTest,
25 ExtensionHostCreation) {
26 ExtensionProcessManager* pm =
27 ExtensionSystem::Get(profile())->process_manager();
28
29 // We start with no background hosts.
30 ASSERT_EQ(0u, pm->background_hosts().size());
31 ASSERT_EQ(0u, pm->GetAllViews().size());
32
33 // Load an extension with a background page.
34 scoped_refptr<const Extension> extension =
35 LoadExtension(test_data_dir_.AppendASCII("api_test")
36 .AppendASCII("browser_action")
37 .AppendASCII("none"));
38 ASSERT_TRUE(extension.get());
39
40 // Process manager gains a background host.
41 EXPECT_EQ(1u, pm->background_hosts().size());
42 EXPECT_EQ(1u, pm->GetAllViews().size());
43 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id()));
44 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()));
45 EXPECT_EQ(1u, pm->GetRenderViewHostsForExtension(extension->id()).size());
46 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id()));
47 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get()));
48
49 // Unload the extension.
50 UnloadExtension(extension->id());
51
52 // Background host disappears.
53 EXPECT_EQ(0u, pm->background_hosts().size());
54 EXPECT_EQ(0u, pm->GetAllViews().size());
55 EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id()));
56 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url()));
57 EXPECT_EQ(0u, pm->GetRenderViewHostsForExtension(extension->id()).size());
58 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id()));
59 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get()));
60 }
61
62 // Test that loading an extension with a browser action does not create a
63 // background page and that clicking on the action creates the appropriate
64 // ExtensionHost.
65 // Disabled due to flake, see http://crbug.com/315242
66 IN_PROC_BROWSER_TEST_F(ExtensionProcessManagerBrowserTest,
67 DISABLED_PopupHostCreation) {
68 ExtensionProcessManager* pm =
69 ExtensionSystem::Get(profile())->process_manager();
70
71 // Load an extension with the ability to open a popup but no background
72 // page.
73 scoped_refptr<const Extension> popup =
74 LoadExtension(test_data_dir_.AppendASCII("api_test")
75 .AppendASCII("browser_action")
76 .AppendASCII("popup"));
77 ASSERT_TRUE(popup);
78
79 // No background host was added.
80 EXPECT_EQ(0u, pm->background_hosts().size());
81 EXPECT_EQ(0u, pm->GetAllViews().size());
82 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id()));
83 EXPECT_EQ(0u, pm->GetRenderViewHostsForExtension(popup->id()).size());
84 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url()));
85 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id()));
86 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get()));
87
88 // Simulate clicking on the action to open a popup.
89 BrowserActionTestUtil test_util(browser());
90 content::WindowedNotificationObserver frame_observer(
91 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
92 content::NotificationService::AllSources());
93 // Open popup in the first extension.
94 test_util.Press(0);
95 frame_observer.Wait();
96 ASSERT_TRUE(test_util.HasPopup());
97
98 // We now have a view, but still no background hosts.
99 EXPECT_EQ(0u, pm->background_hosts().size());
100 EXPECT_EQ(1u, pm->GetAllViews().size());
101 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id()));
102 EXPECT_EQ(1u, pm->GetRenderViewHostsForExtension(popup->id()).size());
103 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url()));
104 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id()));
105 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get()));
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698