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

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

Issue 11728003: Change ExecuteJavaScript* helper functions in browser_test_utils.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding files for gpu_tests and NaCl browser tests. Created 7 years, 11 months 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
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/extensions/extension_system.h" 8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 30 matching lines...) Expand all
41 FilePath extension_dir = 41 FilePath extension_dir =
42 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins"); 42 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins");
43 43
44 ui_test_utils::NavigateToURL(browser(), 44 ui_test_utils::NavigateToURL(browser(),
45 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); 45 net::FilePathToFileURL(extension_dir.AppendASCII("test.html")));
46 WebContents* tab = chrome::GetActiveWebContents(browser()); 46 WebContents* tab = chrome::GetActiveWebContents(browser());
47 47
48 // With no extensions, the plugin should not be loaded. 48 // With no extensions, the plugin should not be loaded.
49 bool result = false; 49 bool result = false;
50 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 50 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
51 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 51 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
52 EXPECT_FALSE(result); 52 EXPECT_FALSE(result);
53 53
54 ExtensionService* service = extensions::ExtensionSystem::Get( 54 ExtensionService* service = extensions::ExtensionSystem::Get(
55 browser()->profile())->extension_service(); 55 browser()->profile())->extension_service();
56 service->set_show_extensions_prompts(false); 56 service->set_show_extensions_prompts(false);
57 const size_t size_before = service->extensions()->size(); 57 const size_t size_before = service->extensions()->size();
58 const Extension* extension = LoadExtension(extension_dir); 58 const Extension* extension = LoadExtension(extension_dir);
59 ASSERT_TRUE(extension); 59 ASSERT_TRUE(extension);
60 EXPECT_EQ(size_before + 1, service->extensions()->size()); 60 EXPECT_EQ(size_before + 1, service->extensions()->size());
61 // Now the plugin should be in the cache. 61 // Now the plugin should be in the cache.
62 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 62 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
63 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 63 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
64 // We don't allow extension plugins to run on ChromeOS. 64 // We don't allow extension plugins to run on ChromeOS.
65 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
66 EXPECT_FALSE(result); 66 EXPECT_FALSE(result);
67 #else 67 #else
68 EXPECT_TRUE(result); 68 EXPECT_TRUE(result);
69 #endif 69 #endif
70 70
71 EXPECT_EQ(size_before + 1, service->extensions()->size()); 71 EXPECT_EQ(size_before + 1, service->extensions()->size());
72 UnloadExtension(extension->id()); 72 UnloadExtension(extension->id());
73 EXPECT_EQ(size_before, service->extensions()->size()); 73 EXPECT_EQ(size_before, service->extensions()->size());
74 74
75 // Now the plugin should be unloaded, and the page should be broken. 75 // Now the plugin should be unloaded, and the page should be broken.
76 76
77 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 77 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
78 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 78 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
79 EXPECT_FALSE(result); 79 EXPECT_FALSE(result);
80 80
81 // If we reload the extension and page, it should work again. 81 // If we reload the extension and page, it should work again.
82 82
83 ASSERT_TRUE(LoadExtension(extension_dir)); 83 ASSERT_TRUE(LoadExtension(extension_dir));
84 EXPECT_EQ(size_before + 1, service->extensions()->size()); 84 EXPECT_EQ(size_before + 1, service->extensions()->size());
85 { 85 {
86 content::WindowedNotificationObserver observer( 86 content::WindowedNotificationObserver observer(
87 content::NOTIFICATION_LOAD_STOP, 87 content::NOTIFICATION_LOAD_STOP,
88 content::Source<NavigationController>( 88 content::Source<NavigationController>(
89 &chrome::GetActiveWebContents(browser())->GetController())); 89 &chrome::GetActiveWebContents(browser())->GetController()));
90 chrome::Reload(browser(), CURRENT_TAB); 90 chrome::Reload(browser(), CURRENT_TAB);
91 observer.Wait(); 91 observer.Wait();
92 } 92 }
93 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 93 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
94 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 94 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
95 // We don't allow extension plugins to run on ChromeOS. 95 // We don't allow extension plugins to run on ChromeOS.
96 #if defined(OS_CHROMEOS) 96 #if defined(OS_CHROMEOS)
97 EXPECT_FALSE(result); 97 EXPECT_FALSE(result);
98 #else 98 #else
99 EXPECT_TRUE(result); 99 EXPECT_TRUE(result);
100 #endif 100 #endif
101 } 101 }
102 102
103 // Tests that private extension plugins are only visible to the extension. 103 // Tests that private extension plugins are only visible to the extension.
104 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PluginPrivate) { 104 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PluginPrivate) {
(...skipping 13 matching lines...) Expand all
118 const Extension* extension = LoadExtension(extension_dir); 118 const Extension* extension = LoadExtension(extension_dir);
119 ASSERT_TRUE(extension); 119 ASSERT_TRUE(extension);
120 EXPECT_EQ(size_before + 1, service->extensions()->size()); 120 EXPECT_EQ(size_before + 1, service->extensions()->size());
121 121
122 // Load the test page through the extension URL, and the plugin should work. 122 // Load the test page through the extension URL, and the plugin should work.
123 ui_test_utils::NavigateToURL(browser(), 123 ui_test_utils::NavigateToURL(browser(),
124 extension->GetResourceURL("test.html")); 124 extension->GetResourceURL("test.html"));
125 WebContents* tab = chrome::GetActiveWebContents(browser()); 125 WebContents* tab = chrome::GetActiveWebContents(browser());
126 bool result = false; 126 bool result = false;
127 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 127 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
128 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 128 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
129 // We don't allow extension plugins to run on ChromeOS. 129 // We don't allow extension plugins to run on ChromeOS.
130 #if defined(OS_CHROMEOS) 130 #if defined(OS_CHROMEOS)
131 EXPECT_FALSE(result); 131 EXPECT_FALSE(result);
132 #else 132 #else
133 // TODO(bauerb): This might wrongly fail if the plug-in takes too long 133 // TODO(bauerb): This might wrongly fail if the plug-in takes too long
134 // to load. Extension-private plug-ins don't appear in navigator.plugins, so 134 // to load. Extension-private plug-ins don't appear in navigator.plugins, so
135 // we can't check for the plug-in in Javascript. 135 // we can't check for the plug-in in Javascript.
136 EXPECT_TRUE(result); 136 EXPECT_TRUE(result);
137 #endif 137 #endif
138 138
139 // Regression test for http://crbug.com/131811: The plug-in should be 139 // Regression test for http://crbug.com/131811: The plug-in should be
140 // whitelisted for the extension (and only for the extension), so it should be 140 // whitelisted for the extension (and only for the extension), so it should be
141 // loaded even if content settings are set to block plug-ins. 141 // loaded even if content settings are set to block plug-ins.
142 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 142 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
143 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 143 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
144 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 144 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
145 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 145 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
146 // We don't allow extension plugins to run on ChromeOS. 146 // We don't allow extension plugins to run on ChromeOS.
147 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
148 EXPECT_FALSE(result); 148 EXPECT_FALSE(result);
149 #else 149 #else
150 EXPECT_TRUE(result); 150 EXPECT_TRUE(result);
151 #endif 151 #endif
152 152
153 // Now load it through a file URL. The plugin should not load. 153 // Now load it through a file URL. The plugin should not load.
154 ui_test_utils::NavigateToURL(browser(), 154 ui_test_utils::NavigateToURL(browser(),
155 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); 155 net::FilePathToFileURL(extension_dir.AppendASCII("test.html")));
156 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 156 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
157 tab->GetRenderViewHost(), L"", L"testPluginWorks()", &result)); 157 tab->GetRenderViewHost(), "", "testPluginWorks()", &result));
158 EXPECT_FALSE(result); 158 EXPECT_FALSE(result);
159 } 159 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/options_page_apitest.cc ('k') | chrome/browser/extensions/subscribe_page_action_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698