OLD | NEW |
(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_host_factory.h" |
| 6 |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "extensions/common/view_type.h" |
| 10 |
| 11 namespace extensions { |
| 12 |
| 13 typedef ExtensionBrowserTest ExtensionHostFactoryTest; |
| 14 |
| 15 // Tests that ExtensionHosts are created with the correct type and profiles. |
| 16 IN_PROC_BROWSER_TEST_F(ExtensionHostFactoryTest, CreateExtensionHosts) { |
| 17 // Load a very simple extension with just a background page. |
| 18 scoped_refptr<const Extension> extension = |
| 19 LoadExtension(test_data_dir_.AppendASCII("api_test") |
| 20 .AppendASCII("browser_action") |
| 21 .AppendASCII("none")); |
| 22 ASSERT_TRUE(extension.get()); |
| 23 |
| 24 { |
| 25 // Popup hosts are created with the correct type and profile. |
| 26 scoped_ptr<ExtensionHost> host( |
| 27 ExtensionHostFactory::CreatePopupHost(extension->url(), browser())); |
| 28 EXPECT_EQ(extension.get(), host->extension()); |
| 29 EXPECT_EQ(browser()->profile(), host->profile()); |
| 30 EXPECT_EQ(VIEW_TYPE_EXTENSION_POPUP, host->extension_host_type()); |
| 31 } |
| 32 |
| 33 { |
| 34 // Infobar hosts are created with the correct type and profile. |
| 35 scoped_ptr<ExtensionHost> host( |
| 36 ExtensionHostFactory::CreateInfobarHost(extension->url(), browser())); |
| 37 EXPECT_EQ(extension.get(), host->extension()); |
| 38 EXPECT_EQ(browser()->profile(), host->profile()); |
| 39 EXPECT_EQ(VIEW_TYPE_EXTENSION_INFOBAR, host->extension_host_type()); |
| 40 } |
| 41 |
| 42 { |
| 43 // Dialog hosts are created with the correct type and profile. |
| 44 scoped_ptr<ExtensionHost> host(ExtensionHostFactory::CreateDialogHost( |
| 45 extension->url(), browser()->profile())); |
| 46 EXPECT_EQ(extension.get(), host->extension()); |
| 47 EXPECT_EQ(browser()->profile(), host->profile()); |
| 48 EXPECT_EQ(VIEW_TYPE_EXTENSION_DIALOG, host->extension_host_type()); |
| 49 } |
| 50 } |
| 51 |
| 52 // Tests that extensions loaded in incognito mode have the correct profiles |
| 53 // for split-mode and non-split-mode. |
| 54 IN_PROC_BROWSER_TEST_F(ExtensionHostFactoryTest, IncognitoExtensionHosts) { |
| 55 // Open an incognito browser. |
| 56 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
| 57 browser()->profile(), GURL("about:blank")); |
| 58 |
| 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()); |
| 65 |
| 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 ExtensionHostFactory::CreatePopupHost( |
| 70 regular_extension->url(), incognito_browser)); |
| 71 EXPECT_EQ(browser()->profile(), regular_host->profile()); |
| 72 |
| 73 // Load a split-mode incognito extension. |
| 74 scoped_refptr<const Extension> split_mode_extension = |
| 75 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") |
| 76 .AppendASCII("browser_action") |
| 77 .AppendASCII("split_mode")); |
| 78 ASSERT_TRUE(split_mode_extension.get()); |
| 79 |
| 80 // The ExtensionHost for a split-mode extension is associated with the |
| 81 // incognito profile. |
| 82 scoped_ptr<ExtensionHost> split_mode_host( |
| 83 ExtensionHostFactory::CreatePopupHost( |
| 84 split_mode_extension->url(), incognito_browser)); |
| 85 EXPECT_EQ(incognito_browser->profile(), split_mode_host->profile()); |
| 86 } |
| 87 |
| 88 } // namespace extensions |
OLD | NEW |