Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_view_host_factory_browsertest.cc
blob83d468a3b93ef67194bb22192351a8a92fc9ffdb
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.
5 #include "chrome/browser/extensions/extension_view_host_factory.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_view_host.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "extensions/common/view_type.h"
14 namespace extensions {
16 typedef ExtensionBrowserTest ExtensionViewHostFactoryTest;
18 // Tests that ExtensionHosts are created with the correct type and profiles.
19 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest, CreateExtensionHosts) {
20 // Load a very simple extension with just a background page.
21 scoped_refptr<const Extension> extension =
22 LoadExtension(test_data_dir_.AppendASCII("api_test")
23 .AppendASCII("browser_action")
24 .AppendASCII("none"));
25 ASSERT_TRUE(extension.get());
27 content::BrowserContext* browser_context = browser()->profile();
29 // Popup hosts are created with the correct type and profile.
30 scoped_ptr<ExtensionViewHost> host(
31 ExtensionViewHostFactory::CreatePopupHost(extension->url(), browser()));
32 EXPECT_EQ(extension.get(), host->extension());
33 EXPECT_EQ(browser_context, host->browser_context());
34 EXPECT_EQ(VIEW_TYPE_EXTENSION_POPUP, host->extension_host_type());
35 EXPECT_TRUE(host->view());
39 // Dialog hosts are created with the correct type and profile.
40 scoped_ptr<ExtensionViewHost> host(
41 ExtensionViewHostFactory::CreateDialogHost(extension->url(),
42 browser()->profile()));
43 EXPECT_EQ(extension.get(), host->extension());
44 EXPECT_EQ(browser_context, host->browser_context());
45 EXPECT_EQ(VIEW_TYPE_EXTENSION_DIALOG, host->extension_host_type());
46 EXPECT_TRUE(host->view());
50 // Tests that extensions loaded in incognito mode have the correct profiles
51 // for split-mode and non-split-mode.
52 // Crashing intermittently on multiple platforms. http://crbug.com/316334
53 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest,
54 DISABLED_IncognitoExtensionHosts) {
55 // Open an incognito browser.
56 Browser* incognito_browser =
57 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
59 // Load a non-split-mode extension, enabled in incognito.
60 scoped_refptr<const Extension> regular_extension =
61 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test")
62 .AppendASCII("browser_action")
63 .AppendASCII("none"));
64 ASSERT_TRUE(regular_extension.get());
66 // The ExtensionHost for a regular extension in an incognito window is
67 // associated with the original window's profile.
68 scoped_ptr<ExtensionHost> regular_host(
69 ExtensionViewHostFactory::CreatePopupHost(
70 regular_extension->url(), incognito_browser));
71 content::BrowserContext* browser_context = browser()->profile();
72 EXPECT_EQ(browser_context, regular_host->browser_context());
74 // Load a split-mode incognito extension.
75 scoped_refptr<const Extension> split_mode_extension =
76 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test")
77 .AppendASCII("browser_action")
78 .AppendASCII("split_mode"));
79 ASSERT_TRUE(split_mode_extension.get());
81 // The ExtensionHost for a split-mode extension is associated with the
82 // incognito profile.
83 scoped_ptr<ExtensionHost> split_mode_host(
84 ExtensionViewHostFactory::CreatePopupHost(
85 split_mode_extension->url(), incognito_browser));
86 content::BrowserContext* incognito_context = incognito_browser->profile();
87 EXPECT_EQ(incognito_context, split_mode_host->browser_context());
90 } // namespace extensions