OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_view_host_factory.h" | 5 #include "chrome/browser/extensions/extension_view_host_factory.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
8 #include "chrome/browser/extensions/extension_view_host.h" | 8 #include "chrome/browser/extensions/extension_view_host.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
12 #include "extensions/common/view_type.h" | 12 #include "extensions/common/view_type.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 typedef ExtensionBrowserTest ExtensionViewHostFactoryTest; | 16 typedef ExtensionBrowserTest ExtensionViewHostFactoryTest; |
17 | 17 |
18 // Tests that ExtensionHosts are created with the correct type and profiles. | 18 // Tests that ExtensionHosts are created with the correct type and profiles. |
19 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest, CreateExtensionHosts) { | 19 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest, CreateExtensionHosts) { |
20 // Load a very simple extension with just a background page. | 20 // Load a very simple extension with just a background page. |
21 scoped_refptr<const Extension> extension = | 21 scoped_refptr<const Extension> extension = |
22 LoadExtension(test_data_dir_.AppendASCII("api_test") | 22 LoadExtension(test_data_dir_.AppendASCII("api_test") |
23 .AppendASCII("browser_action") | 23 .AppendASCII("browser_action") |
24 .AppendASCII("none")); | 24 .AppendASCII("none")); |
25 ASSERT_TRUE(extension.get()); | 25 ASSERT_TRUE(extension.get()); |
26 | 26 |
27 content::BrowserContext* browser_context = browser()->profile(); | 27 content::BrowserContext* browser_context = browser()->profile(); |
28 { | 28 { |
29 // Popup hosts are created with the correct type and profile. | 29 // Popup hosts are created with the correct type and profile. |
30 scoped_ptr<ExtensionViewHost> host( | 30 std::unique_ptr<ExtensionViewHost> host( |
31 ExtensionViewHostFactory::CreatePopupHost(extension->url(), browser())); | 31 ExtensionViewHostFactory::CreatePopupHost(extension->url(), browser())); |
32 EXPECT_EQ(extension.get(), host->extension()); | 32 EXPECT_EQ(extension.get(), host->extension()); |
33 EXPECT_EQ(browser_context, host->browser_context()); | 33 EXPECT_EQ(browser_context, host->browser_context()); |
34 EXPECT_EQ(VIEW_TYPE_EXTENSION_POPUP, host->extension_host_type()); | 34 EXPECT_EQ(VIEW_TYPE_EXTENSION_POPUP, host->extension_host_type()); |
35 EXPECT_TRUE(host->view()); | 35 EXPECT_TRUE(host->view()); |
36 } | 36 } |
37 | 37 |
38 { | 38 { |
39 // Dialog hosts are created with the correct type and profile. | 39 // Dialog hosts are created with the correct type and profile. |
40 scoped_ptr<ExtensionViewHost> host( | 40 std::unique_ptr<ExtensionViewHost> host( |
41 ExtensionViewHostFactory::CreateDialogHost(extension->url(), | 41 ExtensionViewHostFactory::CreateDialogHost(extension->url(), |
42 browser()->profile())); | 42 browser()->profile())); |
43 EXPECT_EQ(extension.get(), host->extension()); | 43 EXPECT_EQ(extension.get(), host->extension()); |
44 EXPECT_EQ(browser_context, host->browser_context()); | 44 EXPECT_EQ(browser_context, host->browser_context()); |
45 EXPECT_EQ(VIEW_TYPE_EXTENSION_DIALOG, host->extension_host_type()); | 45 EXPECT_EQ(VIEW_TYPE_EXTENSION_DIALOG, host->extension_host_type()); |
46 EXPECT_TRUE(host->view()); | 46 EXPECT_TRUE(host->view()); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 // Tests that extensions loaded in incognito mode have the correct profiles | 50 // Tests that extensions loaded in incognito mode have the correct profiles |
51 // for split-mode and non-split-mode. | 51 // for split-mode and non-split-mode. |
52 // Crashing intermittently on multiple platforms. http://crbug.com/316334 | 52 // Crashing intermittently on multiple platforms. http://crbug.com/316334 |
53 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest, | 53 IN_PROC_BROWSER_TEST_F(ExtensionViewHostFactoryTest, |
54 DISABLED_IncognitoExtensionHosts) { | 54 DISABLED_IncognitoExtensionHosts) { |
55 // Open an incognito browser. | 55 // Open an incognito browser. |
56 Browser* incognito_browser = | 56 Browser* incognito_browser = |
57 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 57 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
58 | 58 |
59 // Load a non-split-mode extension, enabled in incognito. | 59 // Load a non-split-mode extension, enabled in incognito. |
60 scoped_refptr<const Extension> regular_extension = | 60 scoped_refptr<const Extension> regular_extension = |
61 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") | 61 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") |
62 .AppendASCII("browser_action") | 62 .AppendASCII("browser_action") |
63 .AppendASCII("none")); | 63 .AppendASCII("none")); |
64 ASSERT_TRUE(regular_extension.get()); | 64 ASSERT_TRUE(regular_extension.get()); |
65 | 65 |
66 // The ExtensionHost for a regular extension in an incognito window is | 66 // The ExtensionHost for a regular extension in an incognito window is |
67 // associated with the original window's profile. | 67 // associated with the original window's profile. |
68 scoped_ptr<ExtensionHost> regular_host( | 68 std::unique_ptr<ExtensionHost> regular_host( |
69 ExtensionViewHostFactory::CreatePopupHost( | 69 ExtensionViewHostFactory::CreatePopupHost(regular_extension->url(), |
70 regular_extension->url(), incognito_browser)); | 70 incognito_browser)); |
71 content::BrowserContext* browser_context = browser()->profile(); | 71 content::BrowserContext* browser_context = browser()->profile(); |
72 EXPECT_EQ(browser_context, regular_host->browser_context()); | 72 EXPECT_EQ(browser_context, regular_host->browser_context()); |
73 | 73 |
74 // Load a split-mode incognito extension. | 74 // Load a split-mode incognito extension. |
75 scoped_refptr<const Extension> split_mode_extension = | 75 scoped_refptr<const Extension> split_mode_extension = |
76 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") | 76 LoadExtensionIncognito(test_data_dir_.AppendASCII("api_test") |
77 .AppendASCII("browser_action") | 77 .AppendASCII("browser_action") |
78 .AppendASCII("split_mode")); | 78 .AppendASCII("split_mode")); |
79 ASSERT_TRUE(split_mode_extension.get()); | 79 ASSERT_TRUE(split_mode_extension.get()); |
80 | 80 |
81 // The ExtensionHost for a split-mode extension is associated with the | 81 // The ExtensionHost for a split-mode extension is associated with the |
82 // incognito profile. | 82 // incognito profile. |
83 scoped_ptr<ExtensionHost> split_mode_host( | 83 std::unique_ptr<ExtensionHost> split_mode_host( |
84 ExtensionViewHostFactory::CreatePopupHost( | 84 ExtensionViewHostFactory::CreatePopupHost(split_mode_extension->url(), |
85 split_mode_extension->url(), incognito_browser)); | 85 incognito_browser)); |
86 content::BrowserContext* incognito_context = incognito_browser->profile(); | 86 content::BrowserContext* incognito_context = incognito_browser->profile(); |
87 EXPECT_EQ(incognito_context, split_mode_host->browser_context()); | 87 EXPECT_EQ(incognito_context, split_mode_host->browser_context()); |
88 } | 88 } |
89 | 89 |
90 } // namespace extensions | 90 } // namespace extensions |
OLD | NEW |