OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 #include "chrome/browser/extensions/extension_browsertest.h" | 6 #include "chrome/browser/extensions/extension_browsertest.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
18 | 19 |
19 using content::NavigationController; | 20 using content::NavigationController; |
20 using content::WebContents; | 21 using content::WebContents; |
(...skipping 10 matching lines...) Expand all Loading... |
31 // unload an extension that contains a plugin. | 32 // unload an extension that contains a plugin. |
32 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) { | 33 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) { |
33 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, | 34 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, |
34 true); | 35 true); |
35 | 36 |
36 FilePath extension_dir = | 37 FilePath extension_dir = |
37 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins"); | 38 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins"); |
38 | 39 |
39 ui_test_utils::NavigateToURL(browser(), | 40 ui_test_utils::NavigateToURL(browser(), |
40 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); | 41 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); |
41 WebContents* tab = browser()->GetActiveWebContents(); | 42 WebContents* tab = chrome::GetActiveWebContents(browser()); |
42 | 43 |
43 // With no extensions, the plugin should not be loaded. | 44 // With no extensions, the plugin should not be loaded. |
44 bool result = false; | 45 bool result = false; |
45 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 46 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
46 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); | 47 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); |
47 EXPECT_FALSE(result); | 48 EXPECT_FALSE(result); |
48 | 49 |
49 ExtensionService* service = browser()->profile()->GetExtensionService(); | 50 ExtensionService* service = browser()->profile()->GetExtensionService(); |
50 service->set_show_extensions_prompts(false); | 51 service->set_show_extensions_prompts(false); |
51 const size_t size_before = service->extensions()->size(); | 52 const size_t size_before = service->extensions()->size(); |
(...skipping 21 matching lines...) Expand all Loading... |
73 EXPECT_FALSE(result); | 74 EXPECT_FALSE(result); |
74 | 75 |
75 // If we reload the extension and page, it should work again. | 76 // If we reload the extension and page, it should work again. |
76 | 77 |
77 ASSERT_TRUE(LoadExtension(extension_dir)); | 78 ASSERT_TRUE(LoadExtension(extension_dir)); |
78 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 79 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
79 { | 80 { |
80 ui_test_utils::WindowedNotificationObserver observer( | 81 ui_test_utils::WindowedNotificationObserver observer( |
81 content::NOTIFICATION_LOAD_STOP, | 82 content::NOTIFICATION_LOAD_STOP, |
82 content::Source<NavigationController>( | 83 content::Source<NavigationController>( |
83 &browser()->GetActiveWebContents()->GetController())); | 84 &chrome::GetActiveWebContents(browser())->GetController())); |
84 chrome::Reload(browser(), CURRENT_TAB); | 85 chrome::Reload(browser(), CURRENT_TAB); |
85 observer.Wait(); | 86 observer.Wait(); |
86 } | 87 } |
87 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 88 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
88 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); | 89 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); |
89 // We don't allow extension plugins to run on ChromeOS. | 90 // We don't allow extension plugins to run on ChromeOS. |
90 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
91 EXPECT_FALSE(result); | 92 EXPECT_FALSE(result); |
92 #else | 93 #else |
93 EXPECT_TRUE(result); | 94 EXPECT_TRUE(result); |
(...skipping 11 matching lines...) Expand all Loading... |
105 ExtensionService* service = browser()->profile()->GetExtensionService(); | 106 ExtensionService* service = browser()->profile()->GetExtensionService(); |
106 service->set_show_extensions_prompts(false); | 107 service->set_show_extensions_prompts(false); |
107 const size_t size_before = service->extensions()->size(); | 108 const size_t size_before = service->extensions()->size(); |
108 const Extension* extension = LoadExtension(extension_dir); | 109 const Extension* extension = LoadExtension(extension_dir); |
109 ASSERT_TRUE(extension); | 110 ASSERT_TRUE(extension); |
110 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 111 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
111 | 112 |
112 // Load the test page through the extension URL, and the plugin should work. | 113 // Load the test page through the extension URL, and the plugin should work. |
113 ui_test_utils::NavigateToURL(browser(), | 114 ui_test_utils::NavigateToURL(browser(), |
114 extension->GetResourceURL("test.html")); | 115 extension->GetResourceURL("test.html")); |
115 WebContents* tab = browser()->GetActiveWebContents(); | 116 WebContents* tab = chrome::GetActiveWebContents(browser()); |
116 bool result = false; | 117 bool result = false; |
117 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 118 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
118 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); | 119 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); |
119 // We don't allow extension plugins to run on ChromeOS. | 120 // We don't allow extension plugins to run on ChromeOS. |
120 #if defined(OS_CHROMEOS) | 121 #if defined(OS_CHROMEOS) |
121 EXPECT_FALSE(result); | 122 EXPECT_FALSE(result); |
122 #else | 123 #else |
123 // TODO(bauerb): This might wrongly fail if the plug-in takes too long | 124 // TODO(bauerb): This might wrongly fail if the plug-in takes too long |
124 // to load. Extension-private plug-ins don't appear in navigator.plugins, so | 125 // to load. Extension-private plug-ins don't appear in navigator.plugins, so |
125 // we can't check for the plug-in in Javascript. | 126 // we can't check for the plug-in in Javascript. |
(...skipping 13 matching lines...) Expand all Loading... |
139 EXPECT_TRUE(result); | 140 EXPECT_TRUE(result); |
140 #endif | 141 #endif |
141 | 142 |
142 // Now load it through a file URL. The plugin should not load. | 143 // Now load it through a file URL. The plugin should not load. |
143 ui_test_utils::NavigateToURL(browser(), | 144 ui_test_utils::NavigateToURL(browser(), |
144 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); | 145 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); |
145 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 146 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
146 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); | 147 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); |
147 EXPECT_FALSE(result); | 148 EXPECT_FALSE(result); |
148 } | 149 } |
OLD | NEW |